Class: Fog::AWS::IAM::Group

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/iam/group.rb

Instance Method Summary collapse

Instance Method Details

#add_user(user_or_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/aws/models/iam/group.rb', line 13

def add_user(user_or_name)
  requires :name

  user = if user_or_name.is_a?(Fog::AWS::IAM::User)
           user_or_name
         else
           service.users.new(:id => user_or_name)
         end

  service.add_user_to_group(self.name, user.identity)
  merge_attributes(:users => self.users + [user])
end

#attach(policy_or_arn) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/aws/models/iam/group.rb', line 26

def attach(policy_or_arn)
  requires :name

  arn = if policy_or_arn.respond_to?(:arn)
          policy_or_arn.arn
        else
          policy_or_arn
        end

  service.attach_group_policy(self.name, arn)
end

#attached_policiesObject



38
39
40
41
42
# File 'lib/fog/aws/models/iam/group.rb', line 38

def attached_policies
  requires :name

  service.managed_policies(:group_name => self.name)
end

#destroyObject



44
45
46
47
48
49
# File 'lib/fog/aws/models/iam/group.rb', line 44

def destroy
  requires :name

  service.delete_group(self.name)
  true
end

#detach(policy_or_arn) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/aws/models/iam/group.rb', line 51

def detach(policy_or_arn)
  requires :name

  arn = if policy_or_arn.respond_to?(:arn)
          policy_or_arn.arn
        else
          policy_or_arn
        end

  service.detach_group_policy(self.name, arn)
end

#policiesObject



86
87
88
89
90
# File 'lib/fog/aws/models/iam/group.rb', line 86

def policies
  requires :name

  service.policies(:group_name => self.name)
end

#reloadObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/aws/models/iam/group.rb', line 92

def reload
  requires :name

  data = begin
           collection.get(self.name)
         rescue Excon::Errors::SocketError
           nil
         end

  return unless data

  merge_attributes(data.attributes)
  self
end

#saveObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/aws/models/iam/group.rb', line 63

def save
  if !persisted?
    requires :name

    merge_attributes(
      service.create_group(self.name, self.path).body["Group"]
    )
  else
    params = {}

    if self.name
      params['NewGroupName'] = self.name
    end

    if self.path
      params['NewPath'] = self.path
    end

    service.update_group(self.name, params)
    true
  end
end