1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|iam] add get_server_certificate request

This commit is contained in:
Blake Gentry 2011-07-18 17:04:40 -07:00
parent 1f717648c2
commit 773ba300d0
3 changed files with 59 additions and 1 deletions

View file

@ -31,6 +31,7 @@ module Fog
request :get_user_policy
request :get_group
request :get_group_policy
request :get_server_certificate
request :list_access_keys
request :list_account_aliases
request :list_groups
@ -152,7 +153,7 @@ module Fog
rescue Excon::Errors::HTTPStatusError => error
if match = error.message.match(/<Code>(.*)<\/Code>(?:.*<Message>(.*)<\/Message>)?/m)
case match[1]
when 'CertificateNotFound'
when 'CertificateNotFound', 'NoSuchEntity'
raise Fog::AWS::IAM::NotFound.slurp(error, match[2])
when 'EntityAlreadyExists'
raise Fog::AWS::IAM::EntityAlreadyExists.slurp(error, match[2])

View file

@ -0,0 +1,50 @@
module Fog
module AWS
class IAM
class Real
require 'fog/aws/parsers/iam/upload_server_certificate'
# Gets the specified server certificate.
#
# ==== Parameters
# * server_certificate_name<~String>: The name of the server certificate you want to get.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'RequestId'<~String> - Id of the request
#
# ==== See Also
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetServerCertificate.html
#
def get_server_certificate(server_certificate_name)
request({
'Action' => 'GetServerCertificate',
'ServerCertificateName' => server_certificate_name,
:parser => Fog::Parsers::AWS::IAM::UploadServerCertificate.new
})
end
end
class Mock
def get_server_certificate(server_certificate_name)
raise Fog::AWS::IAM::NotFound unless self.data[:server_certificates].key?(server_certificate_name)
response = Excon::Response.new
response.status = 200
response.body = {
'Certificate' => self.data[:server_certificates][server_certificate_name],
'RequestId' => Fog::AWS::Mock.request_id
}
self.data[:server_certificates]
response
end
end
end
end
end

View file

@ -19,6 +19,13 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
AWS[:iam].upload_server_certificate(public_key, private_key, @key_name).body
end
tests('#get_server_certificate').formats(@upload_format) do
tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do
AWS[:iam].get_server_certificate("#{@key_name}fake")
end
AWS[:iam].get_server_certificate(@key_name).body
end
@list_format = { 'Certificates' => [@certificate_format] }
tests('#list_server_certificates').formats(@list_format) do
result = AWS[:iam].list_server_certificates.body