1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/compute/requests/aws/import_key_pair.rb

57 lines
1.8 KiB
Ruby
Raw Normal View History

module Fog
module Compute
class AWS
class Real
2011-01-07 19:52:09 -05:00
require 'fog/compute/parsers/aws/import_key_pair'
# Import an existing public key to create a new key pair
#
# ==== Parameters
# * key_name<~String> - Unique name for key pair.
# * public_key_material<~String> - RSA public key
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'keyFingerprint'<~String> - SHA-1 digest of DER encoded private key
# * 'keyName'<~String> - Name of key
# * 'requestId'<~String> - Id of request
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ImportKeyPair.html]
def import_key_pair(key_name, public_key_material)
request(
'Action' => 'ImportKeyPair',
'KeyName' => key_name,
'PublicKeyMaterial' => Base64::encode64(public_key_material),
:parser => Fog::Parsers::Compute::AWS::ImportKeyPair.new
)
end
end
class Mock
def import_key_pair(key_name, public_key_material)
response = Excon::Response.new
2011-05-19 18:35:33 -04:00
unless self.data[:key_pairs][key_name]
response.status = 200
data = {
'keyFingerprint' => Fog::AWS::Mock.key_fingerprint,
'keyName' => key_name
}
2011-05-19 18:35:33 -04:00
self.data[:key_pairs][key_name] = data
response.body = {
'requestId' => Fog::AWS::Mock.request_id
}.merge!(data)
response
else
raise Fog::Compute::AWS::Error.new("InvalidKeyPair.Duplicate => The keypair '#{key_name}' already exists.")
end
end
end
end
end
end