diff options
author | Carsten Lund <lund@research.att.com> | 2017-06-09 16:33:47 +0000 |
---|---|---|
committer | Carsten Lund <lund@research.att.com> | 2017-06-09 16:33:47 +0000 |
commit | c4eb1d5671e95358b9864dc80d1fee4a3a2d49ad (patch) | |
tree | 327e99521a8cb0bd2b2499dbf6eb52b01a0d096f /operation-utils/src | |
parent | 4458bfeff660e31cb21fd8d2c9d4a78fc2f64d7d (diff) |
Change-Id: Ic808bf2a8b2a167b8dd62e75fafb46242c1fdb90
Signed-off-by: Carsten Lund <lund@research.att.com>
Diffstat (limited to 'operation-utils/src')
3 files changed, 36 insertions, 17 deletions
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); |