Class: AWS::EC2::KeyPair
- Inherits:
-
Resource
- Object
- Core::Resource
- Resource
- AWS::EC2::KeyPair
- Defined in:
- lib/aws/ec2/key_pair.rb
Overview
Represents an EC2 key pair.
Instance Attribute Summary collapse
-
#fingerprint ⇒ String
readonly
A SHA-1 digest of the DER encoded private key.
-
#name ⇒ String
readonly
The name of the key pair.
Attributes included from Core::Model
Instance Method Summary collapse
-
#delete ⇒ true
Deletes this key pair from EC2.
-
#exists? ⇒ Boolean
True if the key pair exists.
-
#initialize(name, options = {}) ⇒ KeyPair
constructor
A new instance of KeyPair.
-
#private_key ⇒ String
Returns the private key.
Methods inherited from Core::Resource
attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from
Methods included from Core::Cacheable
Methods included from Core::Model
#client, #config_prefix, #inspect
Constructor Details
#initialize(name, options = {}) ⇒ KeyPair
Returns a new instance of KeyPair.
22 23 24 25 26 |
# File 'lib/aws/ec2/key_pair.rb', line 22 def initialize name, = {} @name = name.to_s @private_key = [:private_key] super end |
Instance Attribute Details
#fingerprint ⇒ String (readonly)
A SHA-1 digest of the DER encoded private key
20 21 22 |
# File 'lib/aws/ec2/key_pair.rb', line 20 def fingerprint @fingerprint end |
#name ⇒ String (readonly)
Returns The name of the key pair.
29 30 31 |
# File 'lib/aws/ec2/key_pair.rb', line 29 def name @name end |
Instance Method Details
#delete ⇒ true
Deletes this key pair from EC2.
65 66 67 68 |
# File 'lib/aws/ec2/key_pair.rb', line 65 def delete client.delete_key_pair(:key_name => name) true end |
#exists? ⇒ Boolean
Returns True if the key pair exists.
42 43 44 45 46 47 |
# File 'lib/aws/ec2/key_pair.rb', line 42 def exists? resp = client.describe_key_pairs(:filters => [ { :name => "key-name", :values => [name] } ]) !resp.key_set.empty? end |
#private_key ⇒ String
Note:
Only call this method on newly created keys.
Returns the private key. Raises an exception if called against an existing key. You can only get the private key at the time of creation.
56 57 58 59 60 61 |
# File 'lib/aws/ec2/key_pair.rb', line 56 def private_key unless @private_key raise 'you can only get the private key for just-created keypairs' end @private_key end |