lib/security.rb in forj-0.0.36 vs lib/security.rb in forj-0.0.37
- old
+ new
@@ -135,22 +135,44 @@
rule = create_security_group_rule(oFC, security_group_id, protocol, port_min, port_max)
end
rule
end
- def hpc_import_pubkey(oConfig, account)
+ def hpc_import_key(oConfig, account)
key_name = oConfig.get('keypair_name')
key_path = oConfig.get('keypair_path')
+ mObj = key_path.match(/^(.*)(\.pem)?$/)
+
+ key_path = mObj[1]
+
Logging.fatal(1, "'keypair_path' undefined. check your config.yaml file.") if not key_path
Logging.fatal(1, "'keypair_name' undefined. check your config.yaml file.") if not key_name
pubkey_path = key_path + '.pub'
Logging.fatal(1, "keypair '%s' are missing. Please call 'forj setup %s' to create the missing key pair required." % [pubkey_path, account]) if not File.exists?(pubkey_path)
-
- Logging.info("Importing your forj keypair '%s' to hpcloud." % pubkey_path)
- command = 'hpcloud keypairs:import %s %s -a %s' % [key_name, pubkey_path, account]
- Logging.debug("Executing command '%s'" % command)
- Kernel.system(command)
+ if not File.exists?(File.join($HPC_KEYPAIRS, key_name + '.pub'))
+ Logging.info("Importing your forj public key '%s' to hpcloud." % pubkey_path)
+ command = 'hpcloud keypairs:import %s %s -a %s' % [key_name, pubkey_path, account]
+ Logging.debug("Executing command '%s'" % command)
+ Kernel.system(command)
+ else
+ Logging.info("Using '%s' as public key." % pubkey_path)
+ end
+ private_key = nil
+ private_key = key_path if File.exists?(key_path)
+ private_key = key_path + '.pem' if File.exists?(key_path + '.pem')
+ if not File.exists?(File.join($HPC_KEYPAIRS, key_name + '.pem'))
+ if private_key
+ Logging.info("Importing your forj private key '%s' to hpcloud." % private_key)
+ command = 'hpcloud keypairs:private:add %s %s' % [key_name, private_key]
+ Logging.debug("Executing command '%s'" % command)
+ Kernel.system(command)
+ else
+ Logging.warning('Unable to find the private key. This will be required to access with ssh to Maestro and any blueprint boxes.')
+ end
+ else
+ Logging.info("Using '%s' as private key." % key_path)
+ end
end
end