Skip to content

Commit

Permalink
Merge pull request #3 from mbaris/improvement/refactor
Browse files Browse the repository at this point in the history
disable secret key logging
minor refactors
  • Loading branch information
mbaris authored Aug 22, 2017
2 parents ee5df74 + f158a6d commit 7e20544
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/opsgenie/tools/backup/BackupUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<String> findIntegrationDirectories(String path) {
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/opsgenie/tools/backup/ExportMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
}
}
}
12 changes: 0 additions & 12 deletions src/main/java/com/opsgenie/tools/backup/ImportMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ protected void exportFile(String fileName, T bean) {

@Override
public void export() {
List<T> currentBeanList = null;
List<T> 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);
Expand Down

0 comments on commit 7e20544

Please sign in to comment.