aws-sdk-code-generator 0.2.4.pre → 0.3.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/aws-sdk-code-generator/client_constructor.rb +4 -1
  3. data/lib/aws-sdk-code-generator/client_operation_documentation.rb +10 -4
  4. data/lib/aws-sdk-code-generator/code_builder.rb +78 -9
  5. data/lib/aws-sdk-code-generator/codegenerated_plugin.rb +34 -0
  6. data/lib/aws-sdk-code-generator/gem_builder.rb +4 -5
  7. data/lib/aws-sdk-code-generator/plugin_list.rb +29 -9
  8. data/lib/aws-sdk-code-generator/service.rb +22 -0
  9. data/lib/aws-sdk-code-generator/views/async_client_class.rb +6 -2
  10. data/lib/aws-sdk-code-generator/views/client_api_module.rb +18 -2
  11. data/lib/aws-sdk-code-generator/views/client_class.rb +7 -2
  12. data/lib/aws-sdk-code-generator/views/endpoint_parameters_class.rb +80 -0
  13. data/lib/aws-sdk-code-generator/views/endpoint_provider_class.rb +34 -0
  14. data/lib/aws-sdk-code-generator/views/endpoints_module.rb +177 -0
  15. data/lib/aws-sdk-code-generator/views/endpoints_plugin.rb +85 -0
  16. data/lib/aws-sdk-code-generator/views/gemspec.rb +4 -0
  17. data/lib/aws-sdk-code-generator/views/service_module.rb +15 -1
  18. data/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb +198 -0
  19. data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -4
  20. data/lib/aws-sdk-code-generator/views/types_module.rb +8 -7
  21. data/lib/aws-sdk-code-generator.rb +6 -0
  22. data/templates/async_client_class.mustache +2 -2
  23. data/templates/client_api_module.mustache +7 -0
  24. data/templates/client_class.mustache +4 -1
  25. data/templates/endpoint_parameters_class.mustache +50 -0
  26. data/templates/endpoint_provider_class.mustache +30 -0
  27. data/templates/endpoints_module.mustache +33 -0
  28. data/templates/endpoints_plugin.mustache +76 -0
  29. data/templates/gemspec.mustache +1 -1
  30. data/templates/spec/endpoint_provider_spec_class.mustache +76 -0
  31. data/templates/spec/spec_helper.mustache +5 -0
  32. metadata +14 -3
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+ module {{module_name}}
7
+ class EndpointProvider
8
+ def initialize(rule_set = nil)
9
+ @@rule_set ||= begin
10
+ endpoint_rules = Aws::Json.load(Base64.decode64(RULES))
11
+ Aws::Endpoints::RuleSet.new(
12
+ version: endpoint_rules['version'],
13
+ service_id: endpoint_rules['serviceId'],
14
+ parameters: endpoint_rules['parameters'],
15
+ rules: endpoint_rules['rules']
16
+ )
17
+ end
18
+ @provider = Aws::Endpoints::RulesProvider.new(rule_set || @@rule_set)
19
+ end
20
+
21
+ def resolve_endpoint(parameters)
22
+ @provider.resolve_endpoint(parameters)
23
+ end
24
+
25
+ # @api private
26
+ RULES = <<-JSON
27
+ {{endpoint_rules_encoded}}
28
+ JSON
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+
7
+ module {{module_name}}
8
+ module Endpoints
9
+
10
+ {{#endpoint_classes}}
11
+ class {{name}}
12
+ def self.build(context)
13
+ {{#has_endpoint_built_in?}}
14
+ unless context.config.regional_endpoint
15
+ endpoint = context.config.endpoint.to_s
16
+ end
17
+ {{/has_endpoint_built_in?}}
18
+ {{module_name}}::EndpointParameters.new(
19
+ {{#parameters}}
20
+ {{#static_string?}}
21
+ {{key}}: "{{{value}}}",
22
+ {{/static_string?}}
23
+ {{^static_string?}}
24
+ {{key}}: {{{value}}},
25
+ {{/static_string?}}
26
+ {{/parameters}}
27
+ )
28
+ end
29
+ end
30
+
31
+ {{/endpoint_classes}}
32
+ end
33
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+
7
+ module {{module_name}}
8
+ module Plugins
9
+ class Endpoints < Seahorse::Client::Plugin
10
+ option(
11
+ :endpoint_provider,
12
+ doc_type: '{{module_name}}::EndpointProvider',
13
+ docstring: 'The endpoint provider used to resolve endpoints. Any '\
14
+ 'object that responds to `#resolve_endpoint(parameters)` '\
15
+ 'where `parameters` is a Struct similar to '\
16
+ '`{{module_name}}::EndpointParameters`'
17
+ ) do |cfg|
18
+ {{module_name}}::EndpointProvider.new
19
+ end
20
+
21
+ {{#endpoint_options}}
22
+ option(
23
+ :{{name}},
24
+ doc_type: '{{doc_type}}',
25
+ default: {{{default}}},
26
+ docstring: "{{{docstring}}}")
27
+
28
+ {{/endpoint_options}}
29
+ # @api private
30
+ class Handler < Seahorse::Client::Handler
31
+ def call(context)
32
+ # If endpoint was discovered, do not resolve or apply the endpoint.
33
+ unless context[:discovered_endpoint]
34
+ params = parameters_for_operation(context)
35
+ endpoint = context.config.endpoint_provider.resolve_endpoint(params)
36
+
37
+ context.http_request.endpoint = endpoint.url
38
+ apply_endpoint_headers(context, endpoint.headers)
39
+ end
40
+
41
+ context[:endpoint_params] = params
42
+ context[:auth_scheme] =
43
+ Aws::Endpoints.resolve_auth_scheme(context, endpoint)
44
+
45
+ @handler.call(context)
46
+ end
47
+
48
+ private
49
+
50
+ def apply_endpoint_headers(context, headers)
51
+ headers.each do |key, values|
52
+ value = values
53
+ .compact
54
+ .map { |s| Seahorse::Util.escape_header_list_string(s.to_s) }
55
+ .join(',')
56
+
57
+ context.http_request.headers[key] = value
58
+ end
59
+ end
60
+
61
+ def parameters_for_operation(context)
62
+ case context.operation_name
63
+ {{#endpoint_classes}}
64
+ when :{{operation_name}}
65
+ {{module_name}}::Endpoints::{{class_name}}.build(context)
66
+ {{/endpoint_classes}}
67
+ end
68
+ end
69
+ end
70
+
71
+ def add_handlers(handlers, _config)
72
+ handlers.add(Handler, step: :build, priority: 75)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = 'Apache-2.0'
15
15
  spec.email = ['{{email}}']
16
16
  spec.require_paths = ['lib']
17
- spec.files = Dir['LICENSE.txt', 'CHANGELOG.md', 'VERSION', 'lib/**/*.rb']
17
+ spec.files = Dir{{{files}}}
18
18
 
19
19
  {{#metadata}}
20
20
  spec.metadata = {
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ {{#generated_src_warning}}
4
+ {{generated_src_warning}}
5
+ {{/generated_src_warning}}
6
+
7
+ require_relative 'spec_helper'
8
+
9
+ module {{module_name}}
10
+ describe EndpointProvider do
11
+ subject { {{module_name}}::EndpointProvider.new }
12
+
13
+ {{#endpoint_tests}}
14
+ context '{{documentation}}' do
15
+ let(:expected) do
16
+ {{{expect}}}
17
+ end
18
+
19
+ it 'produces the expected output from the EndpointProvider' do
20
+ params = EndpointParameters.new(**{{{params}}})
21
+ {{#expect_error?}}
22
+ expect do
23
+ subject.resolve_endpoint(params)
24
+ end.to raise_error(ArgumentError, expected['error'])
25
+ {{/expect_error?}}
26
+ {{^expect_error?}}
27
+ endpoint = subject.resolve_endpoint(params)
28
+ expect(endpoint.url).to eq(expected['endpoint']['url'])
29
+ expect(endpoint.headers).to eq(expected['endpoint']['headers'] || {})
30
+ expect(endpoint.properties).to eq(expected['endpoint']['properties'] || {})
31
+ {{/expect_error?}}
32
+ end
33
+ {{#operation_inputs}}
34
+
35
+ it 'produces the correct output from the client when calling {{operation_name}}' do
36
+ client = Client.new(
37
+ {{#client_params}}
38
+ {{param}}: {{{value}}},
39
+ {{/client_params}}
40
+ stub_responses: true
41
+ )
42
+ {{#expect_error?}}
43
+ expect do
44
+ client.{{operation_name}}(
45
+ {{#operation_params}}
46
+ {{param}}: {{{value}}},
47
+ {{/operation_params}}
48
+ )
49
+ end.to raise_error(ArgumentError, expected['error'])
50
+ {{/expect_error?}}
51
+ {{^expect_error?}}
52
+ {{#expect_auth?}}
53
+ expect_auth({{{expected_auth}}})
54
+ {{/expect_auth?}}
55
+ resp = client.{{operation_name}}(
56
+ {{#operation_params}}
57
+ {{param}}: {{{value}}},
58
+ {{/operation_params}}
59
+ )
60
+ expected_uri = URI.parse(expected['endpoint']['url'])
61
+ expect(resp.context.http_request.endpoint.to_s).to include(expected_uri.host)
62
+ expect(resp.context.http_request.endpoint.to_s).to include(expected_uri.scheme)
63
+ expect(resp.context.http_request.endpoint.to_s).to include(expected_uri.path)
64
+ {{#expect_headers?}}
65
+ {{#expected_headers}}
66
+ expect(resp.context.http_request.headers['{{param}}']).to eq({{{value}}})
67
+ {{/expected_headers}}
68
+ {{/expect_headers?}}
69
+ {{/expect_error?}}
70
+ end
71
+ {{/operation_inputs}}
72
+ end
73
+
74
+ {{/endpoint_tests}}
75
+ end
76
+ end
@@ -3,7 +3,12 @@
3
3
  {{#generated_src_warning}}
4
4
  {{generated_src_warning}}
5
5
  {{/generated_src_warning}}
6
+ {{#included_in_core}}
7
+ require_relative '../../shared_spec_helper'
8
+ {{/included_in_core}}
9
+ {{^included_in_core}}
6
10
  require_relative '../../aws-sdk-core/spec/shared_spec_helper'
11
+ {{/included_in_core}}
7
12
 
8
13
  $:.unshift(File.expand_path('../../lib', __FILE__))
9
14
  {{#gem_dependencies}}
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.2.4.pre
4
+ version: 0.3.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: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2022-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -53,6 +53,7 @@ files:
53
53
  - lib/aws-sdk-code-generator/client_operation_list.rb
54
54
  - lib/aws-sdk-code-generator/client_response_structure_example.rb
55
55
  - lib/aws-sdk-code-generator/code_builder.rb
56
+ - lib/aws-sdk-code-generator/codegenerated_plugin.rb
56
57
  - lib/aws-sdk-code-generator/crosslink.rb
57
58
  - lib/aws-sdk-code-generator/docstring.rb
58
59
  - lib/aws-sdk-code-generator/error_list.rb
@@ -99,6 +100,10 @@ files:
99
100
  - lib/aws-sdk-code-generator/views/client_api_module.rb
100
101
  - lib/aws-sdk-code-generator/views/client_class.rb
101
102
  - lib/aws-sdk-code-generator/views/docstring.rb
103
+ - lib/aws-sdk-code-generator/views/endpoint_parameters_class.rb
104
+ - lib/aws-sdk-code-generator/views/endpoint_provider_class.rb
105
+ - lib/aws-sdk-code-generator/views/endpoints_module.rb
106
+ - lib/aws-sdk-code-generator/views/endpoints_plugin.rb
102
107
  - lib/aws-sdk-code-generator/views/errors_module.rb
103
108
  - lib/aws-sdk-code-generator/views/event_streams_module.rb
104
109
  - lib/aws-sdk-code-generator/views/features/env.rb
@@ -109,6 +114,7 @@ files:
109
114
  - lib/aws-sdk-code-generator/views/resource_class.rb
110
115
  - lib/aws-sdk-code-generator/views/root_resource_class.rb
111
116
  - lib/aws-sdk-code-generator/views/service_module.rb
117
+ - lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb
112
118
  - lib/aws-sdk-code-generator/views/spec/spec_helper.rb
113
119
  - lib/aws-sdk-code-generator/views/types_module.rb
114
120
  - lib/aws-sdk-code-generator/views/version.rb
@@ -123,6 +129,10 @@ files:
123
129
  - templates/client_class.mustache
124
130
  - templates/code.mustache
125
131
  - templates/documentation.mustache
132
+ - templates/endpoint_parameters_class.mustache
133
+ - templates/endpoint_provider_class.mustache
134
+ - templates/endpoints_module.mustache
135
+ - templates/endpoints_plugin.mustache
126
136
  - templates/errors_module.mustache
127
137
  - templates/event_streams_module.mustache
128
138
  - templates/features/env.mustache
@@ -135,6 +145,7 @@ files:
135
145
  - templates/resource_class.mustache
136
146
  - templates/root_resource_class.mustache
137
147
  - templates/service_module.mustache
148
+ - templates/spec/endpoint_provider_spec_class.mustache
138
149
  - templates/spec/spec_helper.mustache
139
150
  - templates/types_module.mustache
140
151
  - templates/version.mustache
@@ -158,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
169
  - !ruby/object:Gem::Version
159
170
  version: 1.3.1
160
171
  requirements: []
161
- rubygems_version: 3.2.7
172
+ rubygems_version: 3.2.22
162
173
  signing_key:
163
174
  specification_version: 4
164
175
  summary: AWS SDK for Ruby - Code Generator