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

Expanding IAM support

Adding:
* Create/Delete Policy Versions
* Set Default Policy Version
* Add Update Assume Role Policy
This commit is contained in:
Jack Thomas 2016-07-11 13:24:53 +01:00
parent fbfba3dd14
commit ae856e304f
5 changed files with 191 additions and 0 deletions

View file

@ -24,6 +24,7 @@ module Fog
request :create_instance_profile
request :create_login_profile
request :create_policy
request :create_policy_version
request :create_role
request :create_user
request :delete_access_key
@ -34,6 +35,7 @@ module Fog
request :delete_instance_profile
request :delete_login_profile
request :delete_policy
request :delete_policy_version
request :delete_role
request :delete_role_policy
request :delete_server_certificate
@ -78,10 +80,12 @@ module Fog
request :put_user_policy
request :remove_role_from_instance_profile
request :remove_user_from_group
request :set_default_policy_version
request :update_access_key
request :update_group
request :update_login_profile
request :update_account_password_policy
request :update_assume_role_policy
request :update_server_certificate
request :update_signing_certificate
request :update_user

View file

@ -0,0 +1,63 @@
module Fog
module AWS
class IAM
class Real
require 'fog/aws/parsers/iam/policy_version'
# Creates a managed policy
#
# ==== Parameters
# * policy_arn<~String>: arn of the policy
# * policy_document<~Hash>: policy document, see: http://docs.amazonwebservices.com/IAM/latest/UserGuide/PoliciesOverview.html
# * set_as_default<~Boolean>: sets policy to default version
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'RequestId'<~String> - Id of the request
# * 'PolicyVersion'<~Array>:
# * CreateDate<~DateTime> The date and time, in ISO 8601 date-time format, when the policy version was created.
# * Document<~String> The policy document. Pattern: [\u0009\u000A\u000D\u0020-\u00FF]+
# * IsDefaultVersion<~String> Specifies whether the policy version is set as the policy's default version.
# * VersionId<~String> The identifier for the policy version.
# ==== See Also
# http://docs.aws.amazon.com/IAM/latest/APIReference/API_CreatePolicyVersion.html
#
def create_policy_version(policy_arn, policy_document, set_as_default=true)
request({
'Action' => 'CreatePolicyVersion',
'PolicyArn' => policy_name,
'PolicyDocument' => Fog::JSON.encode(policy_document),
'SetAsDefault' => set_as_default,
:parser => Fog::Parsers::AWS::IAM::PolicyVersion.new
}.reject {|_, value| value.nil?})
end
end
class Mock
def create_policy_version(policy_arn, policy_document, set_as_default=true)
managed_policy_versions = self.data[:managed_policy_versions][policy_arn]
unless managed_policy_versions
raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} version #{version_id} does not exist."
end
version = managed_policy_versions[version_id]
unless version
raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} version #{version_id} does not exist."
end
Excon::Response.new.tap do |response|
response.body = {
'PolicyVersion' => version,
'RequestId' => Fog::AWS::Mock.request_id
}
response.status = 200
end
end
end
end
end
end

View file

@ -0,0 +1,41 @@
module Fog
module AWS
class IAM
class Real
require 'fog/aws/parsers/iam/basic'
# Deletes a manged policy
#
# ==== Parameters
# * policy_arn<~String>: arn of the policy
# * version_id<~String>: version of policy to delete
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'RequestId'<~String> - Id of the request
#
# ==== See Also
# http://docs.aws.amazon.com/IAM/latest/APIReference/API_DeletePolicyVersion.html
#
def delete_policy(policy_arn, version_id)
request(
'Action' => 'DeletePolicyVersion',
'PolicyArn' => policy_arn,
'VersionId' => version_id,
:parser => Fog::Parsers::AWS::IAM::Basic.new
)
end
class Mock
def delete_policy(policy_arn, version_id)
Excon::Response.new.tap do |response|
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
end
end
end
end
end
end

View file

@ -0,0 +1,42 @@
module Fog
module AWS
class IAM
class Real
require 'fog/aws/parsers/iam/basic'
# Remove a user from a group
#
# ==== Parameters
# * policy_arn<~String>: arn of the policy
# * version_id<~String>: version of policy to delete
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'RequestId'<~String> - Id of the request
#
# ==== See Also
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_SetDefaultPolicyVersion.html
#
def set_default_policy_version(policy_arn, version_id)
request(
'Action' => 'SetDefaultPolicyVersion',
'PolicyArn' => policy_arn,
'VersionId' => version_id,
:parser => Fog::Parsers::AWS::IAM::Basic.new
)
end
end
class Mock
def set_default_policy_version(policy_arn, version_id)
Excon::Response.new.tap do |response|
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
end
end
end
end
end

View file

@ -0,0 +1,41 @@
module Fog
module AWS
class IAM
class Real
require 'fog/aws/parsers/iam/basic'
# Creates a managed policy
#
# ==== Parameters
# * policy_document<~Hash>: policy document, see: http://docs.amazonwebservices.com/IAM/latest/UserGuide/PoliciesOverview.html
# * role_name<~String>: name of role to update
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'RequestId'<~String> - Id of the request
#
# ==== See Also
# http://docs.aws.amazon.com/IAM/latest/APIReference/API_UpdateAssumeRolePolicy.html
#
def update_assume_role_policy(policy_document, role_name)
request({
'Action' => 'UpdateAssumeRolePolicy',
'PolicyDocument' => Fog::JSON.encode(policy_document),
'RoleName' => policy_name,
:parser => Fog::Parsers::AWS::IAM::Basic.new
}.reject {|_, value| value.nil?})
end
class Mock
def update_assume_role_policy(policy_document, role_name)
Excon::Response.new.tap do |response|
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
end
end
end
end
end
end