Skip to content

Commit

Permalink
Merge pull request #32 from MissionCriticalCloud/remove/main_methods
Browse files Browse the repository at this point in the history
Remove unused main methods.
  • Loading branch information
bheuvel authored Jul 7, 2016
2 parents a5e11e6 + b6fb915 commit 95a4490
Show file tree
Hide file tree
Showing 15 changed files with 0 additions and 809 deletions.
5 changes: 0 additions & 5 deletions cosmic-core/api/src/main/java/com/cloud/host/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ public static String[] toStrings(final Status... states) {
return strs;
}

public static void main(final String[] args) {
System.out.println("Finite State Machine for Host:");
System.out.println(s_fsm.toString());
}

public boolean updateManagementServer() {
return updateManagementServer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
package com.cloud.utils.crypt;

import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.properties.EncryptableProperties;

/*
* EncryptionSecretKeyChanger updates Management Secret Key / DB Secret Key or both.
Expand All @@ -39,139 +27,6 @@ public class EncryptionSecretKeyChanger {
private final StandardPBEStringEncryptor oldEncryptor = new StandardPBEStringEncryptor();
private final StandardPBEStringEncryptor newEncryptor = new StandardPBEStringEncryptor();

public static void main(final String[] args) {
final List<String> argsList = Arrays.asList(args);
final Iterator<String> iter = argsList.iterator();
String oldMSKey = null;
String oldDBKey = null;
String newMSKey = null;
String newDBKey = null;

//Parse command-line args
while (iter.hasNext()) {
final String arg = iter.next();
// Old MS Key
if (arg.equals("-m")) {
oldMSKey = iter.next();
}
// Old DB Key
if (arg.equals("-d")) {
oldDBKey = iter.next();
}
// New MS Key
if (arg.equals("-n")) {
newMSKey = iter.next();
}
// New DB Key
if (arg.equals("-e")) {
newDBKey = iter.next();
}
}

if (oldMSKey == null || oldDBKey == null) {
System.out.println("Existing MS secret key or DB secret key is not provided");
usage();
return;
}

if (newMSKey == null && newDBKey == null) {
System.out.println("New MS secret key and DB secret are both not provided");
usage();
return;
}

final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
final Properties dbProps;
final EncryptionSecretKeyChanger keyChanger = new EncryptionSecretKeyChanger();
final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
keyChanger.initEncryptor(encryptor, oldMSKey);
dbProps = new EncryptableProperties(encryptor);
PropertiesConfiguration backupDBProps = null;

System.out.println("Parsing db.properties file");
try (FileInputStream db_prop_fstream = new FileInputStream(dbPropsFile)) {
dbProps.load(db_prop_fstream);
backupDBProps = new PropertiesConfiguration(dbPropsFile);
} catch (final FileNotFoundException e) {
System.out.println("db.properties file not found while reading DB secret key" + e.getMessage());
} catch (final IOException e) {
System.out.println("Error while reading DB secret key from db.properties" + e.getMessage());
} catch (final ConfigurationException e) {
e.printStackTrace();
}

String dbSecretKey = null;
try {
dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret");
} catch (final EncryptionOperationNotPossibleException e) {
System.out.println("Failed to decrypt existing DB secret key from db.properties. " + e.getMessage());
return;
}

if (!oldDBKey.equals(dbSecretKey)) {
System.out.println("Incorrect MS Secret Key or DB Secret Key");
return;
}

System.out.println("Secret key provided matched the key in db.properties");
final String encryptionType = dbProps.getProperty("db.cloud.encryption.type");

if (newMSKey == null) {
System.out.println("No change in MS Key. Skipping migrating db.properties");
} else {
if (!keyChanger.migrateProperties(dbPropsFile, dbProps, newMSKey, newDBKey)) {
System.out.println("Failed to update db.properties");
return;
} else {
//db.properties updated successfully
if (encryptionType.equals("file")) {
//update key file with new MS key
try (FileWriter fwriter = new FileWriter(keyFile);
BufferedWriter bwriter = new BufferedWriter(fwriter)) {
bwriter.write(newMSKey);
} catch (final IOException e) {
System.out.println("Failed to write new secret to file. Please update the file manually");
}
}
}
}

boolean success = false;
if (newDBKey == null || newDBKey.equals(oldDBKey)) {
System.out.println("No change in DB Secret Key. Skipping Data Migration");
} else {
EncryptionSecretKeyChecker.initEncryptorForMigration(oldMSKey);
try {
success = keyChanger.migrateData(oldDBKey, newDBKey);
} catch (final Exception e) {
System.out.println("Error during data migration");
e.printStackTrace();
success = false;
}
}

if (success) {
System.out.println("Successfully updated secret key(s)");
} else {
System.out.println("Data Migration failed. Reverting db.properties");
//revert db.properties
try {
backupDBProps.save();
} catch (final ConfigurationException e) {
e.printStackTrace();
}
if (encryptionType.equals("file")) {
//revert secret key in file
try (FileWriter fwriter = new FileWriter(keyFile);
BufferedWriter bwriter = new BufferedWriter(fwriter)) {
bwriter.write(oldMSKey);
} catch (final IOException e) {
System.out.println("Failed to revert to old secret to file. Please update the file manually");
}
}
}
}

private static void usage() {
System.out.println("Usage: \tEncryptionSecretKeyChanger \n" + "\t\t-m <Mgmt Secret Key> \n" + "\t\t-d <DB Secret Key> \n" + "\t\t-n [New Mgmt Secret Key] \n"
+ "\t\t-e [New DB Secret Key]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
public class AsyncSampleEventDrivenStyleCaller {
private AsyncSampleCallee _ds;

public static void main(final String[] args) {
final AsyncSampleEventDrivenStyleCaller caller = new AsyncSampleEventDrivenStyleCaller();
caller.MethodThatWillCallAsyncMethod();
}

@Test
public void MethodThatWillCallAsyncMethod() {
final String vol = new String("Hello");
Expand Down

This file was deleted.

Loading

0 comments on commit 95a4490

Please # to comment.