Method: Fog::AWS::IAM::Mock#list_groups_for_user

Defined in:
lib/fog/aws/requests/iam/list_groups_for_user.rb

#list_groups_for_user(user_name, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/aws/requests/iam/list_groups_for_user.rb', line 41

def list_groups_for_user(user_name, options = {})
  #FIXME: Does not consider options
  if data[:users].key? user_name
    Excon::Response.new.tap do |response|
      response.status = 200
      response.body = { 'GroupsForUser' => data[:groups].select do |name, group|
                                             group[:members].include? user_name
                                           end.map do |name, group|
                                             { 'GroupId'   => group[:group_id],
                                               'GroupName' => name,
                                               'Path'      => group[:path],
                                               'Arn'       => (group[:arn]).strip }
                                           end,
                        'IsTruncated' => false,
                        'RequestId' => Fog::AWS::Mock.request_id
                      }
    end
  else
    raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
  end
end