Skip to content

Commit a3f158e

Browse files
Merge customizations for DynamoDB
1 parent e6ef6d8 commit a3f158e

32 files changed

+333
-128
lines changed

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoint_provider_class.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class EndpointProviderClass < View
99
def initialize(options)
1010
@service = options.fetch(:service)
1111
@endpoint_rules = @service.endpoint_rules
12+
# Used to collect metrics in the generated endpoint provider
13+
@has_account_id_endpoint_mode =
14+
@endpoint_rules['parameters'].find do |_, param|
15+
param['builtIn'] == 'AWS::Auth::AccountIdEndpointMode'
16+
end
1217

1318
version = @endpoint_rules['version']
1419
return if version&.match(/^\d+\.\d+$/) # && version == '1.0'
@@ -76,6 +81,10 @@ def endpoint(endpoint, levels)
7681
if endpoint['properties']
7782
res << ", properties: #{templated_hash_to_s(endpoint['properties'])}"
7883
end
84+
if @has_account_id_endpoint_mode
85+
account_id_endpoint = endpoint['url'].include?('{AccountId}')
86+
res << ", metadata: { account_id_endpoint: #{account_id_endpoint} }"
87+
end
7988
res << ")\n"
8089
indent(res.string, levels)
8190
end

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ def built_in_client_context_param_value(param_data)
134134
else
135135
'context.config.use_dualstack_endpoint'
136136
end
137+
when 'AWS::Auth::AccountId'
138+
'context.config.credentials.credentials.account_id'
139+
when 'AWS::Auth::AccountIdEndpointMode'
140+
'context.config.account_id_endpoint_mode'
137141
when 'AWS::STS::UseGlobalEndpoint'
138142
"context.config.sts_regional_endpoints == 'legacy'"
139143
when 'AWS::S3::UseGlobalEndpoint'

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_plugin.rb

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,33 @@ class EndpointsPlugin < View
66
# @option options [required, Service] :service
77
def initialize(options)
88
@service = options.fetch(:service)
9-
if (client_options = @service.api['clientContextParams'])
10-
endpoint_parameters = @service.endpoint_rules.fetch('parameters', {})
9+
endpoint_parameters = @service.endpoint_rules.fetch('parameters', {})
10+
11+
# HACK: AccountIdEndpointMode should likely be a client context
12+
# param, but it's a built in that should be per-service.
13+
@endpoint_options = []
14+
endpoint_parameters.each do |_key, data|
15+
next unless data['builtIn'] == 'AWS::Auth::AccountIdEndpointMode'
1116

12-
@endpoint_options = client_options.each.with_object([]) do |(name, _data), array|
17+
@endpoint_options << account_id_endpoint_mode_option
18+
@account_id_endpoint_mode = true
19+
end
20+
21+
if (client_options = @service.api['clientContextParams'])
22+
client_options.each do |name, _data|
1323
param_data = endpoint_parameters[name]
1424

1525
next if param_data['builtIn']
1626

17-
array << EndpointOption.new(
27+
@endpoint_options << EndpointOption.new(
1828
name: Underscore.underscore(name),
1929
docstring: param_data['documentation'],
2030
doc_type: param_data['type'],
2131
default: param_data['default']
2232
)
2333
end
2434
end
35+
2536
@endpoint_classes = @service.api['operations'].each.with_object([]) do
2637
|(op, _api), array|
2738
array << EndpointClass.new(
@@ -47,6 +58,37 @@ def module_name
4758
@service.module_name
4859
end
4960

61+
def has_account_id_endpoint_mode?
62+
@account_id_endpoint_mode
63+
end
64+
65+
private
66+
67+
def account_id_endpoint_mode_option
68+
docstring = <<-DOCSTRING.chomp
69+
The account ID endpoint mode to use. This can be one of the following values:
70+
* `preferred` - The default behavior. Use the account ID endpoint if
71+
available, otherwise use the standard endpoint.
72+
* `disabled` - Never use the account ID endpoint. Only use the standard
73+
endpoint.
74+
* `required` - Always use the account ID endpoint. If the account ID
75+
cannot be retrieved from credentials, an error is raised.
76+
DOCSTRING
77+
78+
default = <<-DEFAULT.chomp
79+
value = ENV['AWS_ACCOUNT_ID_ENDPOINT_MODE']
80+
value ||= Aws.shared_config.account_id_endpoint_mode(profile: cfg.profile)
81+
value || 'preferred'
82+
DEFAULT
83+
84+
EndpointOption.new(
85+
name: 'account_id_endpoint_mode',
86+
docstring: docstring,
87+
doc_type: 'String',
88+
default: default
89+
)
90+
end
91+
5092
class EndpointClass
5193
def initialize(options)
5294
@operation_name = options[:operation_name]

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/rbs/client_class.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def build_keyword_arguments(plugins)
138138
grouped = buffer.group_by { |name, _| name }
139139
grouped.transform_values(&:count).find_all { |_, c| 1 < c }.each do |name,|
140140
case name
141-
when :endpoint, :endpoint_provider, :retry_limit, :disable_s3_express_session_auth
141+
when :endpoint, :endpoint_provider, :retry_limit, :disable_s3_express_session_auth, :account_id_endpoint_mode
142142
# ok
143143
else
144144
warn("Duplicate client option in #{@service_name}: `#{grouped[name].map { |g| g.values_at(0, 2) }}`", uplevel: 0)

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ def built_in_to_param(built_in, value)
159159
Param.new('use_fips_endpoint', value)
160160
when 'AWS::UseDualStack'
161161
Param.new('use_dualstack_endpoint', value)
162+
when 'AWS::Auth::AccountId'
163+
Param.new(
164+
'credentials',
165+
"Aws::Credentials.new('stubbed-akid', 'stubbed-secret', account_id: '#{value}')",
166+
true
167+
)
168+
when 'AWS::Auth::AccountIdEndpointMode'
169+
Param.new('account_id_endpoint_mode', value)
162170
when 'AWS::STS::UseGlobalEndpoint'
163171
Param.new('sts_regional_endpoints', value ? 'legacy' : 'regional')
164172
when 'AWS::S3::UseGlobalEndpoint'
@@ -167,9 +175,7 @@ def built_in_to_param(built_in, value)
167175
Param.new('use_accelerate_endpoint', value)
168176
when 'AWS::S3::ForcePathStyle'
169177
Param.new('force_path_style', value)
170-
when 'AWS::S3::UseArnRegion'
171-
Param.new('s3_use_arn_region', value)
172-
when 'AWS::S3Control::UseArnRegion'
178+
when 'AWS::S3::UseArnRegion', 'AWS::S3Control::UseArnRegion'
173179
Param.new('s3_use_arn_region', value)
174180
when 'AWS::S3::DisableMultiRegionAccessPoints'
175181
Param.new('s3_disable_multiregion_access_points', value)
@@ -182,14 +188,16 @@ def built_in_to_param(built_in, value)
182188
end
183189

184190
class Param
185-
def initialize(param, value)
191+
def initialize(param, value, literal = false)
186192
@param = param
187193
@value = value
194+
@literal = literal
188195
end
196+
189197
attr_accessor :param
190198

191199
def value
192-
if @value.is_a? String
200+
if @value.is_a?(String) && !@literal
193201
"'#{@value}'"
194202
else
195203
@value

build_tools/aws-sdk-code-generator/spec/fixtures/interfaces/endpoints_built_ins/endpoint-rule-set.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
"required": false,
2727
"documentation": "Override the endpoint used to send this request",
2828
"type": "String"
29+
},
30+
"AccountIdEndpointMode": {
31+
"builtIn": "AWS::Auth::AccountIdEndpointMode",
32+
"required": false,
33+
"documentation": "The AccountId Endpoint Mode.",
34+
"type": "String"
2935
}
3036
},
3137
"rules": [

build_tools/aws-sdk-code-generator/spec/interfaces/plugins/endpoints_spec.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
region: region,
7676
endpoint: endpoint,
7777
use_fips: true,
78-
use_dual_stack: true
78+
use_dual_stack: true,
79+
account_id_endpoint_mode: 'preferred'
7980
).and_call_original
8081

8182
client.operation
@@ -93,6 +94,25 @@
9394
expect(params.use_fips).to eq(false)
9495
expect(params.endpoint).to be_nil
9596
end
97+
98+
describe 'account id endpoint mode option' do
99+
it 'is configured to use preferred by default' do
100+
expect(client.config.account_id_endpoint_mode).to eq 'preferred'
101+
end
102+
103+
it 'can be configured using shared config' do
104+
allow_any_instance_of(Aws::SharedConfig)
105+
.to receive(:account_id_endpoint_mode).and_return('disabled')
106+
expect(client.config.account_id_endpoint_mode).to eq 'disabled'
107+
end
108+
109+
it 'can be configured using ENV with precedence over shared config' do
110+
allow_any_instance_of(Aws::SharedConfig)
111+
.to receive(:account_id_endpoint_mode).and_return('disabled')
112+
ENV['AWS_ACCOUNT_ID_ENDPOINT_MODE'] = 'required'
113+
expect(client.config.account_id_endpoint_mode).to eq 'required'
114+
end
115+
end
96116
end
97117

98118
context 'Param Precedence' do

build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ module {{module_name}}
1111
:endpoint_provider,
1212
doc_type: '{{module_name}}::EndpointProvider',
1313
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
1919
{{module_name}}::EndpointProvider.new
2020
end
2121

2222
{{#endpoint_options}}
2323
option(
2424
:{{name}},
2525
doc_type: '{{doc_type}}',
26-
default: {{{default}}},
27-
docstring: "{{{docstring}}}")
26+
docstring: <<~DOCS) do |cfg|
27+
{{{docstring}}}
28+
DOCS
29+
{{{default}}}
30+
end
2831

2932
{{/endpoint_options}}
3033
# @api private
@@ -55,6 +58,19 @@ module {{module_name}}
5558
if context[:auth_scheme] && context[:auth_scheme]['name'] == 'sigv4a'
5659
metrics << 'SIGV4A_SIGNING'
5760
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
5874
Aws::Plugins::UserAgent.metric(*metrics, &block)
5975
end
6076

build_tools/services.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class ServiceEnumerator
1010
MANIFEST_PATH = File.expand_path('../../services.json', __FILE__)
1111

1212
# Minimum `aws-sdk-core` version for new gem builds
13-
MINIMUM_CORE_VERSION = "3.205.0"
13+
MINIMUM_CORE_VERSION = "3.207.0"
1414

1515
# Minimum `aws-sdk-core` version for new S3 gem builds
16-
MINIMUM_CORE_VERSION_S3 = "3.205.0"
16+
MINIMUM_CORE_VERSION_S3 = "3.207.0"
1717

1818
EVENTSTREAM_PLUGIN = "Aws::Plugins::EventStreamConfiguration"
1919

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Unreleased Changes
22
------------------
33

4+
* Feature - Support Account ID credentials using `ENV['AWS_ACCOUNT_ID']`, `aws_account_id` shared config, or the `account_id` Client configuration option.
5+
6+
* Feature - Support Account ID endpoint mode using `ENV['AWS_ACCOUNT_ID_ENDPOINT_MODE']`, `aws_account_id_endpoint_mode` shared config, or the `account_id_endpoint_mode` Client configuration option. Defaults to `preferred`, which will use the account id endpoint if available. Set to `disabled` to disable account id endpoints. Set to `required` to require account id endpoint usage; an error is raised if credentials do not have an account id.
7+
48
3.206.0 (2024-09-17)
59
------------------
610

@@ -64,6 +68,7 @@ Unreleased Changes
6468
------------------
6569

6670
* Issue - Allow legacy/undocumented `sigv4_signer` configuration to override resolved signer.
71+
6772
* Issue - Consider sigv4a supported without crt check.
6873

6974
3.201.4 (2024-08-08)

0 commit comments

Comments
 (0)