From f57213358f29497ff1522afa03bf6a6ecfbd5993 Mon Sep 17 00:00:00 2001 From: hisener Date: Tue, 22 Aug 2017 16:08:03 +0300 Subject: [PATCH 1/3] Refactor ObjectMapper as static final in BackupUtils.java --- .../java/com/opsgenie/tools/backup/BackupUtils.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/opsgenie/tools/backup/BackupUtils.java b/src/main/java/com/opsgenie/tools/backup/BackupUtils.java index 360c95e..2140e20 100644 --- a/src/main/java/com/opsgenie/tools/backup/BackupUtils.java +++ b/src/main/java/com/opsgenie/tools/backup/BackupUtils.java @@ -16,6 +16,13 @@ public class BackupUtils { private static final Logger logger = LogManager.getLogger(BackupUtils.class); + private static final ObjectMapper mapper = new ObjectMapper(); + + static { + mapper.registerModule(new JodaModule()); + mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm")); + } + public static String readFile(String fileName) throws IOException { InputStream is = new FileInputStream(fileName); BufferedReader buf = new BufferedReader(new InputStreamReader(is)); @@ -69,17 +76,11 @@ public static boolean deleteDirectory(File dir) { } public static String toJson(Object object) throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JodaModule()); return mapper.writeValueAsString(object); } public static void fromJson(Object object, String json) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JodaModule()); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); mapper.readerForUpdating(object).readValue(json); - mapper.setDateFormat(sdf); } public static List findIntegrationDirectories(String path) { From 4db706f14df38ea92686f5439a2d466405427025 Mon Sep 17 00:00:00 2001 From: hisener Date: Tue, 22 Aug 2017 16:09:47 +0300 Subject: [PATCH 2/3] Refactor export method in BaseExporter.java --- .../opsgenie/tools/backup/exporters/BaseExporter.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/opsgenie/tools/backup/exporters/BaseExporter.java b/src/main/java/com/opsgenie/tools/backup/exporters/BaseExporter.java index 4328f13..43e28a3 100644 --- a/src/main/java/com/opsgenie/tools/backup/exporters/BaseExporter.java +++ b/src/main/java/com/opsgenie/tools/backup/exporters/BaseExporter.java @@ -33,16 +33,17 @@ protected void exportFile(String fileName, T bean) { @Override public void export() { - List currentBeanList = null; + List currentBeanList; try { currentBeanList = retrieveEntities(); } catch (Exception e) { logger.error("Error at Listing " + exportDirectory.getName(), e); + return; + } + + for (T bean : currentBeanList) { + exportFile(getExportDirectory().getAbsolutePath() + "/" + getBeanFileName(bean) + ".json", bean); } - if (currentBeanList != null) - for (T bean : currentBeanList) { - exportFile(getExportDirectory().getAbsolutePath() + "/" + getBeanFileName(bean) + ".json", bean); - } } protected abstract String getBeanFileName(T bean); From f158a6d2398a42c3015460e27664929ded088f51 Mon Sep 17 00:00:00 2001 From: hisener Date: Tue, 22 Aug 2017 17:53:29 +0300 Subject: [PATCH 3/3] Remove apiKey and ssh key logs --- .../java/com/opsgenie/tools/backup/ExportMain.java | 13 ------------- .../java/com/opsgenie/tools/backup/ImportMain.java | 12 ------------ 2 files changed, 25 deletions(-) diff --git a/src/main/java/com/opsgenie/tools/backup/ExportMain.java b/src/main/java/com/opsgenie/tools/backup/ExportMain.java index 0fbe6d7..b2308c0 100644 --- a/src/main/java/com/opsgenie/tools/backup/ExportMain.java +++ b/src/main/java/com/opsgenie/tools/backup/ExportMain.java @@ -35,7 +35,6 @@ public static void main(String[] args) throws Exception { logger.info("Export directory path: " + backupPath); properties.setPath(backupPath); - logger.info("The api key:" + apiKey); properties.setApiKey(apiKey); logger.info("Opsgenie host: " + opsGenieHost); @@ -52,7 +51,6 @@ public static void main(String[] args) throws Exception { logger.info("The SSH key path: " + sshKeyPath); properties.setSshKeyPath(sshKeyPath); - logSecretKey("SSH key passphrase", sshPassphrase); properties.setPassphrase(sshPassphrase); } @@ -71,16 +69,5 @@ public static void main(String[] args) throws Exception { exporter.export(); logger.info("Finished"); - - } - - private static void logSecretKey(String propName, String secretKey) { - if (secretKey != null) { - String criptedKey = secretKey.substring(0, secretKey.length() / 2); - for (int i = criptedKey.length(); i < secretKey.length(); i++) { - criptedKey += "*"; - } - logger.info("The " + propName + " is = " + criptedKey); - } } } diff --git a/src/main/java/com/opsgenie/tools/backup/ImportMain.java b/src/main/java/com/opsgenie/tools/backup/ImportMain.java index 8f99856..fba3af6 100644 --- a/src/main/java/com/opsgenie/tools/backup/ImportMain.java +++ b/src/main/java/com/opsgenie/tools/backup/ImportMain.java @@ -45,7 +45,6 @@ public static void main(String[] args) throws Exception { logger.info("Import directory path: " + backupPath); properties.setPath(backupPath); - logger.info("Api Key: " + apiKey); properties.setApiKey(apiKey); logger.info("Opsgenie host: " + opsGenieHost); @@ -59,7 +58,6 @@ public static void main(String[] args) throws Exception { logger.info("Restore from git is enabled."); logger.info("Git ssh url:" + sshUrl); logger.info("Ssh key path: " + sshKeyPath); - logSecretKey("Ssh key passphrase: ", sshPassphrase); } final ApiClient defaultApiClient = Configuration.getDefaultApiClient(); @@ -90,16 +88,6 @@ public static void main(String[] args) throws Exception { } - private static void logSecretKey(String propName, String secretKey) { - if (secretKey != null) { - String criptedKey = secretKey.substring(0, secretKey.length() / 2); - for (int i = criptedKey.length(); i < secretKey.length(); i++) { - criptedKey += "*"; - } - logger.info("The " + propName + " is = " + criptedKey); - } - } - public static ImportConfig extractRestoreConfig() throws IOException { File configFile = new File("restoreConfig.properties"); Properties props = null;