aws-sdk-code-generator 0.1.0.pre → 0.2.0.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.
- checksums.yaml +5 -5
- data/lib/aws-sdk-code-generator.rb +68 -75
- data/lib/aws-sdk-code-generator/api.rb +130 -0
- data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
- data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
- data/lib/aws-sdk-code-generator/client_operation_documentation.rb +268 -0
- data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
- data/lib/aws-sdk-code-generator/client_response_structure_example.rb +108 -0
- data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
- data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
- data/lib/aws-sdk-code-generator/docstring.rb +199 -0
- data/lib/aws-sdk-code-generator/error_list.rb +77 -0
- data/lib/aws-sdk-code-generator/errors.rb +2 -0
- data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
- data/lib/aws-sdk-code-generator/gem_builder.rb +19 -25
- data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
- data/lib/aws-sdk-code-generator/helper.rb +77 -61
- data/lib/aws-sdk-code-generator/plugin_list.rb +146 -0
- data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
- data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
- data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
- data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
- data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
- data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
- data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
- data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
- data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
- data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
- data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
- data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
- data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
- data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
- data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
- data/lib/aws-sdk-code-generator/service.rb +30 -7
- data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
- data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
- data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
- data/lib/aws-sdk-code-generator/underscore.rb +10 -5
- data/lib/aws-sdk-code-generator/view.rb +33 -0
- data/lib/aws-sdk-code-generator/views.rb +2 -0
- data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
- data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
- data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
- data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
- data/lib/aws-sdk-code-generator/views/client_api_module.rb +583 -0
- data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
- data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
- data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
- data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
- data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
- data/lib/aws-sdk-code-generator/views/features/smoke.rb +51 -0
- data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
- data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +2 -0
- data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
- data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
- data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
- data/lib/aws-sdk-code-generator/views/service_module.rb +30 -14
- data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
- data/lib/aws-sdk-code-generator/views/types_module.rb +294 -0
- data/lib/aws-sdk-code-generator/views/version.rb +2 -0
- data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
- data/lib/aws-sdk-code-generator/waiter.rb +95 -0
- data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
- metadata +61 -68
- data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
- data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
- data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
- data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
- data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
- data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
- data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
- data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
- data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
- data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
- data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
- data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
- data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
- data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
- data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
- data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
- data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
- data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
- data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
- data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
- data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
- data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
- data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
- data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
- data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
- data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
- data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
- data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
- data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
- data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
- data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
- data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
- data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
- data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
- data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
- data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
- data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
- data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
- data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
- data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
- data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
- data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AwsSdkCodeGenerator
|
2
4
|
class GemBuilder
|
3
5
|
|
4
6
|
# @param [Hash] options
|
5
|
-
# @option
|
7
|
+
# @option (see CodeBuilder#initialize)
|
6
8
|
def initialize(options)
|
7
9
|
@options = options
|
8
10
|
@service = options.fetch(:service)
|
@@ -13,13 +15,17 @@ module AwsSdkCodeGenerator
|
|
13
15
|
|
14
16
|
def each(&block)
|
15
17
|
Enumerator.new do |y|
|
16
|
-
y.yield(
|
17
|
-
y.yield(
|
18
|
-
y.yield(
|
19
|
-
y.yield(
|
20
|
-
|
18
|
+
y.yield("#{@service.gem_name}.gemspec", gemspec_file)
|
19
|
+
y.yield('features/env.rb', features_env_file)
|
20
|
+
y.yield('features/step_definitions.rb', features_step_definitions_file)
|
21
|
+
y.yield('spec/spec_helper.rb', spec_helper_file)
|
22
|
+
if @service.smoke_tests
|
23
|
+
y.yield('features/smoke.feature', smoke_file)
|
24
|
+
y.yield('features/smoke_step_definitions.rb', smoke_step_definitions_file)
|
25
|
+
end
|
26
|
+
y.yield('VERSION', version_file)
|
21
27
|
code = CodeBuilder.new(@options)
|
22
|
-
code.source_files
|
28
|
+
code.source_files.each do |path, code|
|
23
29
|
y.yield("lib/#{path}", code)
|
24
30
|
end
|
25
31
|
end.each(&block)
|
@@ -27,42 +33,30 @@ module AwsSdkCodeGenerator
|
|
27
33
|
|
28
34
|
private
|
29
35
|
|
30
|
-
def gemspec_path
|
31
|
-
"#{@service.gem_name}.gemspec"
|
32
|
-
end
|
33
|
-
|
34
36
|
def gemspec_file
|
35
37
|
Views::Gemspec.new(options).render
|
36
38
|
end
|
37
39
|
|
38
|
-
def features_env_path
|
39
|
-
'features/env.rb'
|
40
|
-
end
|
41
|
-
|
42
40
|
def features_env_file
|
43
41
|
Views::Features::Env.new(options).render
|
44
42
|
end
|
45
43
|
|
46
|
-
def
|
47
|
-
|
44
|
+
def smoke_file
|
45
|
+
Views::Features::Smoke.new(options).render
|
48
46
|
end
|
49
47
|
|
50
|
-
def
|
51
|
-
Views::Features::
|
48
|
+
def smoke_step_definitions_file
|
49
|
+
Views::Features::SmokeStepDefinitions.new(options).render
|
52
50
|
end
|
53
51
|
|
54
|
-
def
|
55
|
-
|
52
|
+
def features_step_definitions_file
|
53
|
+
Views::Features::StepDefinitions.new(options).render
|
56
54
|
end
|
57
55
|
|
58
56
|
def spec_helper_file
|
59
57
|
Views::Spec::SpecHelper.new(options).render
|
60
58
|
end
|
61
59
|
|
62
|
-
def version_path
|
63
|
-
'VERSION'
|
64
|
-
end
|
65
|
-
|
66
60
|
def version_file
|
67
61
|
Views::Version.new(options).render
|
68
62
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AwsSdkCodeGenerator
|
2
4
|
class HashFormatter
|
3
5
|
|
@@ -15,10 +17,11 @@ module AwsSdkCodeGenerator
|
|
15
17
|
@wrap = options.fetch(:wrap, true)
|
16
18
|
@inline = options.fetch(:inline, false)
|
17
19
|
@quote_strings = options.fetch(:quote_strings, false)
|
20
|
+
@indent = options.fetch(:indent, '')
|
18
21
|
end
|
19
22
|
|
20
23
|
def format(obj)
|
21
|
-
result = hash(obj, i:
|
24
|
+
result = hash(obj, i: @indent, inline:@inline)
|
22
25
|
result = unwrap(result, obj.size) if !@wrap
|
23
26
|
result = result.strip if @inline && result.lines.to_a.length == 1
|
24
27
|
result
|
@@ -34,7 +37,7 @@ module AwsSdkCodeGenerator
|
|
34
37
|
when Array then array(obj, i:i)
|
35
38
|
when String then @quote_strings ? obj.inspect : obj
|
36
39
|
when Symbol then obj.inspect
|
37
|
-
when
|
40
|
+
when Integer, true, false then obj.inspect
|
38
41
|
else raise ArgumentError, "unsupported value `#{obj.class}'"
|
39
42
|
end
|
40
43
|
end
|
@@ -1,5 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'set'
|
4
|
+
# kramdown
|
5
|
+
require 'kramdown'
|
3
6
|
|
4
7
|
# disable inline attribute lists
|
5
8
|
class Kramdown::Converter::Kramdown
|
@@ -7,6 +10,7 @@ class Kramdown::Converter::Kramdown
|
|
7
10
|
nil
|
8
11
|
end
|
9
12
|
end
|
13
|
+
# end kramdown
|
10
14
|
|
11
15
|
module AwsSdkCodeGenerator
|
12
16
|
module Helper
|
@@ -21,31 +25,6 @@ module AwsSdkCodeGenerator
|
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
# @param [Array<Array<String>>]
|
25
|
-
def markdown_table(table)
|
26
|
-
# compute the width of each column by scanning for longest values
|
27
|
-
column_width = lambda do |col|
|
28
|
-
table.map { |row| row[col].size }.max
|
29
|
-
end
|
30
|
-
widths = [
|
31
|
-
column_width.call(0),
|
32
|
-
column_width.call(1),
|
33
|
-
column_width.call(2),
|
34
|
-
column_width.call(3),
|
35
|
-
]
|
36
|
-
|
37
|
-
# insert a dashed line after the header row
|
38
|
-
table = [
|
39
|
-
table[0],
|
40
|
-
['-' * widths[0], '-' * widths[1], '-' * widths[2], '-' * widths[3]]
|
41
|
-
] + table[1..-1]
|
42
|
-
|
43
|
-
# build the final table
|
44
|
-
line = "| #{widths.map{|n| "%-#{n}s" }.join(' | ')} |"
|
45
|
-
table.map { |row| line % row }.join("\n")
|
46
|
-
end
|
47
|
-
module_function :markdown_table
|
48
|
-
|
49
28
|
def underscore(str)
|
50
29
|
str.split('.').map do |part|
|
51
30
|
Underscore.underscore(part)
|
@@ -143,6 +122,30 @@ module AwsSdkCodeGenerator
|
|
143
122
|
shape(member_ref)
|
144
123
|
end
|
145
124
|
|
125
|
+
def upcase_first(name)
|
126
|
+
if name[0] =~ /[a-z]/
|
127
|
+
name.size == 1 ? name.upcase : name[0].upcase + name[1..-1]
|
128
|
+
else
|
129
|
+
name
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def downcase_first(name)
|
134
|
+
if name[0] =~/[A-Z]/
|
135
|
+
name.size == 1 ? name.downcase : name[0].downcase + name[1..-1]
|
136
|
+
else
|
137
|
+
name
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def lstrip_prefix(name)
|
142
|
+
name.start_with?("__") ? name[2..-1] : name
|
143
|
+
end
|
144
|
+
|
145
|
+
def apig_prefix(name)
|
146
|
+
"__#{name}"
|
147
|
+
end
|
148
|
+
|
146
149
|
def shape(ref)
|
147
150
|
if ref.nil?
|
148
151
|
nil
|
@@ -153,46 +156,52 @@ module AwsSdkCodeGenerator
|
|
153
156
|
end
|
154
157
|
end
|
155
158
|
|
159
|
+
# @param [String<HTML>] html
|
156
160
|
# @option options [Integer] :line_width (70)
|
157
161
|
def markdown(html, options = {})
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
html = html.gsub(' target="_blank"', '')
|
174
|
-
|
175
|
-
# There are quite a few empty <a> tags. These appear to be code names,
|
176
|
-
# such as structure member names, or structure type names. We should
|
177
|
-
# investigate if it is possible to inflect these properly and then
|
178
|
-
# turn them into YARD links.
|
179
|
-
html = html.gsub(/<a>(.+?)<\/a>/) { $1 }
|
180
|
-
|
181
|
-
# <important> tag doesn't render well
|
182
|
-
html = html.gsub(/<important>(.+?)<\/important>/){ "<p>#{$1}</p>" }
|
183
|
-
|
184
|
-
markdown = Kramdown::Document.new(
|
185
|
-
html,
|
186
|
-
input: 'html',
|
187
|
-
line_width: line_width,
|
188
|
-
auto_ids: false
|
189
|
-
).to_kramdown.strip
|
190
|
-
|
191
|
-
# remove extra escape
|
192
|
-
markdown.gsub(/\\(\*|`|'|")/, '\1')
|
162
|
+
Docstring.html_to_markdown(html, options)
|
163
|
+
end
|
164
|
+
|
165
|
+
def operation_streaming?(operation, api)
|
166
|
+
return unless operation.key? 'output'
|
167
|
+
output = operation['output']['shape']
|
168
|
+
if api['shapes'][output].key? 'payload'
|
169
|
+
output_shape = api['shapes'][output]
|
170
|
+
payload = output_shape['payload']
|
171
|
+
if output_shape.key? 'members'
|
172
|
+
payload_ref = output_shape['members'][payload]
|
173
|
+
elsif output_shape.key? 'member'
|
174
|
+
payload_ref = output_shape['member'][payload]
|
175
|
+
end
|
176
|
+
Api.streaming?(payload_ref, api)
|
193
177
|
end
|
194
178
|
end
|
195
179
|
|
180
|
+
def operation_eventstreaming?(operation, api)
|
181
|
+
!!eventstream_input?(operation, api) ||
|
182
|
+
!!eventstream_output?(operation, api)
|
183
|
+
end
|
184
|
+
|
185
|
+
def eventstream_output?(operation, api)
|
186
|
+
return false unless operation.key? 'output'
|
187
|
+
output_shape = api['shapes'][operation['output']['shape']]
|
188
|
+
return false unless output_shape.key? 'members'
|
189
|
+
output_shape['members'].each do |name, ref|
|
190
|
+
return ref['shape'] if Api.eventstream?(ref, api)
|
191
|
+
end
|
192
|
+
return false
|
193
|
+
end
|
194
|
+
|
195
|
+
def eventstream_input?(operation, api)
|
196
|
+
return false unless operation.key? 'input'
|
197
|
+
input_shape = api['shapes'][operation['input']['shape']]
|
198
|
+
return false unless input_shape.key? 'members'
|
199
|
+
input_shape['members'].each do |name, ref|
|
200
|
+
return ref['shape'] if Api.eventstream?(ref, api)
|
201
|
+
end
|
202
|
+
return false
|
203
|
+
end
|
204
|
+
|
196
205
|
def deep_copy(obj)
|
197
206
|
case obj
|
198
207
|
when nil then nil
|
@@ -211,5 +220,12 @@ module AwsSdkCodeGenerator
|
|
211
220
|
end
|
212
221
|
end
|
213
222
|
|
223
|
+
def wrap_string(str, width, indent = '')
|
224
|
+
str.gsub(/(.{1,#{width}})(\s+|\Z)/, "#{indent}\\1\n").chomp
|
225
|
+
end
|
226
|
+
|
227
|
+
module_function :deep_copy, :operation_streaming?, :downcase_first, :wrap_string, :apig_prefix,
|
228
|
+
:eventstream_output?, :eventstream_input?, :operation_eventstreaming?
|
229
|
+
|
214
230
|
end
|
215
231
|
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsSdkCodeGenerator
|
4
|
+
class PluginList
|
5
|
+
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@aws_sdk_core_lib_path = options.fetch(:aws_sdk_core_lib_path)
|
10
|
+
@plugins = compute_plugins(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Enumerable<Plugin>]
|
14
|
+
def each(&block)
|
15
|
+
@plugins.each(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def compute_plugins(options)
|
21
|
+
plugins = {}
|
22
|
+
plugins.update(options[:async_client] ? default_async_plugins : default_plugins)
|
23
|
+
plugins.update(signature_plugins(options.fetch(:signature_version)))
|
24
|
+
plugins.update(protocol_plugins(options.fetch(:protocol)))
|
25
|
+
plugins.update(options.fetch(:add_plugins))
|
26
|
+
options.fetch(:remove_plugins).each do |plugin_name|
|
27
|
+
plugins.delete(plugin_name)
|
28
|
+
end
|
29
|
+
plugins.map do |class_name, path|
|
30
|
+
path = "./#{path}" unless path[0] == '/'
|
31
|
+
Kernel.require(path)
|
32
|
+
|
33
|
+
Plugin.new(
|
34
|
+
class_name: class_name,
|
35
|
+
options: const_get(class_name).options,
|
36
|
+
path: path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_plugins
|
41
|
+
{
|
42
|
+
'Seahorse::Client::Plugins::ContentLength' => "#{seahorse_plugins}/content_length.rb",
|
43
|
+
'Aws::Plugins::CredentialsConfiguration' => "#{core_plugins}/credentials_configuration.rb",
|
44
|
+
'Aws::Plugins::Logging' => "#{core_plugins}/logging.rb",
|
45
|
+
'Aws::Plugins::ParamConverter' => "#{core_plugins}/param_converter.rb",
|
46
|
+
'Aws::Plugins::ParamValidator' => "#{core_plugins}/param_validator.rb",
|
47
|
+
'Aws::Plugins::UserAgent' => "#{core_plugins}/user_agent.rb",
|
48
|
+
'Aws::Plugins::HelpfulSocketErrors' => "#{core_plugins}/helpful_socket_errors.rb",
|
49
|
+
'Aws::Plugins::RetryErrors' => "#{core_plugins}/retry_errors.rb",
|
50
|
+
'Aws::Plugins::GlobalConfiguration' => "#{core_plugins}/global_configuration.rb",
|
51
|
+
'Aws::Plugins::RegionalEndpoint' => "#{core_plugins}/regional_endpoint.rb",
|
52
|
+
'Aws::Plugins::EndpointDiscovery' => "#{core_plugins}/endpoint_discovery.rb",
|
53
|
+
'Aws::Plugins::EndpointPattern' => "#{core_plugins}/endpoint_pattern.rb",
|
54
|
+
'Aws::Plugins::ResponsePaging' => "#{core_plugins}/response_paging.rb",
|
55
|
+
'Aws::Plugins::StubResponses' => "#{core_plugins}/stub_responses.rb",
|
56
|
+
'Aws::Plugins::IdempotencyToken' => "#{core_plugins}/idempotency_token.rb",
|
57
|
+
'Aws::Plugins::JsonvalueConverter' => "#{core_plugins}/jsonvalue_converter.rb",
|
58
|
+
'Aws::Plugins::ClientMetricsPlugin' => "#{core_plugins}/client_metrics_plugin.rb",
|
59
|
+
'Aws::Plugins::ClientMetricsSendPlugin' => "#{core_plugins}/client_metrics_send_plugin.rb",
|
60
|
+
'Aws::Plugins::TransferEncoding' => "#{core_plugins}/transfer_encoding.rb",
|
61
|
+
'Aws::Plugins::HttpChecksum' => "#{core_plugins}/http_checksum.rb"
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def default_async_plugins
|
66
|
+
plugins = default_plugins.dup
|
67
|
+
plugins.delete('Aws::Plugins::ResponsePaging')
|
68
|
+
plugins.delete('Aws::Plugins::EndpointDiscovery')
|
69
|
+
plugins.delete('Aws::Plugins::EndpointPattern')
|
70
|
+
plugins.delete('Aws::Plugins::ClientMetricsPlugin')
|
71
|
+
plugins.delete('Aws::Plugins::ClientMetricsSendPlugin')
|
72
|
+
plugins.delete('Aws::Plugins::TransferEncoding')
|
73
|
+
plugins['Aws::Plugins::InvocationId'] = "#{core_plugins}/invocation_id.rb"
|
74
|
+
plugins
|
75
|
+
end
|
76
|
+
|
77
|
+
def protocol_plugins(protocol)
|
78
|
+
{
|
79
|
+
'json' => { 'Aws::Plugins::Protocols::JsonRpc' => "#{core_plugins}/protocols/json_rpc.rb" },
|
80
|
+
'rest-json' => { 'Aws::Plugins::Protocols::RestJson' => "#{core_plugins}/protocols/rest_json.rb" },
|
81
|
+
'rest-xml' => { 'Aws::Plugins::Protocols::RestXml' => "#{core_plugins}/protocols/rest_xml.rb" },
|
82
|
+
'query' => { 'Aws::Plugins::Protocols::Query' => "#{core_plugins}/protocols/query.rb" },
|
83
|
+
'ec2' => { 'Aws::Plugins::Protocols::EC2' => "#{core_plugins}/protocols/ec2.rb" },
|
84
|
+
'api-gateway' => {
|
85
|
+
'Aws::Plugins::Protocols::ApiGateway' => "#{core_plugins}/protocols/api_gateway.rb",
|
86
|
+
'Aws::Plugins::ApiKey' => "#{core_plugins}/api_key.rb",
|
87
|
+
'Aws::Plugins::APIGUserAgent' => "#{core_plugins}/apig_user_agent.rb",
|
88
|
+
'Aws::Plugins::APIGAuthorizerToken' => "#{core_plugins}/apig_authorizer_token.rb",
|
89
|
+
'Aws::Plugins::APIGCredentialsConfiguration' => "#{core_plugins}/apig_credentials_configuration.rb"
|
90
|
+
},
|
91
|
+
nil => {}
|
92
|
+
}[protocol]
|
93
|
+
end
|
94
|
+
|
95
|
+
def signature_plugins(signature_version)
|
96
|
+
case signature_version
|
97
|
+
when 'v4'
|
98
|
+
{ 'Aws::Plugins::SignatureV4' => "#{core_plugins}/signature_v4.rb" }
|
99
|
+
when 'v2'
|
100
|
+
{ 'Aws::Plugins::SignatureV2' => "#{core_plugins}/signature_v2.rb" }
|
101
|
+
else
|
102
|
+
{}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def core_plugins
|
107
|
+
File.join(@aws_sdk_core_lib_path, 'aws-sdk-core/plugins')
|
108
|
+
end
|
109
|
+
|
110
|
+
def seahorse_plugins
|
111
|
+
File.join(@aws_sdk_core_lib_path, 'seahorse/client/plugins')
|
112
|
+
end
|
113
|
+
|
114
|
+
def core_lib
|
115
|
+
# TODO : may need to register the default plugins directory rather
|
116
|
+
# than have the hard-coded here as a relative path
|
117
|
+
File.expand_path('../../../../../gems/aws-sdk-core/lib', __FILE__)
|
118
|
+
end
|
119
|
+
|
120
|
+
def const_get(class_name)
|
121
|
+
const_names = class_name.split('::')
|
122
|
+
const_names.inject(Kernel) do |const, const_name|
|
123
|
+
const.const_get(const_name)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class Plugin
|
128
|
+
|
129
|
+
def initialize(options)
|
130
|
+
@class_name = options.fetch(:class_name)
|
131
|
+
@options = options.fetch(:options)
|
132
|
+
@require_path = options.fetch(:path).split('/lib/').last
|
133
|
+
end
|
134
|
+
|
135
|
+
# @return [String]
|
136
|
+
attr_reader :class_name
|
137
|
+
|
138
|
+
# @return [Array<Seahorse::Client::Plugin::PluginOption>]
|
139
|
+
attr_reader :options
|
140
|
+
|
141
|
+
# @return [String]
|
142
|
+
attr_reader :require_path
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsSdkCodeGenerator
|
4
|
+
class ResourceAction
|
5
|
+
class << self
|
6
|
+
|
7
|
+
include Helper
|
8
|
+
|
9
|
+
# @return [Array<ResourceMethod>]
|
10
|
+
def build_list(resource_name, resource, api)
|
11
|
+
resource.fetch('actions', {}).map do |action_name, action|
|
12
|
+
build(
|
13
|
+
resource_name: resource_name,
|
14
|
+
action_name: action_name,
|
15
|
+
action: action,
|
16
|
+
api: api
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @option options [required, String] :resource_name
|
22
|
+
# @option options [required, String] :action_name
|
23
|
+
# @option options [required, String] :action
|
24
|
+
# @option options [required, String] :api
|
25
|
+
def build(options)
|
26
|
+
ResourceMethod.new.tap do |m|
|
27
|
+
m.method_name = Underscore.underscore(options.fetch(:action_name))
|
28
|
+
m.arguments = 'options = {}'
|
29
|
+
operation_name = options.fetch(:action)['request']['operation']
|
30
|
+
api = options.fetch(:api)
|
31
|
+
if operation_streaming?(api['operations'][operation_name], api)
|
32
|
+
m.arguments += ', &block'
|
33
|
+
options[:streaming] = true
|
34
|
+
end
|
35
|
+
m.code = ResourceActionCode.new(options).build
|
36
|
+
m.documentation = documentation(options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def documentation(options)
|
43
|
+
api = options.fetch(:api)
|
44
|
+
action = options.fetch(:action)
|
45
|
+
operation = api['operations'][action['request']['operation']]
|
46
|
+
ResourceClientReqeustDocumentation.new(
|
47
|
+
method_name: Underscore.underscore(options.fetch(:action_name)),
|
48
|
+
receiver: Underscore.underscore(options.fetch(:resource_name)),
|
49
|
+
resp_var: action['resource'] ? action['resource']['type'].downcase : nil,
|
50
|
+
returns: returns(action, operation),
|
51
|
+
request: action['request'],
|
52
|
+
api: api,
|
53
|
+
).build
|
54
|
+
end
|
55
|
+
|
56
|
+
def returns(action, operation)
|
57
|
+
if action['resource']
|
58
|
+
resource = action['resource']
|
59
|
+
Api.plural?(resource) ? "#{resource['type']}::Collection" : resource['type']
|
60
|
+
elsif operation['output']
|
61
|
+
"Types::#{operation['output']['shape']}"
|
62
|
+
else
|
63
|
+
"EmptyStructure"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|