Class: Fog::AWS::IAM::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/iam.rb,
lib/fog/aws/requests/iam/create_user.rb,
lib/fog/aws/requests/iam/delete_user.rb,
lib/fog/aws/requests/iam/list_groups.rb,
lib/fog/aws/requests/iam/create_group.rb,
lib/fog/aws/requests/iam/delete_group.rb,
lib/fog/aws/requests/iam/put_group_policy.rb,
lib/fog/aws/requests/iam/add_user_to_group.rb,
lib/fog/aws/requests/iam/delete_group_policy.rb,
lib/fog/aws/requests/iam/list_group_policies.rb,
lib/fog/aws/requests/iam/remove_user_from_group.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Initialize connection to IAM

Notes

options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection

Examples

iam = IAM.new(
 :aws_access_key_id => your_aws_access_key_id,
 :aws_secret_access_key => your_aws_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

Returns

  • IAM object with connection to AWS.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/aws/iam.rb', line 45

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)
  @host       = options[:host]      || 'iam.amazonaws.com'
  @path       = options[:path]      || '/'
  @port       = options[:port]      || 443
  @scheme     = options[:scheme]    || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
end

Instance Method Details

#add_user_to_group(group_name, user_name) ⇒ Object

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

docs.amazonwebservices.com/IAM/latest/APIReference/API_AddUserToGroup.html



22
23
24
25
26
27
28
29
# File 'lib/fog/aws/requests/iam/add_user_to_group.rb', line 22

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

#create_group(group_name, path = '/') ⇒ Object

Create a new group

Parameters

  • 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>:

    • body<~Hash>:

      • ‘Group’<~Hash>:

        • Arn<~String> -

        • GroupId<~String> -

        • GroupName<~String> -

        • Path<~String> -

      • ‘RequestId’<~String> - Id of the request

See Also

docs.amazonwebservices.com/IAM/latest/APIReference/API_CreateGroup.html



27
28
29
30
31
32
33
34
# File 'lib/fog/aws/requests/iam/create_group.rb', line 27

def create_group(group_name, path = '/')
  request(
    'Action'    => 'CreateGroup',
    'GroupName' => group_name,
    'Path'      => path,
    :parser     => Fog::Parsers::AWS::IAM::CreateGroup.new
  )
end

#create_user(user_name, path = '/') ⇒ Object

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

docs.amazonwebservices.com/IAM/latest/APIReference/API_CreateUser.html



27
28
29
30
31
32
33
34
# File 'lib/fog/aws/requests/iam/create_user.rb', line 27

def create_user(user_name, path = '/')
  request(
    'Action'    => 'CreateUser',
    'UserName'  => user_name,
    'Path'      => path,
    :parser     => Fog::Parsers::AWS::IAM::CreateUser.new
  )
end

#delete_group(group_name) ⇒ Object

Delete a group

Parameters

  • group_name<~String>: name of the group to delete

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request

See Also

docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteGroup.html



21
22
23
24
25
26
27
# File 'lib/fog/aws/requests/iam/delete_group.rb', line 21

def delete_group(group_name)
  request(
    'Action'    => 'DeleteGroup',
    'GroupName' => group_name,
    :parser     => Fog::Parsers::AWS::IAM::Basic.new
  )
end

#delete_group_policy(group_name, policy_name) ⇒ Object

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

docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteGroupPolicy.html



22
23
24
25
26
27
28
29
# File 'lib/fog/aws/requests/iam/delete_group_policy.rb', line 22

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

#delete_user(user_name) ⇒ Object

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

docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteUser.html



21
22
23
24
25
26
27
# File 'lib/fog/aws/requests/iam/delete_user.rb', line 21

def delete_user(user_name)
  request(
    'Action'    => 'DeleteUser',
    'UserName'  => user_name,
    :parser     => Fog::Parsers::AWS::IAM::Basic.new
  )
end

#list_group_policies(group_name, options = {}) ⇒ Object

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

docs.amazonwebservices.com/IAM/latest/APIReference/API_ListGroupPolicies.html



28
29
30
31
32
33
34
# File 'lib/fog/aws/requests/iam/list_group_policies.rb', line 28

def list_group_policies(group_name, options = {})
  request({
    'Action'    => 'ListGroupPolicies',
    'GroupName' => group_name,
    :parser     => Fog::Parsers::AWS::IAM::ListGroupPolicies.new
  }.merge!(options))
end

#list_groups(options = {}) ⇒ Object

List groups

Parameters

  • options<~Hash>:

    • ‘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>:

      • ‘Groups’<~Array> - Matching groups

        • group<~Hash>:

          • Arn<~String> -

          • GroupId<~String> -

          • 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

See Also

docs.amazonwebservices.com/IAM/latest/APIReference/API_ListGroups.html



32
33
34
35
36
37
# File 'lib/fog/aws/requests/iam/list_groups.rb', line 32

def list_groups(options = {})
  request({
    'Action'  => 'ListGroups',
    :parser   => Fog::Parsers::AWS::IAM::ListGroups.new
  }.merge!(options))
end

#put_group_policy(group_name, policy_name, policy_document) ⇒ Object

Add or update a policy for a group

Parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘RequestId’<~String> - Id of the request def put_group_policy(group_name, path = ‘/’)

See Also

docs.amazonwebservices.com/IAM/latest/APIReference/API_PutGroupPolicy.html



23
24
25
26
27
28
29
30
31
# File 'lib/fog/aws/requests/iam/put_group_policy.rb', line 23

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

#reloadObject



57
58
59
# File 'lib/fog/aws/iam.rb', line 57

def reload
  @connection.reset
end

#remove_user_from_group(group_name, user_name) ⇒ Object

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

docs.amazonwebservices.com/IAM/latest/APIReference/API_RemoveUserFromGroup.html



22
23
24
25
26
27
28
29
# File 'lib/fog/aws/requests/iam/remove_user_from_group.rb', line 22

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