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/aws/requests/ec2/create_key_pair.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

2010-03-16 18:46:21 -04:00
module Fog
module AWS
module EC2
class Real
# Create a new key pair
#
# ==== Parameters
# * key_name<~String> - Unique name for key pair.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'keyFingerprint'<~String> - SHA-1 digest of DER encoded private key
# * 'keyMaterial'<~String> - Unencrypted encoded PEM private key
# * 'keyName'<~String> - Name of key
# * 'requestId'<~String> - Id of request
def create_key_pair(key_name)
request(
'Action' => 'CreateKeyPair',
'KeyName' => key_name,
:parser => Fog::Parsers::AWS::EC2::CreateKeyPair.new
)
end
end
2010-03-16 18:46:21 -04:00
class Mock
def create_key_pair(key_name)
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
2010-03-16 18:46:21 -04:00
unless @data[:key_pairs][key_name]
response.status = 200
data = {
'keyFingerprint' => Fog::AWS::Mock.key_fingerprint,
'keyMaterial' => Fog::AWS::Mock.key_material,
'keyName' => key_name
}
2010-03-16 18:46:21 -04:00
@data[:key_pairs][key_name] = data
response.body = {
'requestId' => Fog::AWS::Mock.request_id
}.merge!(data)
else
response.status = 400
2009-11-20 14:08:08 -05:00
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
end
end
end
end