Class: Nephophobia::Resource::Credential

Inherits:
Object
  • Object
show all
Defined in:
lib/nephophobia/resource/credential.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Credential

Returns a new instance of Credential.



4
5
6
# File 'lib/nephophobia/resource/credential.rb', line 4

def initialize client
  @client = client
end

Instance Method Details

#allObject

Returns information about key pairs that @client owns.



11
12
13
14
15
16
17
18
# File 'lib/nephophobia/resource/credential.rb', line 11

def all
  response = @client.action "DescribeKeyPairs", {}

  key_set = response.body['DescribeKeyPairsResponse']['keySet']
  key_set && Nephophobia::Util.coerce(key_set['item']).collect do |data|
    Response::Credential.new data
  end
end

#create(key_name) ⇒ Object

Create a key pair with the given ‘key_name’. Returns information about the new key.

key_name: A String containing a unique name for the key pair.



26
27
28
29
30
31
32
33
34
# File 'lib/nephophobia/resource/credential.rb', line 26

def create key_name
  params = {
    "KeyName" => key_name
  }

  response = @client.action "CreateKeyPair", params

  Response::Credential.new response.body['CreateKeyPairResponse']
end

#destroy(key_name) ⇒ Object

Deletes the key pair for the given ‘key_name’. Returns a response to the state change.

key_name: A String containing a unique name for the key pair.



57
58
59
60
61
62
63
64
65
# File 'lib/nephophobia/resource/credential.rb', line 57

def destroy key_name
  params = {
    "KeyName" => key_name
  }

  response = @client.action "DeleteKeyPair", params

  Response::Return.new response.body['DeleteKeyPairResponse']
end

#import_public_key(key_name, pubkey, fprint = nil) ⇒ Object

Import a key pair



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nephophobia/resource/credential.rb', line 39

def import_public_key key_name, pubkey, fprint=nil
  params = { 
    'KeyName' => key_name,
    'PublicKey' => pubkey
  }
  params.merge!( 'Fingerprint' => fprint ) unless fprint.nil?

  response = @client.action "ImportPublicKey", params

  Response::Credential.new response.body["ImportPublicKeyResponse"]['return']
end