aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/DbServiceUtil.java17
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java2
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java6
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java139
4 files changed, 64 insertions, 100 deletions
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/DbServiceUtil.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/DbServiceUtil.java
index 25b01544f..caa13d4d9 100644
--- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/DbServiceUtil.java
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/DbServiceUtil.java
@@ -1,5 +1,4 @@
-/*-
- * ============LICENSE_START=======================================================
+/*===============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
@@ -27,6 +26,7 @@ import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.List;
+import java.util.ArrayList;
import java.util.Properties;
import javax.sql.rowset.CachedRowSet;
import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
@@ -52,9 +52,21 @@ public class DbServiceUtil {
String selectQuery = "select " + getselectData + "from " + tableName + " where " + getDataClasue;
return jdbcDataSource.getData(selectQuery, Lists.newArrayList(argList), schema);
+ }
+
+ public static boolean deleteData(String tableName, List<String> argList) throws SQLException {
+ String deleteQuery = "delete from " + tableName;
+ log.info(deleteQuery);
+ return jdbcDataSource.writeData(deleteQuery, Lists.newArrayList(argList), Constants.SCHEMA_SDNCTL);
}
+ public static boolean insertDB(String tableName, List<String> argList, String setClause,String whereClause)
+ throws SQLException {
+ String insertPasswordString = "INSERT INTO " + tableName + " (" + setClause + " ) VALUES (" + whereClause +")";
+ log.info(insertPasswordString + " insert statement " + argList);
+ return jdbcDataSource.writeData(insertPasswordString, Lists.newArrayList(argList), Constants.SCHEMA_SDNCTL);
+ }
public static DBResourceManager initDbLibService() throws IOException {
Properties props = new Properties();
File file = new File("/opt/onap/appc/data/properties/dblib.properties");
@@ -64,3 +76,4 @@ public class DbServiceUtil {
return jdbcDataSource;
}
}
+
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java
index 54d450826..49bc15f97 100644
--- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java
@@ -106,4 +106,4 @@ public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
throw new SvcLogicException(e.getMessage());
}
}
-} \ No newline at end of file
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java
index b1a074720..9a9d49582 100644
--- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java
@@ -62,9 +62,9 @@ public class LoadFromDB {
log.info("Size of Map data:"+mp.size());
- File file = new File(System.getenv("APPC_CONFIG_DIR"));
+ File file = new File(Constants.APPC_CONFIG_DIR );
file.mkdir();
- file = new File(System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties");
+ file = new File(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
if(file.exists())
{
log.info("APPC-MESSAGE:" + " File already Exists");
@@ -81,7 +81,7 @@ public class LoadFromDB {
log.info("Size of Map file:"+mp.size());
PropertiesConfiguration conf = new PropertiesConfiguration(
- System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties");
+ Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
for (Map.Entry<String, String> key : mp.entrySet()) {
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
index 6091e4cf2..f71bee1ec 100644
--- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
@@ -23,9 +23,10 @@
package org.onap.appc.encryptiontool.wrapper;
-import java.util.Iterator;
-import org.apache.commons.configuration.PropertiesConfiguration;
+import java.util.ArrayList;
+import javax.sql.rowset.CachedRowSet;
import org.apache.commons.lang.StringUtils;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,14 +42,13 @@ public class WrapperEncryptionTool {
}
public static void main(String[] args) {
- String vnfType = args[0];
- String protocol = args[1];
- String user = args[2];
- String password = args[3];
- String action = args[4];
- String port = args[5];
- String url = args[6];
-
+ String vnfType = args[0];
+ String protocol = args[1];
+ String user = args[2];
+ String password = args[3];
+ String action = args[4];
+ String port = args[5];
+ String url = args[6];
if (StringUtils.isBlank(user)) {
log.info("ERROR-USER can not be null");
return;
@@ -61,104 +61,55 @@ public class WrapperEncryptionTool {
log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null");
return;
}
-
EncryptionTool et = EncryptionTool.getInstance();
String enPass = et.encrypt(password);
-
- if (StringUtils.isBlank(protocol)) {
- updateProperties(user, vnfType, enPass, action, port, url, protocol);
- }
+ updateProperties(user, vnfType, enPass, action, port, url, protocol);
}
- public static void updateProperties(String user, String vnfType, String password, String action, String port,
- String url, String protocol) {
+ public static void updateProperties(String user, String vnfType, String enPass, String action, String port,
+ String url, String protocol) {
+ DBResourceManager dbResourceManager = null;
+ ArrayList<String> getList = new ArrayList<>();
+ getList.add(vnfType);
+ getList.add(protocol);
+ getList.add(action);
+ String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? ";
+ String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ?,URL = ? ";
+ String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
+ String insertsetClause = " ?,?,?,?,?,?,?";
try {
- log.info("Received Inputs protocol:%s User:%s vnfType:%s action:%surl:%s port:%s ", protocol, user,
- vnfType, action, url, port);
- String property = protocol;
- if (StringUtils.isNotBlank(vnfType)) {
- if (StringUtils.isNotBlank(protocol) && StringUtils.isNotBlank(action)) {
- property = vnfType + "." + protocol + "." + action;
- } else if (StringUtils.isNotBlank(protocol)){
- property = vnfType;
- }
- } else if (StringUtils.isNotBlank(protocol)){
- property = protocol;
+ dbResourceManager = DbServiceUtil.initDbLibService();
+ CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
+ "*", whereClause);
+ int rowCount = 0;
+ if (data.first()) {
+ rowCount++;
+ log.info(rowCount + "rowcount");
}
-
- PropertiesConfiguration conf = new PropertiesConfiguration(
- System.getenv("APPC_CONFIG_DIR") + "/appc_southbound.properties");
-
- if (conf.subset(property) != null) {
-
- Iterator<String> it = conf.subset(property).getKeys();
- if (it.hasNext()) {
- while (it.hasNext()) {
- String key = it.next();
- log.info("key---value pairs");
- log.info(property + "." + key + "------" + conf.getProperty(property + "." + key));
- resolveProperty(user, password, port, url, property, conf, key);
- }
- } else {
- resolvePropertyAction(user, password, port, url, property, conf);
- }
+ getList.clear();
+ getList.add(user);
+ getList.add(enPass);
+ getList.add(port);
+ getList.add(url);
+ getList.add(vnfType);
+ getList.add(protocol);
+ getList.add(action);
+ if (rowCount == 1) {
+ DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
+ log.info("APPC-MESSAGE: Password Updated Successfully");
+ } else {
+ DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
+ log.info("APPC-MESSAGE: password Inserted Successfully");
}
- conf.save();
} catch (Exception e) {
log.debug("Caught Exception", e);
log.info("Caught exception", e);
log.info("APPC-MESSAGE:" + e.getMessage());
+ dbResourceManager.cleanUp();
} finally {
- System.exit(0);
- }
- }
-
- private static void resolvePropertyAction(String user, String password, String port, String url, String property,
- PropertiesConfiguration conf) {
- if (containsParam(user, property, conf, USER_PARAM)) {
- conf.setProperty(property + "." + USER_PARAM, user);
- } else {
- conf.addProperty(property + "." + USER_PARAM, user);
- }
- if (containsParam(user, property, conf, PASS_PARAM)) {
- conf.setProperty(property + "." + PASS_PARAM, password);
- } else {
- conf.addProperty(property + "." + PASS_PARAM, password);
- }
- if (containsParam(user, property, conf, PORT_PARAM)) {
- conf.setProperty(property + "." + PORT_PARAM, port);
- } else if (port != null && !port.isEmpty()) {
- conf.addProperty(property + "." + PORT_PARAM, port);
- }
- if (containsParam(user, property, conf, URL_PARAM)) {
- conf.setProperty(property + "." + URL_PARAM, url);
- } else {
- conf.addProperty(property + "." + URL_PARAM, url);
+ dbResourceManager.cleanUp();
}
}
- private static void resolveProperty(String user, String password, String port, String url, String property,
- PropertiesConfiguration conf, String key) {
- if (contains(user, property, key, USER_PARAM)) {
- conf.setProperty(property + "." + key, user);
- }
- if (contains(user, property, key, PASS_PARAM)) {
- conf.setProperty(property + "." + key, password);
- }
- if (contains(user, property, key, PORT_PARAM)) {
- conf.setProperty(property + "." + key, port);
- }
- if (contains(user, property, key, URL_PARAM)) {
- conf.setProperty(property + "." + key, url);
- }
- }
-
- private static boolean containsParam(String var, String property, PropertiesConfiguration conf, String param) {
- return StringUtils.isNotBlank(var) && conf.containsKey(property + "." + param);
- }
-
- private static boolean contains(String var, String property, String key, String param) {
- return StringUtils.isNotBlank(var) && (property + "." + key).contains(param);
- }
}