Skip to content

Commit

Permalink
#58: added key generation in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jun 27, 2013
1 parent 832d412 commit 0fa7f5b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
#

BASEDIR=`cd $(dirname $0)/.. ; pwd`
$BASEDIR/packages/org.linkedin.glu.packaging-setup-5.0.0-SNAPSHOT/bin/setup.sh "$@"
$BASEDIR/packages/org.linkedin.glu.packaging-setup-@glu.version@/bin/setup.sh "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,37 @@ def fabric = 'glu-dev-1'
def gluVersion = '@glu.version@'
def zooKeeperVersion = '@zooKeeper.version@'

fabrics[fabric] = [
keys: [
agentKeyStore: [
uri: 'agent.keystore',
checksum: 'JSHZAn5IQfBVp1sy0PgA36fT_fD',
storePassword: 'nacEn92x8-1',
keyPassword: 'nWVxpMg6Tkv'
],
def keys = [
agentKeyStore: [
uri: 'agent.keystore',
checksum: 'JSHZAn5IQfBVp1sy0PgA36fT_fD',
storePassword: 'nacEn92x8-1',
keyPassword: 'nWVxpMg6Tkv'
],

agentTrustStore: [
uri: 'agent.truststore',
checksum: 'CvFUauURMt-gxbOkkInZ4CIV50y',
storePassword: 'nacEn92x8-1',
keyPassword: 'nWVxpMg6Tkv'
],
agentTrustStore: [
uri: 'agent.truststore',
checksum: 'CvFUauURMt-gxbOkkInZ4CIV50y',
storePassword: 'nacEn92x8-1',
keyPassword: 'nWVxpMg6Tkv'
],

consoleKeyStore: [
uri: 'console.keystore',
checksum: 'wxiKSyNAHN2sOatUG2qqIpuVYxb',
storePassword: 'nacEn92x8-1',
keyPassword: 'nWVxpMg6Tkv'
],
consoleKeyStore: [
uri: 'console.keystore',
checksum: 'wxiKSyNAHN2sOatUG2qqIpuVYxb',
storePassword: 'nacEn92x8-1',
keyPassword: 'nWVxpMg6Tkv'
],

consoleTrustStore: [
uri: 'console.truststore',
checksum: 'qUFMIePiJhz8i7Ow9lZmN5pyZjl',
storePassword: 'nacEn92x8-1',
],
consoleTrustStore: [
uri: 'console.truststore',
checksum: 'qUFMIePiJhz8i7Ow9lZmN5pyZjl',
storePassword: 'nacEn92x8-1',
],
]

fabrics[fabric] = [
keys: keys,
console: 'tutorialConsole',
zooKeeperCluster: 'tutorialZooKeeperCluster'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class KeysGenerator

KeysMetaModelImpl keys
def passwords = [:]
def encryptedPasswords = [:]

def passwordGenerator = { String name ->
OneWayCodec codec = OneWayMessageDigestCodec.createSHA1Instance(masterPassword, base64Codec)
Expand Down Expand Up @@ -104,11 +105,16 @@ public class KeysGenerator

def getEncryptedPasswords()
{
Base64Codec codec = new Base64Codec(encryptingKey);
if(!encryptedPasswords)
{
Base64Codec codec = new Base64Codec(encryptingKey);

passwords.collectEntries { k, v ->
[k, CodecUtils.encodeString(codec, v.toString())]
encryptedPasswords = getPasswords().collectEntries { k, v ->
[k, CodecUtils.encodeString(codec, v.toString())]
}
}

return encryptedPasswords
}

String computeChecksum(Resource resource)
Expand Down Expand Up @@ -337,14 +343,19 @@ public class KeysGenerator
}

private Resource createResourceInOutputFolder(String name,
boolean callClosureOnlyIfFileDoesNotExist = true,
boolean failOnFileAlreadyExists = true,
Closure<Resource> closure)
{
if(!outputFolder.exists())
shell.mkdirs(outputFolder)
Resource resource = outputFolder.createRelative(name)
if(!callClosureOnlyIfFileDoesNotExist || !resource.exists())
if(!failOnFileAlreadyExists || !resource.exists())
{
shell.rm(resource)
resource = closure(resource)
}
else
throw new IllegalStateException("${resource} already exists")
return resource
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SetupMain
protected Resource outputFolder
protected Shell shell = ShellImpl.createRootShell()

private int exitValue = 0

SetupMain()
{
JulToSLF4jBridge.installBridge()
Expand Down Expand Up @@ -112,25 +114,34 @@ public class SetupMain
def gen_keys = {
println "Generating keys..."
char[] masterPassword = System.console().readPassword("Enter a master password:")
def kmm = new KeysGenerator(shell: shell,
outputFolder: outputFolder.createRelative('keys'),
masterPassword: new String(masterPassword)).generateKeys().toExternalRepresentation()
println "Keys have been generated in the following folder: ${outputFolder.path}"
def km = new KeysGenerator(shell: shell,
outputFolder: outputFolder.createRelative('keys'),
masterPassword: new String(masterPassword))
try
{
def kmm = km.generateKeys().toExternalRepresentation()

println "Copy the following section in your meta model (see comment in meta model)"
println "Keys have been generated in the following folder: ${outputFolder.path}"

println "//" * 20
println "Copy the following section in your meta model (see comment in meta model)"

println "keys: ["
kmm.each { storeName, store ->
println " ${storeName}: ["
println store.findAll {k, v -> v != null}.collect { k, v -> " ${k}: '${v}'"}.join(',\n')
println " ],"
}
println "]"
println "//" * 20

println "//" * 20
println "def keys = ["
kmm.each { storeName, store ->
println " ${storeName}: ["
println store.findAll {k, v -> v != null}.collect { k, v -> " ${k}: '${v}'"}.join(',\n')
println " ],"
}
println "]"

println "//" * 20
}
catch(IllegalStateException e)
{
exitValue = 1
println "${e.message} => if you want to generate new keys, either provide another folder or delete them first"
}
}

public static void main(String[] args)
Expand All @@ -150,6 +161,8 @@ public class SetupMain
clientMain.cli.usage()
}
}

System.exit(clientMain.exitValue)
}

protected def getConfig(cli, options)
Expand Down

0 comments on commit 0fa7f5b

Please sign in to comment.