From 242595e919ada988940d34512a575ea3172b03d3 Mon Sep 17 00:00:00 2001 From: Allan Date: Fri, 28 Jan 2011 10:11:15 +0800 Subject: [PATCH] Added IAM signing certificate support --- lib/fog/aws/iam.rb | 3 ++ .../parsers/iam/list_signing_certificates.rb | 32 +++++++++++++ .../parsers/iam/upload_signing_certificate.rb | 26 +++++++++++ .../iam/delete_signing_certificate.rb | 41 +++++++++++++++++ .../requests/iam/list_signing_certificates.rb | 46 +++++++++++++++++++ .../iam/upload_signing_certificate.rb | 46 +++++++++++++++++++ 6 files changed, 194 insertions(+) create mode 100644 lib/fog/aws/parsers/iam/list_signing_certificates.rb create mode 100644 lib/fog/aws/parsers/iam/upload_signing_certificate.rb create mode 100644 lib/fog/aws/requests/iam/delete_signing_certificate.rb create mode 100644 lib/fog/aws/requests/iam/list_signing_certificates.rb create mode 100644 lib/fog/aws/requests/iam/upload_signing_certificate.rb diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index 94033ee1e..bea78ec6a 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -13,18 +13,21 @@ module Fog request :delete_access_key request :delete_group request :delete_group_policy + request :delete_signing_certificate request :delete_user request :delete_user_policy request :get_user request :list_access_keys request :list_groups request :list_group_policies + request :list_signing_certificates request :list_user_policies request :list_users request :put_group_policy request :put_user_policy request :remove_user_from_group request :update_access_key + request :upload_signing_certificate class Mock diff --git a/lib/fog/aws/parsers/iam/list_signing_certificates.rb b/lib/fog/aws/parsers/iam/list_signing_certificates.rb new file mode 100644 index 000000000..845a16751 --- /dev/null +++ b/lib/fog/aws/parsers/iam/list_signing_certificates.rb @@ -0,0 +1,32 @@ +module Fog + module Parsers + module AWS + module IAM + + class ListSigningCertificates < Fog::Parsers::Base + + def reset + @signing_certificate = {} + @response = { 'SigningCertificates' => [] } + end + + def end_element(name) + case name + when 'UserName', 'CertificateId', 'CertificateBody', 'Status' + @signing_certificate[name] = @value + when 'member' + @response['SigningCertificates'] << @signing_certificate + @signing_certificate = {} + when 'IsTruncated' + response[name] = (@value == 'true') + when 'Marker', 'RequestId' + response[name] = @value + end + end + + end + end + end + end +end + diff --git a/lib/fog/aws/parsers/iam/upload_signing_certificate.rb b/lib/fog/aws/parsers/iam/upload_signing_certificate.rb new file mode 100644 index 000000000..17402ce18 --- /dev/null +++ b/lib/fog/aws/parsers/iam/upload_signing_certificate.rb @@ -0,0 +1,26 @@ +module Fog + module Parsers + module AWS + module IAM + + class UploadSigningCertificate < Fog::Parsers::Base + + def reset + @response = { 'Certificate' => {} } + end + + def end_element(name) + case name + when 'CertificateId', 'UserName', 'CertificateBody', 'Status' + @response['Certificate'][name] = @value + when 'RequestId' + @response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/requests/iam/delete_signing_certificate.rb b/lib/fog/aws/requests/iam/delete_signing_certificate.rb new file mode 100644 index 000000000..93dee4973 --- /dev/null +++ b/lib/fog/aws/requests/iam/delete_signing_certificate.rb @@ -0,0 +1,41 @@ +module Fog + module AWS + class IAM + class Real + + require 'fog/aws/parsers/iam/basic' + + # Upload signing certificate for user (by default detects user from access credentials) + # + # ==== Parameters + # * options<~Hash>: + # * 'UserName'<~String> - name of the user to upload certificate for (do not include path) + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'RequestId'<~String> - Id of the request + # + # ==== See Also + # http://docs.amazonwebservices.com/IAM/latest/APIReference/index.html?API_DeleteSigningCertificate.html + # + def delete_signing_certificate(certificate_id, options = {}) + request({ + 'Action' => 'DeleteSigningCertificate', + 'CertificateId' => certificate_id, + :parser => Fog::Parsers::AWS::IAM::Basic.new + }.merge!(options)) + end + + end + + class Mock + + def delete_signing_certificate(user_name = nil) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/iam/list_signing_certificates.rb b/lib/fog/aws/requests/iam/list_signing_certificates.rb new file mode 100644 index 000000000..f9e1db980 --- /dev/null +++ b/lib/fog/aws/requests/iam/list_signing_certificates.rb @@ -0,0 +1,46 @@ +module Fog + module AWS + class IAM + class Real + + require 'fog/aws/parsers/iam/list_signing_certificates' + + # List signing certificates for user (by default detects user from access credentials) + # + # ==== Parameters + # * options<~Hash>: + # * 'UserName'<~String> - name of the user to list certificates for (do not include path) + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'SigningCertificates'<~Array> - Matching signing certificates + # * signing_certificate<~Hash>: + # * CertificateId<~String> - + # * Status<~String> - + # * 'IsTruncated'<~Boolean> - Whether or not the results were truncated + # * 'Marker'<~String> - appears when IsTruncated is true as the next marker to use + # * 'RequestId'<~String> - Id of the request + # + # ==== See Also + # http://docs.amazonwebservices.com/IAM/latest/APIReference/index.html?API_ListSigningCertificates.html + # + def list_signing_certificates(options = {}) + request({ + 'Action' => 'ListSigningCertificates', + :parser => Fog::Parsers::AWS::IAM::ListSigningCertificates.new + }.merge!(options)) + end + + end + + class Mock + + def list_signing_certificates(user_name = nil) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/iam/upload_signing_certificate.rb b/lib/fog/aws/requests/iam/upload_signing_certificate.rb new file mode 100644 index 000000000..93dc2316a --- /dev/null +++ b/lib/fog/aws/requests/iam/upload_signing_certificate.rb @@ -0,0 +1,46 @@ +module Fog + module AWS + class IAM + class Real + + require 'fog/aws/parsers/iam/upload_signing_certificate' + + # Upload signing certificate for user (by default detects user from access credentials) + # + # ==== Parameters + # * options<~Hash>: + # * 'UserName'<~String> - name of the user to upload certificate for (do not include path) + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'Certificate'<~Hash>: + # * 'CertificateId'<~String> - + # * 'UserName'<~String> - + # * 'CertificateBody'<~String> - + # * 'Status'<~String> - + # * 'RequestId'<~String> - Id of the request + # + # ==== See Also + # http://docs.amazonwebservices.com/IAM/latest/APIReference/index.html?API_UploadSigningCertificate.html + # + def upload_signing_certificate(certificate, options = {}) + request({ + 'Action' => 'UploadSigningCertificate', + 'CertificateBody' => certificate, + :parser => Fog::Parsers::AWS::IAM::UploadSigningCertificate.new + }.merge!(options)) + end + + end + + class Mock + + def upload_signing_certificate(user_name = nil) + Fog::Mock.not_implemented + end + + end + end + end +end