Add support for loading VNF Catalog XML files
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / config / ModelLoaderConfig.java
index 3f03bb5..01505ba 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
@@ -21,6 +21,8 @@
 package org.onap.aai.modelloader.config;
 
 import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
@@ -43,6 +45,9 @@ public class ModelLoaderConfig implements IConfiguration {
     private static final String SUFFIX_KEYSTORE_FILE = "KEYSTORE_FILE";
     private static final String SUFFIX_KEYSTORE_PASS = "KEYSTORE_PASSWORD";
 
+    private static final String SUFFIX_TRUSTSTORE_FILE = "TRUSTSTORE_FILE";
+    private static final String SUFFIX_TRUSTSTORE_PASS = "TRUSTSTORE_PASSWORD";
+
     // Configuration file properties
     protected static final String PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH =
             PREFIX_DISTRIBUTION_CLIENT + "ACTIVE_SERVER_TLS_AUTH";
@@ -80,32 +85,21 @@ public class ModelLoaderConfig implements IConfiguration {
     protected static final String PROP_BABEL_BASE_URL = PREFIX_BABEL + "BASE_URL";
     protected static final String PROP_BABEL_KEYSTORE_FILE = PREFIX_BABEL + SUFFIX_KEYSTORE_FILE;
     protected static final String PROP_BABEL_KEYSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_KEYSTORE_PASS;
+    protected static final String PROP_BABEL_TRUSTSTORE_FILE = PREFIX_BABEL + SUFFIX_TRUSTSTORE_FILE;
+    protected static final String PROP_BABEL_TRUSTSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_TRUSTSTORE_PASS;
     protected static final String PROP_BABEL_GENERATE_RESOURCE_URL = PREFIX_BABEL + "GENERATE_ARTIFACTS_URL";
 
     protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR";
-    private static String configHome;
+    protected static final String FILESEP =
+            (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
 
+    private static String configHome;
     private Properties modelLoaderProperties = null;
-
     private String certLocation = ".";
-
     private List<String> artifactTypes = null;
-
     private List<String> msgBusAddrs = null;
-
     private String modelVersion = null;
 
-    protected static final String FILESEP =
-            (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
-
-    public static void setConfigHome(String configHome) {
-        ModelLoaderConfig.configHome = configHome;
-    }
-
-    public static String propertiesFile() {
-        return configHome + FILESEP + "model-loader.properties";
-    }
-
     public ModelLoaderConfig(Properties configProperties) {
         this(configProperties, ModelLoaderConfig.configHome + FILESEP + "auth" + FILESEP);
     }
@@ -139,11 +133,18 @@ public class ModelLoaderConfig implements IConfiguration {
         }
     }
 
+    public static void setConfigHome(String configHome) {
+        ModelLoaderConfig.configHome = configHome;
+    }
+
+    public static Path propertiesFile() {
+        return Paths.get(configHome, "model-loader.properties");
+    }
 
     @Override
     public boolean activateServerTLSAuth() {
         String value = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH);
-        return value == null ? false : Boolean.parseBoolean(value);
+        return value != null && Boolean.parseBoolean(value);
     }
 
     @Override
@@ -209,7 +210,7 @@ public class ModelLoaderConfig implements IConfiguration {
     @Override
     public Boolean isUseHttpsWithDmaap() {
         String useHTTPS = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP);
-        return useHTTPS == null ? false : Boolean.valueOf(useHTTPS);
+        return useHTTPS != null && Boolean.valueOf(useHTTPS);
     }
 
     @Override
@@ -227,7 +228,7 @@ public class ModelLoaderConfig implements IConfiguration {
             return null;
         } else {
             return certLocation + File.separator + filename;
-        }   
+        }
     }
 
     public String getAaiKeyStorePassword() {
@@ -238,6 +239,19 @@ public class ModelLoaderConfig implements IConfiguration {
         return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_BABEL_KEYSTORE_PASSWORD));
     }
 
+    public String getBabelTrustStorePath() {
+        String filename = modelLoaderProperties.getProperty(PROP_BABEL_TRUSTSTORE_FILE);
+        if (filename == null) {
+            return null;
+        } else {
+            return certLocation + File.separator + filename;
+        }
+    }
+
+    public String getBabelTrustStorePassword() {
+        return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_BABEL_TRUSTSTORE_PASSWORD));
+    }
+
     public String getAaiBaseUrl() {
         return modelLoaderProperties.getProperty(PROP_AAI_BASE_URL);
     }