Class: Dcmgr::Cli::KeyPair
- Includes:
- Helpers::CliHelper
- Defined in:
- lib/dcmgr/cli/keypair.rb
Constant Summary collapse
Instance Method Summary collapse
Methods included from Helpers::CliHelper
Instance Method Details
#add ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dcmgr/cli/keypair.rb', line 15 def add UnknownUUIDError.raise([:account_id]) if M::Account[[:account_id]].nil? private_key_path = File.([:private_key]) public_key_path = File.([:public_key]) Error.raise "Private key file doesn't exist",100 unless File.exists?(private_key_path) || [:private_key] Error.raise "Public key file doesn't exist",100 unless File.exists?(public_key_path) fields = .dup #Get the keys from their respective files. fields[:public_key] = File.open(public_key_path) {|f| f.readline} fields[:private_key] = File.open(private_key_path) {|f| f.readlines.map.join} #Generate the fingerprint from the public key file res = sh("ssh-keygen -lf #{[:public_key]}") fields[:finger_print] = res[:stdout].split(' ')[1] puts super(M::SshKeyPair,fields) end |
#del(uuid) ⇒ Object
44 45 46 |
# File 'lib/dcmgr/cli/keypair.rb', line 44 def del(uuid) super(M::SshKeyPair,uuid) end |
#modify(uuid) ⇒ Object
38 39 40 41 |
# File 'lib/dcmgr/cli/keypair.rb', line 38 def modify(uuid) UnknownUUIDError.raise([:account_id]) if [:account_id] && M::Account[[:account_id]].nil? super(M::SshKeyPair,uuid,) end |
#show(uuid = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dcmgr/cli/keypair.rb', line 49 def show(uuid=nil) if uuid keypair = M::SshKeyPair[uuid] || UnknownUUIDError.raise(uuid) puts ERB.new(<<__END, nil, '-').result(binding) Keypair UUID: <%= keypair.canonical_uuid %> Account id: <%= keypair.account_id %> Finger print: <%= keypair.finger_print %> Public Key: <%= keypair.public_key%> <%- if keypair.description -%> Description: <%= keypair.description %> <%- end -%> __END else puts ERB.new(<<__END, nil, '-').result(binding) <%- M::SshKeyPair.each { |row| -%> <%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.finger_print %> <%- } -%> __END end end |