From a8378ebfc6b48aaef22001fe96731faf4550d701 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Sun, 16 Feb 2014 22:27:02 -0400 Subject: [PATCH] [aws|iam] Add get_account_summary. --- lib/fog/aws/iam.rb | 1 + .../aws/parsers/iam/get_account_summary.rb | 46 +++++++++++ .../aws/requests/iam/get_account_summary.rb | 80 +++++++++++++++++++ tests/aws/requests/iam/account_tests.rb | 34 ++++++++ 4 files changed, 161 insertions(+) create mode 100644 lib/fog/aws/parsers/iam/get_account_summary.rb create mode 100644 lib/fog/aws/requests/iam/get_account_summary.rb create mode 100644 tests/aws/requests/iam/account_tests.rb diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index 8ffb81d76..d9693f061 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -35,6 +35,7 @@ module Fog request :delete_signing_certificate request :delete_user request :delete_user_policy + request :get_account_summary request :get_group request :get_group_policy request :get_instance_profile diff --git a/lib/fog/aws/parsers/iam/get_account_summary.rb b/lib/fog/aws/parsers/iam/get_account_summary.rb new file mode 100644 index 000000000..2d10fd969 --- /dev/null +++ b/lib/fog/aws/parsers/iam/get_account_summary.rb @@ -0,0 +1,46 @@ +module Fog + module Parsers + module AWS + module IAM + + class GetAccountSummary < Fog::Parsers::Base + + def reset + super + @stack = [] + @response = {'Summary' => {}} + end + + def start_element(name, attrs = []) + super + case name + when 'SummaryMap' + @stack << name + end + end + + def end_element(name) + case name + when 'SummaryMap' + @stack.pop + when 'key' + if @stack.last == 'SummaryMap' + @key = value + end + when 'value' + if @stack.last == 'SummaryMap' + @response['Summary'][@key] = value.strip.to_i + end + when 'RequestId' + if @stack.empty? + @response['RequestId'] = value.strip + end + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/requests/iam/get_account_summary.rb b/lib/fog/aws/requests/iam/get_account_summary.rb new file mode 100644 index 000000000..6a650162c --- /dev/null +++ b/lib/fog/aws/requests/iam/get_account_summary.rb @@ -0,0 +1,80 @@ +module Fog + module AWS + class IAM + class Real + + require 'fog/aws/parsers/iam/get_account_summary' + + # Retrieve account level information about account entity usage and IAM quotas + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'Summary'<~Hash>: + # * 'AccessKeysPerUserQuota'<~Integer> - Maximum number of access keys that can be created per user + # * 'AccountMFAEnabled'<~Integer> - 1 if the root account has an MFA device assigned to it, 0 otherwise + # * 'AssumeRolePolicySizeQuota'<~Integer> - Maximum allowed size for assume role policy documents (in kilobytes) + # * 'GroupPolicySizeQuota'<~Integer> - Maximum allowed size for Group policy documents (in kilobytes) + # * 'Groups'<~Integer> - Number of Groups for the AWS account + # * 'GroupsPerUserQuota'<~Integer> - Maximum number of groups a user can belong to + # * 'GroupsQuota'<~Integer> - Maximum groups allowed for the AWS account + # * 'InstanceProfiles'<~Integer> - Number of instance profiles for the AWS account + # * 'InstanceProfilesQuota'<~Integer> - Maximum instance profiles allowed for the AWS account + # * 'MFADevices'<~Integer> - Number of MFA devices, either assigned or unassigned + # * 'MFADevicesInUse'<~Integer> - Number of MFA devices that have been assigned to an IAM user or to the root account + # * 'Providers'<~Integer> - + # * 'RolePolicySizeQuota'<~Integer> - Maximum allowed size for role policy documents (in kilobytes) + # * 'Roles'<~Integer> - Number of roles for the AWS account + # * 'RolesQuota'<~Integer> - Maximum roles allowed for the AWS account + # * 'ServerCertificates'<~Integer> - Number of server certificates for the AWS account + # * 'ServerCertificatesQuota'<~Integer> - Maximum server certificates allowed for the AWS account + # * 'SigningCertificatesPerUserQuota'<~Integer> - Maximum number of X509 certificates allowed for a user + # * 'UserPolicySizeQuota'<~Integer> - Maximum allowed size for user policy documents (in kilobytes) + # * 'Users'<~Integer> - Number of users for the AWS account + # * 'UsersQuota'<~Integer> - Maximum users allowed for the AWS account + # * 'RequestId'<~String> - Id of the request + # + # ==== See Also + # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_CreateAccessKey.html + # + def get_account_summary + request( + 'Action' => 'GetAccountSummary', + :parser => Fog::Parsers::AWS::IAM::GetAccountSummary.new + ) + end + + end + + class Mock + + def get_account_summary + Excon::Response.new.tap do |response| + response.status = 200 + response.body = { + 'Summary' => { + 'AccessKeysPerUserQuota' => 2, + 'AccountMFAEnabled' => 0, + 'GroupPolicySizeQuota' => 10240, + 'Groups' => 31, + 'GroupsPerUserQuota' => 10, + 'GroupsQuota' => 50, + 'MFADevices' => 20, + 'MFADevicesInUse' => 10, + 'ServerCertificates' => 5, + 'ServerCertificatesQuota' => 10, + 'SigningCertificatesPerUserQuota' => 2, + 'UserPolicySizeQuota' => 10240, + 'Users' => 35, + 'UsersQuota' => 150, + }, + 'RequestId' => Fog::AWS::Mock.request_id + } + end + end + + end + + end + end +end diff --git a/tests/aws/requests/iam/account_tests.rb b/tests/aws/requests/iam/account_tests.rb new file mode 100644 index 000000000..6cad2e7a4 --- /dev/null +++ b/tests/aws/requests/iam/account_tests.rb @@ -0,0 +1,34 @@ +Shindo.tests('AWS::IAM | account requests', ['aws']) do + tests('success') do + @get_account_summary_format = { + 'Summary' => { + 'AccessKeysPerUserQuota' => Integer, + 'AccountMFAEnabled' => Integer, + 'AssumeRolePolicySizeQuota' => Fog::Nullable::Integer, + 'GroupPolicySizeQuota' => Integer, + 'Groups' => Integer, + 'GroupsPerUserQuota' => Integer, + 'GroupsQuota' => Integer, + 'InstanceProfiles' => Fog::Nullable::Integer, + 'InstanceProfilesQuota' => Fog::Nullable::Integer, + 'MFADevices' => Integer, + 'MFADevicesInUse' => Integer, + 'Providers' => Fog::Nullable::Integer, + 'RolePolicySizeQuota' => Fog::Nullable::Integer, + 'Roles' => Fog::Nullable::Integer, + 'RolesQuota' => Fog::Nullable::Integer, + 'ServerCertificates' => Integer, + 'ServerCertificatesQuota' => Integer, + 'SigningCertificatesPerUserQuota' => Integer, + 'UserPolicySizeQuota' => Integer, + 'Users' => Integer, + 'UsersQuota' => Integer, + }, + 'RequestId' => String, + } + + tests('#get_account_summary').formats(@get_account_summary_format) do + Fog::AWS[:iam].get_account_summary.body + end + end +end