aws-sdk-core 2.0.2 → 2.0.3

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.
@@ -68,7 +68,9 @@ module Aws
68
68
  end
69
69
 
70
70
  autoload :Client, 'aws-sdk-core/client'
71
+ autoload :ClientPaging, 'aws-sdk-core/client_paging'
71
72
  autoload :ClientStubs, 'aws-sdk-core/client_stubs'
73
+ autoload :ClientWaiters, 'aws-sdk-core/client_waiters'
72
74
  autoload :CredentialProviderChain, 'aws-sdk-core/credential_provider_chain'
73
75
  autoload :Credentials, 'aws-sdk-core/credentials'
74
76
  autoload :EmptyStructure, 'aws-sdk-core/empty_structure'
@@ -216,7 +218,7 @@ module Aws
216
218
 
217
219
  # @api private
218
220
  def load_json(path)
219
- MultiJson.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
221
+ Seahorse::Util.load_json(path)
220
222
  end
221
223
 
222
224
  # Registers a new service.
@@ -259,42 +261,18 @@ module Aws
259
261
 
260
262
  # build service client classes
261
263
  service_added do |name, svc_module, options|
264
+
262
265
  svc_module.const_set(:Client, Client.define(name, options))
263
266
  svc_module.const_set(:Errors, Module.new { extend Errors::DynamicErrors })
264
- end
265
-
266
- # build service paginators
267
- service_added do |name, svc_module, options|
268
- paginators = options[:paginators]
269
- paginators = case paginators
270
- when Paging::Provider then paginators
271
- when Hash then Paging::Provider.new(paginators)
272
- when String then Paging::Provider.new(Aws.load_json(paginators))
273
- when nil then Paging::NullProvider.new
274
- else raise ArgumentError, 'invalid :paginators option'
275
- end
276
- svc_module.const_get(:Client).paginators = paginators
277
- end
278
267
 
279
- # build service waiters
280
- service_added do |name, svc_module, options|
281
- waiters = options[:waiters]
282
- waiters = case waiters
283
- when Waiters::Provider then waiters
284
- when Hash then Waiters::Provider.new(waiters)
285
- when String then Waiters::Provider.new(Aws.load_json(waiters))
286
- when nil then Waiters::NullProvider.new
287
- else raise ArgumentError, 'invalid :waiters option'
288
- end
268
+ # temporary workaround for issue with S3 waiter definition
289
269
  if name == 'S3'
290
- # temporary workaround for issue with S3 waiter definition
291
- defs = waiters.instance_variable_get("@definitions")
270
+ defs = svc_module::Client.waiters.instance_variable_get("@definitions")
292
271
  defs[:bucket_exists]['ignore_errors'] = ['NotFound']
293
272
  defs[:object_exists]['ignore_errors'] = ['NotFound']
294
273
  defs[:bucket_not_exists]['success_value'] = 'NotFound'
295
274
  defs[:object_not_exists]['success_value'] = 'NotFound'
296
275
  end
297
- svc_module.const_get(:Client).waiters = waiters
298
276
  end
299
277
 
300
278
  end
@@ -2,19 +2,6 @@ module Aws
2
2
  module Api
3
3
  module ServiceCustomizations
4
4
 
5
- DEFAULT_PLUGINS = [
6
- 'Seahorse::Client::Plugins::Logging',
7
- 'Seahorse::Client::Plugins::RestfulBindings',
8
- 'Seahorse::Client::Plugins::ContentLength',
9
- 'Aws::Plugins::UserAgent',
10
- 'Aws::Plugins::RetryErrors',
11
- 'Aws::Plugins::GlobalConfiguration',
12
- 'Aws::Plugins::RegionalEndpoint',
13
- 'Aws::Plugins::ResponsePaging',
14
- 'Aws::Plugins::RequestSigner',
15
- 'Aws::Plugins::StubResponses',
16
- ]
17
-
18
5
  @customizations = Hash.new {|h,k| h[k] = [] }
19
6
 
20
7
  class << self
@@ -40,7 +27,7 @@ module Aws
40
27
  # @see {#customize}
41
28
  # @see {Customizer}
42
29
  def apply(client_class)
43
- apply_plugins(client_class)
30
+ apply_protocol_plugin(client_class)
44
31
  endpoint_prefix = client_class.api.metadata('endpointPrefix')
45
32
  @customizations[endpoint_prefix].each do |customization|
46
33
  Customizer.new(client_class).apply(&customization)
@@ -49,17 +36,6 @@ module Aws
49
36
 
50
37
  private
51
38
 
52
- def apply_plugins(client_class)
53
- apply_default_plugins(client_class)
54
- apply_protocol_plugin(client_class)
55
- end
56
-
57
- def apply_default_plugins(client_class)
58
- DEFAULT_PLUGINS.each do |plugin|
59
- client_class.add_plugin(plugin)
60
- end
61
- end
62
-
63
39
  def apply_protocol_plugin(client_class)
64
40
  protocol = client_class.api.metadata('protocol')
65
41
  plugin = case protocol
@@ -126,6 +102,11 @@ module Aws
126
102
  add_plugin 'Aws::Plugins::S3Redirects'
127
103
  add_plugin 'Aws::Plugins::S3SseCpk'
128
104
  add_plugin 'Aws::Plugins::S3UrlEncodedKeys'
105
+ defs = client_class.waiters.instance_variable_get("@definitions")
106
+ defs[:bucket_exists]['ignore_errors'] = ['NotFound']
107
+ defs[:object_exists]['ignore_errors'] = ['NotFound']
108
+ defs[:bucket_not_exists]['success_value'] = 'NotFound'
109
+ defs[:object_not_exists]['success_value'] = 'NotFound'
129
110
  end
130
111
 
131
112
  customize 'sqs' do
@@ -2,85 +2,21 @@ module Aws
2
2
  # Base class for all {Aws} service clients.
3
3
  class Client < Seahorse::Client::Base
4
4
 
5
+ # @api private
6
+ DEFAULT_PLUGINS = [
7
+ 'Seahorse::Client::Plugins::Logging',
8
+ 'Seahorse::Client::Plugins::RestfulBindings',
9
+ 'Seahorse::Client::Plugins::ContentLength',
10
+ 'Aws::Plugins::UserAgent',
11
+ 'Aws::Plugins::RetryErrors',
12
+ 'Aws::Plugins::GlobalConfiguration',
13
+ 'Aws::Plugins::RegionalEndpoint',
14
+ 'Aws::Plugins::RequestSigner',
15
+ ]
16
+
17
+ include ClientPaging
5
18
  include ClientStubs
6
-
7
- # Waits until a particular condition is satisfied. This works by
8
- # polling a client request and checking for particular response
9
- # data or errors. Waiters each have a default duration max attempts
10
- # which are configurable. Additionally, you can register callbacks
11
- # and stop waiters by throwing `:success` or `:failure`.
12
- #
13
- # @example Basic usage
14
- # client.wait_until(:waiter_name)
15
- #
16
- # @example Configuring interval and maximum attempts
17
- # client.wait_until(:waiter_name) do |w|
18
- # w.interval = 10 # number of seconds to sleep between attempts
19
- # w.max_attempts = 6 # maximum number of polling attempts
20
- # end
21
- #
22
- # @example Rescuing a failed wait
23
- # begin
24
- # client.wait_until(:waiter_name)
25
- # rescue Aws::Waiters::Errors::WaiterFailed
26
- # # gave up waiting
27
- # end
28
- #
29
- # @example Waiting with progress callbacks
30
- # client.wait_until(:waiter_name) do |w|
31
- #
32
- # # yields just before polling for change
33
- # w.before_attempt do |attempt|
34
- # # attempts - number of previous attempts made
35
- # end
36
- #
37
- # # yields before sleeping
38
- # w.before_wait do |attempt, prev_response|
39
- # # attempts - number of previous attempts made
40
- # # prev_response - the last client response received
41
- # end
42
- # end
43
- #
44
- # @example Throw :success or :failure to terminate early
45
- # # wait for an hour, not for a number of requests
46
- # client.wait_until(:waiter_name) do |waiter|
47
- # one_hour = Time.now + 3600
48
- # waiter.max_attempts = nil
49
- # waiter.before_attempt do |attempt|
50
- # throw(:failure, 'waited to long') if Time.now > one_hour
51
- # end
52
- # end
53
- #
54
- # @param [Symbol] waiter_name The name of the waiter. See {#waiter_names}
55
- # for a full list of supported waiters.
56
- # @param [Hash] params Additional request parameters. See the {#waiter_names}
57
- # for a list of supported waiters and what request they call. The
58
- # called request determines the list of accepted parameters.
59
- # @return [Seahorse::Client::Response] Returns the client response from
60
- # the successful polling request. If `:success` is thrown from a callback,
61
- # then the 2nd argument to `#throw` is returned.
62
- # @yieldparam [Waiters::Waiter] waiter Yields a {Waiters::Waiter Waiter}
63
- # object that can be configured prior to waiting.
64
- # @raise [Waiters::Errors::NoSuchWaiter] Raised when the named waiter
65
- # is not defined.
66
- # @raise [Waiters::Errors::WaiterFailed] Raised when one of the
67
- # following conditions is met:
68
- #
69
- # * A failure condition is detected
70
- # * The maximum number of attempts has been made without success
71
- # * `:failure` is thrown from a callback
72
- #
73
- def wait_until(waiter_name, params = {}, &block)
74
- waiter = self.class.waiters.waiter(waiter_name)
75
- yield(waiter) if block_given?
76
- waiter.wait(self, params)
77
- end
78
-
79
- # Returns the list of supported waiters.
80
- # @return [Array<Symbol>]
81
- def waiter_names
82
- self.class.waiters.waiter_names
83
- end
19
+ include ClientWaiters
84
20
 
85
21
  class << self
86
22
 
@@ -88,35 +24,18 @@ module Aws
88
24
  # @api private
89
25
  attr_accessor :identifier
90
26
 
91
- # @return [Paging::Provider]
92
- # @api private
93
- attr_accessor :paginators
94
-
95
- # @return [Waiters::Provider]
96
- # @api private
97
- attr_accessor :waiters
98
-
99
27
  # @api private
100
28
  def define(svc_name, options)
101
29
  client_class = Class.new(self)
102
30
  client_class.identifier = svc_name.downcase.to_sym
103
- client_class.set_api(load_api(options[:api]))
31
+ [:api, :paginators, :waiters].each do |definition|
32
+ client_class.send("set_#{definition}", options[definition])
33
+ end
34
+ DEFAULT_PLUGINS.each { |plugin| client_class.add_plugin(plugin) }
104
35
  Api::ServiceCustomizations.apply(client_class)
105
36
  client_class
106
37
  end
107
38
 
108
- private
109
-
110
- def load_api(api)
111
- case api
112
- when Seahorse::Model::Api then api
113
- when Hash then Seahorse::Model::Api.new(api)
114
- when String then Seahorse::Model::Api.new(Aws.load_json(api))
115
- when nil then Seahorse::Model::Api.new({})
116
- else raise ArgumentError, "invalid api definition #{api}"
117
- end
118
- end
119
-
120
39
  end
121
40
  end
122
41
  end
@@ -0,0 +1,29 @@
1
+ module Aws
2
+ # @api private
3
+ module ClientPaging
4
+
5
+ # @api private
6
+ def self.included(subclass)
7
+
8
+ subclass.add_plugin('Aws::Plugins::ResponsePaging')
9
+
10
+ class << subclass
11
+
12
+ def set_paginators(paginators)
13
+ @paginators = case paginators
14
+ when Paging::Provider then paginators
15
+ when Hash then Paging::Provider.new(paginators)
16
+ when String then Paging::Provider.new(Aws.load_json(paginators))
17
+ when nil then Paging::NullProvider.new
18
+ else raise ArgumentError, 'invalid paginators'
19
+ end
20
+ end
21
+
22
+ def paginators
23
+ @paginators
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  module Aws
2
4
 
3
5
  # This module provides the ability to specify the data and/or errors to
@@ -6,8 +8,14 @@ module Aws
6
8
  # behavior.
7
9
  module ClientStubs
8
10
 
11
+ # @api private
12
+ def self.included(subclass)
13
+ subclass.add_plugin('Aws::Plugins::StubResponses')
14
+ end
15
+
9
16
  def initialize(*args)
10
17
  @stubs = {}
18
+ @stub_mutex = Mutex.new
11
19
  super
12
20
  end
13
21
 
@@ -83,11 +91,13 @@ module Aws
83
91
 
84
92
  # @api private
85
93
  def next_stub(operation_name)
86
- stubs = @stubs[operation_name.to_sym] || []
87
- case stubs.length
88
- when 0 then new_stub(operation_name)
89
- when 1 then stubs.first
90
- else stubs.shift
94
+ @stub_mutex.synchronize do
95
+ stubs = @stubs[operation_name.to_sym] || []
96
+ case stubs.length
97
+ when 0 then new_stub(operation_name)
98
+ when 1 then stubs.first
99
+ else stubs.shift
100
+ end
91
101
  end
92
102
  end
93
103
 
@@ -101,12 +111,14 @@ module Aws
101
111
  end
102
112
 
103
113
  def apply_stubs(operation_name, stubs)
104
- @stubs[operation_name.to_sym] = stubs.map do |stub|
105
- case stub
106
- when Exception then stub
107
- when String then service_error_class(stub)
108
- when Hash then new_stub(operation_name, stub)
109
- else stub
114
+ @stub_mutex.synchronize do
115
+ @stubs[operation_name.to_sym] = stubs.map do |stub|
116
+ case stub
117
+ when Exception then stub
118
+ when String then service_error_class(stub)
119
+ when Hash then new_stub(operation_name, stub)
120
+ else stub
121
+ end
110
122
  end
111
123
  end
112
124
  end
@@ -0,0 +1,105 @@
1
+ module Aws
2
+ module ClientWaiters
3
+
4
+ # @api private
5
+ def self.included(subclass)
6
+ class << subclass
7
+
8
+ def set_waiters(waiters)
9
+ @waiters =
10
+ case waiters
11
+ when Waiters::Provider then waiters
12
+ when Hash then Waiters::Provider.new(waiters)
13
+ when String then Waiters::Provider.new(Aws.load_json(waiters))
14
+ when nil then Waiters::NullProvider.new
15
+ else raise ArgumentError, 'invalid waiters'
16
+ end
17
+ end
18
+
19
+ def waiters
20
+ @waiters
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+ # Waits until a particular condition is satisfied. This works by
27
+ # polling a client request and checking for particular response
28
+ # data or errors. Waiters each have a default duration max attempts
29
+ # which are configurable. Additionally, you can register callbacks
30
+ # and stop waiters by throwing `:success` or `:failure`.
31
+ #
32
+ # @example Basic usage
33
+ # client.wait_until(:waiter_name)
34
+ #
35
+ # @example Configuring interval and maximum attempts
36
+ # client.wait_until(:waiter_name) do |w|
37
+ # w.interval = 10 # number of seconds to sleep between attempts
38
+ # w.max_attempts = 6 # maximum number of polling attempts
39
+ # end
40
+ #
41
+ # @example Rescuing a failed wait
42
+ # begin
43
+ # client.wait_until(:waiter_name)
44
+ # rescue Aws::Waiters::Errors::WaiterFailed
45
+ # # gave up waiting
46
+ # end
47
+ #
48
+ # @example Waiting with progress callbacks
49
+ # client.wait_until(:waiter_name) do |w|
50
+ #
51
+ # # yields just before polling for change
52
+ # w.before_attempt do |attempt|
53
+ # # attempts - number of previous attempts made
54
+ # end
55
+ #
56
+ # # yields before sleeping
57
+ # w.before_wait do |attempt, prev_response|
58
+ # # attempts - number of previous attempts made
59
+ # # prev_response - the last client response received
60
+ # end
61
+ # end
62
+ #
63
+ # @example Throw :success or :failure to terminate early
64
+ # # wait for an hour, not for a number of requests
65
+ # client.wait_until(:waiter_name) do |waiter|
66
+ # one_hour = Time.now + 3600
67
+ # waiter.max_attempts = nil
68
+ # waiter.before_attempt do |attempt|
69
+ # throw(:failure, 'waited to long') if Time.now > one_hour
70
+ # end
71
+ # end
72
+ #
73
+ # @param [Symbol] waiter_name The name of the waiter. See {#waiter_names}
74
+ # for a full list of supported waiters.
75
+ # @param [Hash] params Additional request parameters. See the {#waiter_names}
76
+ # for a list of supported waiters and what request they call. The
77
+ # called request determines the list of accepted parameters.
78
+ # @return [Seahorse::Client::Response] Returns the client response from
79
+ # the successful polling request. If `:success` is thrown from a callback,
80
+ # then the 2nd argument to `#throw` is returned.
81
+ # @yieldparam [Waiters::Waiter] waiter Yields a {Waiters::Waiter Waiter}
82
+ # object that can be configured prior to waiting.
83
+ # @raise [Waiters::Errors::NoSuchWaiter] Raised when the named waiter
84
+ # is not defined.
85
+ # @raise [Waiters::Errors::WaiterFailed] Raised when one of the
86
+ # following conditions is met:
87
+ #
88
+ # * A failure condition is detected
89
+ # * The maximum number of attempts has been made without success
90
+ # * `:failure` is thrown from a callback
91
+ #
92
+ def wait_until(waiter_name, params = {}, &block)
93
+ waiter = self.class.waiters.waiter(waiter_name)
94
+ yield(waiter) if block_given?
95
+ waiter.wait(self, params)
96
+ end
97
+
98
+ # Returns the list of supported waiters.
99
+ # @return [Array<Symbol>]
100
+ def waiter_names
101
+ self.class.waiters.waiter_names
102
+ end
103
+
104
+ end
105
+ end