diff options
author | pwielebs <piotr.wielebski@nokia.com> | 2020-06-10 11:02:19 +0200 |
---|---|---|
committer | pwielebs <piotr.wielebski@nokia.com> | 2020-06-17 14:48:28 +0200 |
commit | 8464ed158369bbb5b047a63ddea3b483f6a79454 (patch) | |
tree | d03253929821e53127fd691b6bbccf51b8d9f956 /certServiceClient/src/main | |
parent | fc666727897c9f78fdcddbf4b678e1c0b0c413a9 (diff) |
Add validation for OUTPUT_TYPE parameter
Issue-ID: AAF-1152
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Change-Id: Iec46b8a7b8e1818b62877f5272368636dc1929a0
Diffstat (limited to 'certServiceClient/src/main')
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()); |