Class: Fog::Compute::AWS::KeyPair
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::AWS::KeyPair
- Defined in:
- lib/fog/aws/models/compute/key_pair.rb
Instance Attribute Summary collapse
-
#public_key ⇒ Object
Returns the value of attribute public_key.
Instance Method Summary collapse
- #destroy ⇒ Object
- #save ⇒ Object
- #writable? ⇒ Boolean
- #write(path = "#{ENV['HOME']}/.ssh/fog_#{Fog.credential.to_s}_#{name}.pem") ⇒ Object
Instance Attribute Details
#public_key ⇒ Object
Returns the value of attribute public_key.
12 13 14 |
# File 'lib/fog/aws/models/compute/key_pair.rb', line 12 def public_key @public_key end |
Instance Method Details
#destroy ⇒ Object
14 15 16 17 18 19 |
# File 'lib/fog/aws/models/compute/key_pair.rb', line 14 def destroy requires :name service.delete_key_pair(name) true end |
#save ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/aws/models/compute/key_pair.rb', line 21 def save requires :name data = if public_key service.import_key_pair(name, public_key).body else service.create_key_pair(name).body end new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)} merge_attributes(new_attributes) true end |
#writable? ⇒ Boolean
47 48 49 |
# File 'lib/fog/aws/models/compute/key_pair.rb', line 47 def writable? !!(private_key && ENV.key?('HOME')) end |
#write(path = "#{ENV['HOME']}/.ssh/fog_#{Fog.credential.to_s}_#{name}.pem") ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fog/aws/models/compute/key_pair.rb', line 34 def write(path="#{ENV['HOME']}/.ssh/fog_#{Fog.credential.to_s}_#{name}.pem") if writable? split_private_key = private_key.split(/\n/) File.open(path, "w") do |f| split_private_key.each {|line| f.puts line} f.chmod 0600 end "Key file built: #{path}" else "Invalid private key" end end |