fog-aws 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b755e78b954c63b5857d91ec7054021ad448bf51
4
- data.tar.gz: f9f118f04869ec1ec925fda14d3a896a7a48c40f
3
+ metadata.gz: 6fadd0502aac63d36fb75307b3f73c318aa7b761
4
+ data.tar.gz: 91359d42a5922d20b668da81fc7073bf0534a5ba
5
5
  SHA512:
6
- metadata.gz: 824e71f7f75c19fd9e0d0fea083f3538f7f302f763d532eaa92f51d111e9bc4afaa4f406f88e856c19fcdda555ce4bbb5e40c6a8b860996ce1df06ccdc43d7be
7
- data.tar.gz: 68e19eed81bd3f187ac2f39cc12b5a8389af3cc077d2ef2459392a6acfa2601b6732c79926392e10fc1cc7ff84d92cdf6ebc03b8613eac94dbe67f9aea0d7fd1
6
+ metadata.gz: 14e6301495abbdfeaf6f03a007495a4cbab38dedfd44bcea3871b97b5a284e0fd7503082cab5c495c54f8bf963b03157b0238a8c1541d77889bf4e9501589cef
7
+ data.tar.gz: 75d9dfc7a737ea2656f54fce0c2a49abf95f7daa6f6c45e07bc81e3ec95e479945273a55dd81706ebef896ec8579dafd05047bc7ee97532ab8308047e59bde61
@@ -99,6 +99,7 @@ module Fog
99
99
  request :describe_dhcp_options
100
100
  request :describe_images
101
101
  request :describe_instances
102
+ request :describe_instance_attribute
102
103
  request :describe_internet_gateways
103
104
  request :describe_reserved_instances
104
105
  request :describe_instance_status
@@ -162,8 +162,9 @@ module Fog
162
162
  end
163
163
 
164
164
  def initialize(options={})
165
- @use_iam_profile = options[:use_iam_profile]
165
+ @use_iam_profile = options[:use_iam_profile]
166
166
  @aws_credentials_expire_at = Time::now + 20
167
+
167
168
  setup_credentials(options)
168
169
  end
169
170
 
@@ -173,11 +174,16 @@ module Fog
173
174
 
174
175
  def reset_data
175
176
  self.class.data.delete(@aws_access_key_id)
177
+ current_user
176
178
  end
177
179
 
178
180
  def setup_credentials(options)
179
181
  @aws_access_key_id = options[:aws_access_key_id]
180
182
  end
183
+
184
+ def current_user
185
+ self.data[:users]["root"]
186
+ end
181
187
  end
182
188
 
183
189
  class Real
@@ -201,11 +207,11 @@ module Fog
201
207
  # ==== Returns
202
208
  # * IAM object with connection to AWS.
203
209
  def initialize(options={})
210
+ @use_iam_profile = options[:use_iam_profile]
211
+ @connection_options = options[:connection_options] || {}
212
+ @instrumentor = options[:instrumentor]
213
+ @instrumentor_name = options[:instrumentor_name] || 'fog.aws.iam'
204
214
 
205
- @use_iam_profile = options[:use_iam_profile]
206
- @connection_options = options[:connection_options] || {}
207
- @instrumentor = options[:instrumentor]
208
- @instrumentor_name = options[:instrumentor_name] || 'fog.aws.iam'
209
215
  @host = options[:host] || 'iam.amazonaws.com'
210
216
  @path = options[:path] || '/'
211
217
  @persistent = options[:persistent] || false
@@ -215,7 +221,6 @@ module Fog
215
221
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
216
222
 
217
223
  setup_credentials(options)
218
-
219
224
  end
220
225
 
221
226
  def reload
@@ -225,14 +230,14 @@ module Fog
225
230
  private
226
231
 
227
232
  def setup_credentials(options)
228
- @aws_access_key_id = options[:aws_access_key_id]
229
- @aws_secret_access_key = options[:aws_secret_access_key]
230
- @aws_session_token = options[:aws_session_token]
233
+ @aws_access_key_id = options[:aws_access_key_id]
234
+ @aws_secret_access_key = options[:aws_secret_access_key]
235
+ @aws_session_token = options[:aws_session_token]
231
236
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]
232
237
 
233
238
  #global services that have no region are signed with the us-east-1 region
234
239
  #the only exception is GovCloud, which requires the region to be explicitly specified as us-gov-west-1
235
- @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key, @region,'iam')
240
+ @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'iam')
236
241
  end
237
242
 
238
243
  def request(params)
@@ -6,32 +6,30 @@ module Fog
6
6
  class Policies < Fog::Collection
7
7
  model Fog::AWS::IAM::Policy
8
8
 
9
- def initialize(attributes = {})
10
- @username = attributes[:username]
11
- raise ArgumentError.new("Can't get a policy's user without a username") unless @username
12
- super
13
- end
9
+ attribute :username
14
10
 
15
11
  def all
12
+ requires :username
16
13
  # AWS method get_user_policy only returns an array of policy names, this is kind of useless,
17
14
  # that's why it has to loop through the list to get the details of each element. I don't like it because it makes this method slow
18
- policy_names = service.list_user_policies(@username).body['PolicyNames'] # it returns an array
19
- policies = []
20
- policy_names.each do |policy_name|
21
- policies << service.get_user_policy(policy_name,@username).body['Policy']
15
+ policy_names = service.list_user_policies(self.username).body['PolicyNames'] # it returns an array
16
+ policies = policy_names.map do |policy_name|
17
+ service.get_user_policy(policy_name, self.username).body['Policy']
22
18
  end
23
19
  load(policies) # data is an array of attribute hashes
24
20
  end
25
21
 
26
22
  def get(identity)
27
- data = service.get_user_policy(identity,@username).body['Policy']
23
+ requires :username
24
+
25
+ data = service.get_user_policy(identity, self.username).body['Policy']
28
26
  new(data) # data is an attribute hash
29
27
  rescue Fog::AWS::IAM::NotFound
30
28
  nil
31
29
  end
32
30
 
33
31
  def new(attributes = {})
34
- super({ :username => @username }.merge!(attributes))
32
+ super({ :username => self.username }.merge!(attributes))
35
33
  end
36
34
  end
37
35
  end
@@ -16,6 +16,10 @@ module Fog
16
16
  load(data['Users']) # data is an array of attribute hashes
17
17
  end
18
18
 
19
+ def current
20
+ new(service.get_user.body['User'])
21
+ end
22
+
19
23
  def get(identity)
20
24
  data = service.get_user(identity).body['User']
21
25
  new(data) # data is an attribute hash
@@ -0,0 +1,178 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module AWS
5
+ class DescribeInstanceAttribute < Fog::Parsers::Base
6
+ def reset
7
+ @response = { }
8
+ @in_instanceType = false
9
+ @in_kernelId = false
10
+ @in_ramdiskId = false
11
+ @in_userData = false
12
+ @in_disableApiTermination = false
13
+ @in_instanceInitiatedShutdownBehavior = false
14
+ @in_rootDeviceName = false
15
+ @in_blockDeviceMapping = false
16
+ @in_productCodes = false
17
+ @in_ebsOptimized = false
18
+ @in_sriovNetSupport = false
19
+ @in_sourceDestCheck = false
20
+ @in_groupSet = false
21
+ end
22
+
23
+ def start_element(name, attrs = [])
24
+ super
25
+ case name
26
+ when 'instanceType'
27
+ @in_instanceType = true
28
+ when 'kernel'
29
+ @in_kernel = true
30
+ when 'ramdisk'
31
+ @in_ramdisk = true
32
+ when 'userData'
33
+ @in_userData = true
34
+ when 'disableApiTermination'
35
+ @in_disableApiTermination = true
36
+ when 'instanceInitiatedShutdownBehavior'
37
+ @in_instanceInitiatedShutdownBehavior = true
38
+ when 'rootDeviceName'
39
+ @in_rootDeviceName = true
40
+ when 'blockDeviceMapping'
41
+ @in_blockDeviceMapping = true
42
+ @block_device_mapping = {}
43
+ unless @response.key?('blockDeviceMapping')
44
+ @response['blockDeviceMapping'] = []
45
+ end
46
+ when 'productCodes'
47
+ @in_productCodes = true
48
+ unless @response.key?('productCodes')
49
+ @response['productCodes'] = []
50
+ end
51
+ when 'ebsOptimized'
52
+ @in_ebsOptimized = true
53
+ when 'sriovNetSupport'
54
+ @in_sriovNetSupport = true
55
+ when 'sourceDestCheck'
56
+ @in_sourceDestCheck = true
57
+ when 'groupSet'
58
+ @in_groupSet = true
59
+ @group = {}
60
+ unless @response.key?('groupSet')
61
+ @response['groupSet'] = []
62
+ end
63
+ end
64
+ end
65
+
66
+ def end_element(name)
67
+ if @in_instanceType
68
+ case name
69
+ when 'value'
70
+ @response['instanceType'] = value
71
+ when 'instanceType'
72
+ @in_instanceType = false
73
+ end
74
+ elsif @in_kernel
75
+ case name
76
+ when 'value'
77
+ @response['kernelId'] = value
78
+ when 'kernel'
79
+ @in_kernelId = false
80
+ end
81
+ elsif @in_ramdisk
82
+ case name
83
+ when 'value'
84
+ @response['ramdiskId'] = value
85
+ when 'ramdisk'
86
+ @in_ramdiskId = false
87
+ end
88
+ elsif @in_userData
89
+ case name
90
+ when 'value'
91
+ @response['userData'] = value
92
+ when 'userData'
93
+ @in_userData = false
94
+ end
95
+ elsif @in_disableApiTermination
96
+ case name
97
+ when 'value'
98
+ @response['disableApiTermination'] = (value == 'true')
99
+ when 'disableApiTermination'
100
+ @in_disableApiTermination = false
101
+ end
102
+ elsif @in_instanceInitiatedShutdownBehavior
103
+ case name
104
+ when 'value'
105
+ @response['instanceInitiatedShutdownBehavior'] = value
106
+ when 'instanceInitiatedShutdownBehavior'
107
+ @in_instanceInitiatedShutdownBehavior = false
108
+ end
109
+ elsif @in_rootDeviceName
110
+ case name
111
+ when 'value'
112
+ @response['rootDeviceName'] = value
113
+ when 'rootDeviceName'
114
+ @in_rootDeviceName = false
115
+ end
116
+ elsif @in_blockDeviceMapping
117
+ case name
118
+ when 'item'
119
+ @response["blockDeviceMapping"] << @block_device_mapping
120
+ @block_device_mapping = {}
121
+ when 'volumeId', 'status', 'deviceName'
122
+ @block_device_mapping[name] = value
123
+ when 'attachTime'
124
+ @block_device_mapping['attachTime'] = Time.parse(value)
125
+ when 'deleteOnTermination'
126
+ @block_device_mapping['deleteOnTermination'] = (value == 'true')
127
+ when 'blockDeviceMapping'
128
+ @in_blockDeviceMapping = false
129
+ end
130
+ elsif @in_productCodes
131
+ @response['productCodes'] << value
132
+ case name
133
+ when 'productCodes'
134
+ @in_productCodes = false
135
+ end
136
+ elsif @in_ebsOptimized
137
+ case name
138
+ when 'value'
139
+ @response['ebsOptimized'] = (value == 'true')
140
+ when 'ebsOptimized'
141
+ @in_ebsOptimized = false
142
+ end
143
+ elsif @in_sriovNetSupport
144
+ case name
145
+ when 'value'
146
+ @response["sriovNetSupport"] = value
147
+ when "sriovNetSupport"
148
+ @in_sriovNetSupport = false
149
+ end
150
+ elsif @in_sourceDestCheck
151
+ case name
152
+ when 'value'
153
+ @response['sourceDestCheck'] = (value == 'true')
154
+ when 'sourceDestCheck'
155
+ @in_sourceDestCheck = false
156
+ end
157
+ elsif @in_groupSet
158
+ case name
159
+ when 'item'
160
+ @response['groupSet'] << @group
161
+ @group = {}
162
+ when 'groupId'
163
+ @group["groupId"] = value
164
+ when 'groupSet'
165
+ @in_groupSet = false
166
+ end
167
+ else
168
+ case name
169
+ when 'requestId', 'instanceId'
170
+ @response[name] = value
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,87 @@
1
+ module Fog
2
+ module Compute
3
+ class AWS
4
+ class Real
5
+ require 'fog/aws/parsers/compute/describe_instance_attribute'
6
+ # Describes an instance attribute value
7
+ #
8
+ # ==== Parameters
9
+ # * instance_id<~String> - The ID of the instance you want to describe an attribute of
10
+ # * attribute<~String> - The attribute to describe, must be one of the following:
11
+ # -'instanceType'
12
+ # -'kernel'
13
+ # -'ramdisk'
14
+ # -'userData'
15
+ # -'disableApiTermination'
16
+ # -'instanceInitiatedShutdownBehavior'
17
+ # -'rootDeviceName'
18
+ # -'blockDeviceMapping'
19
+ # -'productCodes'
20
+ # -'sourceDestCheck'
21
+ # -'groupSet'
22
+ # -'ebsOptimized'
23
+ # -'sriovNetSupport'
24
+ #
25
+ # === Returns
26
+ # * response<~Excon::Response>:
27
+ # * body<~Hash>:
28
+ # * 'requestId'<~String> - Id of request
29
+ # * 'instanceId'<~String> - The ID of the instance
30
+ # * 'instanceType'<~String> - Instance type
31
+ # * 'kernelId'<~String> - The kernel ID
32
+ # * 'ramdiskId'<~String> - The RAM disk ID
33
+ # * 'userData'<~String> - The Base64-encoded MIME user data
34
+ # * 'disableApiTermination'<~Boolean> - If the value is true , you can't terminate the instance through the Amazon EC2 console, CLI, or API; otherwise, you can.
35
+ # * 'instanceInitiatedShutdownBehavior'<~String> - Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown)
36
+ # * 'rootDeviceName'<~String> - The name of the root device (for example, /dev/sda1 or /dev/xvda )
37
+ # * 'blockDeviceMapping'<~List> - The block device mapping of the instance
38
+ # * 'productCodes'<~List> - A list of product codes
39
+ # * 'ebsOptimized'<~Boolean> - Indicates whether the instance is optimized for EBS I/O
40
+ # * 'sriovNetSupport'<~String> - The value to use for a resource attribute
41
+ # * 'sourceDestCheck'<~Boolean> - Indicates whether source/destination checking is enabled. A value of true means checking is enabled, and false means checking is disabled. This value must be false for a NAT instance to perform NAT
42
+ # * 'groupSet'<~List> - The security groups associated with the instance
43
+ # (Amazon API Reference)[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstanceAttribute.html]
44
+ def describe_instance_attribute(instance_id, attribute)
45
+ request(
46
+ 'Action' => 'DescribeInstanceAttribute',
47
+ 'InstanceId' => instance_id,
48
+ 'Attribute' => attribute,
49
+ :parser => Fog::Parsers::Compute::AWS::DescribeInstanceAttribute.new
50
+ )
51
+ end
52
+ end
53
+
54
+ class Mock
55
+ def describe_instance_attribute(instance_id, attribute)
56
+ response = Excon::Response.new
57
+ if instance = self.data[:instances].values.find{ |i| i['instanceId'] == instance_id }
58
+ response.status = 200
59
+ response.body = {
60
+ 'requestId' => Fog::AWS::Mock.request_id,
61
+ 'instanceId' => instance_id
62
+ }
63
+ case attribute
64
+ when 'kernel'
65
+ response.body[attribute] = instance["kernelId"]
66
+ when 'ramdisk'
67
+ response.body[attribute] = instance["ramdiskId"]
68
+ when 'disableApiTermination'
69
+ response.body[attribute] = false
70
+ when 'instanceInitiatedShutdownBehavior'
71
+ response.body['instanceInitiatedShutdownBehavior'] = 'stop'
72
+ when 'sourceDestCheck'
73
+ response.body[attribute] = true
74
+ when 'sriovNetSupport'
75
+ response.body[attribute] = 'simple'
76
+ else
77
+ response.body[attribute] = instance[attribute]
78
+ end
79
+ response
80
+ else
81
+ raise Fog::Compute::AWS::NotFound.new("The Instance '#{instance_id}' does not exist")
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -35,22 +35,22 @@ module Fog
35
35
 
36
36
  class Mock
37
37
  def create_user(user_name, path='/')
38
- if data[:users].key? user_name
38
+ if data[:users].key?(user_name)
39
39
  raise Fog::AWS::IAM::EntityAlreadyExists.new "User with name #{user_name} already exists."
40
- else
41
- data[:users][user_name][:path] = path
42
- Excon::Response.new.tap do |response|
43
- response.status = 200
44
- response.body = { 'User' => {
45
- "UserId" => data[:users][user_name][:user_id],
46
- "Path" => path,
47
- "UserName" => user_name,
48
- "Arn" => (data[:users][user_name][:arn]).strip,
49
- "CreateDate" => data[:users][user_name][:created_at]
50
- },
51
- 'RequestId' => Fog::AWS::Mock.request_id
52
- }
53
- end
40
+ end
41
+
42
+ data[:users][user_name][:path] = path
43
+
44
+ Excon::Response.new.tap do |response|
45
+ response.status = 200
46
+ response.body = { 'User' => {
47
+ "UserId" => data[:users][user_name][:user_id],
48
+ "Path" => path,
49
+ "UserName" => user_name,
50
+ "Arn" => (data[:users][user_name][:arn]).strip,
51
+ },
52
+ 'RequestId' => Fog::AWS::Mock.request_id
53
+ }
54
54
  end
55
55
  end
56
56
  end
@@ -23,31 +23,55 @@ module Fog
23
23
  # ==== See Also
24
24
  # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_Getuser.html
25
25
  #
26
- def get_user(username, options = {})
27
- request({
28
- 'Action' => 'GetUser',
29
- 'UserName' => username,
30
- :parser => Fog::Parsers::AWS::IAM::GetUser.new
31
- }.merge!(options))
26
+ def get_user(username = nil, options = {})
27
+ params = {
28
+ 'Action' => 'GetUser',
29
+ :parser => Fog::Parsers::AWS::IAM::GetUser.new
30
+ }
31
+
32
+ if username
33
+ params.merge!('UserName' => username)
34
+ end
35
+
36
+ request(params.merge(options))
32
37
  end
33
38
  end
34
39
 
35
40
  class Mock
36
- def get_user(user, options = {})
37
- raise Fog::AWS::IAM::NotFound.new(
38
- "The user with name #{user} cannot be found."
39
- ) unless self.data[:users].key?(user)
40
- Excon::Response.new.tap do |response|
41
- response.body = {'User' => {
42
- 'UserId' => data[:users][user][:user_id],
43
- 'Path' => data[:users][user][:path],
44
- 'UserName' => user,
45
- 'Arn' => (data[:users][user][:arn]).strip,
46
- 'CreateDate' => data[:users][user][:created_at]
47
- },
48
- 'RequestId' => Fog::AWS::Mock.request_id }
49
- response.status = 200
41
+ def get_user(username = nil, options = {})
42
+ response = Excon::Response.new
43
+ user_body = nil
44
+
45
+ if username.nil? # show current user
46
+ user = self.current_user
47
+
48
+ user_body = {
49
+ 'UserId' => user[:user_id],
50
+ 'Arn' => user[:arn].strip,
51
+ 'CreateDate' => user[:created_at]
52
+ }
53
+
54
+ elsif !self.data[:users].key?(username)
55
+ raise Fog::AWS::IAM::NotFound.new("The user with name #{username} cannot be found.")
56
+ else
57
+ user = self.data[:users][username]
58
+
59
+ user_body = {
60
+ 'UserId' => user[:user_id],
61
+ 'Path' => user[:path],
62
+ 'UserName' => username,
63
+ 'Arn' => user[:arn].strip,
64
+ 'CreateDate' => user[:created_at]
65
+ }
50
66
  end
67
+
68
+ response.status = 200
69
+ response.body = {
70
+ 'User' => user_body,
71
+ 'RequestId' => Fog::AWS::Mock.request_id
72
+ }
73
+
74
+ response
51
75
  end
52
76
  end
53
77
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AWS
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -38,6 +38,10 @@ Shindo.tests("Fog::Compute[:iam] | users", ['aws','iam']) do
38
38
  @iam.users.get(@user_one_name).id == @user_one_name
39
39
  end
40
40
 
41
+ tests('#current').succeeds do
42
+ @iam.users.current
43
+ end
44
+
41
45
  tests('#get',"returns nil if the user doesn't exists").succeeds do
42
46
  @iam.users.get('non-exists') == nil
43
47
  end
@@ -0,0 +1,168 @@
1
+ Shindo.tests('Fog::Compute[:aws] | describe_instance_attribute request', ['aws']) do
2
+ @instance_attributes = [
3
+ 'instanceType',
4
+ 'kernel',
5
+ 'ramdisk',
6
+ 'userData',
7
+ 'disableApiTermination',
8
+ 'instanceInitiatedShutdownBehavior',
9
+ 'rootDeviceName',
10
+ 'blockDeviceMapping',
11
+ 'productCodes',
12
+ 'groupSet',
13
+ 'ebsOptimized',
14
+ 'sourceDestCheck',
15
+ 'sriovNetSupport'
16
+ ]
17
+
18
+ @instance_attribute_common_format = {
19
+ "requestId" => String,
20
+ "instanceId" => String
21
+ }
22
+
23
+ @instance_attribute_format = {
24
+ "instanceType" => Fog::Nullable::String,
25
+ "kernelId" => Fog::Nullable::String,
26
+ "ramdiskId" => Fog::Nullable::String,
27
+ "userData" => Fog::Nullable::String,
28
+ "disableApiTermination" => Fog::Nullable::Boolean,
29
+ "instanceInitiatedShutdownBehavior" => Fog::Nullable::String,
30
+ "rootDeviceName" => Fog::Nullable::String,
31
+ "blockDeviceMapping" => [Fog::Nullable::Hash],
32
+ "productCodes" => Fog::Nullable::Array,
33
+ "ebsOptimized" => Fog::Nullable::Boolean,
34
+ "sriovNetSupport" => Fog::Nullable::String,
35
+ "sourceDestCheck" => Fog::Nullable::Boolean,
36
+ "groupSet" => [Fog::Nullable::Hash]
37
+ }
38
+
39
+ tests('success') do
40
+
41
+ # In mocking the groupSet attribute is returned as nil
42
+ if Fog.mocking?
43
+ @instance_attribute_format["groupSet"] = Fog::Nullable::Array
44
+ end
45
+ # Setting up the environment
46
+ @instance_id = nil
47
+ @ami = 'ami-79c0ae10'
48
+ key_name = 'fog-test-key'
49
+ @key = Fog::Compute[:aws].key_pairs.create(:name => key_name)
50
+ instance_type = "t1.micro"
51
+ @az = "us-east-1a"
52
+ vpc = Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/16')
53
+ subnet = Fog::Compute[:aws].subnets.create('vpc_id' => vpc.id, 'cidr_block' => '10.0.10.0/16', "availability_zone" => @az)
54
+ security_groups = Fog::Compute[:aws].security_groups.all
55
+ @launch_config = {
56
+ :image_id => @ami,
57
+ :flavor_id => instance_type,
58
+ :key_name => key_name,
59
+ :subnet_id => subnet.subnet_id,
60
+ :disable_api_termination => false
61
+ }
62
+ if !Fog.mocking?
63
+ security_group = security_groups.select { |group| group.vpc_id == vpc.id }
64
+ security_group_ids = security_group.collect { |group| group.group_id }
65
+ @launch_config[:security_group_ids] = security_group_ids
66
+ block_device_mapping = [{"DeviceName" => "/dev/sdp1", "VirtualName" => nil, "Ebs.VolumeSize" => 15}]
67
+ @launch_config[:block_device_mapping] = block_device_mapping
68
+ else
69
+ security_group_ids = [nil]
70
+ # In mocking the first device provided in block_device_mapping is set as the root device. There is no root device by default. So setting the root device here so that the tests for rootDeviceName and blockDeviceMapping attribute get passed
71
+ block_device_mapping = [{"DeviceName" => "/dev/sda1", "VirtualName" => nil, "Ebs.VolumeSize" => 15},{"DeviceName" => "/dev/sdp1", "VirtualName" => nil, "Ebs.VolumeSize" => 15}]
72
+ @launch_config[:block_device_mapping] = block_device_mapping
73
+ end
74
+
75
+
76
+
77
+ server = Fog::Compute[:aws].servers.create(@launch_config)
78
+ server.wait_for { ready? }
79
+ server.reload
80
+ @instance_id = server.id
81
+ ################
82
+ # BEGIN TESTS #
83
+ ################
84
+ @instance_attributes.each do |attrib|
85
+ # Creating format schema for each attribute
86
+ describe_instance_attribute_format = @instance_attribute_common_format.clone
87
+ if attrib == "kernel"
88
+ key = "kernelId"
89
+ elsif attrib == "ramdisk"
90
+ key = "ramdiskId"
91
+ else
92
+ key = attrib
93
+ end
94
+ describe_instance_attribute_format[key] = @instance_attribute_format[key]
95
+ # Running format check
96
+ tests("#describe_instance_attribute('#{@instance_id}', #{attrib})").formats(describe_instance_attribute_format,false) do
97
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, attrib).body
98
+ end
99
+ # Running test to see proper instance Id is get in each response
100
+ tests("#describe_instance_attribute('#{@instance_id}', #{attrib})").returns(@instance_id) do
101
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, attrib).body['instanceId']
102
+ end
103
+ end
104
+
105
+ # Test for instanceType attribute
106
+ tests("#describe_instance_attribute(#{@instance_id}, 'instanceType')").returns(instance_type) do
107
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'instanceType').body["instanceType"]
108
+ end
109
+ # Test for disableApiTermination attribute
110
+ tests("#describe_instance_attribute(#{@instance_id}, 'disableApiTermination')").returns(false) do
111
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'disableApiTermination').body["disableApiTermination"]
112
+ end
113
+ # Test for instanceInitiatedShutdownBehavior attribute
114
+ tests("#describe_instance_attribute(#{@instance_id}, 'instanceInitiatedShutdownBehavior')").returns('stop') do
115
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'instanceInitiatedShutdownBehavior').body["instanceInitiatedShutdownBehavior"]
116
+ end
117
+ # Test for rootDeviceName attribute
118
+ tests("#describe_instance_attribute(#{@instance_id}, 'rootDeviceName')").returns('/dev/sda1') do
119
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'rootDeviceName').body["rootDeviceName"]
120
+ end
121
+ # Test to see there are two devices for blockDeviceMapping attribute
122
+ tests("#describe_instance_attribute(#{@instance_id}, 'blockDeviceMapping')").returns(2) do
123
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'blockDeviceMapping').body["blockDeviceMapping"].count
124
+ end
125
+ # Test to check the device name /dev/sdp1 passed in block_device_mapping is returned correctly
126
+ tests("#describe_instance_attribute(#{@instance_id}, 'blockDeviceMapping')").returns("/dev/sdp1") do
127
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'blockDeviceMapping').body["blockDeviceMapping"].last["deviceName"]
128
+ end
129
+ # Test for groupSet attribute
130
+ tests("#describe_instance_attribute(#{@instance_id}, 'groupSet')").returns(security_group_ids) do
131
+ group_set = Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'groupSet').body["groupSet"]
132
+ group_set.collect { |g| g["groupId"]}
133
+ end
134
+ # Test for sourceDestCheck attribute (This attribute is set only for VPC instances. So created the instance in a VPC during setup process)
135
+ tests("#describe_instance_attribute(#{@instance_id}, 'sourceDestCheck')").returns(true) do
136
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'sourceDestCheck').body["sourceDestCheck"]
137
+ end
138
+ # Test for ebsOptimized attribute
139
+ tests("#describe_instance_attribute(#{@instance_id}, 'ebsOptimized')").returns(false) do
140
+ Fog::Compute[:aws].describe_instance_attribute(@instance_id, 'ebsOptimized').body["ebsOptimized"]
141
+ end
142
+ ###############
143
+ # END OF TEST #
144
+ ###############
145
+
146
+ # Tear down
147
+ if !Fog.mocking?
148
+ @key.destroy
149
+ server.destroy
150
+ until server.state == "terminated"
151
+ sleep 5 #Wait for the server to be terminated
152
+ server.reload
153
+ end
154
+ subnet.destroy
155
+ vpc.destroy
156
+ end
157
+
158
+ end
159
+
160
+ tests('failure') do
161
+ @instance_attributes.each do |attrib|
162
+ tests("#describe_instance_attribute('i-00000000', #{attrib})").raises(Fog::Compute::AWS::NotFound) do
163
+ Fog::Compute[:aws].describe_instance_attribute('i-00000000', attrib)
164
+ end
165
+ end
166
+ end
167
+
168
+ end
@@ -23,7 +23,7 @@ ACtzLycIhlMTmDr0xBeIBx3lpgw2K0+4oefMS8Z17eeZPeNodxnz56juJm81BZwt
23
23
  DF3qnnPyArLFx0HLB7wQdm9xYVIqQuLO+V6GRuOd+uSX//aDLDZhwbERf35hoyto
24
24
  Jfk4gX/qwuRFNy0vjQeTzdvhB1igG/w=
25
25
  -----END CERTIFICATE-----
26
- }
26
+ }
27
27
  # The public key for SERVER_CERT. Generated using the command:
28
28
  # openssl x509 -inform pem -in server-public.crt -pubkey -noout > server.pubkey
29
29
  SERVER_CERT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0CR76sovjdmpWRmEaf8XaG+nGe7czhpdLKkau2b16VtSjkPctxPL5U4vaMxQUboLPr+9oL+9fSYN31VzDD4hyaeGoeI5fhnGeqk71kq5uHONBOQUMbZbBQ8PVd9Sdk+y9JJ6E5fC+GhLL5I+y2DK7syBzyymq1Wi6rPp1XXF7AQIDAQAB"
@@ -43,7 +43,7 @@ c0AQtoYBTJePxiYyd8i32ypkkK83ar+sFoxKO9jYwD1IkZax2xZ0aoTdMindQPR7
43
43
  Yjs+QiLmOHcbPqX+GHcCQERsSn0RjzKmKirDntseMB59BB/cEN32+gMDVsZuCfb+
44
44
  fOy2ZavFl13afnhbh2/AjKeDhnb19x/uXjF7JCUtwpA=
45
45
  -----END RSA PRIVATE KEY-----
46
- }
46
+ }
47
47
 
48
48
  # openssl pkcs8 -nocrypt -topk8 -in SERVER_CERT_PRIVATE_KEY.key -outform pem
49
49
  SERVER_CERT_PRIVATE_KEY_PKCS8 = %{-----BEGIN PRIVATE KEY-----
@@ -62,7 +62,7 @@ v6wWjEo72NjAPUiRlrHbFnRqhN0yKd1A9HtiOz5CIuY4dxs+pf4YdwJARGxKfRGP
62
62
  MqYqKsOe2x4wHn0EH9wQ3fb6AwNWxm4J9v587LZlq8WXXdp+eFuHb8CMp4OGdvX3
63
63
  H+5eMXskJS3CkA==
64
64
  -----END PRIVATE KEY-----
65
- }
65
+ }
66
66
 
67
67
  SERVER_CERT_PRIVATE_KEY_MISMATCHED = %{-----BEGIN RSA PRIVATE KEY-----
68
68
  MIIEowIBAAKCAQEAyITMqYJMzkPMcaC+x0W2hnZVW99RXzLR8RYyD3xo2AotdJKx
@@ -91,12 +91,46 @@ cxyt9QKBgF4bFLw1Iw2RBngQxIzoDbElEqme20FUyGGzyFQtxVwmwNr4OY5UzJzX
91
91
  7G6diyzGrvRX81Yw616ppKJUJVr/zRc13K+eRXXKtNpGkf35B+1NDDjjWZpIHqgx
92
92
  Xb9WSr07saxZQbxBPQyTlb0Q9Tu2djAq2/o/nYD1/50/fXUTuWMB
93
93
  -----END RSA PRIVATE KEY-----
94
- }
94
+ }
95
95
 
96
96
  module Formats
97
97
  BASIC = {
98
98
  'RequestId' => String
99
99
  }
100
+
101
+ USER = {
102
+ 'Arn' => String,
103
+ 'Path' => String,
104
+ 'UserId' => String,
105
+ 'UserName' => String,
106
+ }
107
+
108
+ CREATE_USER = BASIC.merge('User' => USER)
109
+
110
+ GET_USER = BASIC.merge('User' => USER.merge('CreateDate' => Time))
111
+
112
+ GET_CURRENT_USER = BASIC.merge(
113
+ 'User' => {
114
+ 'Arn' => String,
115
+ 'UserId' => String,
116
+ 'CreateDate' => Time
117
+ }
118
+ )
119
+
120
+ LIST_USER = BASIC.merge(
121
+ 'Users' => [USER.merge('CreateDate' => Time)],
122
+ 'IsTruncated' => Fog::Boolean
123
+ )
124
+
125
+ GROUPS = BASIC.merge(
126
+ 'GroupsForUser' => [{
127
+ 'Arn' => String,
128
+ 'GroupId' => String,
129
+ 'GroupName' => String,
130
+ 'Path' => String
131
+ }],
132
+ 'IsTruncated' => Fog::Boolean
133
+ )
100
134
  end
101
135
  end
102
136
  end
@@ -1,75 +1,48 @@
1
1
  Shindo.tests('AWS::IAM | user requests', ['aws']) do
2
2
 
3
- Fog::AWS[:iam].create_group('fog_user_tests')
4
-
5
- tests('success') do
6
-
7
- @user_format = {
8
- 'User' => {
9
- 'Arn' => String,
10
- 'Path' => String,
11
- 'UserId' => String,
12
- 'UserName' => String,
13
- 'CreateDate' => Time
14
- },
15
- 'RequestId' => String
16
- }
3
+ begin
4
+ Fog::AWS[:iam].delete_group('fog_user_tests')
5
+ rescue Fog::AWS::IAM::NotFound
6
+ end
17
7
 
18
- tests("#create_user('fog_user')").formats(@user_format) do
19
- Fog::AWS[:iam].create_user('fog_user').body
20
- end
8
+ begin
9
+ Fog::AWS[:iam].delete_user('fog_user').body
10
+ rescue Fog::AWS::IAM::NotFound
11
+ end
21
12
 
22
- @users_format = {
23
- 'Users' => [{
24
- 'Arn' => String,
25
- 'Path' => String,
26
- 'UserId' => String,
27
- 'UserName' => String,
28
- 'CreateDate' => Time
29
- }],
30
- 'IsTruncated' => Fog::Boolean,
31
- 'RequestId' => String
32
- }
13
+ Fog::AWS[:iam].create_group('fog_user_tests')
33
14
 
34
- tests("#list_users").formats(@users_format) do
35
- Fog::AWS[:iam].list_users.body
36
- end
37
15
 
38
- tests("#get_user").formats(@user_format) do
39
- Fog::AWS[:iam].get_user('fog_user').body
40
- end
16
+ tests("#create_user('fog_user')").data_matches_schema(AWS::IAM::Formats::CREATE_USER) do
17
+ Fog::AWS[:iam].create_user('fog_user').body
18
+ end
41
19
 
42
- tests("#add_user_to_group('fog_user_tests', 'fog_user')").formats(AWS::IAM::Formats::BASIC) do
43
- Fog::AWS[:iam].add_user_to_group('fog_user_tests', 'fog_user').body
44
- end
20
+ tests("#list_users").data_matches_schema(AWS::IAM::Formats::LIST_USER) do
21
+ Fog::AWS[:iam].list_users.body
22
+ end
45
23
 
46
- @groups_format = {
47
- 'GroupsForUser' => [{
48
- 'Arn' => String,
49
- 'GroupId' => String,
50
- 'GroupName' => String,
51
- 'Path' => String
52
- }],
53
- 'IsTruncated' => Fog::Boolean,
54
- 'RequestId' => String
55
- }
24
+ tests("#get_user('fog_user')").data_matches_schema(AWS::IAM::Formats::GET_USER) do
25
+ Fog::AWS[:iam].get_user('fog_user').body
26
+ end
56
27
 
57
- tests("#list_groups_for_user('fog_user')").formats(@groups_format) do
58
- Fog::AWS[:iam].list_groups_for_user('fog_user').body
59
- end
28
+ tests("#get_user").data_matches_schema(AWS::IAM::Formats::GET_CURRENT_USER) do
29
+ Fog::AWS[:iam].get_user.body
30
+ end
60
31
 
61
- tests("#remove_user_from_group('fog_user_tests', 'fog_user')").formats(AWS::IAM::Formats::BASIC) do
62
- Fog::AWS[:iam].remove_user_from_group('fog_user_tests', 'fog_user').body
63
- end
32
+ tests("#add_user_to_group('fog_user_tests', 'fog_user')").data_matches_schema(AWS::IAM::Formats::BASIC) do
33
+ Fog::AWS[:iam].add_user_to_group('fog_user_tests', 'fog_user').body
34
+ end
64
35
 
65
- tests("#delete_user('fog_user')").formats(AWS::IAM::Formats::BASIC) do
66
- Fog::AWS[:iam].delete_user('fog_user').body
67
- end
36
+ tests("#list_groups_for_user('fog_user')").data_matches_schema(AWS::IAM::Formats::GROUPS) do
37
+ Fog::AWS[:iam].list_groups_for_user('fog_user').body
38
+ end
68
39
 
40
+ tests("#remove_user_from_group('fog_user_tests', 'fog_user')").data_matches_schema(AWS::IAM::Formats::BASIC) do
41
+ Fog::AWS[:iam].remove_user_from_group('fog_user_tests', 'fog_user').body
69
42
  end
70
43
 
71
- tests('failure') do
72
- test('failing conditions')
44
+ tests("#delete_user('fog_user')").data_matches_schema(AWS::IAM::Formats::BASIC) do
45
+ Fog::AWS[:iam].delete_user('fog_user').body
73
46
  end
74
47
 
75
48
  Fog::AWS[:iam].delete_group('fog_user_tests')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-13 00:00:00.000000000 Z
12
+ date: 2015-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -386,6 +386,7 @@ files:
386
386
  - lib/fog/aws/parsers/compute/describe_classic_link_instances.rb
387
387
  - lib/fog/aws/parsers/compute/describe_dhcp_options.rb
388
388
  - lib/fog/aws/parsers/compute/describe_images.rb
389
+ - lib/fog/aws/parsers/compute/describe_instance_attribute.rb
389
390
  - lib/fog/aws/parsers/compute/describe_instance_status.rb
390
391
  - lib/fog/aws/parsers/compute/describe_instances.rb
391
392
  - lib/fog/aws/parsers/compute/describe_internet_gateways.rb
@@ -789,6 +790,7 @@ files:
789
790
  - lib/fog/aws/requests/compute/describe_classic_link_instances.rb
790
791
  - lib/fog/aws/requests/compute/describe_dhcp_options.rb
791
792
  - lib/fog/aws/requests/compute/describe_images.rb
793
+ - lib/fog/aws/requests/compute/describe_instance_attribute.rb
792
794
  - lib/fog/aws/requests/compute/describe_instance_status.rb
793
795
  - lib/fog/aws/requests/compute/describe_instances.rb
794
796
  - lib/fog/aws/requests/compute/describe_internet_gateways.rb
@@ -1333,6 +1335,7 @@ files:
1333
1335
  - tests/requests/compute/dhcp_options_tests.rb
1334
1336
  - tests/requests/compute/helper.rb
1335
1337
  - tests/requests/compute/image_tests.rb
1338
+ - tests/requests/compute/instance_attrib_tests.rb
1336
1339
  - tests/requests/compute/instance_tests.rb
1337
1340
  - tests/requests/compute/internet_gateway_tests.rb
1338
1341
  - tests/requests/compute/key_pair_tests.rb