From c4eb1d5671e95358b9864dc80d1fee4a3a2d49ad Mon Sep 17 00:00:00 2001
From: Carsten Lund <lund@research.att.com>
Date: Fri, 9 Jun 2017 16:33:47 +0000
Subject: [DCAE-15] Final update for rebased code.

Change-Id: Ic808bf2a8b2a167b8dd62e75fafb46242c1fdb90
Signed-off-by: Carsten Lund <lund@research.att.com>
---
 .../entity/EcompSubComponentInstance.java          |  9 +++---
 .../utils/ConvertMessagePropertiesToYaml.java      |  8 ++++-
 .../main/java/org/openecomp/utils/YamlToJava.java  | 36 ++++++++++++++--------
 3 files changed, 36 insertions(+), 17 deletions(-)

(limited to 'operation-utils/src')

diff --git a/operation-utils/src/main/java/org/openecomp/entity/EcompSubComponentInstance.java b/operation-utils/src/main/java/org/openecomp/entity/EcompSubComponentInstance.java
index 2654dea..eece518 100644
--- a/operation-utils/src/main/java/org/openecomp/entity/EcompSubComponentInstance.java
+++ b/operation-utils/src/main/java/org/openecomp/entity/EcompSubComponentInstance.java
@@ -27,6 +27,8 @@ import java.util.UUID;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.openecomp.ncomp.utils.SecurityUtils;
+
 public class EcompSubComponentInstance {
 	private static final Logger logger = Logger.getLogger(EcompSubComponentInstance.class.getName());
 
@@ -51,10 +53,9 @@ public class EcompSubComponentInstance {
 		uuid = instanceID;
 		if (serverIP == null || serverName == null || ("").equals(serverIP) || ("").equals(serverName)) {
 			try {
-				InetAddress server = InetAddress.getLocalHost();
-				serverIP = server.getHostAddress();
-				serverName = server.getCanonicalHostName();
-			} catch (UnknownHostException e) {
+				serverIP = SecurityUtils.getHostAddress();
+				serverName = SecurityUtils.getCanonicalHostName();
+			} catch (Exception e) {
 				logger.log(Level.SEVERE, "Could not get local hostname", e);
 				serverIP = "";
 				serverName = "";
diff --git a/operation-utils/src/main/java/org/openecomp/utils/ConvertMessagePropertiesToYaml.java b/operation-utils/src/main/java/org/openecomp/utils/ConvertMessagePropertiesToYaml.java
index 28026d6..aa4babf 100644
--- a/operation-utils/src/main/java/org/openecomp/utils/ConvertMessagePropertiesToYaml.java
+++ b/operation-utils/src/main/java/org/openecomp/utils/ConvertMessagePropertiesToYaml.java
@@ -40,7 +40,13 @@ public class ConvertMessagePropertiesToYaml {
 		Properties props = new Properties();
 		String pname = "GenericMessages.properties";
 		String fname = "src/main/resources/GenericMessages.yaml";
-		props.load(ConvertMessagePropertiesToYaml.class.getClassLoader().getResourceAsStream(pname));
+		InputStream in = null;
+		try {
+			in = ConvertMessagePropertiesToYaml.class.getClassLoader().getResourceAsStream(pname);
+			props.load(in);
+		} finally {
+			if (in != null) in.close();
+		}
 		DumperOptions options = new DumperOptions();
 		options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
 		Yaml y = new Yaml(options);
diff --git a/operation-utils/src/main/java/org/openecomp/utils/YamlToJava.java b/operation-utils/src/main/java/org/openecomp/utils/YamlToJava.java
index fb3b1f4..f21d951 100644
--- a/operation-utils/src/main/java/org/openecomp/utils/YamlToJava.java
+++ b/operation-utils/src/main/java/org/openecomp/utils/YamlToJava.java
@@ -18,7 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END============================================
  */
-	
+
 package org.openecomp.utils;
 
 import java.io.ByteArrayOutputStream;
@@ -39,6 +39,7 @@ import groovy.lang.Writable;
 import groovy.text.SimpleTemplateEngine;
 
 import org.openecomp.ncomp.utils.PropertyUtil;
+import org.openecomp.ncomp.utils.SecurityUtils;
 import org.openecomp.ncomp.webservice.utils.FileUtils;
 
 public class YamlToJava {
@@ -66,6 +67,7 @@ public class YamlToJava {
 			String packageName) {
 		try {
 			System.out.println("Enterting YAML Convert)");
+			yamlFileName = SecurityUtils.safeFileName(yamlFileName);
 			if (!(new File(yamlFileName).exists())) {
 				System.err.println(yamlFileName + " does not exists");
 				return;
@@ -108,13 +110,19 @@ public class YamlToJava {
 	}
 
 	private static String getTemplate(String res) throws IOException {
-		InputStream in = YamlToJava.class.getClassLoader().getResourceAsStream(res);
-		if (in == null) {
-			throw new RuntimeException("Unable to find resource: " + res);
+		InputStream in = null;
+		try {
+			in = YamlToJava.class.getClassLoader().getResourceAsStream(res);
+			if (in == null) {
+				throw new RuntimeException("Unable to find resource: " + res);
+			}
+			ByteArrayOutputStream o = new ByteArrayOutputStream();
+			FileUtils.copyStream(in, o);
+			return o.toString();
+		} finally {
+			if (in != null)
+				in.close();
 		}
-		ByteArrayOutputStream o = new ByteArrayOutputStream();
-		FileUtils.copyStream(in, o);
-		return o.toString();
 	}
 
 	public static void main(String[] args) throws IOException {
@@ -130,8 +138,10 @@ public class YamlToJava {
 			String javaDest = (String) (m.containsKey("java-root") ? m.get("java-root") : "src/main/java-gen");
 			String resourcesDest = (String) (m.containsKey("resources-root") ? m.get("resources-root")
 					: "src/main/resources-gen");
-			if (! javaDest.startsWith("/")) javaDest = baseDir + "/" + javaDest;
-			if (! resourcesDest.startsWith("/")) resourcesDest = baseDir + "/" + resourcesDest;
+			if (!javaDest.startsWith("/"))
+				javaDest = baseDir + "/" + javaDest;
+			if (!resourcesDest.startsWith("/"))
+				resourcesDest = baseDir + "/" + resourcesDest;
 			String packageName = (String) m.get("package-name");
 			if (packageName == null) {
 				System.err.println("No package-name attribute in: " + args[0]);
@@ -153,11 +163,12 @@ public class YamlToJava {
 	}
 
 	private static String findBaseDir(String filename) {
-		File f = new File(filename);
+		File f = new File(SecurityUtils.safeFileName(filename));
 		f = f.getParentFile();
 		while (f != null) {
-			File pom = new File(f,"pom.xml");
-			if (pom.exists()) return f.getAbsolutePath();
+			File pom = new File(f, "pom.xml");
+			if (pom.exists())
+				return f.getAbsolutePath();
 			f = f.getParentFile();
 		}
 		return ".";
@@ -165,6 +176,7 @@ public class YamlToJava {
 
 	@SuppressWarnings("unchecked")
 	private static Map<String, Object> file2yaml(String yamlFileName) {
+		yamlFileName = SecurityUtils.safeFileName(yamlFileName);
 		if (!(new File(yamlFileName).exists())) {
 			System.err.println(yamlFileName + " does not exists");
 			System.exit(2);
-- 
cgit 1.2.3-korg