Class: AWS::IAM::UserPolicy

Inherits:
Resource
  • Object
show all
Defined in:
lib/aws/iam/user_policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, name, options = {}) ⇒ UserPolicy

Returns a new instance of UserPolicy.

Parameters:

  • user (User)

    The user this user policy belongs to.

  • name (String)

    The name of this user policy.

  • options (Hash) (defaults to: {})


24
25
26
27
28
# File 'lib/aws/iam/user_policy.rb', line 24

def initialize user, name, options = {}
  @user = user
  @name = name
  super
end

Instance Attribute Details

#nameString (readonly)

Returns the name of this user policy.

Returns:

  • (String)

    Returns the name of this user policy.



34
35
36
# File 'lib/aws/iam/user_policy.rb', line 34

def name
  @name
end

#userUser (readonly)

Returns the user this user policy belongs to.

Returns:

  • (User)

    Returns the user this user policy belongs to.



31
32
33
# File 'lib/aws/iam/user_policy.rb', line 31

def user
  @user
end

Instance Method Details

#deletenil

Deletes this user policy.

Returns:

  • (nil)


82
83
84
85
# File 'lib/aws/iam/user_policy.rb', line 82

def delete
  client.delete_user_policy(:user_name => user.name, :policy_name => name)
  nil
end

#policyPolicy

Returns the actual policy document for this user policy.

Returns:

  • (Policy)

    Returns the actual policy document for this user policy.



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

def policy

  response = client.get_user_policy(
    :user_name => user.name,
    :policy_name => name)

  policy = Policy.from_json(URI.decode(response.policy_document))
  policy.extend(PolicyProxy)
  policy.user_policy = self
  policy

end

#policy=(policy) ⇒ nil

Replaces or updates the user policy with the given policy document.

Parameters:

Returns:

  • (nil)


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aws/iam/user_policy.rb', line 66

def policy= policy

  policy_document = policy.is_a?(String) ? policy : policy.to_json

  options = {}
  options[:user_name] = user.name
  options[:policy_name] = name
  options[:policy_document] = policy_document

  client.put_user_policy(options)

  nil
end