aws-sdk-code-generator 0.2.0.pre → 0.2.1.pre

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.
@@ -0,0 +1,4 @@
1
+ {{#code}}
2
+ {{#lines}}
3
+ {{{.}}}{{/lines}}
4
+ {{/code}}
@@ -0,0 +1,4 @@
1
+ {{#documentation}}
2
+ {{#lines}}
3
+ {{{.}}}{{/lines}}
4
+ {{/documentation}}
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+ module {{module_name}}
7
+
8
+ # When {{service_name}} returns an error response, the Ruby SDK constructs and raises an error.
9
+ # These errors all extend {{module_name}}::Errors::ServiceError < {Aws::Errors::ServiceError}
10
+ #
11
+ # You can rescue all {{service_name}} errors using ServiceError:
12
+ #
13
+ # begin
14
+ # # do stuff
15
+ # rescue {{module_name}}::Errors::ServiceError
16
+ # # rescues all {{service_name}} API errors
17
+ # end
18
+ #
19
+ #
20
+ # ## Request Context
21
+ # ServiceError objects have a {Aws::Errors::ServiceError#context #context} method that returns
22
+ # information about the request that generated the error.
23
+ # See {Seahorse::Client::RequestContext} for more information.
24
+ #
25
+ # ## Error Classes
26
+ {{#errors}}
27
+ {{=<% %>=}}
28
+ # * {<% name %>}
29
+ <%={{ }}=%>
30
+ {{/errors}}
31
+ #
32
+ # Additionally, error classes are dynamically generated for service errors based on the error code
33
+ # if they are not defined above.
34
+ module Errors
35
+
36
+ extend Aws::Errors::DynamicErrors
37
+
38
+ {{#errors}}
39
+ class {{name}} < ServiceError
40
+
41
+ # @param [Seahorse::Client::RequestContext] context
42
+ # @param [String] message
43
+ # @param [{{data_type}}] data
44
+ def initialize(context, message, data = Aws::EmptyStructure.new)
45
+ super(context, message, data)
46
+ end
47
+ {{#members}}
48
+
49
+ # @return [{{type}}]
50
+ def {{name}}
51
+ {{#shared}}@{{name}} || {{/shared}}@data[:{{name}}]
52
+ end
53
+ {{/members}}
54
+ {{#retryable}}
55
+
56
+ def retryable?
57
+ true
58
+ end
59
+ {{/retryable}}
60
+ {{#throttling}}
61
+
62
+ def throttling?
63
+ true
64
+ end
65
+ {{/throttling}}
66
+ end
67
+
68
+ {{/errors}}
69
+ end
70
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+ module {{module_name}}
7
+ module EventStreams
8
+ {{#input_eventstreams}}
9
+ class {{class_name}}
10
+
11
+ def initialize
12
+ @event_emitter = Aws::EventEmitter.new
13
+ end
14
+
15
+ {{#event_entries}}
16
+ {{param_hash}}
17
+ def signal_{{name}}_event(params = {})
18
+ @event_emitter.emit(:{{name}}, params)
19
+ end
20
+
21
+ {{/event_entries}}
22
+ def signal_end_stream
23
+ @event_emitter.emit(:end_stream, {})
24
+ end
25
+
26
+ # @api private
27
+ # @return Aws::EventEmitter
28
+ attr_reader :event_emitter
29
+
30
+ end
31
+
32
+ {{/input_eventstreams}}
33
+ {{#output_eventstreams}}
34
+ class {{class_name}}
35
+
36
+ def initialize
37
+ @event_emitter = Aws::EventEmitter.new
38
+ end
39
+
40
+ {{#types}}
41
+ def on_{{.}}_event(&block)
42
+ @event_emitter.on(:{{.}}, block) if block_given?
43
+ end
44
+
45
+ {{/types}}
46
+ def on_error_event(&block)
47
+ @event_emitter.on(:error, block) if block_given?
48
+ end
49
+
50
+ def on_initial_response_event(&block)
51
+ @event_emitter.on(:initial_response, block) if block_given?
52
+ end
53
+
54
+ def on_unknown_event(&block)
55
+ @event_emitter.on(:unknown_event, block) if block_given?
56
+ end
57
+
58
+ def on_event(&block)
59
+ {{#types}}
60
+ on_{{.}}_event(&block)
61
+ {{/types}}
62
+ on_error_event(&block)
63
+ on_initial_response_event(&block)
64
+ on_unknown_event(&block)
65
+ end
66
+
67
+ # @api private
68
+ # @return Aws::EventEmitter
69
+ attr_reader :event_emitter
70
+
71
+ end
72
+ {{/output_eventstreams}}
73
+
74
+ end
75
+ end
76
+
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+ $:.unshift(File.expand_path('../../lib', __FILE__))
7
+ $:.unshift(File.expand_path('../../../aws-sdk-core/features', __FILE__))
8
+ {{#gem_dependencies}}
9
+ $:.unshift(File.expand_path('../../../{{dependency}}/lib', __FILE__))
10
+ {{/gem_dependencies}}
11
+
12
+ require 'features_helper'
13
+ require '{{gem_name}}'
14
+
15
+ {{module_name}}::Client.add_plugin(ApiCallTracker)
@@ -0,0 +1,17 @@
1
+ {{#generated_src_warning}}
2
+ {{generated_src_warning}}
3
+ {{/generated_src_warning}}
4
+ Feature: Smoke tests for {{service}}
5
+
6
+ Background:
7
+ Given I create a client in region '{{client_region}}'
8
+ {{#smoke_tests}}
9
+
10
+ {{smoke_test_tags}}
11
+ Scenario: {{scenario_string}}
12
+ When I call the operation '{{operation}}' with params:
13
+ """
14
+ {{&param_hash}}
15
+ """
16
+ Then {{error_expectation}}
17
+ {{/smoke_tests}}
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+ # Shared Smoke Test Definitions
7
+ Given(/I create a client in region '(.*?)'/) do |region|
8
+ @regional_client = {{module_name}}::Client.new(region: region)
9
+ end
10
+
11
+ When(/I call the operation '(.*?)' with params:/) do |operation, params|
12
+ opts = JSON.parse(params, symbolize_names: true)
13
+ begin
14
+ @regional_client.send(operation.to_sym, opts)
15
+ @operation_raised_error = false
16
+ rescue StandardError
17
+ @operation_raised_error = true
18
+ end
19
+ end
20
+
21
+ Then(/I expect an error was raised/) do
22
+ expect(@operation_raised_error).to be_truthy
23
+ end
24
+
25
+ Then(/I expect an error was not raised/) do
26
+ expect(@operation_raised_error).not_to be_truthy
27
+ end
@@ -0,0 +1,8 @@
1
+ Before("@{{var_name}}") do
2
+ @service = {{module_name}}::Resource.new
3
+ @client = @service.client
4
+ end
5
+
6
+ After("@{{var_name}}") do
7
+ # shared cleanup logic
8
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = '{{gem_name}}'
9
+ spec.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
10
+ spec.summary = '{{summary}}'
11
+ spec.description = '{{description}}'
12
+ spec.author = '{{author}}'
13
+ spec.homepage = '{{homepage}}'
14
+ spec.license = 'Apache-2.0'
15
+ spec.email = ['{{email}}']
16
+ spec.require_paths = ['lib']
17
+ spec.files = Dir['lib/**/*.rb']
18
+
19
+ {{#metadata}}
20
+ spec.metadata = {
21
+ 'source_code_uri' => '{{code_uri}}',
22
+ 'changelog_uri' => '{{code_uri}}/CHANGELOG.md'
23
+ }
24
+
25
+ {{/metadata}}
26
+ {{#dependencies}}
27
+ spec.add_dependency('{{gem}}', '{{&version}}')
28
+ {{/dependencies}}
29
+
30
+ end
@@ -0,0 +1,7 @@
1
+ {{> documentation}}
2
+ def {{method_name}}{{#arguments}}({{{.}}}){{/arguments}}
3
+ {{> code}}
4
+ end
5
+ {{#alias}}
6
+ alias {{alias}} {{method_name}}
7
+ {{/alias}}
@@ -0,0 +1,304 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+ module {{module_name}}
7
+
8
+ class {{class_name}}
9
+
10
+ extend Aws::Deprecations
11
+
12
+ # @overload def initialize({{#identifiers}}{{name}}, {{/identifiers}}options = {})
13
+ {{#identifiers}}
14
+ # @param [{{type}}] {{name}}
15
+ {{/identifiers}}
16
+ # @option options [Client] :client
17
+ {{#identifiers?}}
18
+ # @overload def initialize(options = {})
19
+ {{#identifiers}}
20
+ # @option options [required, {{type}}] :{{name}}
21
+ {{/identifiers}}
22
+ # @option options [Client] :client
23
+ {{/identifiers?}}
24
+ def initialize(*args)
25
+ options = Hash === args.last ? args.pop.dup : {}
26
+ {{#identifiers}}
27
+ @{{name}} = extract_{{name}}(args, options)
28
+ {{/identifiers}}
29
+ {{#shape}}
30
+ @data = options.delete(:data)
31
+ {{/shape}}
32
+ {{^shape}}
33
+ @data = Aws::EmptyStructure.new
34
+ {{/shape}}
35
+ @client = options.delete(:client) || Client.new(options)
36
+ @waiter_block_warned = false
37
+ end
38
+
39
+ # @!group Read-Only Attributes
40
+ {{#identifiers}}
41
+
42
+ # @return [{{type}}]
43
+ def {{name}}
44
+ @{{name}}
45
+ end
46
+ {{#alias}}
47
+ alias :{{alias}} :{{name}}
48
+ {{/alias}}
49
+ {{/identifiers}}
50
+ {{#data_attributes}}
51
+
52
+ {{> documentation}}
53
+ def {{name}}
54
+ data[:{{name}}]
55
+ end
56
+ {{/data_attributes}}
57
+
58
+ # @!endgroup
59
+
60
+ # @return [Client]
61
+ def client
62
+ @client
63
+ end
64
+
65
+ {{#load_method}}
66
+ {{> method}}
67
+ {{/load_method}}
68
+ alias :reload :load
69
+
70
+ {{#data_method}}
71
+ {{> method}}
72
+ {{/data_method}}
73
+
74
+ # @return [Boolean]
75
+ # Returns `true` if this resource is loaded. Accessing attributes or
76
+ # {#data} on an unloaded resource will trigger a call to {#load}.
77
+ def data_loaded?
78
+ !!@data
79
+ end
80
+ {{#exists_waiter}}
81
+
82
+ # @param [Hash] options ({})
83
+ # @return [Boolean]
84
+ # Returns `true` if the {{class_name}} exists.
85
+ def exists?(options = {})
86
+ begin
87
+ wait_until_exists(options.merge(max_attempts: 1))
88
+ true
89
+ rescue Aws::Waiters::Errors::UnexpectedError => e
90
+ raise e.error
91
+ rescue Aws::Waiters::Errors::WaiterFailed
92
+ false
93
+ end
94
+ end
95
+ {{/exists_waiter}}
96
+ {{#waiters}}
97
+
98
+ # @param [Hash] options ({})
99
+ # @option options [Integer] :max_attempts ({{max_attempts}})
100
+ # @option options [Float] :delay ({{delay}})
101
+ # @option options [Proc] :before_attempt
102
+ # @option options [Proc] :before_wait
103
+ # @return [{{class_name}}]
104
+ def wait_until_{{name}}(options = {}, &block)
105
+ options, params = separate_params_and_options(options)
106
+ waiter = Waiters::{{waiter_class_name}}.new(options)
107
+ yield_waiter_and_warn(waiter, &block) if block_given?
108
+ {{#wait_call}}
109
+ {{#lines}}
110
+ {{{.}}}{{/lines}}
111
+ {{/wait_call}}
112
+ {{class_name}}.new({
113
+ {{#constructor_args}}
114
+ {{#lines}}
115
+ {{{.}}}{{/lines}}
116
+ {{/constructor_args}}
117
+ })
118
+ end
119
+ {{/waiters}}
120
+ {{#wait_until}}
121
+
122
+ # @deprecated Use [{{module_name}}::Client] #wait_until instead
123
+ #
124
+ # Waiter polls an API operation until a resource enters a desired
125
+ # state.
126
+ #
127
+ # @note The waiting operation is performed on a copy. The original resource
128
+ # remains unchanged.
129
+ #
130
+ # ## Basic Usage
131
+ #
132
+ # Waiter will polls until it is successful, it fails by
133
+ # entering a terminal state, or until a maximum number of attempts
134
+ # are made.
135
+ #
136
+ # # polls in a loop until condition is true
137
+ # resource.wait_until(options) {|resource| condition}
138
+ #
139
+ # ## Example
140
+ #
141
+ # instance.wait_until(max_attempts:10, delay:5) do |instance|
142
+ # instance.state.name == 'running'
143
+ # end
144
+ #
145
+ # ## Configuration
146
+ #
147
+ # You can configure the maximum number of polling attempts, and the
148
+ # delay (in seconds) between each polling attempt. The waiting condition is
149
+ # set by passing a block to {#wait_until}:
150
+ #
151
+ # # poll for ~25 seconds
152
+ # resource.wait_until(max_attempts:5,delay:5) {|resource|...}
153
+ #
154
+ # ## Callbacks
155
+ #
156
+ # You can be notified before each polling attempt and before each
157
+ # delay. If you throw `:success` or `:failure` from these callbacks,
158
+ # it will terminate the waiter.
159
+ #
160
+ # started_at = Time.now
161
+ # # poll for 1 hour, instead of a number of attempts
162
+ # proc = Proc.new do |attempts, response|
163
+ # throw :failure if Time.now - started_at > 3600
164
+ # end
165
+ #
166
+ # # disable max attempts
167
+ # instance.wait_until(before_wait:proc, max_attempts:nil) {...}
168
+ #
169
+ # ## Handling Errors
170
+ #
171
+ # When a waiter is successful, it returns the Resource. When a waiter
172
+ # fails, it raises an error.
173
+ #
174
+ # begin
175
+ # resource.wait_until(...)
176
+ # rescue Aws::Waiters::Errors::WaiterFailed
177
+ # # resource did not enter the desired state in time
178
+ # end
179
+ #
180
+ # @yieldparam [Resource] resource to be used in the waiting condition.
181
+ #
182
+ # @raise [Aws::Waiters::Errors::FailureStateError] Raised when the waiter
183
+ # terminates because the waiter has entered a state that it will not
184
+ # transition out of, preventing success.
185
+ #
186
+ # yet successful.
187
+ #
188
+ # @raise [Aws::Waiters::Errors::UnexpectedError] Raised when an error is
189
+ # encountered while polling for a resource that is not expected.
190
+ #
191
+ # @raise [NotImplementedError] Raised when the resource does not
192
+ #
193
+ # @option options [Integer] :max_attempts (10) Maximum number of
194
+ # attempts
195
+ # @option options [Integer] :delay (10) Delay between each
196
+ # attempt in seconds
197
+ # @option options [Proc] :before_attempt (nil) Callback
198
+ # invoked before each attempt
199
+ # @option options [Proc] :before_wait (nil) Callback
200
+ # invoked before each wait
201
+ # @return [Resource] if the waiter was successful
202
+ def wait_until(options = {}, &block)
203
+ self_copy = self.dup
204
+ attempts = 0
205
+ options[:max_attempts] = 10 unless options.key?(:max_attempts)
206
+ options[:delay] ||= 10
207
+ options[:poller] = Proc.new do
208
+ attempts += 1
209
+ if block.call(self_copy)
210
+ [:success, self_copy]
211
+ else
212
+ self_copy.reload unless attempts == options[:max_attempts]
213
+ :retry
214
+ end
215
+ end
216
+ Aws::Waiters::Waiter.new(options).wait({})
217
+ end
218
+ {{/wait_until}}
219
+ {{#actions?}}
220
+
221
+ # @!group Actions
222
+ {{#actions}}
223
+
224
+ {{> method}}
225
+ {{/actions}}
226
+ {{/actions?}}
227
+ {{#associations?}}
228
+
229
+ # @!group Associations
230
+ {{#associations}}
231
+
232
+ {{> method}}
233
+ {{/associations}}
234
+ {{/associations?}}
235
+
236
+ {{#identifiers_method}}
237
+ {{> method}}
238
+ {{/identifiers_method}}
239
+ deprecated(:identifiers)
240
+ {{#identifiers?}}
241
+
242
+ private
243
+ {{#identifiers}}
244
+
245
+ def extract_{{name}}(args, options)
246
+ value = args[{{offset}}] || options.delete(:{{name}})
247
+ case value
248
+ when {{type}} then value
249
+ when nil then raise ArgumentError, "missing required option :{{name}}"
250
+ else
251
+ msg = "expected :{{name}} to be a {{type}}, got #{value.class}"
252
+ raise ArgumentError, msg
253
+ end
254
+ end
255
+ {{/identifiers}}
256
+ {{/identifiers?}}
257
+ {{#waiters?}}
258
+
259
+ def yield_waiter_and_warn(waiter, &block)
260
+ if !@waiter_block_warned
261
+ msg = "pass options to configure the waiter; "\
262
+ "yielding the waiter is deprecated"
263
+ warn(msg)
264
+ @waiter_block_warned = true
265
+ end
266
+ yield(waiter.waiter)
267
+ end
268
+
269
+ def separate_params_and_options(options)
270
+ opts = Set.new(
271
+ [:client, :max_attempts, :delay, :before_attempt, :before_wait]
272
+ )
273
+ waiter_opts = {}
274
+ waiter_params = {}
275
+ options.each_pair do |key, value|
276
+ if opts.include?(key)
277
+ waiter_opts[key] = value
278
+ else
279
+ waiter_params[key] = value
280
+ end
281
+ end
282
+ waiter_opts[:client] ||= @client
283
+ [waiter_opts, waiter_params]
284
+ end
285
+ {{/waiters?}}
286
+
287
+ {{^batch_actions?}}
288
+ class Collection < Aws::Resources::Collection; end
289
+ {{/batch_actions?}}
290
+ {{#batch_actions?}}
291
+ class Collection < Aws::Resources::Collection
292
+
293
+ # @!group Batch Actions
294
+ {{#batch_actions}}
295
+
296
+ {{> method}}
297
+ {{/batch_actions}}
298
+
299
+ # @!endgroup
300
+
301
+ end
302
+ {{/batch_actions?}}
303
+ end
304
+ end