mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|iam] fleshing out more parts towarda complete workflow
This commit is contained in:
parent
f171505a59
commit
6c82489ac9
15 changed files with 390 additions and 11 deletions
|
|
@ -5,9 +5,16 @@ module Fog
|
|||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
|
||||
request_path 'fog/aws/requests/iam'
|
||||
request :add_user_to_group
|
||||
request :create_group
|
||||
request :create_user
|
||||
request :delete_group
|
||||
request :delete_group_policy
|
||||
request :delete_user
|
||||
request :list_groups
|
||||
request :list_group_policies
|
||||
request :put_group_policy
|
||||
request :remove_user_from_group
|
||||
|
||||
class Mock
|
||||
|
||||
|
|
@ -36,6 +43,7 @@ module Fog
|
|||
# ==== Returns
|
||||
# * IAM object with connection to AWS.
|
||||
def initialize(options={})
|
||||
require 'json'
|
||||
@aws_access_key_id = options[:aws_access_key_id]
|
||||
@aws_secret_access_key = options[:aws_secret_access_key]
|
||||
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
module AWS
|
||||
module IAM
|
||||
|
||||
class CreateGroups < Fog::Parsers::Base
|
||||
class CreateGroup < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'Group' => {} }
|
||||
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
when 'Arn', 'GroupId', 'GroupName', 'Path'
|
||||
@response['Group'][name] = @value
|
||||
when 'RequestId'
|
||||
response[name] = @value
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
26
lib/fog/aws/parsers/iam/create_user.rb
Normal file
26
lib/fog/aws/parsers/iam/create_user.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module IAM
|
||||
|
||||
class CreateUser < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'User' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Arn', 'UserId', 'UserName', 'Path'
|
||||
@response['User'][name] = @value
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
28
lib/fog/aws/parsers/iam/list_group_policies.rb
Normal file
28
lib/fog/aws/parsers/iam/list_group_policies.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module IAM
|
||||
|
||||
class ListGroups < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'PolicyNames' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'member'
|
||||
@response['PolicyNames'] << @value
|
||||
when 'IsTruncated'
|
||||
response[name] = (@value == 'true')
|
||||
when 'Marker', 'RequestId'
|
||||
response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -19,7 +19,7 @@ module Fog
|
|||
@group = {}
|
||||
when 'IsTruncated'
|
||||
response[name] = (@value == 'true')
|
||||
when 'RequestId'
|
||||
when 'Marker', 'RequestId'
|
||||
response[name] = @value
|
||||
end
|
||||
end
|
||||
|
|
|
|||
42
lib/fog/aws/requests/iam/add_user_to_group.rb
Normal file
42
lib/fog/aws/requests/iam/add_user_to_group.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/basic'
|
||||
|
||||
# Add a user to a group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * group_name<~String>: name of the group
|
||||
# * user_name<~String>: name of user to add
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_AddUserToGroup.html
|
||||
#
|
||||
def add_user_to_group(group_name, user_name)
|
||||
request(
|
||||
'Action' => 'AddUserToGroup',
|
||||
'GroupName' => group_name,
|
||||
'UserName' => user_name,
|
||||
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def add_user_to_group(group_name, user_name)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -8,8 +8,8 @@ module Fog
|
|||
# Create a new group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'GroupName'<~String>: name of the group to create (do not include path)
|
||||
# * 'Path'<~String>: optional path to group, defaults to '/'
|
||||
# * group_name<~String>: name of the group to create (do not include path)
|
||||
# * path<~String>: optional path to group, defaults to '/'
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
|
@ -20,12 +20,16 @@ module Fog
|
|||
# * GroupName<~String> -
|
||||
# * Path<~String> -
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_CreateGroup.html
|
||||
#
|
||||
def create_group(group_name, path = '/')
|
||||
request(
|
||||
'Action' => 'CreateGroup',
|
||||
'GroupName' => group_name,
|
||||
'Path' => path,
|
||||
:parser => Fog::Parsers::AWS::IAM::CreateGroups.new
|
||||
:parser => Fog::Parsers::AWS::IAM::CreateGroup.new
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
47
lib/fog/aws/requests/iam/create_user.rb
Normal file
47
lib/fog/aws/requests/iam/create_user.rb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/create_user'
|
||||
|
||||
# Create a new user
|
||||
#
|
||||
# ==== Parameters
|
||||
# * user_name<~String>: name of the user to create (do not include path)
|
||||
# * path<~String>: optional path to group, defaults to '/'
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'User'<~Hash>:
|
||||
# * Arn<~String> -
|
||||
# * GroupId<~String> -
|
||||
# * GroupName<~String> -
|
||||
# * Path<~String> -
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_CreateUser.html
|
||||
#
|
||||
def create_user(user_name, path = '/')
|
||||
request(
|
||||
'Action' => 'CreateUser',
|
||||
'UserName' => user_name,
|
||||
'Path' => path,
|
||||
:parser => Fog::Parsers::AWS::IAM::CreateUser.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_user(user_name, path = '/')
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -8,12 +8,16 @@ module Fog
|
|||
# Delete a group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'GroupName'<~String>: name of the group to delete
|
||||
# * group_name<~String>: name of the group to delete
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteGroup.html
|
||||
#
|
||||
def delete_group(group_name)
|
||||
request(
|
||||
'Action' => 'DeleteGroup',
|
||||
|
|
|
|||
42
lib/fog/aws/requests/iam/delete_group_policy.rb
Normal file
42
lib/fog/aws/requests/iam/delete_group_policy.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/basic'
|
||||
|
||||
# Remove a policy from a group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * group_name<~String>: name of the group
|
||||
# * policy_name<~String>: name of policy document
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of the request def put_group_policy(group_name, path = '/')
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteGroupPolicy.html
|
||||
#
|
||||
def delete_group_policy(group_name, policy_name)
|
||||
request(
|
||||
'Action' => 'DeleteGroupPolicy',
|
||||
'GroupName' => group_name,
|
||||
'PolicyName' => policy_name,
|
||||
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def delete_group_policy(group_name, policy_name)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
40
lib/fog/aws/requests/iam/delete_user.rb
Normal file
40
lib/fog/aws/requests/iam/delete_user.rb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/basic'
|
||||
|
||||
# Delete a user
|
||||
#
|
||||
# ==== Parameters
|
||||
# * user_name<~String>: name of the user to delete
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteUser.html
|
||||
#
|
||||
def delete_user(user_name)
|
||||
request(
|
||||
'Action' => 'DeleteUser',
|
||||
'UserName' => user_name,
|
||||
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def delete_user(user_name)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
47
lib/fog/aws/requests/iam/list_group_policies.rb
Normal file
47
lib/fog/aws/requests/iam/list_group_policies.rb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/list_group_policies'
|
||||
|
||||
# List policies for a group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * group_name<~String> - Name of group to list policies for
|
||||
# * options<~Hash>: Optional
|
||||
# * 'Marker'<~String>: used to paginate subsequent requests
|
||||
# * 'MaxItems'<~Integer>: limit results to this number per page
|
||||
# * 'PathPrefix'<~String>: prefix for filtering results
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'PolicyNames'<~Array> - Matching policy names
|
||||
# * 'IsTruncated<~Boolean> - Whether or not 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/API_ListGroupPolicies.html
|
||||
#
|
||||
def list_group_policies(group_name, options = {})
|
||||
request({
|
||||
'Action' => 'ListGroupPolicies',
|
||||
'GroupName' => group_name,
|
||||
:parser => Fog::Parsers::AWS::IAM::ListGroupPolicies.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_group_policies(group_name, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -23,19 +23,24 @@ module Fog
|
|||
# * GroupName<~String> -
|
||||
# * Path<~String> -
|
||||
# * 'IsTruncated<~Boolean> - Whether or not results were truncated
|
||||
# * 'Marker'<~String> - appears when IsTruncated is true as the next marker to use
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
def list_groups
|
||||
request(
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_ListGroups.html
|
||||
#
|
||||
def list_groups(options = {})
|
||||
request({
|
||||
'Action' => 'ListGroups',
|
||||
:parser => Fog::Parsers::AWS::IAM::ListGroups.new
|
||||
)
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_groups
|
||||
def list_groups(options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
|
|
|
|||
44
lib/fog/aws/requests/iam/put_group_policy.rb
Normal file
44
lib/fog/aws/requests/iam/put_group_policy.rb
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/basic'
|
||||
|
||||
# Add or update a policy for a group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * group_name<~String>: name of the group
|
||||
# * policy_name<~String>: name of policy document
|
||||
# * policy_document<~Hash>: policy document, see: http://docs.amazonwebservices.com/IAM/latest/UserGuide/PoliciesOverview.html
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of the request def put_group_policy(group_name, path = '/')
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_PutGroupPolicy.html
|
||||
#
|
||||
def put_group_policy(group_name, policy_name, policy_document)
|
||||
request(
|
||||
'Action' => 'PutGroupPolicy',
|
||||
'GroupName' => group_name,
|
||||
'PolicyName' => policy_name,
|
||||
'PolicyDocument' => policy_document.to_json,
|
||||
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def put_group_policy(group_name, policy_name, policy_document)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
42
lib/fog/aws/requests/iam/remove_user_from_group.rb
Normal file
42
lib/fog/aws/requests/iam/remove_user_from_group.rb
Normal 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
|
||||
# * group_name<~String>: name of the group
|
||||
# * user_name<~String>: name of user to remove
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_RemoveUserFromGroup.html
|
||||
#
|
||||
def remove_user_from_group(group_name, user_name)
|
||||
request(
|
||||
'Action' => 'RemoveUserFromGroup',
|
||||
'GroupName' => group_name,
|
||||
'UserName' => user_name,
|
||||
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def remove_user_from_group(group_name, user_name)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue