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/describe_key_pairs.rb

57 lines
1.7 KiB
Ruby
Raw Normal View History

2010-03-16 18:46:21 -04:00
module Fog
module AWS
module EC2
class Real
# Describe all or specified key pairs
#
# ==== Parameters
# * key_name<~Array>:: List of key names to describe, defaults to all
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'keySet'<~Array>:
# * 'keyName'<~String> - Name of key
# * 'keyFingerprint'<~String> - Fingerprint of key
def describe_key_pairs(key_name = [])
params = AWS.indexed_param('KeyName', key_name)
request({
'Action' => 'DescribeKeyPairs',
:parser => Fog::Parsers::AWS::EC2::DescribeKeyPairs.new
}.merge!(params))
end
end
2010-03-16 18:46:21 -04:00
class Mock
def describe_key_pairs(key_name = [])
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
key_name = [*key_name]
if key_name != []
2010-03-16 18:46:21 -04:00
key_set = @data[:key_pairs].reject {|key, value| !key_name.include?(key)}.values
else
2010-03-16 18:46:21 -04:00
key_set = @data[:key_pairs].values
end
if key_name.length == 0 || key_name.length == key_set.length
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'keySet' => key_set.map do |key|
key.reject {|key,value| !['keyFingerprint', 'keyName'].include?(key)}
end
}
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