aws-sdk 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/aws.rb +10 -9
- data/lib/aws/api_config/IAM-2010-07-15.yml +632 -0
- data/lib/aws/base_client.rb +1 -1
- data/lib/aws/cacheable.rb +34 -46
- data/lib/aws/client_logging.rb +19 -14
- data/lib/aws/collections.rb +230 -0
- data/lib/aws/common.rb +4 -0
- data/lib/aws/configuration.rb +7 -0
- data/lib/aws/ec2.rb +2 -2
- data/lib/aws/ec2/attachment.rb +64 -71
- data/lib/aws/ec2/attachment_collection.rb +11 -9
- data/lib/aws/ec2/availability_zone.rb +40 -31
- data/lib/aws/ec2/availability_zone_collection.rb +2 -3
- data/lib/aws/ec2/elastic_ip.rb +25 -22
- data/lib/aws/ec2/elastic_ip_collection.rb +5 -2
- data/lib/aws/ec2/image.rb +113 -129
- data/lib/aws/ec2/image_collection.rb +5 -6
- data/lib/aws/ec2/instance.rb +290 -233
- data/lib/aws/ec2/instance_collection.rb +72 -67
- data/lib/aws/ec2/key_pair.rb +16 -18
- data/lib/aws/ec2/region.rb +25 -17
- data/lib/aws/ec2/reserved_instances.rb +7 -1
- data/lib/aws/ec2/reserved_instances_collection.rb +3 -3
- data/lib/aws/ec2/reserved_instances_offering.rb +7 -1
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +3 -3
- data/lib/aws/ec2/resource.rb +41 -222
- data/lib/aws/ec2/security_group.rb +22 -18
- data/lib/aws/ec2/security_group_collection.rb +2 -5
- data/lib/aws/ec2/snapshot.rb +44 -35
- data/lib/aws/ec2/snapshot_collection.rb +43 -1
- data/lib/aws/ec2/tag.rb +14 -18
- data/lib/aws/ec2/volume.rb +59 -72
- data/lib/aws/ec2/volume_collection.rb +16 -12
- data/lib/aws/errors.rb +14 -5
- data/lib/aws/http/httparty_handler.rb +2 -2
- data/lib/aws/iam.rb +306 -0
- data/lib/aws/iam/access_key.rb +183 -0
- data/lib/aws/iam/access_key_collection.rb +131 -0
- data/lib/aws/iam/account_alias_collection.rb +81 -0
- data/lib/aws/iam/client.rb +44 -0
- data/lib/aws/iam/client/xml.rb +38 -0
- data/lib/aws/iam/collection.rb +87 -0
- data/lib/aws/iam/errors.rb +29 -0
- data/lib/aws/iam/group.rb +117 -0
- data/lib/aws/iam/group_collection.rb +135 -0
- data/lib/aws/iam/group_policy_collection.rb +49 -0
- data/lib/aws/iam/group_user_collection.rb +94 -0
- data/lib/aws/iam/login_profile.rb +97 -0
- data/lib/aws/iam/mfa_device.rb +52 -0
- data/lib/aws/iam/mfa_device_collection.rb +119 -0
- data/lib/aws/iam/policy.rb +48 -0
- data/lib/aws/iam/policy_collection.rb +191 -0
- data/lib/aws/iam/request.rb +27 -0
- data/lib/aws/iam/resource.rb +74 -0
- data/lib/aws/iam/server_certificate.rb +143 -0
- data/lib/aws/iam/server_certificate_collection.rb +174 -0
- data/lib/aws/iam/signing_certificate.rb +171 -0
- data/lib/aws/iam/signing_certificate_collection.rb +134 -0
- data/lib/aws/iam/user.rb +196 -0
- data/lib/aws/iam/user_collection.rb +136 -0
- data/lib/aws/iam/user_group_collection.rb +101 -0
- data/lib/aws/iam/user_policy.rb +90 -0
- data/lib/aws/iam/user_policy_collection.rb +48 -0
- data/lib/aws/resource.rb +381 -0
- data/lib/aws/resource_cache.rb +1 -2
- data/lib/aws/response.rb +5 -1
- data/lib/aws/response_cache.rb +1 -1
- data/lib/aws/s3/client.rb +3 -1
- data/lib/aws/s3/presigned_post.rb +1 -1
- data/lib/aws/simple_db.rb +1 -1
- metadata +113 -50
data/lib/aws/iam/user.rb
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
5
|
+
# the License is located at
|
6
|
+
#
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
8
|
+
#
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
12
|
+
# language governing permissions and limitations under the License.
|
13
|
+
|
14
|
+
require 'aws/iam/resource'
|
15
|
+
require 'aws/iam/mfa_device_collection'
|
16
|
+
require 'aws/iam/user_policy_collection'
|
17
|
+
require 'aws/iam/signing_certificate_collection'
|
18
|
+
require 'aws/iam/login_profile'
|
19
|
+
require 'aws/iam/user_group_collection'
|
20
|
+
|
21
|
+
module AWS
|
22
|
+
class IAM
|
23
|
+
|
24
|
+
|
25
|
+
# Represents an IAM User. Each AWS account can have many users. Users
|
26
|
+
# can be organized (optionally) into groups. Users (and groups) can be
|
27
|
+
# given policies that affect that they can do.
|
28
|
+
#
|
29
|
+
# == Creating A User
|
30
|
+
#
|
31
|
+
# iam = AWS::IAM.new
|
32
|
+
#
|
33
|
+
# user = iam.users.create('johndoe')
|
34
|
+
#
|
35
|
+
#
|
36
|
+
# == Renaming a User
|
37
|
+
#
|
38
|
+
# You can only edit a user's name and path (both of which will modify
|
39
|
+
# the user's ARN).
|
40
|
+
#
|
41
|
+
# user = iam.users['johndoe']
|
42
|
+
# user.name = 'newname'
|
43
|
+
#
|
44
|
+
# == User Path
|
45
|
+
#
|
46
|
+
# When you create a user you can assign a path. Paths must begin and
|
47
|
+
# end with a forward slash (/).
|
48
|
+
#
|
49
|
+
# user = iam.users.create('newuser', :path => '/developers/ruby/')
|
50
|
+
#
|
51
|
+
# Paths are a useful tool for organizing/tagging users. You can later
|
52
|
+
# enumerate users by their path prefixes:
|
53
|
+
#
|
54
|
+
# iam.users.each(:path_prefix => '/developers').each do |developer|
|
55
|
+
# puts developer.name
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# == Login Profile
|
59
|
+
#
|
60
|
+
# A login profile is required for an IAM user to use the AWS Management
|
61
|
+
# console (web interface). See {LoginProfile} for more information.
|
62
|
+
#
|
63
|
+
# == Deleting Users
|
64
|
+
#
|
65
|
+
# In order to delete a user you must first remove it from all of its
|
66
|
+
# groups and delete all of its signing certificates. Once this is done:
|
67
|
+
#
|
68
|
+
class User < Resource
|
69
|
+
|
70
|
+
prefix_update_attributes
|
71
|
+
|
72
|
+
# @param [String] name The IAM user name for this user.
|
73
|
+
# @param [Hash] options
|
74
|
+
def initialize name, options = {}
|
75
|
+
options[:name] = name
|
76
|
+
super(options)
|
77
|
+
end
|
78
|
+
|
79
|
+
# @attr [String] The IAM user name.
|
80
|
+
mutable_attribute :name, :static => true, :as => :user_name
|
81
|
+
|
82
|
+
# @attr_reader [String] The user's unique ID.
|
83
|
+
attribute :id, :static => true, :as => :user_id
|
84
|
+
|
85
|
+
# @attr_reader [Time] When the user was created.
|
86
|
+
attribute :create_date, :static => true
|
87
|
+
|
88
|
+
# @attr_reader [String] The user's ARN (Amazon Resource Name).
|
89
|
+
attribute :arn
|
90
|
+
|
91
|
+
# @attr [String] The path for this user. Paths are used to
|
92
|
+
# identify which division or part of an organization the user
|
93
|
+
# belongs to.
|
94
|
+
mutable_attribute :path
|
95
|
+
|
96
|
+
populates_from(:create_user, :get_user) do |resp|
|
97
|
+
resp.user if resp.user.user_name == name
|
98
|
+
end
|
99
|
+
|
100
|
+
populates_from(:list_users, :get_group) do |resp|
|
101
|
+
resp.users.find{|u| u.user_name == name }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Deletes this user.
|
105
|
+
# @return [nil]
|
106
|
+
def delete
|
107
|
+
client.delete_user(resource_options)
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete!
|
112
|
+
groups.clear
|
113
|
+
access_keys.clear
|
114
|
+
policies.clear
|
115
|
+
mfa_devices.clear
|
116
|
+
signing_certificates.clear
|
117
|
+
login_profile.delete if login_profile.exists?
|
118
|
+
delete
|
119
|
+
end
|
120
|
+
|
121
|
+
# Returns a collection that represents all policies for this user.
|
122
|
+
#
|
123
|
+
# user.policies.each do |policy|
|
124
|
+
# puts policy.name
|
125
|
+
# end
|
126
|
+
#
|
127
|
+
# @return [PolicyCollection] Returns a collection that represents
|
128
|
+
# all policies for this user.
|
129
|
+
def policies
|
130
|
+
UserPolicyCollection.new(self)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns a collection that represents the signing certificates
|
134
|
+
# belonging to this user.
|
135
|
+
#
|
136
|
+
# user.signing_certificates.each do |cert|
|
137
|
+
# # ...
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# If you need to access the signing certificates of this AWS account,
|
141
|
+
# see {IAM#signing_certificates}.
|
142
|
+
#
|
143
|
+
# @return [SigningCertificateCollection] Returns a collection that
|
144
|
+
# represents signing certificates for this user.
|
145
|
+
def signing_certificates
|
146
|
+
SigningCertificateCollection.new(:user => self, :config => config)
|
147
|
+
end
|
148
|
+
|
149
|
+
# @return [MFADeviceCollection] Returns a collection that represents
|
150
|
+
# all MFA devices assigned to this user.
|
151
|
+
def mfa_devices
|
152
|
+
MFADeviceCollection.new(self)
|
153
|
+
end
|
154
|
+
|
155
|
+
# A login profile is a user name and password that enables a
|
156
|
+
# user to log in to the {http://aws.amazon.com/console AWS
|
157
|
+
# Management Console}. The object returned by this method
|
158
|
+
# allows you to set or delete the password. For example:
|
159
|
+
#
|
160
|
+
# user.login_profile.password = "TheNewPassword"
|
161
|
+
#
|
162
|
+
# @return [LoginProfile] Returns the login profile for this
|
163
|
+
# user.
|
164
|
+
def login_profile
|
165
|
+
LoginProfile.new(self)
|
166
|
+
end
|
167
|
+
|
168
|
+
# Returns a collection that represents the access keys for this user.
|
169
|
+
#
|
170
|
+
# user.access_keys.each do |access_key|
|
171
|
+
# puts access_key.id
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# @return [AccessKeyCollection] Returns a collection that represents all
|
175
|
+
# access keys for this user.
|
176
|
+
def access_keys
|
177
|
+
AccessKeyCollection.new(:user => self)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Returns a collection that includes all of the groups the user
|
181
|
+
# is in.
|
182
|
+
#
|
183
|
+
# @return [UserGroupCollection]
|
184
|
+
def groups
|
185
|
+
UserGroupCollection.new(self)
|
186
|
+
end
|
187
|
+
|
188
|
+
# @private
|
189
|
+
protected
|
190
|
+
def resource_identifiers
|
191
|
+
[[:user_name, name]]
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
5
|
+
# the License is located at
|
6
|
+
#
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
8
|
+
#
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
12
|
+
# language governing permissions and limitations under the License.
|
13
|
+
|
14
|
+
require 'aws/iam/collection'
|
15
|
+
require 'aws/iam/user'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
class IAM
|
19
|
+
|
20
|
+
# A collection that provides access to IAM users belonging to this
|
21
|
+
# account.
|
22
|
+
#
|
23
|
+
# iam = AWS::IAM.new
|
24
|
+
# users = iam.users
|
25
|
+
#
|
26
|
+
# == Creating A User
|
27
|
+
#
|
28
|
+
# To create an IAM user you need only provide a user name.
|
29
|
+
#
|
30
|
+
# user = users.create('username')
|
31
|
+
#
|
32
|
+
# You can also provide an optional +:path+ that can be used to organize
|
33
|
+
# users.
|
34
|
+
#
|
35
|
+
# user = users.create('johndoe', :path => '/staff/customer_support/')
|
36
|
+
#
|
37
|
+
# == Getting a User by Name
|
38
|
+
#
|
39
|
+
# You can get a referene to a user by using array notation:
|
40
|
+
#
|
41
|
+
# user = users['username']
|
42
|
+
#
|
43
|
+
# == Enumerating Users
|
44
|
+
#
|
45
|
+
# A user collection can also be used to enumerate users:
|
46
|
+
#
|
47
|
+
# users.each do |user|
|
48
|
+
# puts user.name
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# == Path Prefixes
|
52
|
+
#
|
53
|
+
# You can also find/enumerate users who's path begins with a given prefix:
|
54
|
+
#
|
55
|
+
# users.each(:path_prefix => '/staff/developers/ruby').each do |ruby_dev|
|
56
|
+
# puts "#{ruby_dev.name} is awesome!"
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
class UserCollection
|
60
|
+
|
61
|
+
include Collection::WithPrefix
|
62
|
+
|
63
|
+
# @param [String] name Name of the user to create.
|
64
|
+
# @option options [String] :path ('/') The path for the user name.
|
65
|
+
# For more information about paths, see
|
66
|
+
# {Identifiers for IAM Entities}[http://docs.amazonwebservices.com/IAM/latest/UserGuide/index.html?Using_Identifiers.html]
|
67
|
+
# @return [User] Returns the newly created user.
|
68
|
+
def create name, options = {}
|
69
|
+
create_opts = {}
|
70
|
+
create_opts[:user_name] = name
|
71
|
+
create_opts[:path] = options[:path] if options[:path]
|
72
|
+
resp = client.create_user(create_opts)
|
73
|
+
User.new_from(:create_user, resp.user,
|
74
|
+
resp.user.user_name, :config => config)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns a reference to the user with the given name:
|
78
|
+
#
|
79
|
+
# user = iam.users['username']
|
80
|
+
#
|
81
|
+
# @param [String] name Name of the user to return a reference for.
|
82
|
+
# @return [User] Returns a reference to the named user.
|
83
|
+
def [] name
|
84
|
+
User.new(name.to_s, :config => config)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Yields once for each user.
|
88
|
+
#
|
89
|
+
# You can limit the number of users yielded using +:limit+ and
|
90
|
+
# +:path_prefix+.
|
91
|
+
#
|
92
|
+
# @param [Hash] options
|
93
|
+
#
|
94
|
+
# @option options [String] :path_prefix ('/') A path prefix that
|
95
|
+
# filters according to the path of the user.
|
96
|
+
#
|
97
|
+
# @option options [Integer] :limit The maximum number of users to yield.
|
98
|
+
#
|
99
|
+
# @option options [Integer] :batch_size The maximum number of users
|
100
|
+
# to retrieve with each service request.
|
101
|
+
#
|
102
|
+
# @yieldparam [User] user
|
103
|
+
# @return [nil]
|
104
|
+
def each options = {}, &block
|
105
|
+
super(options, &block)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns an enumerable object for this collection. This can be
|
109
|
+
# useful if you want to call an enumerable method that does
|
110
|
+
# not accept options (e.g. +collect+, +first+, etc).
|
111
|
+
#
|
112
|
+
# users.enumerator(:path_prefix => '/admin').collect(&:name)
|
113
|
+
#
|
114
|
+
# @param (see #each)
|
115
|
+
# @option (see #each)
|
116
|
+
# @return [Enumerator]
|
117
|
+
def enumerator options = {}
|
118
|
+
super(options)
|
119
|
+
end
|
120
|
+
|
121
|
+
# @private
|
122
|
+
protected
|
123
|
+
def each_item response, &block
|
124
|
+
response.users.each do |item|
|
125
|
+
|
126
|
+
user = User.new_from(:list_users, item,
|
127
|
+
item.user_name, :config => config)
|
128
|
+
|
129
|
+
yield(user)
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
5
|
+
# the License is located at
|
6
|
+
#
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
8
|
+
#
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
12
|
+
# language governing permissions and limitations under the License.
|
13
|
+
|
14
|
+
require 'aws/iam/collection'
|
15
|
+
require 'aws/iam/group'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
class IAM
|
19
|
+
|
20
|
+
# A collection that provides access to IAM groups to which a
|
21
|
+
# particular user belongs.
|
22
|
+
#
|
23
|
+
# user = AWS::IAM.new.users.first
|
24
|
+
# groups = user.groups
|
25
|
+
# groups.each { |g| puts g.name }
|
26
|
+
#
|
27
|
+
class UserGroupCollection
|
28
|
+
|
29
|
+
include Collection
|
30
|
+
|
31
|
+
# @attr_reader [User] The user.
|
32
|
+
attr_reader :user
|
33
|
+
|
34
|
+
# @private
|
35
|
+
def initialize(user, opts = {})
|
36
|
+
@user = user
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
# Adds the user to a group.
|
41
|
+
#
|
42
|
+
# @param [Group] group The group to which the user should be added.
|
43
|
+
def add(group)
|
44
|
+
client.add_user_to_group(:group_name => group.name,
|
45
|
+
:user_name => user.name)
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# Removes the user from a group.
|
50
|
+
#
|
51
|
+
# @param [Group] group The group from which the user should be removed
|
52
|
+
def remove(group)
|
53
|
+
client.remove_user_from_group(:group_name => group.name,
|
54
|
+
:user_name => user.name)
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# Removes this user from all groups.
|
59
|
+
# @return [nil]
|
60
|
+
def clear
|
61
|
+
each do |group|
|
62
|
+
remove(group)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Yields once for each group that the user is in.
|
67
|
+
#
|
68
|
+
# @param [Hash] options
|
69
|
+
#
|
70
|
+
# @option options [Integer] :limit Limits the number of groups
|
71
|
+
# that are returned.
|
72
|
+
#
|
73
|
+
# @option options [Integer] :batch_size Controls how many groups
|
74
|
+
# are requested from the service at once.
|
75
|
+
#
|
76
|
+
# @yieldparam [Group] group
|
77
|
+
#
|
78
|
+
# @return [nil]
|
79
|
+
def each(options = {}, &block)
|
80
|
+
super(options.merge(:user_name => user.name), &block)
|
81
|
+
end
|
82
|
+
|
83
|
+
# @private
|
84
|
+
protected
|
85
|
+
def request_method
|
86
|
+
:list_groups_for_user
|
87
|
+
end
|
88
|
+
|
89
|
+
# @private
|
90
|
+
protected
|
91
|
+
def each_item response
|
92
|
+
response.groups.each do |g|
|
93
|
+
group = Group.new_from(:list_groups_for_user, g, g.group_name, :config => config)
|
94
|
+
yield(group)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
3
|
+
# may not use this file except in compliance with the License. A copy of
|
4
|
+
# the License is located at
|
5
|
+
#
|
6
|
+
# http://aws.amazon.com/apache2.0/
|
7
|
+
#
|
8
|
+
# or in the "license" file accompanying this file. This file is
|
9
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
10
|
+
# ANY KIND, either express or implied. See the License for the specific
|
11
|
+
# language governing permissions and limitations under the License.
|
12
|
+
|
13
|
+
require 'aws/iam/resource'
|
14
|
+
require 'aws/iam/policy'
|
15
|
+
require 'uri'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
class IAM
|
19
|
+
|
20
|
+
class UserPolicy < Resource
|
21
|
+
|
22
|
+
# @param [User] The user this user policy belongs to.
|
23
|
+
# @param [String] The name of this user policy.
|
24
|
+
def initialize user, name, options = {}
|
25
|
+
@user = user
|
26
|
+
@name = name
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [User] Returns the user this user policy belongs to.
|
31
|
+
attr_reader :user
|
32
|
+
|
33
|
+
# @return [String] Returns the name of this user policy.
|
34
|
+
attr_reader :name
|
35
|
+
|
36
|
+
# @private
|
37
|
+
module PolicyProxy
|
38
|
+
|
39
|
+
attr_accessor :user_policy
|
40
|
+
|
41
|
+
def change
|
42
|
+
yield(self)
|
43
|
+
user_policy.policy = self
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Policy] Returns the actual policy document for this
|
49
|
+
# user policy.
|
50
|
+
def policy
|
51
|
+
|
52
|
+
response = client.get_user_policy(
|
53
|
+
:user_name => user.name,
|
54
|
+
:policy_name => name)
|
55
|
+
|
56
|
+
policy = Policy.from_json(URI.decode(response.policy_document))
|
57
|
+
policy.extend(PolicyProxy)
|
58
|
+
policy.user_policy = self
|
59
|
+
policy
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
# Replaces or updates the user policy with the given policy document.
|
64
|
+
# @param [Policy] policy
|
65
|
+
# @return [nil]
|
66
|
+
def policy= policy
|
67
|
+
|
68
|
+
policy_document = policy.is_a?(String) ? policy : policy.to_json
|
69
|
+
|
70
|
+
options = {}
|
71
|
+
options[:user_name] = user.name
|
72
|
+
options[:policy_name] = name
|
73
|
+
options[:policy_document] = policy_document
|
74
|
+
|
75
|
+
client.put_user_policy(options)
|
76
|
+
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
# Deletes this user policy.
|
81
|
+
# @return [nil]
|
82
|
+
def delete
|
83
|
+
client.delete_user_policy(:user_name => user.name, :policy_name => name)
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|