aws-sdk-code-generator 0.5.0.pre → 0.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/aws-sdk-code-generator/api.rb +2 -1
  3. data/lib/aws-sdk-code-generator/client_operation_documentation.rb +2 -1
  4. data/lib/aws-sdk-code-generator/client_operation_list.rb +4 -0
  5. data/lib/aws-sdk-code-generator/code_builder.rb +2 -2
  6. data/lib/aws-sdk-code-generator/endpoint_parameter.rb +190 -0
  7. data/lib/aws-sdk-code-generator/helper.rb +11 -1
  8. data/lib/aws-sdk-code-generator/plugin_list.rb +3 -1
  9. data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +1 -1
  10. data/lib/aws-sdk-code-generator/resource_client_request.rb +1 -1
  11. data/lib/aws-sdk-code-generator/resource_waiter.rb +1 -1
  12. data/lib/aws-sdk-code-generator/service.rb +65 -17
  13. data/lib/aws-sdk-code-generator/views/client_api_module.rb +32 -15
  14. data/lib/aws-sdk-code-generator/views/endpoint_parameters_class.rb +6 -50
  15. data/lib/aws-sdk-code-generator/views/endpoint_provider_class.rb +9 -0
  16. data/lib/aws-sdk-code-generator/views/endpoints_module.rb +18 -124
  17. data/lib/aws-sdk-code-generator/views/endpoints_plugin.rb +46 -4
  18. data/lib/aws-sdk-code-generator/views/errors_module.rb +21 -0
  19. data/lib/aws-sdk-code-generator/views/features/smoke.rb +5 -4
  20. data/lib/aws-sdk-code-generator/views/rbs/client_class.rb +1 -1
  21. data/lib/aws-sdk-code-generator/views/rbs/types_module.rb +2 -2
  22. data/lib/aws-sdk-code-generator/views/resource_class.rb +22 -0
  23. data/lib/aws-sdk-code-generator/views/root_resource_class.rb +19 -0
  24. data/lib/aws-sdk-code-generator/views/service_module.rb +41 -27
  25. data/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb +20 -11
  26. data/lib/aws-sdk-code-generator/views/types_module.rb +28 -4
  27. data/lib/aws-sdk-code-generator.rb +12 -0
  28. data/templates/async_client_class.mustache +6 -1
  29. data/templates/client_api_module.mustache +7 -0
  30. data/templates/client_class.mustache +11 -3
  31. data/templates/endpoint_parameters_class.mustache +16 -13
  32. data/templates/endpoints_module.mustache +18 -11
  33. data/templates/endpoints_plugin.mustache +34 -18
  34. data/templates/errors_module.mustache +5 -0
  35. data/templates/resource_class.mustache +6 -1
  36. data/templates/root_resource_class.mustache +5 -0
  37. data/templates/service_module.mustache +13 -3
  38. data/templates/spec/endpoint_provider_spec_class.mustache +1 -1
  39. data/templates/types_module.mustache +4 -0
  40. metadata +6 -5
@@ -34,7 +34,7 @@ module AwsSdkCodeGenerator
34
34
  # exceptions will not have the event trait.
35
35
  shape['members'].each do |name, ref|
36
36
  if !!@service.api['shapes'][ref['shape']]['exception']
37
- @service.api['shapes'][ref['shape']]['exception_event'] = true
37
+ @service.api['shapes'][ref['shape']]['exceptionEvent'] = true
38
38
  end
39
39
  end
40
40
  end
@@ -80,19 +80,43 @@ module AwsSdkCodeGenerator
80
80
  end
81
81
  end
82
82
 
83
+ # @return [Array<String>]
84
+ def types_customizations
85
+ Dir.glob(File.join(Helper.gem_lib_path(gem_name), "#{gem_name}/customizations/types", '*.rb')).map do |file|
86
+ filename = File.basename(file, '.rb')
87
+ "#{gem_name}/customizations/types/#{filename}"
88
+ end
89
+ end
90
+
83
91
  private
84
92
 
93
+ def gem_name
94
+ "aws-sdk-#{module_name.split('::').last.downcase}"
95
+ end
96
+
85
97
  def struct_members(shape)
86
98
  return if shape['members'].nil?
87
99
  members = shape['members'].map do |member_name, member_ref|
100
+ member_target = @api['shapes'][member_ref['shape']]
88
101
  sensitive = !!(member_ref['sensitive'] ||
89
- @api['shapes'][member_ref['shape']]['sensitive'])
102
+ member_target['sensitive'])
103
+
104
+ case member_target["type"]
105
+ when 'map'
106
+ key_shape = @api['shapes'][member_target['key']['shape']]
107
+ value_shape = @api['shapes'][member_target['value']['shape']]
108
+ sensitive ||= !!(key_shape['sensitive'] || value_shape['sensitive'])
109
+ when 'list'
110
+ list_member = @api['shapes'][member_target['member']['shape']]
111
+ sensitive ||= !!(list_member['sensitive'])
112
+ end
113
+
90
114
  StructMember.new(
91
115
  member_name: underscore(member_name),
92
116
  sensitive: sensitive
93
117
  )
94
118
  end
95
- if shape['event'] || shape['exception_event']
119
+ if shape['event'] || shape['exceptionEvent']
96
120
  members << StructMember.new(member_name: 'event_type')
97
121
  end
98
122
  members
@@ -180,7 +204,7 @@ module AwsSdkCodeGenerator
180
204
 
181
205
  def see_also_tag(shape_name)
182
206
  uid = @api['metadata']['uid']
183
- if @api['metadata']['protocol'] != 'api-gateway' && Crosslink.taggable?(uid)
207
+ if @service.protocol != 'api-gateway' && Crosslink.taggable?(uid)
184
208
  Crosslink.tag_string(uid, shape_name)
185
209
  end
186
210
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'aws-sdk-core'
4
+
3
5
  require_relative 'aws-sdk-code-generator/api'
4
6
  require_relative 'aws-sdk-code-generator/apply_docs'
5
7
  require_relative 'aws-sdk-code-generator/codegenerated_plugin'
@@ -10,6 +12,7 @@ require_relative 'aws-sdk-code-generator/error_list'
10
12
  require_relative 'aws-sdk-code-generator/client_response_structure_example'
11
13
  require_relative 'aws-sdk-code-generator/crosslink'
12
14
  require_relative 'aws-sdk-code-generator/docstring'
15
+ require_relative 'aws-sdk-code-generator/endpoint_parameter'
13
16
  require_relative 'aws-sdk-code-generator/hash_formatter'
14
17
  require_relative 'aws-sdk-code-generator/helper'
15
18
  require_relative 'aws-sdk-code-generator/plugin_list'
@@ -103,4 +106,13 @@ module AwsSdkCodeGenerator
103
106
  # WARNING ABOUT GENERATED CODE
104
107
  WARNING_TXT
105
108
 
109
+ @warnings = []
110
+
111
+ class << self
112
+ attr_reader :warnings
113
+ def warn(service, type, message)
114
+ Kernel.warn(message)
115
+ @warnings << { service: service, type: type, message: message }
116
+ end
117
+ end
106
118
  end
@@ -83,13 +83,18 @@ module {{module_name}}
83
83
  # @api private
84
84
  def build_request(operation_name, params = {})
85
85
  handlers = @handlers.for(operation_name)
86
+ tracer = config.telemetry_provider.tracer_provider.tracer(
87
+ Aws::Telemetry.module_to_tracer_name('{{module_name}}')
88
+ )
86
89
  context = Seahorse::Client::RequestContext.new(
87
90
  operation_name: operation_name,
88
91
  operation: config.api.operation(operation_name),
89
92
  client: self,
90
93
  params: params,
91
94
  http_response: Seahorse::Client::Http::AsyncResponse.new,
92
- config: config)
95
+ config: config,
96
+ tracer: tracer
97
+ )
93
98
  context[:gem_name] = '{{gem_name}}'
94
99
  context[:gem_version] = '{{gem_version}}'
95
100
  Seahorse::Client::Request.new(handlers, context)
@@ -3,6 +3,7 @@
3
3
  {{#generated_src_warning}}
4
4
  {{generated_src_warning}}
5
5
  {{/generated_src_warning}}
6
+
6
7
  module {{module_name}}
7
8
  # @api private
8
9
  module ClientApi
@@ -77,6 +78,12 @@ module {{module_name}}
77
78
  {{#authtype}}
78
79
  o['authtype'] = "{{.}}"
79
80
  {{/authtype}}
81
+ {{#unsigned_payload}}
82
+ o['unsignedPayload'] = true
83
+ {{/unsigned_payload}}
84
+ {{#auth}}
85
+ o['auth'] = {{&auth}}
86
+ {{/auth}}
80
87
  {{#endpoint_trait}}
81
88
  o.endpoint_pattern = {
82
89
  {{#endpoint_pattern}}
@@ -7,8 +7,6 @@
7
7
  require '{{.}}'
8
8
  {{/plugin_requires}}
9
9
 
10
- Aws::Plugins::GlobalConfiguration.add_identifier(:{{service_identifier}})
11
-
12
10
  module {{module_name}}
13
11
  # An API client for {{service_name}}. To construct a client, you need to configure a `:region` and `:credentials`.
14
12
  #
@@ -37,6 +35,11 @@ module {{module_name}}
37
35
  {{#client_constructor}}
38
36
  # @overload initialize(options)
39
37
  # @param [Hash] options
38
+ #
39
+ # @option options [Array<Seahorse::Client::Plugin>] :plugins ([]])
40
+ # A list of plugins to apply to the client. Each plugin is either a
41
+ # class name or an instance of a plugin class.
42
+ #
40
43
  {{>documentation}}
41
44
  {{/client_constructor}}
42
45
  def initialize(*args)
@@ -94,13 +97,18 @@ module {{module_name}}
94
97
  end
95
98
  end
96
99
  {{/authorizer?}}
100
+ tracer = config.telemetry_provider.tracer_provider.tracer(
101
+ Aws::Telemetry.module_to_tracer_name('{{module_name}}')
102
+ )
97
103
  context = Seahorse::Client::RequestContext.new(
98
104
  operation_name: operation_name,
99
105
  operation: config.api.operation(operation_name),{{#authorizer?}}
100
106
  authorizer: authorizer,{{/authorizer?}}
101
107
  client: self,
102
108
  params: params,
103
- config: config)
109
+ config: config,
110
+ tracer: tracer
111
+ )
104
112
  context[:gem_name] = '{{gem_name}}'
105
113
  context[:gem_version] = '{{gem_version}}'
106
114
  Seahorse::Client::Request.new(handlers, context)
@@ -11,7 +11,7 @@ module {{module_name}}
11
11
  {{/parameters}}
12
12
  EndpointParameters = Struct.new(
13
13
  {{#parameters}}
14
- :{{underscore_name}},
14
+ :{{key}},
15
15
  {{/parameters}}
16
16
  {{^parameters}}
17
17
  nil
@@ -23,28 +23,31 @@ module {{module_name}}
23
23
  class << self
24
24
  PARAM_MAP = {
25
25
  {{#parameters}}
26
- '{{name}}' => :{{underscore_name}},
26
+ '{{name}}' => :{{key}},
27
27
  {{/parameters}}
28
28
  }.freeze
29
29
  end
30
30
 
31
31
  def initialize(options = {})
32
32
  {{#parameters}}
33
- self[:{{underscore_name}}] = options[:{{underscore_name}}]
33
+ self[:{{key}}] = options[:{{key}}]
34
34
  {{#default?}}
35
- {{#boolean_default?}}
36
- self[:{{underscore_name}}] = {{default}} if self[:{{underscore_name}}].nil?
37
- {{/boolean_default?}}
38
- {{^boolean_default?}}
39
- self[:{{underscore_name}}] ||= '{{default}}' if self[:{{underscore_name}}].nil?
40
- {{/boolean_default?}}
35
+ self[:{{key}}] = {{{default}}} if self[:{{key}}].nil?
41
36
  {{/default?}}
42
- {{#required}}
43
- if self[:{{underscore_name}}].nil?
44
- raise ArgumentError, "Missing required EndpointParameter: :{{underscore_name}}"
37
+ {{#validate_required?}}
38
+ if self[:{{key}}].nil?
39
+ raise ArgumentError, "Missing required EndpointParameter: :{{key}}"
45
40
  end
46
- {{/required}}
41
+ {{/validate_required?}}
47
42
  {{/parameters}}
48
43
  end
44
+
45
+ def self.create(config, options={})
46
+ new({
47
+ {{#config_parameters}}
48
+ {{key}}: {{{value}}},
49
+ {{/config_parameters}}
50
+ }.merge(options))
51
+ end
49
52
  end
50
53
  end
@@ -11,24 +11,31 @@ module {{module_name}}
11
11
  {{#endpoint_classes}}
12
12
  class {{name}}
13
13
  def self.build(context)
14
- {{#has_endpoint_built_in?}}
15
- unless context.config.regional_endpoint
16
- endpoint = context.config.endpoint.to_s
17
- end
18
- {{/has_endpoint_built_in?}}
19
- {{module_name}}::EndpointParameters.new(
14
+ {{module_name}}::EndpointParameters.create(
15
+ context.config,
20
16
  {{#parameters}}
21
- {{#static_string?}}
22
- {{key}}: "{{{value}}}",
23
- {{/static_string?}}
24
- {{^static_string?}}
25
17
  {{key}}: {{{value}}},
26
- {{/static_string?}}
27
18
  {{/parameters}}
28
19
  )
29
20
  end
30
21
  end
31
22
 
32
23
  {{/endpoint_classes}}
24
+
25
+ def self.parameters_for_operation(context)
26
+ {{#operation_specific_parameters?}}
27
+ {{module_name}}::EndpointParameters.create(context.config)
28
+ {{/operation_specific_parameters?}}
29
+ {{^operation_specific_parameters?}}
30
+ case context.operation_name
31
+ {{#endpoint_classes}}
32
+ when :{{operation}}
33
+ {{name}}.build(context)
34
+ {{/endpoint_classes}}
35
+ else
36
+ {{module_name}}::EndpointParameters.create(context.config)
37
+ end
38
+ {{/operation_specific_parameters?}}
39
+ end
33
40
  end
34
41
  end
@@ -11,11 +11,11 @@ module {{module_name}}
11
11
  :endpoint_provider,
12
12
  doc_type: '{{module_name}}::EndpointProvider',
13
13
  rbs_type: 'untyped',
14
- docstring: 'The endpoint provider used to resolve endpoints. Any '\
15
- 'object that responds to `#resolve_endpoint(parameters)` '\
16
- 'where `parameters` is a Struct similar to '\
17
- '`{{module_name}}::EndpointParameters`'
18
- ) do |cfg|
14
+ docstring: <<~DOCS) do |_cfg|
15
+ The endpoint provider used to resolve endpoints. Any object that responds to
16
+ `#resolve_endpoint(parameters)` where `parameters` is a Struct similar to
17
+ `{{module_name}}::EndpointParameters`.
18
+ DOCS
19
19
  {{module_name}}::EndpointProvider.new
20
20
  end
21
21
 
@@ -23,15 +23,18 @@ module {{module_name}}
23
23
  option(
24
24
  :{{name}},
25
25
  doc_type: '{{doc_type}}',
26
- default: {{{default}}},
27
- docstring: "{{{docstring}}}")
26
+ docstring: <<~DOCS) do |cfg|
27
+ {{{docstring}}}
28
+ DOCS
29
+ {{{default}}}
30
+ end
28
31
 
29
32
  {{/endpoint_options}}
30
33
  # @api private
31
34
  class Handler < Seahorse::Client::Handler
32
35
  def call(context)
33
36
  unless context[:discovered_endpoint]
34
- params = parameters_for_operation(context)
37
+ params = {{module_name}}::Endpoints.parameters_for_operation(context)
35
38
  endpoint = context.config.endpoint_provider.resolve_endpoint(params)
36
39
 
37
40
  context.http_request.endpoint = endpoint.url
@@ -44,11 +47,33 @@ module {{module_name}}
44
47
  context[:auth_scheme] =
45
48
  Aws::Endpoints.resolve_auth_scheme(context, endpoint)
46
49
 
47
- @handler.call(context)
50
+ with_metrics(context) { @handler.call(context) }
48
51
  end
49
52
 
50
53
  private
51
54
 
55
+ def with_metrics(context, &block)
56
+ metrics = []
57
+ metrics << 'ENDPOINT_OVERRIDE' unless context.config.regional_endpoint
58
+ if context[:auth_scheme] && context[:auth_scheme]['name'] == 'sigv4a'
59
+ metrics << 'SIGV4A_SIGNING'
60
+ end
61
+ {{#has_account_id_endpoint_mode?}}
62
+ case context.config.account_id_endpoint_mode
63
+ when 'preferred'
64
+ metrics << 'ACCOUNT_ID_MODE_PREFERRED'
65
+ when 'disabled'
66
+ metrics << 'ACCOUNT_ID_MODE_DISABLED'
67
+ when 'required'
68
+ metrics << 'ACCOUNT_ID_MODE_REQUIRED'
69
+ end
70
+ {{/has_account_id_endpoint_mode?}}
71
+ if context.config.credentials&.credentials&.account_id
72
+ metrics << 'RESOLVED_ACCOUNT_ID'
73
+ end
74
+ Aws::Plugins::UserAgent.metric(*metrics, &block)
75
+ end
76
+
52
77
  def apply_endpoint_headers(context, headers)
53
78
  headers.each do |key, values|
54
79
  value = values
@@ -59,15 +84,6 @@ module {{module_name}}
59
84
  context.http_request.headers[key] = value
60
85
  end
61
86
  end
62
-
63
- def parameters_for_operation(context)
64
- case context.operation_name
65
- {{#endpoint_classes}}
66
- when :{{operation_name}}
67
- {{module_name}}::Endpoints::{{class_name}}.build(context)
68
- {{/endpoint_classes}}
69
- end
70
- end
71
87
  end
72
88
 
73
89
  def add_handlers(handlers, _config)
@@ -68,3 +68,8 @@ module {{module_name}}
68
68
  {{/errors}}
69
69
  end
70
70
  end
71
+ {{#customization_file_exists?}}
72
+
73
+ # Load customizations if they exist
74
+ require '{{customization_file_path}}'
75
+ {{/customization_file_exists?}}
@@ -213,7 +213,7 @@ module {{module_name}}
213
213
  :retry
214
214
  end
215
215
  end
216
- Aws::Plugins::UserAgent.feature('resource') do
216
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
217
217
  Aws::Waiters::Waiter.new(options).wait({})
218
218
  end
219
219
  end
@@ -304,3 +304,8 @@ module {{module_name}}
304
304
  {{/batch_actions?}}
305
305
  end
306
306
  end
307
+ {{#customization_file_exists?}}
308
+
309
+ # Load customizations if they exist
310
+ require '{{resource_customization}}'
311
+ {{/customization_file_exists?}}
@@ -49,3 +49,8 @@ module {{module_name}}
49
49
 
50
50
  end
51
51
  end
52
+ {{#customization_file_exists?}}
53
+
54
+ # Load customizations if they exist
55
+ require '{{customization_file_path}}'
56
+ {{/customization_file_exists?}}
@@ -17,9 +17,7 @@ require '{{.}}'
17
17
  {{/requires}}
18
18
  {{/require_core_guard?}}
19
19
 
20
- {{#relative_requires}}
21
- require_relative '{{.}}'
22
- {{/relative_requires}}
20
+ Aws::Plugins::GlobalConfiguration.add_identifier(:{{service_identifier}})
23
21
 
24
22
  # This module provides support for {{full_name}}. This module is available in the
25
23
  # `{{gem_name}}` gem.
@@ -52,7 +50,19 @@ require_relative '{{.}}'
52
50
  #
53
51
  # @!group service
54
52
  module {{module_name}}
53
+ {{#autoloads}}
54
+ {{#is_plugin}}
55
+ module Plugins
56
+ autoload :{{class_name}}, '{{file_path}}'
57
+ end
58
+ {{/is_plugin}}
59
+ {{^is_plugin}}
60
+ autoload :{{class_name}}, '{{file_path}}'
61
+ {{/is_plugin}}
62
+ {{/autoloads}}
55
63
 
56
64
  GEM_VERSION = '{{gem_version}}'
57
65
 
58
66
  end
67
+
68
+ require_relative '{{prefix}}/customizations'
@@ -11,7 +11,7 @@ module {{module_name}}
11
11
  subject { {{module_name}}::EndpointProvider.new }
12
12
 
13
13
  {{#endpoint_tests}}
14
- context '{{documentation}}' do
14
+ context "{{{documentation}}}" do
15
15
  let(:expected) do
16
16
  {{{expect}}}
17
17
  end
@@ -51,3 +51,7 @@ module {{module_name}}
51
51
 
52
52
  end
53
53
  end
54
+
55
+ {{#types_customizations}}
56
+ require "{{.}}"
57
+ {{/types_customizations}}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-code-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.pre
4
+ version: 0.6.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -56,6 +56,7 @@ files:
56
56
  - lib/aws-sdk-code-generator/codegenerated_plugin.rb
57
57
  - lib/aws-sdk-code-generator/crosslink.rb
58
58
  - lib/aws-sdk-code-generator/docstring.rb
59
+ - lib/aws-sdk-code-generator/endpoint_parameter.rb
59
60
  - lib/aws-sdk-code-generator/error_list.rb
60
61
  - lib/aws-sdk-code-generator/errors.rb
61
62
  - lib/aws-sdk-code-generator/eventstream_example.rb
@@ -184,11 +185,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  requirements:
187
- - - ">"
188
+ - - ">="
188
189
  - !ruby/object:Gem::Version
189
- version: 1.3.1
190
+ version: '0'
190
191
  requirements: []
191
- rubygems_version: 3.4.1
192
+ rubygems_version: 3.5.9
192
193
  signing_key:
193
194
  specification_version: 4
194
195
  summary: AWS SDK for Ruby - Code Generator