summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-encryption-tool
diff options
context:
space:
mode:
authorGeorge, Lina (lg941u) <lg941u@att.com>2019-01-30 16:01:19 -0500
committerPatrick Brady <patrick.brady@att.com>2019-02-05 18:28:34 +0000
commitbeac33deccb8b7f98e7f96a17541abb81b246d16 (patch)
tree1a3ce5be113934c9836634c46a3b6d72093ed390 /appc-config/appc-encryption-tool
parent688a1bd4f99cb856b067c7b38c02cdab27070865 (diff)
Encryption tool changes for multiple ansibleserver
Issue-ID: APPC-1342 Change-Id: Ib1ff7845ad65cf13c06a96d6dcce023b06064dfa Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-config/appc-encryption-tool')
-rw-r--r--appc-config/appc-encryption-tool/provider/pom.xml8
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ArtifactMapper.java45
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/CloudOwnerList.java57
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/FqdnList.java113
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java168
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/RegionIdList.java57
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java10
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java84
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java81
-rw-r--r--appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/MockParseAdminArtifcat.java48
-rw-r--r--appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestParseAdminArtifact.java63
-rw-r--r--appc-config/appc-encryption-tool/provider/src/test/resources/org/onap/appc/adminartifcat.json93
12 files changed, 799 insertions, 28 deletions
diff --git a/appc-config/appc-encryption-tool/provider/pom.xml b/appc-config/appc-encryption-tool/provider/pom.xml
index 39672c6e6..8f3507ec2 100644
--- a/appc-config/appc-encryption-tool/provider/pom.xml
+++ b/appc-config/appc-encryption-tool/provider/pom.xml
@@ -90,6 +90,14 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ArtifactMapper.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ArtifactMapper.java
new file mode 100644
index 000000000..c7a1ad76e
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ArtifactMapper.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool.fqdn;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ArtifactMapper {
+ private List<FqdnList> fqdnList = null;
+
+ @JsonProperty("fqdn-list")
+ public List<FqdnList> getFqdnList() {
+ return fqdnList;
+ }
+
+ @JsonProperty("fqdn-list")
+ public void setFqdnList(List<FqdnList> fqdnList) {
+ this.fqdnList = fqdnList;
+ }
+
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/CloudOwnerList.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/CloudOwnerList.java
new file mode 100644
index 000000000..d12522750
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/CloudOwnerList.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool.fqdn;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "cloud-owner", "region-id-list" })
+public class CloudOwnerList {
+
+ private String cloudOwner;
+ private List<RegionIdList> regionIdList = null;
+
+ @JsonProperty("cloud-owner")
+ public String getCloudOwner() {
+ return cloudOwner;
+ }
+
+ @JsonProperty("cloud-owner")
+ public void setCloudOwner(String cloudOwner) {
+ this.cloudOwner = cloudOwner;
+ }
+
+ @JsonProperty("region-id-list")
+ public List<RegionIdList> getRegionIdList() {
+ return regionIdList;
+ }
+
+ @JsonProperty("region-id-list")
+ public void setRegionIdList(List<RegionIdList> regionIdList) {
+ this.regionIdList = regionIdList;
+ }
+
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/FqdnList.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/FqdnList.java
new file mode 100644
index 000000000..2c5eb202d
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/FqdnList.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool.fqdn;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "vnf-management-server-fqdn", "cloud-owner-list", "description", "username", "create-date",
+ "modify-username", "modify-date" })
+public class FqdnList {
+
+ private String vnfManagementServerFqdn;
+ private List<CloudOwnerList> cloudOwnerList = null;
+ private String description;
+ private String username;
+ private String createDate;
+ private String modifyUsername;
+ private String modifyDate;
+
+ @JsonProperty("vnf-management-server-fqdn")
+ public String getVnfManagementServerFqdn() {
+ return vnfManagementServerFqdn;
+ }
+
+ @JsonProperty("vnf-management-server-fqdn")
+ public void setVnfManagementServerFqdn(String vnfManagementServerFqdn) {
+ this.vnfManagementServerFqdn = vnfManagementServerFqdn;
+ }
+
+ @JsonProperty("cloud-owner-list")
+ public List<CloudOwnerList> getCloudOwnerList() {
+ return cloudOwnerList;
+ }
+
+ @JsonProperty("cloud-owner-list")
+ public void setCloudOwnerList(List<CloudOwnerList> cloudOwnerList) {
+ this.cloudOwnerList = cloudOwnerList;
+ }
+
+ @JsonProperty("description")
+ public String getDescription() {
+ return description;
+ }
+
+ @JsonProperty("description")
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @JsonProperty("username")
+ public String getUsername() {
+ return username;
+ }
+
+ @JsonProperty("username")
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ @JsonProperty("create-date")
+ public String getCreateDate() {
+ return createDate;
+ }
+
+ @JsonProperty("create-date")
+ public void setCreateDate(String createDate) {
+ this.createDate = createDate;
+ }
+
+ @JsonProperty("modify-username")
+ public String getModifyUsername() {
+ return modifyUsername;
+ }
+
+ @JsonProperty("modify-username")
+ public void setModifyUsername(String modifyUsername) {
+ this.modifyUsername = modifyUsername;
+ }
+
+ @JsonProperty("modify-date")
+ public String getModifyDate() {
+ return modifyDate;
+ }
+
+ @JsonProperty("modify-date")
+ public void setModifyDate(String modifyDate) {
+ this.modifyDate = modifyDate;
+ }
+
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java
new file mode 100644
index 000000000..e68a6f444
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java
@@ -0,0 +1,168 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool.fqdn;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import org.apache.commons.lang.StringUtils;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class ParseAdminArtifcat implements SvcLogicJavaPlugin {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(ParseAdminArtifcat.class);
+ private static ParseAdminArtifcat parseArtifact = null;
+ private static String fqdn = null;
+ private SvcLogicResource serviceLogic;
+
+ public static ParseAdminArtifcat initialise() {
+ parseArtifact = new ParseAdminArtifcat();
+ return parseArtifact;
+ }
+
+ public ParseAdminArtifcat() {
+ serviceLogic = new SqlResource();
+ }
+
+ protected ParseAdminArtifcat(SqlResource svcLogic) {
+ serviceLogic = svcLogic;
+ }
+
+ protected static Map<String, String> parseAdminArtifact(ArtifactMapper js) {
+ List<FqdnList> fqdnList = js.getFqdnList();
+ Map<String, String> mp = new HashMap<String, String>();
+ for (FqdnList listFqdn : fqdnList) {
+
+ for (CloudOwnerList clList : listFqdn.getCloudOwnerList()) {
+
+ for (RegionIdList rgList : clList.getRegionIdList()) {
+
+ for (String tenantId : rgList.getTenantIdList()) {
+ mp.put(clList.getCloudOwner().trim() + ";" + rgList.getRegionId().trim() + ";" + tenantId,
+ listFqdn.getVnfManagementServerFqdn());
+ log.info("list of mapped details from admin artifact" + clList.getCloudOwner().trim() + ";"
+ + rgList.getRegionId().trim() + ";" + tenantId + "-->"
+ + listFqdn.getVnfManagementServerFqdn());
+ }
+
+ }
+
+ }
+
+ }
+
+ return mp;
+
+ }
+
+ public String retrieveFqdn(SvcLogicContext ctx)
+ throws SvcLogicException, RuntimeException, JsonProcessingException, IOException {
+ String tenantId = "";
+ String cloudOwner = "";
+ String cloudRegionId = "";
+ String jsonContent = getAdminArtifact(ctx);
+ if (jsonContent == null) {
+ throw new RuntimeException("Artifact content missing");
+ }
+
+ if (StringUtils.isNotBlank(ctx.getAttribute("payloadTenant"))) {
+ tenantId = ctx.getAttribute("payloadTenant");
+ } else {
+ tenantId = ctx.getAttribute("tenantAai");
+ }
+ if (StringUtils.isNotBlank(ctx.getAttribute("payloadCloudOwner"))) {
+ cloudOwner = ctx.getAttribute("payloadCloudOwner");
+ } else {
+ cloudOwner = ctx.getAttribute("cloudOwneraai");
+ }
+ if (StringUtils.isNotBlank(ctx.getAttribute("payloadCloudRegion"))) {
+ cloudRegionId = ctx.getAttribute("payloadCloudRegion");
+ } else {
+ cloudRegionId = ctx.getAttribute("cloudRegionAai");
+
+ }
+
+ String key = cloudOwner.trim() + ";" + cloudRegionId.trim() + ";" + tenantId.trim();
+ log.info("cloudowner--cloudregion--tenantid retrieved constructed :" + key);
+ log.info("tenantid--cloudowner--cloudregion retrieved from payload :" + ctx.getAttribute("payloadTenant") + ":"
+ + ctx.getAttribute("payloadCloudOwner") + ":" + ctx.getAttribute("payloadCloudRegion"));
+ log.info("tenantid--cloudowner--cloudregion retrieved from a&ai : " + ctx.getAttribute("tenantAai") + ":"
+ + ctx.getAttribute("cloudOwneraai") + ":" + ctx.getAttribute("cloudRegionAai"));
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
+ ArtifactMapper js = objectMapper.readValue(jsonContent, ArtifactMapper.class);
+ Map<String, String> mp = parseAdminArtifact(js);
+ for (String t : mp.keySet()) {
+ if (t.contains(key)) {
+ log.info("Matching fqdn from admin artifact found for a&ai data :" + key);
+ fqdn = mp.get(key);
+ }
+ }
+ log.info(fqdn + "--> url and port retrieved ");
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ }
+ return fqdn;
+ }
+
+ public String getAdminArtifact(SvcLogicContext ctx) {
+
+ QueryStatus status = null;
+ String fn = "ParseAdminArtifcat:getAdminArtifact";
+ String jsonContent = null;
+ String artifcatName = "ansible_admin_FQDN_Artifact_0.0.1V.json";
+ try {
+ String query = "SELECT ARTIFACT_CONTENT as adminjson" + " FROM ASDC_ARTIFACTS " + "WHERE ARTIFACT_NAME = '"
+ + artifcatName + "' " + "ORDER BY INTERNAL_VERSION DESC LIMIT 1 ";
+ log.info("Getting artifact details :" + query);
+ status = serviceLogic.query("SQL", false, null, query, null, null, ctx);
+ jsonContent = ctx.getAttribute("adminjson");
+ log.info("adminjsonblock:" + jsonContent);
+ if (status == QueryStatus.FAILURE) {
+ log.info(fn + ": Error retrieving artifact details");
+ throw new SvcLogicException("Error retrieving artifact details");
+ }
+ } catch (Exception e) {
+ log.debug("Error while accessing database" + e.getMessage());
+ log.info("Error connecting to database" + e.getMessage());
+ log.error("Error accessing database", e);
+ throw new RuntimeException(e);
+ }
+ return jsonContent;
+
+ }
+
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/RegionIdList.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/RegionIdList.java
new file mode 100644
index 000000000..20de1fe72
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/RegionIdList.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool.fqdn;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "region-id", "tenant-id-list" })
+public class RegionIdList {
+
+ private String regionId;
+ private List<String> tenantIdList = null;
+
+ @JsonProperty("region-id")
+ public String getRegionId() {
+ return regionId;
+ }
+
+ @JsonProperty("region-id")
+ public void setRegionId(String regionId) {
+ this.regionId = regionId;
+ }
+
+ @JsonProperty("tenant-id-list")
+ public List<String> getTenantIdList() {
+ return tenantIdList;
+ }
+
+ @JsonProperty("tenant-id-list")
+ public void setTenantIdList(List<String> tenantIdList) {
+ this.tenantIdList = tenantIdList;
+ }
+
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java
index 7575c98b0..e7c4b712c 100644
--- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -32,4 +32,10 @@ public class Constants
private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
public static final String APPC_CONFIG_DIR="/opt/onap/appc/data/properties";
-} \ No newline at end of file
+
+ public static final String VNF_TYPE="vnf_Type";
+ public static final String ACTION="action";
+ public static final String PROTOCOL="protocol";
+ public static final String URL="url";
+
+}
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 fa7075eff..e73004206 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
@@ -35,29 +35,25 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
+import org.onap.appc.encryptiontool.fqdn.ParseAdminArtifcat;
public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolDGWrapper.class);
private SvcLogicResource serviceLogic;
private static EncryptionToolDGWrapper dgGeneralDBService = null;
+ ParseAdminArtifcat artifact = new ParseAdminArtifcat();
public static EncryptionToolDGWrapper initialise() {
- if (dgGeneralDBService == null) {
- dgGeneralDBService = new EncryptionToolDGWrapper();
- }
+ dgGeneralDBService = new EncryptionToolDGWrapper();
return dgGeneralDBService;
}
public EncryptionToolDGWrapper() {
- if (serviceLogic == null) {
- serviceLogic = new SqlResource();
- }
+ serviceLogic = new SqlResource();
}
protected EncryptionToolDGWrapper(SqlResource svcLogic) {
- if (serviceLogic == null) {
- serviceLogic = svcLogic;
- }
+ serviceLogic = svcLogic;
}
public void runEncryption(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
@@ -85,14 +81,76 @@ public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
String password = "";
String port = "0";
String url = "";
+ String key = "";
QueryStatus status = null;
-
+ Integer cnt = 0;
+ String tenantAai = inParams.get("tenantAai");
+ String cloudOwneraai = inParams.get("cldOwnerAai");
+ String cloudRegionAai = inParams.get("cldRegionAai");
+ String payloadFqdn = inParams.get("payloadFqdn");
+ String payloadTenant = inParams.get("payloadTenant");
+ String payloadCloudOwner = inParams.get("payloadCloudOwner");
+ String payloadCloudRegion = inParams.get("payloadCloudRegion");
+ ctx.setAttribute("payloadTenant", payloadTenant);
+ ctx.setAttribute("payloadCloudOwner", payloadCloudOwner);
+ ctx.setAttribute("payloadCloudRegion", payloadCloudRegion);
+ ctx.setAttribute("tenantAai", tenantAai);
+ ctx.setAttribute("cloudOwneraai", cloudOwneraai);
+ ctx.setAttribute("cloudRegionAai", cloudRegionAai);
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
+ String basicQuery = "SELECT USER_NAME ,PASSWORD,PORT_NUMBER ,URL FROM DEVICE_AUTHENTICATION WHERE VNF_TYPE = $"
+ + Constants.VNF_TYPE + " AND PROTOCOL = $" + Constants.PROTOCOL + "" + " AND ACTION = $"
+ + Constants.ACTION + "";
+ String urlAppend = " ";
try {
if (serviceLogic != null && ctx != null) {
- String key = "SELECT USER_NAME ,PASSWORD,PORT_NUMBER,URL FROM DEVICE_AUTHENTICATION WHERE VNF_TYPE = '"
- + vnf_Type + "' AND PROTOCOL = '" + protocol + "' AND ACTION = '" + action + "'";
- log.info("Getting authentication details :" + key);
+ if (protocol.equalsIgnoreCase("ansible")) {
+ if (payloadFqdn != null && payloadFqdn.trim().length() > 0) {
+ url = payloadFqdn;
+ log.info("url from payload" + url);
+ urlAppend = " AND URL = $" + Constants.URL + "";
+ key = basicQuery + urlAppend;
+ } else {
+ key = "SELECT COUNT(*) AS MULTIPLE FROM DEVICE_AUTHENTICATION WHERE VNF_TYPE = $"
+ + Constants.VNF_TYPE + " AND PROTOCOL = $" + Constants.PROTOCOL + " AND ACTION = $"
+ + Constants.ACTION + "";
+ status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
+ log.info("Checking number of records for ansible:" + key);
+ cnt = Integer.parseInt(ctx.getAttribute("MULTIPLE"));
+ if (cnt > 1) {
+ String fqdnwithPort = artifact.retrieveFqdn(ctx);
+ if (StringUtils.isNotBlank(fqdnwithPort) && fqdnwithPort.contains(":")) {
+
+ int index = StringUtils.ordinalIndexOf(fqdnwithPort, ":", 3);
+ url = fqdnwithPort.substring(0, index);
+ urlAppend = " AND URL = $" + Constants.URL + "";
+ key = basicQuery + urlAppend;
+ } else {
+ throw new SvcLogicException(
+ fn + ": NOT_FOUND! No FQDN match found in admin artifact for " + vnf_Type
+ + " " + protocol + "" + action + "");
+ }
+ } else if (cnt == 1) {
+ key = basicQuery;
+ } else {
+ if (status == QueryStatus.FAILURE) {
+ log.info(fn + ":: Error retrieving credentials");
+ throw new SvcLogicException("Error retrieving credentials");
+ }
+ if (status == QueryStatus.NOT_FOUND) {
+ log.info(fn + ":: NOT_FOUND! No data found in device_authentication table for "
+ + vnf_Type + " " + protocol + "" + action + "");
+ throw new SvcLogicException(
+ fn + ":: NOT_FOUND! No data found in device_authentication table for "
+ + vnf_Type + " " + protocol + "" + action + "");
+ }
+ }
+ }
+
+ } else {
+ key = basicQuery;
+ log.info("Getting authentication details :" + key);
+ }
status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
if (status == QueryStatus.FAILURE) {
log.info(fn + ":: Error retrieving credentials");
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 86b0861cb..e29920ec6 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
@@ -42,13 +42,16 @@ 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];
+ log.info("vnfType = " + vnfType + " protocol = " + protocol + " user=" + user + " password=" + password
+ + " action=" + action + " port=" + port + " url=" + url);
+
if (StringUtils.isBlank(user)) {
log.info("ERROR-USER can not be null");
return;
@@ -61,9 +64,63 @@ public class WrapperEncryptionTool {
log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null");
return;
}
+ if (protocol.equalsIgnoreCase("ansible") && (StringUtils.isBlank(url))) {
+ log.info("URL cannot be null for Ansible");
+ return;
+ }
EncryptionTool et = EncryptionTool.getInstance();
String enPass = et.encrypt(password);
- updateProperties(user, vnfType, enPass, action, port, url, protocol);
+ log.info("enPass =" + enPass);
+ if (protocol.equalsIgnoreCase("ansible"))
+ updatePropertiesAnsible(user, vnfType, enPass, action, port, url, protocol);
+ else
+ updateProperties(user, vnfType, enPass, action, port, url, protocol);
+ }
+
+ public static void updatePropertiesAnsible(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);
+ getList.add(url);
+ String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? AND URL = ? ";
+ String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ? ";
+ String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
+ String insertsetClause = " ?,?,?,?,?,?,?";
+ try {
+ 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");
+ }
+ 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");
+ }
+ } catch (Exception e) {
+ log.debug("Caught Exception", e);
+ log.info("Caught exception", e);
+ log.info("APPC-MESSAGE:" + e.getMessage());
+
+ } finally {
+ dbResourceManager.cleanUp();
+ }
}
public static void updateProperties(String user, String vnfType, String enPass, String action, String port,
@@ -84,7 +141,7 @@ public class WrapperEncryptionTool {
int rowCount = 0;
if (data.first()) {
rowCount++;
- log.info(rowCount + "rowcount");
+ log.info(rowCount + "rowcount");
}
getList.clear();
getList.add(user);
@@ -105,11 +162,9 @@ public class WrapperEncryptionTool {
log.debug("Caught Exception", e);
log.info("Caught exception", e);
log.info("APPC-MESSAGE:" + e.getMessage());
+
} finally {
- //When dbResourceManager is not created then no need to cleanup
- if (dbResourceManager != null) {
- dbResourceManager.cleanUp();
- }
+ dbResourceManager.cleanUp();
}
}
diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/MockParseAdminArtifcat.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/MockParseAdminArtifcat.java
new file mode 100644
index 000000000..8f00e5fd3
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/MockParseAdminArtifcat.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import org.apache.commons.io.IOUtils;
+import org.onap.appc.encryptiontool.fqdn.ParseAdminArtifcat;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+public class MockParseAdminArtifcat extends ParseAdminArtifcat {
+
+ @Override
+ public String getAdminArtifact(SvcLogicContext ctx) {
+ try {
+ return readInput("src/test/resources/org/onap/appc/adminartifcat.json");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String readInput(String inputFile) throws IOException {
+ String file = null;
+ FileInputStream fileInputStream = new FileInputStream(inputFile);
+ file = IOUtils.toString(fileInputStream, "UTF-8");
+ return file;
+ }
+
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestParseAdminArtifact.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestParseAdminArtifact.java
new file mode 100644
index 000000000..79c658c55
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestParseAdminArtifact.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.encryptiontool.fqdn.ParseAdminArtifcat;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class TestParseAdminArtifact {
+ SvcLogicContext ctx = null;
+ ParseAdminArtifcat parseAdminArtifact = null;
+
+ @Before
+ public void setup() throws IOException {
+ parseAdminArtifact = new MockParseAdminArtifcat();
+ }
+
+ @Test
+ public void testRetrieveFqdn() throws Exception {
+ ctx = new SvcLogicContext();
+ ctx.setAttribute("tenantAai", "tenantuuid1");
+ ctx.setAttribute("cloudOwneraai", "aic3.0");
+ ctx.setAttribute("cloudRegionAai", "san4a");
+ try {
+ String fqdnMatchPayload = parseAdminArtifact.retrieveFqdn(ctx);
+ assertEquals("fqdn-value1 url:port", fqdnMatchPayload);
+
+ } catch (SvcLogicException | RuntimeException | IOException e) {
+ e.printStackTrace();
+ throw new Exception("Failed to retrieve fqdn:"+ e.getMessage());
+ }
+
+ }
+
+}
diff --git a/appc-config/appc-encryption-tool/provider/src/test/resources/org/onap/appc/adminartifcat.json b/appc-config/appc-encryption-tool/provider/src/test/resources/org/onap/appc/adminartifcat.json
new file mode 100644
index 000000000..94c43df2b
--- /dev/null
+++ b/appc-config/appc-encryption-tool/provider/src/test/resources/org/onap/appc/adminartifcat.json
@@ -0,0 +1,93 @@
+
+
+{"fqdn-list": [
+ {
+ "vnf-management-server-fqdn": "fqdn-value1 url:port",
+ "cloud-owner-list": [
+ {
+ "cloud-owner": "aic3.0",
+ "region-id-list": [
+ {
+ "region-id": "san4a",
+ "tenant-id-list": [
+ "tenantuuid1",
+ "tenantuuid2"
+ ]
+ },
+ {
+ "region-id": "san4b",
+ "tenant-id-list": [
+ "tenantuuid1",
+ "tenantuuid2"
+ ]
+ }
+ ]
+ },
+ {
+ "cloud-owner": "nc1.0",
+ "region-id-list": [
+ {
+ "region-id": "san4a",
+ "tenant-id-list": [
+
+ "tenantuuid3",
+ "tenantuuid4"
+
+ ]
+ }
+ ]
+ }
+ ],
+ "description": "fqdn for east zone vUSP Production",
+ "username": "albino attuid",
+ "create-date": "",
+ "modify-username": "",
+ "modify-date": ""
+ },
+ {
+ "vnf-management-server-fqdn": "fqdn-value2 url:port",
+ "cloud-owner-list": [
+ {
+ "cloud-owner": "aic3.0",
+ "region-id-list": [
+ {
+ "region-id": "san4a",
+ "tenant-id-list": [
+ "tenantuuid5",
+ "tenantuuid6"
+ ]
+ },
+ {
+ "region-id": "san4b",
+ "tenant-id-list": [
+ "tenantuuid5",
+ "tenantuuid6"
+ ]
+ }
+ ]
+ },
+ {
+ "cloud-owner": "nc1.0",
+ "region-id-list": [
+ {
+ "region-id": "san4a",
+ "tenant-id-list": [
+
+ "tenantuuid7",
+ "tenantuuid8"
+
+ ]
+ }
+ ]
+ }
+ ],
+ "description": "fqdn for east zone vUSP E2E",
+ "username": "albino attuid",
+ "create-date": "",
+ "modify-username": "",
+ "modify-date": ""
+ }
+
+ ]
+}
+