configurable param resolution

support config parameter resolution to k8s secret value

Issue-ID: CCSDK-1502
Signed-off-by: Agarwal, Ruchira (ra1926) <ra1926@att.com>
Change-Id: I8acc98fa3fdd9ba46c617b4d0113086c1e889997
diff --git a/properties-node/provider/pom.xml b/properties-node/provider/pom.xml
index da88c07..46c0dba 100755
--- a/properties-node/provider/pom.xml
+++ b/properties-node/provider/pom.xml
@@ -16,15 +16,15 @@
     <name>ccsdk-sli-plugins :: properties-node :: ${project.artifactId}</name>
 
     <dependencyManagement>
-    	<dependencies>
-    		<dependency>
-    			<groupId>org.onap.ccsdk.sli.core</groupId>
-    			<artifactId>sli-core-artifacts</artifactId>
-    			<version>${ccsdk.sli.core.version}</version>
-    			<type>pom</type>
-    			<scope>import</scope>
-    		</dependency>
-    	</dependencies>
+       <dependencies>
+         <dependency>
+            <groupId>org.onap.ccsdk.sli.core</groupId>
+            <artifactId>sli-core-artifacts</artifactId>
+            <version>${ccsdk.sli.core.version}</version>
+            <type>pom</type>
+            <scope>import</scope>
+          </dependency>
+       </dependencies>
     </dependencyManagement>
 
     <dependencies>
@@ -34,6 +34,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>com.github.stefanbirkner</groupId>
+            <artifactId>system-rules</artifactId>
+            <version>1.19.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
             <scope>test</scope>
diff --git a/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java b/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java
index f0c7e0b..b4bc847 100644
--- a/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java
+++ b/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java
@@ -3,7 +3,7 @@
  * openECOMP : SDN-C
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * 			reserved.
+ * reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -63,14 +63,14 @@
                             String name = (String) key;
                             String value = prop.getProperty(name);
                             if (value != null && value.trim().length() > 0) {
-                                ctx.setAttribute(pfx + name, value.trim());
+                                ctx.setAttribute(pfx + name, getObfuscatedVal(value.trim()));
                                 log.info("+++ " + pfx + name + ": [" + maskPassword(pfx + name, value) + "]");
                             }
                         }
                     }
                     if (mm != null) {
                         for (Map.Entry<String, String> entry : mm.entrySet()) {
-                            ctx.setAttribute(pfx + entry.getKey(), entry.getValue());
+                            ctx.setAttribute(pfx + entry.getKey(), getObfuscatedVal(entry.getValue()));
                             log.info("+++ " + pfx + entry.getKey() + ": ["
                                     + maskPassword(pfx + entry.getKey(), entry.getValue()) + "]");
                         }
@@ -81,7 +81,7 @@
                         String name = (String) key;
                         String value = prop.getProperty(name);
                         if (value != null && value.trim().length() > 0) {
-                            ctx.setAttribute(pfx + name, value.trim());
+                            ctx.setAttribute(pfx + name, getObfuscatedVal(value.trim()));
                             log.info("+++ " + pfx + name + ": [" + maskPassword(pfx + name, value) + "]");
                         }
                     }
@@ -92,6 +92,25 @@
         }
     }
 
+    /* Unobfuscate param value */ 
+    private static String getObfuscatedVal(String paramValue) {
+        String resValue = paramValue;
+        if (paramValue != null && paramValue.startsWith("${") && paramValue.endsWith("}"))
+        {
+                String paramStr = paramValue.substring(2, paramValue.length()-1);
+                if (paramStr  != null && paramStr.length() > 0)
+                {
+                        String val = System.getenv(paramStr);
+                        if (val != null && val.length() > 0)
+                        {
+                             resValue=val;
+                             log.info("Obfuscated value RESET for param value:" + paramValue);
+                        }
+                 }
+        }
+        return resValue;
+    }
+
     /*
      * Getting extension has to do the following "" --> "" "name" --> "" "name.txt" --> "txt"
      * ".htpasswd" --> "" "name.with.many.dots.myext" --> "myext"
diff --git a/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java
index f1e0ab6..a858c49 100644
--- a/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java
+++ b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java
@@ -5,7 +5,9 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.contrib.java.lang.system.EnvironmentVariables;
 import static org.junit.Assert.assertEquals;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
@@ -16,6 +18,8 @@
 public class TestPropertiesNode {
 
     private static final Logger log = LoggerFactory.getLogger(TestPropertiesNode.class);
+    @Rule
+    public EnvironmentVariables environmentVariables = new EnvironmentVariables();
     
     @Test
     public void testJSONFileParsing() throws SvcLogicException {
@@ -129,6 +133,10 @@
 
     @Test
     public void testTXTFileParsing() throws SvcLogicException {
+
+        environmentVariables.set("deployer_pass", "sdncp-123");
+        assertEquals("sdncp-123", System.getenv("deployer_pass"));
+
         SvcLogicContext ctx = new SvcLogicContext();
 
         Map<String, String> p = new HashMap<String, String>();
@@ -147,6 +155,7 @@
                                               "access-information.l1-customer-handoff"),"_1000BASELX");
         assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" +
                                               "access-information.vlan-tag-control"),"_1Q");
+        assertEquals(ctx.getAttribute("test-txt.obfuscated-var"), "sdncp-123");
     }
 
     @Test
diff --git a/properties-node/provider/src/test/resources/test.txt b/properties-node/provider/src/test/resources/test.txt
index 79e8acf..68b916c 100644
--- a/properties-node/provider/src/test/resources/test.txt
+++ b/properties-node/provider/src/test/resources/test.txt
@@ -27,4 +27,5 @@
 service-data.avpn-ip-port-information.endpoint-information.bundle-id = 33
 service-data.avpn-ip-port-information.endpoint-information.interface-string = ae0
 service-data.service-information.service-instance-id = ICORESITE-2751508
-service-data.service-information.service-type = AVPN
\ No newline at end of file
+service-data.service-information.service-type = AVPN
+obfuscated-var=${deployer_pass}