Skip to content

Commit e0c61bb

Browse files
authored
Add all core plugins to autoloads (#3116)
1 parent 0219037 commit e0c61bb

File tree

8 files changed

+90
-25
lines changed

8 files changed

+90
-25
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ class ServiceModule < View
1010
# @option options [required, String] :prefix
1111
def initialize(options)
1212
@service = options.fetch(:service)
13-
@service_identifier = @service.identifier
1413
@prefix = options.fetch(:prefix)
1514
@codegenerated_plugins = options.fetch(:codegenerated_plugins) || []
1615
end
1716

1817
# @return [String]
19-
attr_reader :service_identifier
18+
attr_reader :prefix
2019

2120
# @return [String|nil]
2221
def generated_src_warning
@@ -64,6 +63,11 @@ def require_core_guard?
6463
@service.included_in_core?
6564
end
6665

66+
# @return [String]
67+
def service_identifier
68+
@service.identifier
69+
end
70+
6771
# @return [Array<Hash>] list of autoload path hashes with :path, :class_name and
6872
# :is_plugin keys.
6973
def autoloads
@@ -112,10 +116,6 @@ def auto_load(path, class_name, is_plugin = false)
112116
}
113117
end
114118

115-
def prefix
116-
@prefix
117-
end
118-
119119
def example_var_name
120120
underscore(name)
121121
end

gems/aws-sdk-core/CHANGELOG.md

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

4+
* Issue - Add all core plugins to autoloads.
5+
46
3.209.0 (2024-09-24)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'aws-partitions'
44
require 'seahorse'
55
require 'jmespath'
6+
require 'aws-sigv4'
67

78
require_relative 'aws-sdk-core/deprecations'
89
# defaults

gems/aws-sdk-core/lib/aws-sdk-core/assume_role_credentials.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,22 @@ def initialize(options = {})
6262
private
6363

6464
def refresh
65-
c = @client.assume_role(@assume_role_params)
66-
creds = c.credentials
67-
account_id =
68-
begin
69-
ARNParser.parse(c.assumed_role_user.arn).account_id
70-
rescue Aws::Errors::InvalidARNError
71-
nil
72-
end
65+
resp = @client.assume_role(@assume_role_params)
66+
creds = resp.credentials
7367
@credentials = Credentials.new(
7468
creds.access_key_id,
7569
creds.secret_access_key,
7670
creds.session_token,
77-
account_id: account_id
71+
account_id: parse_account_id(resp)
7872
)
7973
@expiration = creds.expiration
8074
end
8175

76+
def parse_account_id(resp)
77+
arn = resp.assumed_role_user&.arn
78+
ARNParser.parse(arn).account_id if ARNParser.arn?(arn)
79+
end
80+
8281
class << self
8382

8483
# @api private

gems/aws-sdk-core/lib/aws-sdk-core/assume_role_web_identity_credentials.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,13 @@ def refresh
7373
# read from token file everytime it refreshes
7474
@assume_role_web_identity_params[:web_identity_token] = _token_from_file(@token_file)
7575

76-
c = @client.assume_role_with_web_identity(@assume_role_web_identity_params)
77-
creds = c.credentials
78-
account_id =
79-
begin
80-
ARNParser.parse(c.assumed_role_user.arn).account_id
81-
rescue Aws::Errors::InvalidARNError
82-
nil
83-
end
76+
resp = @client.assume_role_with_web_identity(@assume_role_web_identity_params)
77+
creds = resp.credentials
8478
@credentials = Credentials.new(
8579
creds.access_key_id,
8680
creds.secret_access_key,
8781
creds.session_token,
88-
account_id: account_id
82+
account_id: parse_account_id(resp)
8983
)
9084
@expiration = creds.expiration
9185
end
@@ -101,6 +95,11 @@ def _session_name
10195
Base64.strict_encode64(SecureRandom.uuid)
10296
end
10397

98+
def parse_account_id(resp)
99+
arn = resp.assumed_role_user&.arn
100+
ARNParser.parse(arn).account_id if ARNParser.arn?(arn)
101+
end
102+
104103
class << self
105104

106105
# @api private

gems/aws-sdk-core/lib/aws-sdk-core/plugins.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,37 @@
33
module Aws
44
# setup autoloading for Plugins
55
# Most plugins are required explicitly from service clients
6+
# but users may reference them outside of client usage.
67
module Plugins
8+
autoload :ApiKey, 'aws-sdk-core/plugins/api_key'
79
autoload :BearerAuthorization, 'aws-sdk-core/plugins/bearer_authorization'
8-
autoload :SignatureV4, 'aws-sdk-core/plugins/signature_v4'
10+
autoload :ChecksumAlgorithm, 'aws-sdk-core/plugins/checksum_algorithm'
11+
autoload :ClientMetricsPlugin, 'aws-sdk-core/plugins/client_metrics_plugin'
12+
autoload :ClientMetricsSendPlugin, 'aws-sdk-core/plugins/client_metrics_send_plugin'
13+
autoload :CredentialsConfiguration, 'aws-sdk-core/plugins/credentials_configuration'
14+
autoload :DefaultsMode, 'aws-sdk-core/plugins/defaults_mode'
15+
autoload :EndpointDiscovery, 'aws-sdk-core/plugins/endpoint_discovery'
16+
autoload :EndpointPattern, 'aws-sdk-core/plugins/endpoint_pattern'
17+
autoload :EventStreamConfiguration, 'aws-sdk-core/plugins/event_stream_configuration'
918
autoload :GlobalConfiguration, 'aws-sdk-core/plugins/global_configuration'
19+
autoload :HelpfulSocketErrors, 'aws-sdk-core/plugins/helpful_socket_errors'
20+
autoload :HttpChecksum, 'aws-sdk-core/plugins/http_checksum'
21+
autoload :IdempotencyToken, 'aws-sdk-core/plugins/idempotency_token'
22+
autoload :InvocationId, 'aws-sdk-core/plugins/invocation_id'
23+
autoload :JsonvalueConverter, 'aws-sdk-core/plugins/jsonvalue_converter'
24+
autoload :Logging, 'aws-sdk-core/plugins/logging'
25+
autoload :ParamConverter, 'aws-sdk-core/plugins/param_converter'
26+
autoload :ParamValidator, 'aws-sdk-core/plugins/param_validator'
27+
autoload :RecursionDetection, 'aws-sdk-core/plugins/recursion_detection'
28+
autoload :RegionalEndpoint, 'aws-sdk-core/plugins/regional_endpoint'
29+
autoload :RequestCompression, 'aws-sdk-core/plugins/request_compression'
30+
autoload :ResponsePaging, 'aws-sdk-core/plugins/response_paging'
31+
autoload :RetryErrors, 'aws-sdk-core/plugins/retry_errors'
32+
autoload :Sign, 'aws-sdk-core/plugins/sign'
33+
autoload :SignatureV4, 'aws-sdk-core/plugins/signature_v4'
34+
autoload :StubResponses, 'aws-sdk-core/plugins/stub_responses'
35+
autoload :Telemetry, 'aws-sdk-core/plugins/telemetry'
36+
autoload :TransferEncoding, 'aws-sdk-core/plugins/transfer_encoding'
37+
autoload :UserAgent, 'aws-sdk-core/plugins/user_agent'
1038
end
1139
end

gems/aws-sdk-core/spec/aws/assume_role_credentials_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ module Aws
118118
expect(c.expiration).to eq(in_one_hour)
119119
end
120120

121+
context 'invalid assumed role arn' do
122+
let(:assumed_role_user) do
123+
double(
124+
'assumed_role_user',
125+
arn: 'invalid_arn',
126+
assumed_role_id: 'role id'
127+
)
128+
end
129+
130+
it 'does not set accountId' do
131+
c = AssumeRoleCredentials.new(
132+
role_arn: 'arn',
133+
role_session_name: 'session'
134+
)
135+
expect(c.credentials.account_id).to be_nil
136+
end
137+
end
138+
121139
it 'refreshes asynchronously' do
122140
# expiration 6 minutes out, within the async exp time window
123141
allow(credentials).to receive(:expiration).and_return(Time.now + (6*60))

gems/aws-sdk-core/spec/aws/assume_role_web_identity_credentials_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ module Aws
168168
expect(c.expiration).to eq(in_one_hour)
169169
end
170170

171+
context 'invalid assumed role arn' do
172+
let(:assumed_role_user) do
173+
double(
174+
'assumed_role_user',
175+
arn: 'invalid_arn',
176+
assumed_role_id: 'role id'
177+
)
178+
end
179+
180+
it 'does not set accountId' do
181+
c = AssumeRoleWebIdentityCredentials.new(
182+
role_arn: 'arn',
183+
web_identity_token_file: token_file_path,
184+
)
185+
expect(c.credentials.account_id).to be_nil
186+
end
187+
end
188+
171189
it 'refreshes asynchronously' do
172190
# expiration 6 minutes out, within the async exp time window
173191
allow(credentials).to receive(:expiration).and_return(Time.now + (6*60))

0 commit comments

Comments
 (0)