aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgarwal, Ruchira (ra1926) <ra1926@att.com>2019-07-22 20:26:50 +0000
committerAgarwal, Ruchira (ra1926) <ra1926@att.com>2019-07-23 14:55:23 +0000
commit57bfbb05e485fb11b620b1bf12e70aa063aaa3c8 (patch)
tree434a13e13cf45004a91f309e86c76038cf1d27af
parent1201ff98e4c7856b03b268302e4aed2cdc6e1dbb (diff)
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
-rwxr-xr-xproperties-node/provider/pom.xml24
-rw-r--r--properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java27
-rw-r--r--properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java9
-rw-r--r--properties-node/provider/src/test/resources/test.txt3
-rwxr-xr-xrestapi-call-node/provider/pom.xml24
-rwxr-xr-xrestapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java21
-rwxr-xr-xrestapi-call-node/provider/src/test/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java64
-rwxr-xr-xrestapi-call-node/provider/src/test/resources/partners.json6
-rw-r--r--restapi-call-node/provider/src/test/resources/ueb.properties6
9 files changed, 138 insertions, 46 deletions
diff --git a/properties-node/provider/pom.xml b/properties-node/provider/pom.xml
index da88c07f..46c0dbac 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 f0c7e0b4..b4bc8474 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 @@ public class PropertiesNode implements SvcLogicJavaPlugin {
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 @@ public class PropertiesNode implements SvcLogicJavaPlugin {
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 @@ public class PropertiesNode implements SvcLogicJavaPlugin {
}
}
+ /* 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 f1e0ab62..a858c49b 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.HashSet;
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 @@ import org.slf4j.LoggerFactory;
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 @@ public class TestPropertiesNode {
@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 @@ public class TestPropertiesNode {
"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 79e8acff..68b916cb 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.contracted-port-speed-units = Kbps
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}
diff --git a/restapi-call-node/provider/pom.xml b/restapi-call-node/provider/pom.xml
index 8c51f997..0373d178 100755
--- a/restapi-call-node/provider/pom.xml
+++ b/restapi-call-node/provider/pom.xml
@@ -16,15 +16,15 @@
<name>ccsdk-sli-plugins :: restapi-call-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>
@@ -73,6 +73,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.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<scope>test</scope>
diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java
index 220e18fd..c539010f 100755
--- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java
+++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java
@@ -141,7 +141,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
}
String userName = partnerObject.getString(partnerUserKey);
String password = partnerObject.getString(partnerPasswordKey);
- PartnerDetails details = new PartnerDetails(userName, password, url);
+ PartnerDetails details = new PartnerDetails(userName, getObfuscatedVal(password), url);
partnerStore.put(partnerKey, details);
log.info("mapped partner using partner key " + partnerKey);
} else {
@@ -153,6 +153,25 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
}
}
+ /* 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;
+ }
+
/**
* Returns parameters from the parameter map.
*
diff --git a/restapi-call-node/provider/src/test/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java
index 50371278..a130d439 100755
--- a/restapi-call-node/provider/src/test/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java
+++ b/restapi-call-node/provider/src/test/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.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.
@@ -27,7 +27,9 @@ import static org.junit.Assert.assertNull;
import java.util.HashMap;
import java.util.Map;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
@@ -38,6 +40,9 @@ public class TestRestapiCallNode {
@SuppressWarnings("unused")
private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
+ @Rule
+ public EnvironmentVariables environmentVariables = new EnvironmentVariables();
+
@Test
@@ -459,11 +464,15 @@ public class TestRestapiCallNode {
*/
@Test
public void testPartners() throws Exception{
- String partnerTwoKey = "partnerTwo";
- String partnerTwoUsername = "controller_user";
- String partnerTwoPassword = "P@ssword";
- System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
+ environmentVariables.set("deployer_pass", "sdncp-123");
+ assertEquals("sdncp-123", System.getenv("deployer_pass"));
+
+ String partnerTwoKey = "partnerTwo";
+ String partnerTwoUsername = "controller_user";
+ String partnerTwoPassword = "P@ssword";
+
+ System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
RestapiCallNode rcn = new RestapiCallNode();
assertNull(rcn.partnerStore.get("partnerOne"));
PartnerDetails details = rcn.partnerStore.get(partnerTwoKey);
@@ -474,7 +483,7 @@ public class TestRestapiCallNode {
//In this scenario the caller expects username, password and url to be picked up from the partners json
Map<String, String> paramMap = new HashMap<String,String>();
paramMap.put("partner", partnerTwoKey);
- rcn.handlePartner(paramMap );
+ rcn.handlePartner(paramMap );
assertEquals(partnerTwoUsername,paramMap.get(rcn.restapiUserKey));
assertEquals(partnerTwoPassword,paramMap.get(rcn.restapiPasswordKey));
assertEquals("http://localhost:7002",paramMap.get(rcn.restapiUrlString));
@@ -484,28 +493,39 @@ public class TestRestapiCallNode {
paramMap = new HashMap<String,String>();
paramMap.put("partner", partnerTwoKey);
paramMap.put("restapiUrlSuffix", "/networking/v1/instance/3");
- rcn.handlePartner(paramMap);
- Parameters p = new Parameters();
- RestapiCallNode.getParameters(paramMap, p);
+ rcn.handlePartner(paramMap);
+ p = new Parameters();
+ RestapiCallNode.getParameters(paramMap, p);
assertEquals(partnerTwoUsername,p.restapiUser);
assertEquals(partnerTwoPassword,p.restapiPassword);
assertEquals("http://localhost:7002/networking/v1/instance/3",p.restapiUrl);
+
+ paramMap = new HashMap<String, String>();
+ paramMap.put("partner","partnerFour" );
+ paramMap.put("httpMethod", "delete");
+ paramMap.put("skipSending", "true");
+ rcn.handlePartner(paramMap);
+ Parameters p = new Parameters();
+ RestapiCallNode.getParameters(paramMap, p);
+ assertEquals(p.restapiPassword, "sdncp-123");
+ assertEquals(p.restapiUser, "m30402@sdncp.att.com");
+ assertEquals(p.restapiUrl, "http://localhost:7004");
}
@Test
public void retryPolicyBean() throws Exception {
- Integer retries = 3;
- String first = "http://localhost:7001";
- String second = "http://localhost:7001";
-
- RetryPolicy p = new RetryPolicy(new String[] {first,second}, retries);
- assertEquals(retries,p.getMaximumRetries());
- assertNotNull(p.getRetryMessage());
- String next = p.getNextHostName();
- assertEquals(second,next);
- assertEquals(1,p.getRetryCount());
- next = p.getNextHostName();
- assertEquals(first,next);
- assertEquals(2,p.getRetryCount());
+ Integer retries = 3;
+ String first = "http://localhost:7001";
+ String second = "http://localhost:7001";
+
+ RetryPolicy p = new RetryPolicy(new String[] {first,second}, retries);
+ assertEquals(retries,p.getMaximumRetries());
+ assertNotNull(p.getRetryMessage());
+ String next = p.getNextHostName();
+ assertEquals(second,next);
+ assertEquals(1,p.getRetryCount());
+ next = p.getNextHostName();
+ assertEquals(first,next);
+ assertEquals(2,p.getRetryCount());
}
}
diff --git a/restapi-call-node/provider/src/test/resources/partners.json b/restapi-call-node/provider/src/test/resources/partners.json
index 9a17a1ac..2562d69c 100755
--- a/restapi-call-node/provider/src/test/resources/partners.json
+++ b/restapi-call-node/provider/src/test/resources/partners.json
@@ -12,5 +12,11 @@
"partnerThree": {
"url": "http://localhost:7003",
"user": "controller_admin"
+ },
+ "partnerFour": {
+ "url": "http://localhost:7004",
+ "user": "m30402@sdncp.att.com",
+ "password": "${deployer_pass}",
+ "test": "/metrics"
}
}
diff --git a/restapi-call-node/provider/src/test/resources/ueb.properties b/restapi-call-node/provider/src/test/resources/ueb.properties
new file mode 100644
index 00000000..96657ee1
--- /dev/null
+++ b/restapi-call-node/provider/src/test/resources/ueb.properties
@@ -0,0 +1,6 @@
+#for other servers see http://sa2020.it.att.com:8888/sw/cambria/installs
+
+#to check connectivity http://hostname:3904/metrics
+
+servers=http://uebsb91kcdc.it.att.com:3904 http://uebsb92kcdc.it.att.com:3904 http://uebsb93kcdc.it.att.com:3904
+