aws-sdk 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/lib/aws.rb +10 -9
  2. data/lib/aws/api_config/IAM-2010-07-15.yml +632 -0
  3. data/lib/aws/base_client.rb +1 -1
  4. data/lib/aws/cacheable.rb +34 -46
  5. data/lib/aws/client_logging.rb +19 -14
  6. data/lib/aws/collections.rb +230 -0
  7. data/lib/aws/common.rb +4 -0
  8. data/lib/aws/configuration.rb +7 -0
  9. data/lib/aws/ec2.rb +2 -2
  10. data/lib/aws/ec2/attachment.rb +64 -71
  11. data/lib/aws/ec2/attachment_collection.rb +11 -9
  12. data/lib/aws/ec2/availability_zone.rb +40 -31
  13. data/lib/aws/ec2/availability_zone_collection.rb +2 -3
  14. data/lib/aws/ec2/elastic_ip.rb +25 -22
  15. data/lib/aws/ec2/elastic_ip_collection.rb +5 -2
  16. data/lib/aws/ec2/image.rb +113 -129
  17. data/lib/aws/ec2/image_collection.rb +5 -6
  18. data/lib/aws/ec2/instance.rb +290 -233
  19. data/lib/aws/ec2/instance_collection.rb +72 -67
  20. data/lib/aws/ec2/key_pair.rb +16 -18
  21. data/lib/aws/ec2/region.rb +25 -17
  22. data/lib/aws/ec2/reserved_instances.rb +7 -1
  23. data/lib/aws/ec2/reserved_instances_collection.rb +3 -3
  24. data/lib/aws/ec2/reserved_instances_offering.rb +7 -1
  25. data/lib/aws/ec2/reserved_instances_offering_collection.rb +3 -3
  26. data/lib/aws/ec2/resource.rb +41 -222
  27. data/lib/aws/ec2/security_group.rb +22 -18
  28. data/lib/aws/ec2/security_group_collection.rb +2 -5
  29. data/lib/aws/ec2/snapshot.rb +44 -35
  30. data/lib/aws/ec2/snapshot_collection.rb +43 -1
  31. data/lib/aws/ec2/tag.rb +14 -18
  32. data/lib/aws/ec2/volume.rb +59 -72
  33. data/lib/aws/ec2/volume_collection.rb +16 -12
  34. data/lib/aws/errors.rb +14 -5
  35. data/lib/aws/http/httparty_handler.rb +2 -2
  36. data/lib/aws/iam.rb +306 -0
  37. data/lib/aws/iam/access_key.rb +183 -0
  38. data/lib/aws/iam/access_key_collection.rb +131 -0
  39. data/lib/aws/iam/account_alias_collection.rb +81 -0
  40. data/lib/aws/iam/client.rb +44 -0
  41. data/lib/aws/iam/client/xml.rb +38 -0
  42. data/lib/aws/iam/collection.rb +87 -0
  43. data/lib/aws/iam/errors.rb +29 -0
  44. data/lib/aws/iam/group.rb +117 -0
  45. data/lib/aws/iam/group_collection.rb +135 -0
  46. data/lib/aws/iam/group_policy_collection.rb +49 -0
  47. data/lib/aws/iam/group_user_collection.rb +94 -0
  48. data/lib/aws/iam/login_profile.rb +97 -0
  49. data/lib/aws/iam/mfa_device.rb +52 -0
  50. data/lib/aws/iam/mfa_device_collection.rb +119 -0
  51. data/lib/aws/iam/policy.rb +48 -0
  52. data/lib/aws/iam/policy_collection.rb +191 -0
  53. data/lib/aws/iam/request.rb +27 -0
  54. data/lib/aws/iam/resource.rb +74 -0
  55. data/lib/aws/iam/server_certificate.rb +143 -0
  56. data/lib/aws/iam/server_certificate_collection.rb +174 -0
  57. data/lib/aws/iam/signing_certificate.rb +171 -0
  58. data/lib/aws/iam/signing_certificate_collection.rb +134 -0
  59. data/lib/aws/iam/user.rb +196 -0
  60. data/lib/aws/iam/user_collection.rb +136 -0
  61. data/lib/aws/iam/user_group_collection.rb +101 -0
  62. data/lib/aws/iam/user_policy.rb +90 -0
  63. data/lib/aws/iam/user_policy_collection.rb +48 -0
  64. data/lib/aws/resource.rb +381 -0
  65. data/lib/aws/resource_cache.rb +1 -2
  66. data/lib/aws/response.rb +5 -1
  67. data/lib/aws/response_cache.rb +1 -1
  68. data/lib/aws/s3/client.rb +3 -1
  69. data/lib/aws/s3/presigned_post.rb +1 -1
  70. data/lib/aws/simple_db.rb +1 -1
  71. metadata +113 -50
@@ -0,0 +1,135 @@
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/model'
15
+ require 'aws/iam/group'
16
+
17
+ module AWS
18
+ class IAM
19
+
20
+ # A collection that provides access to IAM groups
21
+ # belonging to this account.
22
+ #
23
+ # iam = AWS::IAM.new
24
+ # groups = iam.groups
25
+ #
26
+ # == Creating a Group
27
+ #
28
+ # You can create a group using the {#create} method:
29
+ #
30
+ # group = iam.groups.create("Developers")
31
+ #
32
+ # == Getting a Group by Name
33
+ #
34
+ # You can get a reference to a server certificate using array notation:
35
+ #
36
+ # group = iam.groups["Developers"]
37
+ #
38
+ # == Enumerating Groups
39
+ #
40
+ # Group collections can also be used to enumerate groups:
41
+ #
42
+ # groups.each do |group|
43
+ # puts group.name
44
+ # end
45
+ #
46
+ # You can limit the groups returned by passing a +:prefix+ option
47
+ # to any of the enumerator methods. When you pass a prefix, only
48
+ # the certificates whose paths start with the given string will be
49
+ # returned.
50
+ class GroupCollection
51
+
52
+ include Collection::WithPrefix
53
+
54
+ # Creates a group.
55
+ #
56
+ # @param [String] name Name of the group to create. Do not
57
+ # include the path in this value.
58
+ #
59
+ # @param [Hash] options Options for creating the group.
60
+ #
61
+ # @option options [String] :path The path to the group.
62
+ def create(name, options = {})
63
+ client_opts = { :group_name => name }.merge(options)
64
+ if path = client_opts[:path]
65
+ client_opts[:path] = "/#{path}/".
66
+ sub(%r{^//}, "/").
67
+ sub(%r{//$}, "/")
68
+ end
69
+ resp = client.create_group(client_opts)
70
+ Group.new(resp.group.group_name, :config => config)
71
+ end
72
+
73
+ # Yields once for each group.
74
+ #
75
+ # You can limit the number of groups yielded using +:limit+ and
76
+ # +:path_prefix+.
77
+ #
78
+ # @param [Hash] options
79
+ #
80
+ # @option options [String] :path_prefix ('/') A path prefix that
81
+ # filters according to the path of the group.
82
+ #
83
+ # @option options [Integer] :limit The maximum number of groups
84
+ # to yield.
85
+ #
86
+ # @option options [Integer] :batch_size The maximum number of
87
+ # groups to retrieve in each service request.
88
+ #
89
+ # @yieldparam [Group] group
90
+ # @return [nil]
91
+ def each options = {}, &block
92
+ super(options, &block)
93
+ end
94
+
95
+ # Returns an enumerable object for this collection. This can be
96
+ # useful if you want to call an enumerable method that does
97
+ # not accept options (e.g. +collect+, +first+, etc).
98
+ #
99
+ # groups.enumerator(:path_prefix => '/admin').collect(&:name)
100
+ #
101
+ # @param (see #each)
102
+ # @option (see #each)
103
+ # @return [Enumerator]
104
+ def enumerator options = {}
105
+ super(options)
106
+ end
107
+
108
+ # Returns a reference to the group with the given name:
109
+ #
110
+ # group = iam.groups['groupname']
111
+ #
112
+ # @param [String] name Name of the group to return a reference for.
113
+ # @return [Group] Returns a reference to the named group.
114
+ def [] name
115
+ Group.new(name, :config => config)
116
+ end
117
+
118
+ # @private
119
+ protected
120
+ def each_item response, &block
121
+ response.groups.each do |item|
122
+
123
+ group = Group.new_from(:list_groups, item,
124
+ item.group_name,
125
+ :config => config)
126
+
127
+ yield(group)
128
+
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+ end
@@ -0,0 +1,49 @@
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/policy_collection'
15
+
16
+ module AWS
17
+ class IAM
18
+
19
+ # A collection that provides access to the policies associated
20
+ # with an IAM group. The interface mimics a hash containing
21
+ # string keys and values that are instances of {Policy}. For
22
+ # example:
23
+ #
24
+ # # add or replace a policy named "ReadOnly"
25
+ # policy = AWS::IAM::Policy.new do |p|
26
+ # # ...
27
+ # end
28
+ # group.policies["ReadOnly"] = policy
29
+ # group.policies.has_key?("ReadOnly") # => true
30
+ #
31
+ # All of the methods for this class are defined in the
32
+ # {PolicyCollection} module.
33
+ class GroupPolicyCollection
34
+
35
+ include PolicyCollection
36
+
37
+ # @attr_reader [Group] The group.
38
+ attr_reader :group
39
+
40
+ # @private
41
+ def initialize group, opts = {}
42
+ @group = group
43
+ super
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,94 @@
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/collections'
15
+ require 'aws/iam/user'
16
+
17
+ module AWS
18
+ class IAM
19
+
20
+ # A collection that provides access to IAM users belonging to a
21
+ # particular group.
22
+ #
23
+ # group = AWS::IAM.new.groups.first
24
+ # users = group.users
25
+ # users.each { |u| puts u.name }
26
+ class GroupUserCollection
27
+
28
+ include Collections::Basic
29
+
30
+ # @attr_reader [Group] The group.
31
+ attr_reader :group
32
+
33
+ # @private
34
+ def initialize(group, opts = {})
35
+ @group = group
36
+ super
37
+ end
38
+
39
+ # Adds a user to the group.
40
+ #
41
+ # @param [User] user The user to add.
42
+ # @return [nil]
43
+ def add(user)
44
+ client.add_user_to_group(:group_name => group.name,
45
+ :user_name => user.name)
46
+ nil
47
+ end
48
+
49
+ # Remove a user from the group.
50
+ #
51
+ # @param [User] user The user to remove.
52
+ # @return [nil]
53
+ def remove(user)
54
+ client.remove_user_from_group(:group_name => group.name,
55
+ :user_name => user.name)
56
+ nil
57
+ end
58
+
59
+ # Removes all users from this group.
60
+ # @return [nil]
61
+ def clear
62
+ each do |user|
63
+ remove(user)
64
+ end
65
+ end
66
+
67
+ # Yields once for each user in the group.
68
+ #
69
+ # @param [Hash] options
70
+ # @yieldparam [User] user
71
+ # @return [nil]
72
+ def each(options = {}, &block)
73
+ super(options.merge(:group_name => group.name), &block)
74
+ end
75
+
76
+ # @private
77
+ protected
78
+ def request_method
79
+ :get_group
80
+ end
81
+
82
+ # @private
83
+ protected
84
+ def each_item response
85
+ response.users.each do |u|
86
+ user = User.new_from(:get_group, u, u.user_name, :config => config)
87
+ yield(user)
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,97 @@
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
+
16
+ module AWS
17
+ class IAM
18
+
19
+ # A login profile is a user name and password that enables a user
20
+ # to log in to the {http://aws.amazon.com/console AWS Management
21
+ # Console}. Without a login profile, a user cannot access the
22
+ # console. (For information about accessing and using the AWS
23
+ # Management Console, see
24
+ # {http://docs.amazonwebservices.com/IAM/latest/UserGuide/Using_AWSManagementConsole.html
25
+ # Using the AWS Management Console}.)
26
+ #
27
+ # @example Setting a password for a user's login profile
28
+ # user.login_profile.password = "TheNewPassword"
29
+ #
30
+ # @example Deleting the login profile for a user
31
+ # user.login_profile.delete
32
+ class LoginProfile < Resource
33
+
34
+ # @private
35
+ def initialize(user, opts = {})
36
+ @user = user
37
+ super
38
+ end
39
+
40
+ # @attr_reader [User] The user to which this login profile
41
+ # belongs.
42
+ attr_reader :user
43
+
44
+ # @attr_reader [Time] The time at which the login profile was
45
+ # created.
46
+ attribute :create_date
47
+
48
+ # Sets a new password for the login profile, creating the
49
+ # profile if no profile currently exists for the user.
50
+ #
51
+ # @param [String] password The new password for the user.
52
+ def password=(password)
53
+ options = resource_options(:password => password)
54
+ client.update_login_profile(options)
55
+ password
56
+ rescue Errors::NoSuchEntity => e
57
+ client.create_login_profile(options)
58
+ password
59
+ end
60
+
61
+ # Deletes the login profile for the specified user, which
62
+ # terminates the user's ability to access AWS services through
63
+ # the IAM login page.
64
+ #
65
+ # @note Deleting a user's login profile does not prevent a user
66
+ # from accessing IAM through the command line interface or the
67
+ # API. To prevent all user access you must also either make
68
+ # the access key inactive or delete it. For more information
69
+ # about making keys inactive or deleting them, see
70
+ # {User#access_keys}.
71
+ #
72
+ def delete
73
+ client.delete_login_profile(resource_options)
74
+ end
75
+
76
+ # @return [Boolean] True if a login profile exists for the user.
77
+ def exists?
78
+ client.get_login_profile(resource_options)
79
+ rescue Errors::NoSuchEntity => e
80
+ false
81
+ else
82
+ true
83
+ end
84
+
85
+ populates_from(:get_login_profile, :create_login_profile) do |resp|
86
+ resp.login_profile if resp.login_profile.user_name == user.name
87
+ end
88
+
89
+ protected
90
+ def resource_identifiers
91
+ [[:user_name, user.name]]
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,52 @@
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/model'
14
+
15
+ module AWS
16
+ class IAM
17
+
18
+ class MFADevice
19
+
20
+ include Model
21
+
22
+ # @param [User] user The user the MFA device is associated with.
23
+ # @param [String] serial_number The MFA device's unique serial number.
24
+ def initialize user, serial_number, options = {}
25
+ @user = user
26
+ @serial_number = serial_number
27
+ super
28
+ end
29
+
30
+ # @return [User] Returns the MFA device's user.
31
+ attr_reader :user
32
+
33
+ # @return [String] Returns the MFA device's serial number
34
+ attr_reader :serial_number
35
+
36
+ # Deactivates the MFA device and removes it from association with the
37
+ # user for which it was originally enabled.
38
+ # @return [nil]
39
+ def deactivate
40
+ client.deactivate_mfa_device({
41
+ :user_name => user.name,
42
+ :serial_number => serial_number,
43
+ })
44
+ nil
45
+ end
46
+
47
+ alias_method :delete, :deactivate
48
+
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,119 @@
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/collection'
14
+ require 'aws/iam/mfa_device'
15
+
16
+ module AWS
17
+ class IAM
18
+
19
+ # @attr_reader [User] user Returns the user that owns this collection.
20
+ class MFADeviceCollection
21
+
22
+ include Collection
23
+
24
+ # @param [User] user The user that owns this device collection.
25
+ def initialize user, options = {}
26
+ @user = user
27
+ super
28
+ end
29
+
30
+ # @return [User] Returns the user that this mfa device collection
31
+ # belongs to.
32
+ attr_reader :user
33
+
34
+ # Enables an MFA device for this user.
35
+ # @param [String] serial_number The serial number that uniquely
36
+ # identifies the MFA device
37
+ # @param [String] authentication_code_1 An authentication code emitted
38
+ # by the device.
39
+ # @param [String] authentication_code_2 A subsequent authentication
40
+ # code emitted by the device.
41
+ # @return [MFADevice] Returns the newly enabled MFA device.
42
+ def enable serial_number, authentication_code_1, authentication_code_2
43
+ client.enable_mfa_device({
44
+ :user_name => user.name,
45
+ :serial_number => serial_number,
46
+ :authentication_code_1 => authentication_code_1.to_s,
47
+ :authentication_code_2 => authentication_code_2.to_s,
48
+ })
49
+ self[serial_number]
50
+ end
51
+
52
+ alias_method :create, :enable
53
+
54
+ # @param [String] serial_number The serial number of the MFA device you
55
+ # want to disable.
56
+ # @return [nil]
57
+ def disable serial_number
58
+ self[serial_number].disable
59
+ nil
60
+ end
61
+
62
+ # @param [String] serial_number The serial number of an MFA device.
63
+ # @return [MFADevice] Returns a reference to an MFA device with the
64
+ # given serial number.
65
+ def [] serial_number
66
+ MFADevice.new(user, serial_number)
67
+ end
68
+
69
+ # Deletes all of the MFA devices in this collection.
70
+ # @return [nil]
71
+ def clear
72
+ each do |device|
73
+ device.delete
74
+ end
75
+ nil
76
+ end
77
+
78
+ # Yields once for each MFA device.
79
+ #
80
+ # You can limit the number of devices yielded using +:limit+.
81
+ #
82
+ # @param [Hash] options
83
+ # @option options [Integer] :limit The maximum number of devices to yield.
84
+ # @option options [Integer] :batch_size The maximum number of devices
85
+ # receive each service reqeust.
86
+ # @yieldparam [User] user
87
+ # @return [nil]
88
+ def each options = {}, &block
89
+ super(options.merge(:user_name => user.name), &block)
90
+ end
91
+
92
+ # Returns an enumerable object for this collection. This can be
93
+ # useful if you want to call an enumerable method that does
94
+ # not accept options (e.g. +collect+, +first+, etc).
95
+ #
96
+ # mfa_devices.enumerator(:limit => 10).collect(&:serial_number)
97
+ #
98
+ # @param (see #each)
99
+ # @option (see #each)
100
+ # @return [Enumerator]
101
+ def enumerator options = {}
102
+ super(options)
103
+ end
104
+
105
+ # @private
106
+ protected
107
+ def each_item response, &block
108
+ response.mfa_devices.each do |item|
109
+
110
+ mfa_device = MFADevice.new(user, item.serial_number)
111
+
112
+ yield(mfa_device)
113
+
114
+ end
115
+ end
116
+
117
+ end
118
+ end
119
+ end