fog-aws 0.7.6 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +1 -0
  4. data/lib/fog/aws/compute.rb +1 -1
  5. data/lib/fog/aws/iam/paged_collection.rb +4 -2
  6. data/lib/fog/aws/models/compute/server.rb +0 -1
  7. data/lib/fog/aws/models/elasticache/cluster.rb +2 -1
  8. data/lib/fog/aws/models/iam/roles.rb +11 -14
  9. data/lib/fog/aws/models/rds/server.rb +2 -1
  10. data/lib/fog/aws/models/storage/directory.rb +1 -1
  11. data/lib/fog/aws/parsers/elasticache/cache_cluster_parser.rb +29 -4
  12. data/lib/fog/aws/parsers/storage/get_bucket_lifecycle.rb +30 -0
  13. data/lib/fog/aws/requests/compute/describe_instances.rb +1 -1
  14. data/lib/fog/aws/requests/compute/start_instances.rb +1 -0
  15. data/lib/fog/aws/requests/compute/stop_instances.rb +1 -0
  16. data/lib/fog/aws/requests/dynamodb/batch_get_item.rb +8 -11
  17. data/lib/fog/aws/requests/dynamodb/batch_write_item.rb +11 -9
  18. data/lib/fog/aws/requests/dynamodb/create_table.rb +9 -14
  19. data/lib/fog/aws/requests/dynamodb/delete_item.rb +5 -15
  20. data/lib/fog/aws/requests/dynamodb/delete_table.rb +4 -8
  21. data/lib/fog/aws/requests/dynamodb/describe_table.rb +7 -8
  22. data/lib/fog/aws/requests/dynamodb/get_item.rb +9 -7
  23. data/lib/fog/aws/requests/dynamodb/list_tables.rb +4 -1
  24. data/lib/fog/aws/requests/dynamodb/put_item.rb +6 -10
  25. data/lib/fog/aws/requests/dynamodb/query.rb +14 -6
  26. data/lib/fog/aws/requests/dynamodb/scan.rb +6 -6
  27. data/lib/fog/aws/requests/dynamodb/update_item.rb +22 -20
  28. data/lib/fog/aws/requests/dynamodb/update_table.rb +6 -7
  29. data/lib/fog/aws/requests/elasticache/create_cache_cluster.rb +1 -0
  30. data/lib/fog/aws/requests/iam/create_role.rb +1 -1
  31. data/lib/fog/aws/requests/iam/get_role.rb +5 -2
  32. data/lib/fog/aws/requests/iam/list_roles.rb +50 -16
  33. data/lib/fog/aws/requests/rds/modify_db_instance.rb +53 -54
  34. data/lib/fog/aws/requests/storage/get_object.rb +5 -3
  35. data/lib/fog/aws/requests/storage/put_bucket_lifecycle.rb +28 -5
  36. data/lib/fog/aws/requests/storage/put_object.rb +4 -0
  37. data/lib/fog/aws/storage.rb +3 -0
  38. data/lib/fog/aws/sts.rb +4 -3
  39. data/lib/fog/aws/version.rb +1 -1
  40. data/tests/models/compute/server_tests.rb +11 -0
  41. data/tests/models/iam/roles_tests.rb +12 -4
  42. data/tests/models/storage/directory_tests.rb +4 -0
  43. data/tests/requests/compute/instance_tests.rb +44 -2
  44. data/tests/requests/dynamodb/item_tests.rb +2 -2
  45. data/tests/requests/storage/bucket_tests.rb +5 -0
  46. metadata +4 -3
@@ -48,15 +48,17 @@ module Fog
48
48
  params[:headers]['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header
49
49
  end
50
50
 
51
+ idempotent = true
51
52
  if block_given?
52
53
  params[:response_block] = Proc.new
54
+ idempotent = false
53
55
  end
54
56
 
55
57
  request(params.merge!({
56
58
  :expects => [ 200, 206 ],
57
59
  :bucket_name => bucket_name,
58
60
  :object_name => object_name,
59
- :idempotent => true,
61
+ :idempotent => idempotent,
60
62
  :method => 'GET',
61
63
  }))
62
64
  end
@@ -115,10 +117,10 @@ module Fog
115
117
  response.body = body
116
118
  else
117
119
  data = StringIO.new(body)
118
- remaining = data.length
120
+ remaining = total_bytes = data.length
119
121
  while remaining > 0
120
122
  chunk = data.read([remaining, Excon::CHUNK_SIZE].min)
121
- block.call(chunk)
123
+ block.call(chunk, remaining, total_bytes)
122
124
  remaining -= Excon::CHUNK_SIZE
123
125
  end
124
126
  end
@@ -10,13 +10,13 @@ module Fog
10
10
  # * ID [String] Unique identifier for the rule
11
11
  # * Prefix [String] Prefix identifying one or more objects to which the rule applies
12
12
  # * Enabled [Boolean] if rule is currently being applied
13
- # * Expiration [Hash] Container for the object expiration rule.
14
- # * Days [Integer] lifetime, in days, of the objects that are subject to the rule
13
+ # * [NoncurrentVersion]Expiration [Hash] Container for the object expiration rule.
14
+ # * [Noncurrent]Days [Integer] lifetime, in days, of the objects that are subject to the rule
15
15
  # * Date [Date] Indicates when the specific rule take effect.
16
16
  # The date value must conform to the ISO 8601 format. The time is always midnight UTC.
17
- # * Transition [Hash] Container for the transition rule that describes when objects transition
17
+ # * [NoncurrentVersion]Transition [Hash] Container for the transition rule that describes when objects transition
18
18
  # to the Glacier storage class
19
- # * Days [Integer] lifetime, in days, of the objects that are subject to the rule
19
+ # * [Noncurrent]Days [Integer] lifetime, in days, of the objects that are subject to the rule
20
20
  # * Date [Date] Indicates when the specific rule take effect.
21
21
  # The date value must conform to the ISO 8601 format. The time is always midnight UTC.
22
22
  # * StorageClass [String] Indicates the Amazon S3 storage class to which you want the object
@@ -33,7 +33,7 @@ module Fog
33
33
  ID rule['ID']
34
34
  Prefix rule['Prefix']
35
35
  Status rule['Enabled'] ? 'Enabled' : 'Disabled'
36
- unless (rule['Expiration'] or rule['Transition'])
36
+ unless (rule['Expiration'] or rule['Transition'] or rule['NoncurrentVersionExpiration'] or rule['NoncurrentVersionTransition'])
37
37
  Expiration { Days rule['Days'] }
38
38
  else
39
39
  if rule['Expiration']
@@ -43,6 +43,19 @@ module Fog
43
43
  Expiration { Date rule['Expiration']['Date'].is_a?(Time) ? rule['Expiration']['Date'].utc.iso8601 : Time.parse(rule['Expiration']['Date']).utc.iso8601 }
44
44
  end
45
45
  end
46
+ if rule['NoncurrentVersionExpiration']
47
+ if rule['NoncurrentVersionExpiration']['NoncurrentDays']
48
+ NoncurrentVersionExpiration { NoncurrentDays rule['NoncurrentVersionExpiration']['NoncurrentDays'] }
49
+ elsif rule['NoncurrentVersionExpiration']['Date']
50
+ NoncurrentVersoinExpiration {
51
+ if Date rule['NoncurrentVersionExpiration']['Date'].is_a?(Time)
52
+ rule['NoncurrentVersionExpiration']['Date'].utc.iso8601
53
+ else
54
+ Time.parse(rule['NoncurrentVersionExpiration']['Date']).utc.iso8601
55
+ end
56
+ }
57
+ end
58
+ end
46
59
  if rule['Transition']
47
60
  Transition {
48
61
  if rule['Transition']['Days']
@@ -53,6 +66,16 @@ module Fog
53
66
  StorageClass rule['Transition']['StorageClass'].nil? ? 'GLACIER' : rule['Transition']['StorageClass']
54
67
  }
55
68
  end
69
+ if rule['NoncurrentVersionTransition']
70
+ NoncurrentVersionTransition {
71
+ if rule['NoncurrentVersionTransition']['NoncurrentDays']
72
+ NoncurrentDays rule['NoncurrentVersionTransition']['NoncurrentDays']
73
+ elsif rule['NoncurrentVersionTransition']['Date']
74
+ Date rule['NoncurrentVersionTransition']['Date'].is_a?(Time) ? time.utc.iso8601 : Time.parse(time).utc.iso8601
75
+ end
76
+ StorageClass rule['NoncurrentVersionTransition']['StorageClass'].nil? ? 'GLACIER' : rule['NoncurrentVersionTransition']['StorageClass']
77
+ }
78
+ end
56
79
  end
57
80
  }
58
81
  end
@@ -18,6 +18,10 @@ module Fog
18
18
  # @option options x-amz-acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
19
19
  # @option options x-amz-storage-class [String] Default is 'STANDARD', set to 'REDUCED_REDUNDANCY' for non-critical, reproducable data
20
20
  # @option options x-amz-meta-#{name} Headers to be returned with object, note total size of request without body must be less than 8 KB. Each name, value pair must conform to US-ASCII.
21
+ # @option options encryption [String] Sets HTTP header for server-side encryption. Set to 'AES256' for SSE-S3 and SSE-C. Set to 'aws:kms' for SSE-KMS
22
+ # @option options encryption_key [String] Encryption customer key for SSE-C
23
+ # @option options x-amz-server-side-encryption-aws-kms-key-id [String] KMS key ID of the encryption key for SSE-KMS
24
+ # @option options x-amz-server-side-encryption-context [String] Encryption context for SSE-KMS
21
25
  #
22
26
  # @return [Excon::Response] response:
23
27
  # * headers [Hash]:
@@ -205,6 +205,8 @@ module Fog
205
205
  case region.to_s
206
206
  when DEFAULT_REGION, ''
207
207
  's3.amazonaws.com'
208
+ when 'cn-north-1'
209
+ 's3.cn-north-1.amazonaws.com.cn'
208
210
  else
209
211
  "s3-#{region}.amazonaws.com"
210
212
  end
@@ -644,6 +646,7 @@ module Fog
644
646
  #we must also reset the signature
645
647
  def rewind
646
648
  self.signature = initial_signature
649
+ self.finished = false
647
650
  body.rewind
648
651
  end
649
652
 
@@ -7,7 +7,7 @@ module Fog
7
7
  class ValidationError < Fog::AWS::STS::Error; end
8
8
  class AwsAccessKeysMissing < Fog::AWS::STS::Error; end
9
9
 
10
- recognizes :aws_access_key_id, :aws_secret_access_key, :host, :path, :port, :scheme, :persistent, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at, :instrumentor, :instrumentor_name
10
+ recognizes :region, :aws_access_key_id, :aws_secret_access_key, :host, :path, :port, :scheme, :persistent, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at, :instrumentor, :instrumentor_name
11
11
 
12
12
  request_path 'fog/aws/requests/sts'
13
13
  request :get_federation_token
@@ -74,12 +74,13 @@ module Fog
74
74
  def initialize(options={})
75
75
 
76
76
  @use_iam_profile = options[:use_iam_profile]
77
+ @region = options[:region] || 'us-east-1'
77
78
  setup_credentials(options)
78
79
  @instrumentor = options[:instrumentor]
79
80
  @instrumentor_name = options[:instrumentor_name] || 'fog.aws.sts'
80
81
  @connection_options = options[:connection_options] || {}
81
82
 
82
- @host = options[:host] || 'sts.amazonaws.com'
83
+ @host = options[:host] || "sts.#{@region}.amazonaws.com"
83
84
  @path = options[:path] || '/'
84
85
  @persistent = options[:persistent] || false
85
86
  @port = options[:port] || 443
@@ -100,7 +101,7 @@ module Fog
100
101
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]
101
102
 
102
103
  if (@aws_access_key_id && @aws_secret_access_key)
103
- @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, 'us-east-1', 'sts')
104
+ @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'sts')
104
105
  end
105
106
  end
106
107
 
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AWS
3
- VERSION = "0.7.6"
3
+ VERSION = "0.8.0"
4
4
  end
5
5
  end
@@ -60,6 +60,17 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do
60
60
  @instance.associate_public_ip == false
61
61
  end
62
62
 
63
+ test('#stop') do
64
+ @instance.stop
65
+ @instance.wait_for { state == "stopped" }
66
+ @instance.state == "stopped"
67
+ end
68
+
69
+ test("#start") do
70
+ @instance.start
71
+ @instance.wait_for { ready? }
72
+ @instance.state == "running"
73
+ end
63
74
  end
64
75
 
65
76
  @instance.destroy
@@ -1,14 +1,12 @@
1
1
  Shindo.tests("Fog::Compute[:iam] | roles", ['aws','iam']) do
2
2
 
3
- pending if Fog.mocking?
4
-
5
3
  @iam = Fog::AWS[:iam]
6
4
  @role_one_name = 'fake_role_one'
7
5
  @role_two_name = 'fake_role_two'
8
6
 
9
7
  @role_three_name = 'fake_role_three'
10
8
  @role_three_path = '/path/to/fake_role_three/'
11
- @role_four_name = 'fake_role_four'
9
+ @role_four_name = 'fake_role_four'
12
10
 
13
11
  tests('#create').succeeds do
14
12
  @role_one = @iam.roles.create(:rolename => @role_one_name)
@@ -37,7 +35,7 @@ Shindo.tests("Fog::Compute[:iam] | roles", ['aws','iam']) do
37
35
  end
38
36
 
39
37
  tests('#get',"returns nil if the role doesn't exists").succeeds do
40
- @iam.roles.get('non-exists') == nil
38
+ @iam.roles.get('blah').nil?
41
39
  end
42
40
 
43
41
  tests('#create', 'assigns path').succeeds do
@@ -54,6 +52,16 @@ Shindo.tests("Fog::Compute[:iam] | roles", ['aws','iam']) do
54
52
  @iam.roles.get(@role_one_name).destroy
55
53
  end
56
54
 
55
+ tests('#all', 'limit 1').succeeds do
56
+ 1 == @iam.roles.all(:limit => 1).size
57
+ end
58
+
59
+ tests('#all', 'each_entry').succeeds do
60
+ roles = []; @iam.roles.each(:limit => 1) { |r| roles << r }
61
+
62
+ 3 == roles.size
63
+ end
64
+
57
65
  tests('#destroy','clean up remaining roles').succeeds do
58
66
  @iam.roles.get(@role_two_name).destroy
59
67
  @iam.roles.get(@role_three_name).destroy
@@ -9,6 +9,10 @@ Shindo.tests("Storage[:aws] | directory", ["aws"]) do
9
9
  @instance.public_url
10
10
  end
11
11
 
12
+ tests('#location').returns('us-east-1') do # == Fog::AWS::Storage::DEFAULT_REGION
13
+ @instance.location
14
+ end
15
+
12
16
  @instance.acl = 'public-read'
13
17
  @instance.save
14
18
 
@@ -81,7 +81,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
81
81
  'timestamp' => Time
82
82
  }
83
83
 
84
- @terminate_instances_format = {
84
+ @instance_state_change_format = {
85
85
  'instancesSet' => [{
86
86
  'currentState' => {'code' => Integer, 'name' => String},
87
87
  'instanceId' => String,
@@ -161,6 +161,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
161
161
  'eventsSet' => [Fog::Nullable::Hash],
162
162
  }]
163
163
  }
164
+
164
165
  tests('success') do
165
166
 
166
167
  @instance_id = nil
@@ -217,6 +218,39 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
217
218
 
218
219
  another_server.destroy
219
220
 
221
+ tests("#run_instances_with_tags").formats(@describe_instances_format) do
222
+
223
+ svr1 = Fog::Compute[:aws].servers.create(
224
+ :availability_zone => 'eu-west-1a',
225
+ :tags => {
226
+ "Name" => "test::test::test",
227
+ "Stack" => "test",
228
+ "Stage" => "test",
229
+ "App" => "test1",
230
+ },
231
+ :image_id => 'ami-3d7e2e54',
232
+ :flavor_id => 't1.micro',
233
+ )
234
+ svr2 = Fog::Compute[:aws].servers.create(
235
+ :availability_zone => 'eu-west-1b',
236
+ :tags => {
237
+ "Name" => "test::test::dev",
238
+ "Stack" => "test",
239
+ "Stage" => "test",
240
+ "App" => "test2",
241
+ },
242
+ :image_id => 'ami-3d7e2e54',
243
+ :flavor_id => 't1.micro',
244
+ )
245
+
246
+ filters = {'tag:App' => ['test1', 'test2']}
247
+ body = Fog::Compute[:aws].describe_instances('tag:App' => ['test1', 'test2']).body
248
+ tests("returns 2 hosts").returns(2) { body['reservationSet'].size }
249
+ svr1.destroy
250
+ svr2.destroy
251
+ body
252
+ end
253
+
220
254
  tests("#get_console_output('#{@instance_id}')").formats(@get_console_output_format) do
221
255
  Fog::Compute[:aws].get_console_output(@instance_id).body
222
256
  end
@@ -246,7 +280,15 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
246
280
  Fog::Compute[:aws].reboot_instances(@instance_id).body
247
281
  end
248
282
 
249
- tests("#terminate_instances('#{@instance_id}')").formats(@terminate_instances_format) do
283
+ tests("#stop_instances('#{@instance_id}')").formats(@instance_state_change_format) do
284
+ Fog::Compute[:aws].stop_instances(@instance_id).body
285
+ end
286
+
287
+ tests("#start_instances('#{@instance_id}')").formats(@instance_state_change_format) do
288
+ Fog::Compute[:aws].start_instances(@instance_id).body
289
+ end
290
+
291
+ tests("#terminate_instances('#{@instance_id}')").formats(@instance_state_change_format) do
250
292
  Fog::Compute[:aws].terminate_instances(@instance_id).body
251
293
  end
252
294
 
@@ -91,10 +91,10 @@ Shindo.tests('Fog::AWS[:dynamodb] | item requests', ['aws']) do
91
91
  'LastEvaluatedKey' => NilClass
92
92
  }
93
93
 
94
- tests("#query('#{@table_name}', {'S' => 'key'}").formats(@query_format) do
94
+ tests("#query('#{@table_name}')").formats(@query_format) do
95
95
  pending if Fog.mocking?
96
96
  pending # requires a table with range key
97
- Fog::AWS[:dynamodb].query(@table_name, {'S' => 'key'}).body
97
+ Fog::AWS[:dynamodb].query(@table_name).body
98
98
  end
99
99
 
100
100
  @scan_format = @query_format.merge('ScannedCount' => Integer)
@@ -277,6 +277,11 @@ Shindo.tests('Fog::Storage[:aws] | bucket requests', ["aws"]) do
277
277
  Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle)
278
278
  Fog::Storage[:aws].get_bucket_lifecycle(@aws_bucket_name).body
279
279
  end
280
+ lifecycle = {'Rules' => [{'ID' => 'test rule', 'Prefix' => '/prefix', 'Enabled' => true, 'NoncurrentVersionExpiration' => {'NoncurrentDays' => 42}, 'NoncurrentVersionTransition' => {'NoncurrentDays' => 6, 'StorageClass'=>'GLACIER'}}]}
281
+ tests('versioned transition').returns(lifecycle) do
282
+ Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle)
283
+ Fog::Storage[:aws].get_bucket_lifecycle(@aws_bucket_name).body
284
+ end
280
285
  lifecycle = {'Rules' => [{'ID' => 'test rule', 'Prefix' => '/prefix', 'Enabled' => true, 'Expiration' => {'Date' => '2012-12-31T00:00:00.000Z'}}]}
281
286
  tests('date').returns(lifecycle) do
282
287
  Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle)
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.7.6
4
+ version: 0.8.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-08-26 00:00:00.000000000 Z
12
+ date: 2016-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -1584,8 +1584,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1584
1584
  version: '0'
1585
1585
  requirements: []
1586
1586
  rubyforge_project:
1587
- rubygems_version: 2.4.5
1587
+ rubygems_version: 2.4.5.1
1588
1588
  signing_key:
1589
1589
  specification_version: 4
1590
1590
  summary: Module for the 'fog' gem to support Amazon Web Services.
1591
1591
  test_files: []
1592
+ has_rdoc: