aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2020-09-02 13:35:29 -0500
committerKevin Smokowski <kevin.smokowski@att.com>2020-09-02 19:05:46 +0000
commit2f5f9dc5c97749679695ff8147a6bf6b4e337ac5 (patch)
treef404a1004e6552bb05871d8c91141afc4c465381
parent0102a5219ebfa0a878f1ac3b03e897ca967518bc (diff)
secure printer changes
add method to print properties alphabetically Issue-ID: CCSDK-2721 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> Change-Id: I3bcb46a1f45dc74a2bc97acff08fa8c2c29d0ba7
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java50
1 files changed, 41 insertions, 9 deletions
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java
index d12729c4..e25aed9f 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java
@@ -1,9 +1,13 @@
package org.onap.ccsdk.sli.core.sli;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Properties;
+import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,6 +17,9 @@ public class SecurePrinter {
private static final String DEFAULT_FILTER = "password,pass,pswd";
private static final String REDACTED = "***REDACTED***";
private static final String FILTER_PROPERTY = "NODE_STRING_FILTER";
+ private static final String SEPERATOR = " = ";
+ private static final String COMMON_ERROR_MESSAGE = "Failed to print properties";
+
private static String[] filterArray;
public SecurePrinter() {
@@ -38,7 +45,7 @@ public class SecurePrinter {
if (LOG.isDebugEnabled()) {
for (Entry<String, String> attribute : attributes.entrySet()) {
String value = filterValue(attribute.getKey(), attribute.getValue());
- LOG.debug(attribute.getKey() + " = " + value);
+ LOG.debug(attribute.getKey() + SEPERATOR + value);
}
}
}
@@ -48,7 +55,7 @@ public class SecurePrinter {
for (Entry<String, String> attribute : attributes.entrySet()) {
if (attribute.getKey().startsWith(subpath)) {
String value = filterValue(attribute.getKey(), attribute.getValue());
- LOG.debug(attribute.getKey() + " = " + value);
+ LOG.debug(attribute.getKey() + SEPERATOR + value);
}
}
}
@@ -61,15 +68,15 @@ public class SecurePrinter {
String keyString = (String) property.getKey();
String valueString = (String) property.getValue();
String value = filterValue(keyString, valueString);
- LOG.debug(keyString + " = " + value);
+ LOG.debug(keyString + SEPERATOR + value);
}
} catch (Exception e) {
- LOG.error("Failed to print properties", e);
+ LOG.error(COMMON_ERROR_MESSAGE, e);
}
}
}
- public void printProperties(Properties props, String subpath) {
+ public void printProperties(Properties props, String subpath) {
if (LOG.isDebugEnabled()) {
try {
for (Entry<Object, Object> property : props.entrySet()) {
@@ -77,15 +84,40 @@ public class SecurePrinter {
if (keyString.startsWith(subpath)) {
String valueString = (String) property.getValue();
String value = filterValue(keyString, valueString);
- LOG.debug(keyString + " = " + value);
+ LOG.debug(keyString + SEPERATOR + value);
}
}
} catch (Exception e) {
- LOG.error("Failed to print properties", e);
+ LOG.error(COMMON_ERROR_MESSAGE, e);
}
}
}
-}
-
+ public void printPropertiesAlphabetically(Properties props) {
+ if (LOG.isDebugEnabled()) {
+ TreeMap<String, String> sortedMap = new TreeMap(props);
+ try {
+ for (Entry<String, String> entry : sortedMap.entrySet()) {
+ String value = filterValue(entry.getKey(), entry.getValue());
+ LOG.debug(entry.getKey() + SEPERATOR + value);
+ }
+ } catch (Exception e) {
+ LOG.error(COMMON_ERROR_MESSAGE, e);
+ }
+ }
+ }
+ public void printAttributesToFile(HashMap<String, String> attributes, String fileName) {
+ try (FileOutputStream fstr = new FileOutputStream(new File(fileName));
+ PrintStream pstr = new PrintStream(fstr, true);) {
+ pstr.println("#######################################");
+ for (Entry<String, String> entry : attributes.entrySet()) {
+ String value = filterValue(entry.getKey(), entry.getValue());
+ pstr.println(entry.getKey() + SEPERATOR + value);
+ }
+ } catch (Exception e) {
+ LOG.error("Cannot write context to file.", e);
+ }
+ }
+
+} \ No newline at end of file