aboutsummaryrefslogtreecommitdiffstats
path: root/trustStoreMerger/src/main/java
diff options
context:
space:
mode:
authorRemigiusz Janeczek <remigiusz.janeczek@nokia.com>2020-08-05 11:36:06 +0200
committerRemigiusz Janeczek <remigiusz.janeczek@nokia.com>2020-08-05 13:53:07 +0200
commit4e61effd4ddd8e6869487914095f81a1566d0142 (patch)
treefeca1a785f14f118c5b406349faf79c7ff33f91f /trustStoreMerger/src/main/java
parent86ba43b6e0d298c469ee93ecfc08052d6e8ab8c9 (diff)
Add loading configuration from env to truststore merger
Issue-ID: DCAEGEN2-2253 Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com> Change-Id: I06b3e3fcebbca96a4b9cbb4c693ae16eb29366eb
Diffstat (limited to 'trustStoreMerger/src/main/java')
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java24
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java4
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/EnvProvider.java29
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PathValidator.java38
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProvider.java69
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProviderException.java30
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfiguration.java44
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationException.java30
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java45
9 files changed, 311 insertions, 2 deletions
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java
index f280800b..ee57b3aa 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java
@@ -20,6 +20,13 @@
package org.onap.oom.truststoremerger;
import org.onap.oom.truststoremerger.api.ExitStatus;
+import org.onap.oom.truststoremerger.api.ExitableException;
+import org.onap.oom.truststoremerger.certification.file.EnvProvider;
+import org.onap.oom.truststoremerger.certification.file.TruststoresPathsProvider;
+import org.onap.oom.truststoremerger.configuration.MergerConfiguration;
+import org.onap.oom.truststoremerger.configuration.MergerConfigurationException;
+import org.onap.oom.truststoremerger.configuration.MergerConfigurationFactory;
+import org.onap.oom.truststoremerger.certification.file.PathValidator;
class TrustStoreMerger {
@@ -30,6 +37,21 @@ class TrustStoreMerger {
}
void run() {
- appExitHandler.exit(ExitStatus.SUCCESS);
+ try {
+ mergeTruststores();
+ appExitHandler.exit(ExitStatus.SUCCESS);
+ } catch (ExitableException e) {
+ appExitHandler.exit(e.applicationExitStatus());
+ }
+ }
+
+ private void mergeTruststores() throws ExitableException {
+ MergerConfiguration configuration = loadConfiguration();
+ }
+
+ private MergerConfiguration loadConfiguration() throws ExitableException {
+ TruststoresPathsProvider truststoresPathsProvider = new TruststoresPathsProvider(new EnvProvider(), new PathValidator());
+ MergerConfigurationFactory factory = new MergerConfigurationFactory(truststoresPathsProvider);
+ return factory.createConfiguration();
}
}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
index 84184e89..ae145f7e 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
@@ -21,7 +21,9 @@ package org.onap.oom.truststoremerger.api;
public enum ExitStatus {
- SUCCESS(0, "Success");
+ SUCCESS(0, "Success"),
+ TRUSTSTORES_PATHS_PROVIDER_EXCEPTION(1, "Invalid paths in environment variables"),
+ MERGER_CONFIGURATION_EXCEPTION(2, "Invalid merger configuration");
private final int value;
private final String message;
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/EnvProvider.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/EnvProvider.java
new file mode 100644
index 00000000..f64edc89
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/EnvProvider.java
@@ -0,0 +1,29 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import java.util.Optional;
+
+public class EnvProvider {
+
+ Optional<String> getEnv(String name) {
+ return Optional.ofNullable(System.getenv(name));
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PathValidator.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PathValidator.java
new file mode 100644
index 00000000..05b80f14
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PathValidator.java
@@ -0,0 +1,38 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+public class PathValidator {
+
+ private static final String TRUSTSTORE_PATH_REGEX = "^(/[a-zA-Z0-9_-]+)+\\.(pem|jks|p12)";
+ private static final String TRUSTSTORE_PASSWORD_PATH_REGEX = "^(/[a-zA-Z0-9_-]+)+\\.pass";
+
+ public boolean isTruststorePathValid(String truststorePath) {
+ return isPathValid(truststorePath, TRUSTSTORE_PATH_REGEX);
+ }
+
+ public boolean isTruststorePasswordPathValid(String truststorePasswordPath) {
+ return truststorePasswordPath.isEmpty() || isPathValid(truststorePasswordPath, TRUSTSTORE_PASSWORD_PATH_REGEX);
+ }
+
+ private boolean isPathValid(String path, String regex) {
+ return path.matches(regex);
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProvider.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProvider.java
new file mode 100644
index 00000000..b7b73e6b
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProvider.java
@@ -0,0 +1,69 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class TruststoresPathsProvider {
+
+ static final String TRUSTSTORES_ENV = "TRUSTSTORES";
+ static final String TRUSTSTORES_PASSWORDS_ENV = "TRUSTSTORES_PASSWORDS";
+ private static final String DELIMITER = ":";
+ private static final int NEGATIVE_SPLIT_LIMIT = -1;
+
+ private EnvProvider envProvider;
+ private PathValidator pathValidator;
+
+ public TruststoresPathsProvider(EnvProvider envProvider, PathValidator pathValidator) {
+ this.envProvider = envProvider;
+ this.pathValidator = pathValidator;
+ }
+
+ public List<String> getTruststores() throws TruststoresPathsProviderException {
+ return envProvider.getEnv(TRUSTSTORES_ENV)
+ .filter(Predicate.not(String::isEmpty))
+ .map(this::splitToList)
+ .filter(this::validateTruststores)
+ .orElseThrow(() -> new TruststoresPathsProviderException("TRUSTSTORES environment variable does not contain valid truststores paths"));
+ }
+
+ public List<String> getTruststoresPasswords() throws TruststoresPathsProviderException {
+ return envProvider.getEnv(TRUSTSTORES_PASSWORDS_ENV)
+ .map(this::splitToList)
+ .filter(this::validateTruststoresPasswords)
+ .orElseThrow(() -> new TruststoresPathsProviderException("TRUSTSTORES_PASSWORDS environment variable does not contain valid passwords paths"));
+ }
+
+ private boolean validateTruststores(List<String> truststores) {
+ return truststores.stream()
+ .allMatch(pathValidator::isTruststorePathValid);
+ }
+
+ private boolean validateTruststoresPasswords(List<String> truststoresPasswords) {
+ return truststoresPasswords.stream()
+ .allMatch(pathValidator::isTruststorePasswordPathValid);
+ }
+
+ private List<String> splitToList(String stringToSplit) {
+ return Arrays.asList(stringToSplit.split(DELIMITER, NEGATIVE_SPLIT_LIMIT));
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProviderException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProviderException.java
new file mode 100644
index 00000000..5f491c36
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProviderException.java
@@ -0,0 +1,30 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import org.onap.oom.truststoremerger.api.ExitStatus;
+import org.onap.oom.truststoremerger.api.ExitableException;
+
+public class TruststoresPathsProviderException extends ExitableException {
+
+ TruststoresPathsProviderException(String message) {
+ super(message, ExitStatus.TRUSTSTORES_PATHS_PROVIDER_EXCEPTION);
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfiguration.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfiguration.java
new file mode 100644
index 00000000..f3b7d935
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfiguration.java
@@ -0,0 +1,44 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.configuration;
+
+import java.util.Collections;
+import java.util.List;
+
+public class MergerConfiguration {
+ private final List<String> truststoreFilePaths;
+ private final List<String> truststoreFilePasswordPaths;
+
+ public MergerConfiguration(List<String> truststoreFilePaths,
+ List<String> truststoreFilePasswordPaths) {
+ this.truststoreFilePaths = List.copyOf(truststoreFilePaths);
+ this.truststoreFilePasswordPaths = List.copyOf(truststoreFilePasswordPaths);
+ }
+
+ public List<String> getTruststoreFilePaths() {
+ return Collections.unmodifiableList(truststoreFilePaths);
+ }
+
+
+ public List<String> getTruststoreFilePasswordPaths() {
+ return Collections.unmodifiableList(truststoreFilePasswordPaths);
+ }
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationException.java
new file mode 100644
index 00000000..54982f5f
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationException.java
@@ -0,0 +1,30 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.configuration;
+
+import org.onap.oom.truststoremerger.api.ExitStatus;
+import org.onap.oom.truststoremerger.api.ExitableException;
+
+public class MergerConfigurationException extends ExitableException {
+
+ MergerConfigurationException(String message) {
+ super(message, ExitStatus.MERGER_CONFIGURATION_EXCEPTION);
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java
new file mode 100644
index 00000000..eea0551d
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java
@@ -0,0 +1,45 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.configuration;
+
+import org.onap.oom.truststoremerger.certification.file.TruststoresPathsProvider;
+import org.onap.oom.truststoremerger.certification.file.TruststoresPathsProviderException;
+
+import java.util.List;
+
+public class MergerConfigurationFactory {
+
+ private final TruststoresPathsProvider pathsProvider;
+
+ public MergerConfigurationFactory(TruststoresPathsProvider pathsProvider) {
+ this.pathsProvider = pathsProvider;
+ }
+
+ public MergerConfiguration createConfiguration() throws MergerConfigurationException, TruststoresPathsProviderException {
+ List<String> truststores = pathsProvider.getTruststores();
+ List<String> truststoresPasswords = pathsProvider.getTruststoresPasswords();
+
+ if (truststores.size() != truststoresPasswords.size()) {
+ throw new MergerConfigurationException("Size of TRUSTSTORES does not match size of TRUSTSTORES_PASSWORDS environment variables");
+ }
+
+ return new MergerConfiguration(truststores, truststoresPasswords);
+ }
+}