summaryrefslogtreecommitdiffstats
path: root/certServiceClient/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'certServiceClient/src/main/java')
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java7
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java11
2 files changed, 16 insertions, 2 deletions
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
index b72ef7a1..b7def803 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
@@ -20,6 +20,8 @@
package org.onap.aaf.certservice.client.configuration.factory;
+
+import org.onap.aaf.certservice.client.certification.conversion.ArtifactsCreatorProvider;
import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurationException;
import org.onap.aaf.certservice.client.configuration.exception.CsrConfigurationException;
import org.onap.aaf.certservice.client.configuration.model.ConfigurationModel;
@@ -55,6 +57,11 @@ public abstract class AbstractConfigurationFactory<T extends ConfigurationModel>
return Arrays.asList(Locale.getISOCountries()).contains(country);
}
+ public boolean isOutputTypeValid(String outputType) {
+ return Arrays.stream(ArtifactsCreatorProvider.values())
+ .anyMatch(artifactsCreatorProvider -> artifactsCreatorProvider.toString().equals(outputType));
+ }
+
private boolean isPortNumberPresent(String stringToCheck) {
return Pattern.compile(":[0-9]{1,5}").matcher(stringToCheck).find();
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java
index 793799e2..d813233a 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java
@@ -27,6 +27,8 @@ import org.onap.aaf.certservice.client.configuration.model.ClientConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Optional;
+
public class ClientConfigurationFactory extends AbstractConfigurationFactory<ClientConfiguration> {
private static final Logger LOGGER = LoggerFactory.getLogger(ClientConfigurationFactory.class);
@@ -41,6 +43,8 @@ public class ClientConfigurationFactory extends AbstractConfigurationFactory<Cli
ClientConfiguration configuration = new ClientConfiguration();
+ Optional<String> outputType = envsForClient.getOutputType();
+
envsForClient.getUrlToCertService()
.map(configuration::setUrlToCertService);
@@ -57,8 +61,11 @@ public class ClientConfigurationFactory extends AbstractConfigurationFactory<Cli
.map(configuration::setCaName)
.orElseThrow(() -> new ClientConfigurationException(ClientConfigurationEnvs.CA_NAME + " is invalid."));
- envsForClient.getOutputType()
- .map(configuration::setOutputType);
+ if (outputType.isPresent()) {
+ outputType.filter(this::isOutputTypeValid)
+ .map(configuration::setOutputType)
+ .orElseThrow(() -> new ClientConfigurationException(ClientConfigurationEnvs.OUTPUT_TYPE + " is invalid."));
+ }
LOGGER.info("Successful validation of Client configuration. Configuration data: {}", configuration.toString());