1 /*============LICENSE_START=======================================================
2 * oom-truststore-merger
3 * ================================================================================
4 * Copyright (C) 2020 Nokia. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.onap.oom.truststoremerger.configuration;
22 import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.KEYSTORE_DESTINATION_PATHS_ENV;
23 import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.KEYSTORE_SOURCE_PATHS_ENV;
24 import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV;
25 import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV;
27 import java.util.List;
28 import org.onap.oom.truststoremerger.configuration.exception.MergerConfigurationException;
29 import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
30 import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
31 import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReader;
33 public class AppConfigurationProvider {
35 private final DelimitedPathsReader truststoresPathsReader;
36 private final DelimitedPathsReader truststoresPasswordsPathsReader;
37 private final DelimitedPathsReader copierPathsReader;
39 public AppConfigurationProvider(DelimitedPathsReader truststoresPathsReader,
40 DelimitedPathsReader truststoresPasswordsPathsReader, DelimitedPathsReader copierPathsReader) {
41 this.truststoresPathsReader = truststoresPathsReader;
42 this.truststoresPasswordsPathsReader = truststoresPasswordsPathsReader;
43 this.copierPathsReader = copierPathsReader;
46 public AppConfiguration createConfiguration()
47 throws MergerConfigurationException, TruststoresPathsProviderException {
48 List<String> truststoresPaths = truststoresPathsReader.get(TRUSTSTORES_PATHS_ENV);
49 List<String> truststoresPasswordsPaths = truststoresPasswordsPathsReader.get(TRUSTSTORES_PASSWORDS_PATHS_ENV);
50 List<String> sourceKeystorePaths = copierPathsReader.get(KEYSTORE_SOURCE_PATHS_ENV);
51 List<String> destinationKeystorePaths = copierPathsReader.get(KEYSTORE_DESTINATION_PATHS_ENV);
53 ensureSameSize(truststoresPaths, truststoresPasswordsPaths, TRUSTSTORES_PATHS_ENV,
54 TRUSTSTORES_PASSWORDS_PATHS_ENV);
55 ensureSameSize(sourceKeystorePaths, destinationKeystorePaths, KEYSTORE_SOURCE_PATHS_ENV,
56 KEYSTORE_DESTINATION_PATHS_ENV);
58 return new AppConfiguration(truststoresPaths, truststoresPasswordsPaths, sourceKeystorePaths,
59 destinationKeystorePaths);
62 private void ensureSameSize(List<String> firstList, List<String> secondList, String firstListEnvName,
63 String secondListEnvName)
64 throws MergerConfigurationException {
65 if (firstList.size() != secondList.size()) {
66 throw new MergerConfigurationException(
67 "Size of " + firstListEnvName
68 + " does not match size of " + secondListEnvName + " environment variables");