2010-03-16 18:46:21 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
module EC2
|
|
|
|
class Real
|
2009-08-17 01:19:35 -04:00
|
|
|
|
|
|
|
# Describe all or specified key pairs
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * key_name<~Array>:: List of key names to describe, defaults to all
|
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-17 01:19:35 -04:00
|
|
|
# * 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 = [])
|
2010-01-31 17:07:26 -05:00
|
|
|
params = AWS.indexed_param('KeyName', key_name)
|
2009-08-17 01:19:35 -04:00
|
|
|
request({
|
2010-03-16 01:15:33 -04:00
|
|
|
'Action' => 'DescribeKeyPairs',
|
|
|
|
:parser => Fog::Parsers::AWS::EC2::DescribeKeyPairs.new
|
|
|
|
}.merge!(params))
|
2009-08-17 01:19:35 -04:00
|
|
|
end
|
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
|
2010-03-16 18:46:21 -04:00
|
|
|
class Mock
|
2009-08-17 01:19:35 -04:00
|
|
|
|
|
|
|
def describe_key_pairs(key_name = [])
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2009-08-20 22:25:52 -04:00
|
|
|
key_name = [*key_name]
|
2009-08-17 01:19:35 -04:00
|
|
|
if key_name != []
|
2010-03-16 18:46:21 -04:00
|
|
|
key_set = @data[:key_pairs].reject {|key, value| !key_name.include?(key)}.values
|
2009-08-17 01:19:35 -04:00
|
|
|
else
|
2010-03-16 18:46:21 -04:00
|
|
|
key_set = @data[:key_pairs].values
|
2009-08-17 01:19:35 -04:00
|
|
|
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))
|
2009-08-17 01:19:35 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|