aws-sdk-core 3.209.1 → 3.228.0

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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +231 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults/default_configuration.rb +1 -2
  5. data/lib/aws-sdk-core/arn.rb +1 -3
  6. data/lib/aws-sdk-core/assume_role_credentials.rb +1 -0
  7. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +1 -0
  8. data/lib/aws-sdk-core/cbor/decoder.rb +0 -2
  9. data/lib/aws-sdk-core/cbor/encoder.rb +2 -2
  10. data/lib/aws-sdk-core/cbor.rb +3 -56
  11. data/lib/aws-sdk-core/client_stubs.rb +29 -55
  12. data/lib/aws-sdk-core/credential_provider.rb +4 -0
  13. data/lib/aws-sdk-core/credential_provider_chain.rb +28 -8
  14. data/lib/aws-sdk-core/credentials.rb +6 -0
  15. data/lib/aws-sdk-core/ecs_credentials.rb +1 -0
  16. data/lib/aws-sdk-core/endpoints/matchers.rb +3 -9
  17. data/lib/aws-sdk-core/endpoints.rb +37 -13
  18. data/lib/aws-sdk-core/error_handler.rb +5 -0
  19. data/lib/aws-sdk-core/errors.rb +2 -2
  20. data/lib/aws-sdk-core/event_emitter.rb +1 -1
  21. data/lib/aws-sdk-core/instance_profile_credentials.rb +147 -157
  22. data/lib/aws-sdk-core/json/error_handler.rb +14 -3
  23. data/lib/aws-sdk-core/json/handler.rb +1 -0
  24. data/lib/aws-sdk-core/log/param_formatter.rb +7 -3
  25. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +332 -170
  26. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +0 -1
  27. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +85 -70
  28. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +40 -32
  29. data/lib/aws-sdk-core/plugins/http_checksum.rb +2 -8
  30. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +44 -25
  31. data/lib/aws-sdk-core/plugins/sign.rb +30 -21
  32. data/lib/aws-sdk-core/plugins/stub_responses.rb +30 -8
  33. data/lib/aws-sdk-core/plugins/user_agent.rb +33 -2
  34. data/lib/aws-sdk-core/process_credentials.rb +1 -1
  35. data/lib/aws-sdk-core/rest/request/headers.rb +3 -3
  36. data/lib/aws-sdk-core/rpc_v2/builder.rb +1 -1
  37. data/lib/aws-sdk-core/{cbor → rpc_v2}/cbor_engine.rb +4 -5
  38. data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +3 -1
  39. data/lib/aws-sdk-core/rpc_v2/error_handler.rb +27 -16
  40. data/lib/aws-sdk-core/rpc_v2/handler.rb +2 -1
  41. data/lib/aws-sdk-core/rpc_v2/parser.rb +9 -1
  42. data/lib/aws-sdk-core/rpc_v2.rb +65 -2
  43. data/lib/aws-sdk-core/shared_config.rb +75 -21
  44. data/lib/aws-sdk-core/shared_credentials.rb +1 -0
  45. data/lib/aws-sdk-core/sso_credentials.rb +2 -0
  46. data/lib/aws-sdk-core/static_token_provider.rb +1 -2
  47. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +12 -11
  48. data/lib/aws-sdk-core/stubbing/protocols/json.rb +11 -10
  49. data/lib/aws-sdk-core/stubbing/protocols/query.rb +7 -6
  50. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +2 -1
  51. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +9 -8
  52. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +6 -5
  53. data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +13 -15
  54. data/lib/aws-sdk-core/stubbing.rb +2 -2
  55. data/lib/aws-sdk-core/token.rb +3 -3
  56. data/lib/aws-sdk-core/token_provider.rb +4 -0
  57. data/lib/aws-sdk-core/token_provider_chain.rb +2 -6
  58. data/lib/aws-sdk-core/util.rb +2 -1
  59. data/lib/aws-sdk-core/xml/error_handler.rb +3 -1
  60. data/lib/aws-sdk-sso/client.rb +71 -39
  61. data/lib/aws-sdk-sso/endpoint_parameters.rb +9 -6
  62. data/lib/aws-sdk-sso/endpoint_provider.rb +14 -18
  63. data/lib/aws-sdk-sso/endpoints.rb +2 -42
  64. data/lib/aws-sdk-sso/plugins/endpoints.rb +1 -14
  65. data/lib/aws-sdk-sso.rb +1 -1
  66. data/lib/aws-sdk-ssooidc/client.rb +108 -59
  67. data/lib/aws-sdk-ssooidc/client_api.rb +6 -0
  68. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +9 -6
  69. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +14 -18
  70. data/lib/aws-sdk-ssooidc/endpoints.rb +2 -42
  71. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +1 -14
  72. data/lib/aws-sdk-ssooidc/types.rb +48 -16
  73. data/lib/aws-sdk-ssooidc.rb +1 -1
  74. data/lib/aws-sdk-sts/client.rb +279 -91
  75. data/lib/aws-sdk-sts/client_api.rb +33 -8
  76. data/lib/aws-sdk-sts/endpoint_parameters.rb +10 -9
  77. data/lib/aws-sdk-sts/endpoint_provider.rb +50 -55
  78. data/lib/aws-sdk-sts/endpoints.rb +2 -94
  79. data/lib/aws-sdk-sts/errors.rb +15 -0
  80. data/lib/aws-sdk-sts/plugins/endpoints.rb +1 -22
  81. data/lib/aws-sdk-sts/presigner.rb +2 -6
  82. data/lib/aws-sdk-sts/types.rb +170 -28
  83. data/lib/aws-sdk-sts.rb +1 -1
  84. data/lib/seahorse/client/async_base.rb +4 -5
  85. data/lib/seahorse/client/base.rb +0 -14
  86. data/lib/seahorse/client/h2/connection.rb +18 -28
  87. data/lib/seahorse/client/http/response.rb +1 -1
  88. data/lib/seahorse/client/net_http/connection_pool.rb +4 -1
  89. data/lib/seahorse/client/networking_error.rb +1 -1
  90. data/lib/seahorse/client/plugins/h2.rb +4 -4
  91. data/lib/seahorse/client/request_context.rb +2 -2
  92. data/lib/seahorse/client/response.rb +2 -0
  93. data/lib/seahorse/util.rb +2 -1
  94. data/sig/aws-sdk-core/async_client_stubs.rbs +21 -0
  95. data/sig/seahorse/client/async_base.rbs +18 -0
  96. metadata +57 -17
@@ -17,61 +17,66 @@ module Aws
17
17
  option(:profile,
18
18
  doc_default: 'default',
19
19
  doc_type: String,
20
- docstring: <<-DOCS)
21
- Used when loading credentials from the shared credentials file
22
- at HOME/.aws/credentials. When not specified, 'default' is used.
20
+ docstring: <<~DOCS)
21
+ Used when loading credentials from the shared credentials file at `HOME/.aws/credentials`.
22
+ When not specified, 'default' is used.
23
23
  DOCS
24
24
 
25
25
  option(:credentials,
26
26
  required: true,
27
27
  doc_type: 'Aws::CredentialProvider',
28
28
  rbs_type: 'untyped',
29
- docstring: <<-DOCS
30
- Your AWS credentials. This can be an instance of any one of the
31
- following classes:
32
-
33
- * `Aws::Credentials` - Used for configuring static, non-refreshing
34
- credentials.
35
-
36
- * `Aws::SharedCredentials` - Used for loading static credentials from a
37
- shared file, such as `~/.aws/config`.
38
-
39
- * `Aws::AssumeRoleCredentials` - Used when you need to assume a role.
40
-
41
- * `Aws::AssumeRoleWebIdentityCredentials` - Used when you need to
42
- assume a role after providing credentials via the web.
43
-
44
- * `Aws::SSOCredentials` - Used for loading credentials from AWS SSO using an
45
- access token generated from `aws login`.
46
-
47
- * `Aws::ProcessCredentials` - Used for loading credentials from a
48
- process that outputs to stdout.
49
-
50
- * `Aws::InstanceProfileCredentials` - Used for loading credentials
51
- from an EC2 IMDS on an EC2 instance.
52
-
53
- * `Aws::ECSCredentials` - Used for loading credentials from
54
- instances running in ECS.
55
-
56
- * `Aws::CognitoIdentityCredentials` - Used for loading credentials
57
- from the Cognito Identity service.
58
-
59
- When `:credentials` are not configured directly, the following
60
- locations will be searched for credentials:
61
-
62
- * `Aws.config[:credentials]`
63
- * The `:access_key_id`, `:secret_access_key`, `:session_token`, and
64
- `:account_id` options.
65
- * ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'],
66
- ENV['AWS_SESSION_TOKEN'], and ENV['AWS_ACCOUNT_ID']
67
- * `~/.aws/credentials`
68
- * `~/.aws/config`
69
- * EC2/ECS IMDS instance profile - When used by default, the timeouts
70
- are very aggressive. Construct and pass an instance of
71
- `Aws::InstanceProfileCredentials` or `Aws::ECSCredentials` to
72
- enable retries and extended timeouts. Instance profile credential
73
- fetching can be disabled by setting ENV['AWS_EC2_METADATA_DISABLED']
74
- to true.
29
+ docstring: <<~DOCS
30
+ Your AWS credentials used for authentication. This can be an instance of any one of the
31
+ following classes:
32
+
33
+ * `Aws::Credentials` - Used for configuring static, non-refreshing
34
+ credentials.
35
+
36
+ * `Aws::SharedCredentials` - Used for loading static credentials from a
37
+ shared file, such as `~/.aws/config`.
38
+
39
+ * `Aws::AssumeRoleCredentials` - Used when you need to assume a role.
40
+
41
+ * `Aws::AssumeRoleWebIdentityCredentials` - Used when you need to
42
+ assume a role after providing credentials via the web.
43
+
44
+ * `Aws::SSOCredentials` - Used for loading credentials from AWS SSO using an
45
+ access token generated from `aws login`.
46
+
47
+ * `Aws::ProcessCredentials` - Used for loading credentials from a
48
+ process that outputs to stdout.
49
+
50
+ * `Aws::InstanceProfileCredentials` - Used for loading credentials
51
+ from an EC2 IMDS on an EC2 instance.
52
+
53
+ * `Aws::ECSCredentials` - Used for loading credentials from
54
+ instances running in ECS.
55
+
56
+ * `Aws::CognitoIdentityCredentials` - Used for loading credentials
57
+ from the Cognito Identity service.
58
+
59
+ When `:credentials` are not configured directly, the following
60
+ locations will be searched for credentials:
61
+
62
+ * `Aws.config[:credentials]`
63
+
64
+ * The `:access_key_id`, `:secret_access_key`, `:session_token`, and
65
+ `:account_id` options.
66
+
67
+ * `ENV['AWS_ACCESS_KEY_ID']`, `ENV['AWS_SECRET_ACCESS_KEY']`,
68
+ `ENV['AWS_SESSION_TOKEN']`, and `ENV['AWS_ACCOUNT_ID']`.
69
+
70
+ * `~/.aws/credentials`
71
+
72
+ * `~/.aws/config`
73
+
74
+ * EC2/ECS IMDS instance profile - When used by default, the timeouts
75
+ are very aggressive. Construct and pass an instance of
76
+ `Aws::InstanceProfileCredentials` or `Aws::ECSCredentials` to
77
+ enable retries and extended timeouts. Instance profile credential
78
+ fetching can be disabled by setting `ENV['AWS_EC2_METADATA_DISABLED']`
79
+ to `true`.
75
80
  DOCS
76
81
  ) do |config|
77
82
  CredentialProviderChain.new(config).resolve
@@ -82,30 +87,40 @@ locations will be searched for credentials:
82
87
  option(:instance_profile_credentials_timeout, 1)
83
88
 
84
89
  option(:token_provider,
85
- required: false,
86
- doc_type: 'Aws::TokenProvider',
87
- rbs_type: 'untyped',
88
- docstring: <<-DOCS
89
- A Bearer Token Provider. This can be an instance of any one of the
90
- following classes:
91
-
92
- * `Aws::StaticTokenProvider` - Used for configuring static, non-refreshing
93
- tokens.
94
-
95
- * `Aws::SSOTokenProvider` - Used for loading tokens from AWS SSO using an
96
- access token generated from `aws login`.
97
-
98
- When `:token_provider` is not configured directly, the `Aws::TokenProviderChain`
99
- will be used to search for tokens configured for your profile in shared configuration files.
100
- DOCS
90
+ doc_type: 'Aws::TokenProvider',
91
+ rbs_type: 'untyped',
92
+ docstring: <<~DOCS
93
+ Your Bearer token used for authentication. This can be an instance of any one of the
94
+ following classes:
95
+
96
+ * `Aws::StaticTokenProvider` - Used for configuring static, non-refreshing
97
+ tokens.
98
+
99
+ * `Aws::SSOTokenProvider` - Used for loading tokens from AWS SSO using an
100
+ access token generated from `aws login`.
101
+
102
+ When `:token_provider` is not configured directly, the `Aws::TokenProviderChain`
103
+ will be used to search for tokens configured for your profile in shared configuration files.
104
+ DOCS
101
105
  ) do |config|
102
- if config.stub_responses
103
- StaticTokenProvider.new('token')
104
- else
105
- TokenProviderChain.new(config).resolve
106
- end
106
+ TokenProviderChain.new(config).resolve
107
107
  end
108
108
 
109
+ option(:auth_scheme_preference,
110
+ doc_type: 'Array<String>',
111
+ rbs_type: 'Array[String]',
112
+ docstring: <<~DOCS
113
+ A list of preferred authentication schemes to use when making a request. Supported values are:
114
+ `sigv4`, `sigv4a`, `httpBearerAuth`, and `noAuth`. When set using `ENV['AWS_AUTH_SCHEME_PREFERENCE']` or in
115
+ shared config as `auth_scheme_preference`, the value should be a comma-separated list.
116
+ DOCS
117
+ ) do |config|
118
+ value =
119
+ ENV['AWS_AUTH_SCHEME_PREFERENCE'] ||
120
+ Aws.shared_config.auth_scheme_preference(profile: config.profile) ||
121
+ ''
122
+ value.gsub(' ', '').gsub("\t", '').split(',')
123
+ end
109
124
  end
110
125
  end
111
126
  end
@@ -4,62 +4,70 @@ module Aws
4
4
  module Plugins
5
5
  # @api private
6
6
  class EndpointPattern < Seahorse::Client::Plugin
7
-
8
- option(:disable_host_prefix_injection,
7
+ option(
8
+ :disable_host_prefix_injection,
9
9
  default: false,
10
10
  doc_type: 'Boolean',
11
- docstring: <<-DOCS
12
- Set to true to disable SDK automatically adding host prefix
13
- to default service endpoint when available.
14
- DOCS
15
- )
11
+ docstring: 'When `true`, the SDK will not prepend the modeled host prefix to the endpoint.'
12
+ ) do |cfg|
13
+ resolve_disable_host_prefix_injection(cfg)
14
+ end
16
15
 
17
- def add_handlers(handlers, config)
16
+ def add_handlers(handlers, _config)
18
17
  handlers.add(Handler, priority: 10)
19
18
  end
20
19
 
21
- class Handler < Seahorse::Client::Handler
20
+ class << self
21
+ private
22
+
23
+ def resolve_disable_host_prefix_injection(cfg)
24
+ value = ENV['AWS_DISABLE_HOST_PREFIX_INJECTION'] ||
25
+ Aws.shared_config.disable_host_prefix_injection(profile: cfg.profile) ||
26
+ 'false'
27
+ value = Aws::Util.str_2_bool(value)
28
+ unless [true, false].include?(value)
29
+ raise ArgumentError,
30
+ 'Must provide either `true` or `false` for '\
31
+ 'disable_host_prefix_injection profile option or for '\
32
+ 'ENV[\'AWS_DISABLE_HOST_PREFIX_INJECTION\']'
33
+ end
34
+ value
35
+ end
36
+ end
22
37
 
38
+ # @api private
39
+ class Handler < Seahorse::Client::Handler
23
40
  def call(context)
24
- if !context.config.disable_host_prefix_injection
41
+ unless context.config.disable_host_prefix_injection
25
42
  endpoint_trait = context.operation.endpoint_pattern
26
- if endpoint_trait && !endpoint_trait.empty?
27
- _apply_endpoint_trait(context, endpoint_trait)
28
- end
43
+ apply_endpoint_trait(context, endpoint_trait) if endpoint_trait && !endpoint_trait.empty?
29
44
  end
30
45
  @handler.call(context)
31
46
  end
32
47
 
33
48
  private
34
49
 
35
- def _apply_endpoint_trait(context, trait)
36
- # currently only support host pattern
37
- ori_host = context.http_request.endpoint.host
38
- if pattern = trait['hostPrefix']
39
- host_prefix = pattern.gsub(/\{.+?\}/) do |label|
40
- label = label.delete("{}")
41
- _replace_label_value(
42
- ori_host, label, context.operation.input, context.params)
43
- end
44
- context.http_request.endpoint.host = host_prefix + context.http_request.endpoint.host
50
+ def apply_endpoint_trait(context, trait)
51
+ pattern = trait['hostPrefix']
52
+ return unless pattern
53
+
54
+ host_prefix = pattern.gsub(/\{.+?}/) do |label|
55
+ label = label.delete('{}')
56
+ replace_label_value(label, context.operation.input, context.params)
45
57
  end
58
+ context.http_request.endpoint.host = host_prefix + context.http_request.endpoint.host
46
59
  end
47
60
 
48
- def _replace_label_value(ori, label, input_ref, params)
61
+ def replace_label_value(label, input_ref, params)
49
62
  name = nil
50
63
  input_ref.shape.members.each do |m_name, ref|
51
- if ref['hostLabel'] && ref['hostLabelName'] == label
52
- name = m_name
53
- end
54
- end
55
- if name.nil? || params[name].nil?
56
- raise Errors::MissingEndpointHostLabelValue.new(name)
64
+ name = m_name if ref['hostLabel'] && ref['hostLabelName'] == label
57
65
  end
66
+ raise Errors::MissingEndpointHostLabelValue, name if name.nil? || params[name].nil?
67
+
58
68
  params[name]
59
69
  end
60
-
61
70
  end
62
-
63
71
  end
64
72
  end
65
73
  end
@@ -11,8 +11,8 @@ module Aws
11
11
  CHUNK_SIZE = 1 * 1024 * 1024 # one MB
12
12
 
13
13
  def call(context)
14
- if checksum_required?(context) &&
15
- !context[:checksum_algorithms] && # skip in favor of flexible checksum
14
+ if context.operation.http_checksum_required &&
15
+ !context[:http_checksum][:request_algorithm] && # skip in favor of flexible checksum
16
16
  !context[:s3_express_endpoint] # s3 express endpoints do not support md5
17
17
  body = context.http_request.body
18
18
  context.http_request.headers['Content-Md5'] ||= md5(body)
@@ -22,12 +22,6 @@ module Aws
22
22
 
23
23
  private
24
24
 
25
- def checksum_required?(context)
26
- context.operation.http_checksum_required ||
27
- (context.operation.http_checksum &&
28
- context.operation.http_checksum['requestChecksumRequired'])
29
- end
30
-
31
25
  # @param [File, Tempfile, IO#read, String] value
32
26
  # @return [String<MD5>]
33
27
  def md5(value)
@@ -20,7 +20,7 @@ a default `:region` is searched for in the following locations:
20
20
  * `ENV['AWS_DEFAULT_REGION']`
21
21
  * `~/.aws/credentials`
22
22
  * `~/.aws/config`
23
- DOCS
23
+ DOCS
24
24
  resolve_region(cfg)
25
25
  end
26
26
 
@@ -35,7 +35,7 @@ in the following locations:
35
35
  * `Aws.config[:sigv4a_signing_region_set]`
36
36
  * `ENV['AWS_SIGV4A_SIGNING_REGION_SET']`
37
37
  * `~/.aws/config`
38
- DOCS
38
+ DOCS
39
39
  resolve_sigv4a_signing_region_set(cfg)
40
40
  end
41
41
 
@@ -44,7 +44,7 @@ in the following locations:
44
44
  docstring: <<-DOCS) do |cfg|
45
45
  When set to `true`, dualstack enabled endpoints (with `.aws` TLD)
46
46
  will be used if available.
47
- DOCS
47
+ DOCS
48
48
  resolve_use_dualstack_endpoint(cfg)
49
49
  end
50
50
 
@@ -54,7 +54,7 @@ will be used if available.
54
54
  When set to `true`, fips compatible endpoints will be used if available.
55
55
  When a `fips` region is used, the region is normalized and this config
56
56
  is set to `true`.
57
- DOCS
57
+ DOCS
58
58
  resolve_use_fips_endpoint(cfg)
59
59
  end
60
60
 
@@ -67,7 +67,7 @@ is set to `true`.
67
67
  docstring: <<-DOCS) do |cfg|
68
68
  Setting to true disables use of endpoint URLs provided via environment
69
69
  variables and the shared configuration file.
70
- DOCS
70
+ DOCS
71
71
  resolve_ignore_configured_endpoint_urls(cfg)
72
72
  end
73
73
 
@@ -75,7 +75,7 @@ variables and the shared configuration file.
75
75
  The client endpoint is normally constructed from the `:region`
76
76
  option. You should only configure an `:endpoint` when connecting
77
77
  to test or custom endpoints. This should be a valid HTTP(S) URI.
78
- DOCS
78
+ DOCS
79
79
  resolve_endpoint(cfg)
80
80
  end
81
81
 
@@ -83,6 +83,9 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
83
83
  region = client.config.region
84
84
  raise Errors::MissingRegionError if region.nil? || region == ''
85
85
 
86
+ # resolve a default endpoint to preserve legacy behavior
87
+ initialize_default_endpoint(client) if client.config.endpoint.nil?
88
+
86
89
  region_set = client.config.sigv4a_signing_region_set
87
90
  return if region_set.nil?
88
91
  raise Errors::InvalidRegionSetError unless region_set.is_a?(Array)
@@ -93,6 +96,39 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
93
96
  client.config.sigv4a_signing_region_set = region_set
94
97
  end
95
98
 
99
+ private
100
+
101
+ def initialize_default_endpoint(client)
102
+ client_module = Object.const_get(client.class.name.rpartition('::').first)
103
+ param_class = client_module.const_get(:EndpointParameters)
104
+ endpoint_provider = client.config.endpoint_provider
105
+ params = param_class.create(client.config)
106
+ endpoint = endpoint_provider.resolve_endpoint(params)
107
+ client.config.endpoint = endpoint.url
108
+ rescue ArgumentError, NameError
109
+ # fallback to legacy
110
+ client.config.endpoint = resolve_legacy_endpoint(client.config)
111
+ end
112
+
113
+ # set a default endpoint in config using legacy (endpoints.json) resolver
114
+ def resolve_legacy_endpoint(cfg)
115
+ endpoint_prefix = cfg.api.metadata['endpointPrefix']
116
+ if cfg.respond_to?(:sts_regional_endpoints)
117
+ sts_regional = cfg.sts_regional_endpoints
118
+ end
119
+
120
+ endpoint = Aws::Partitions::EndpointProvider.resolve(
121
+ cfg.region,
122
+ endpoint_prefix,
123
+ sts_regional,
124
+ {
125
+ dualstack: cfg.use_dualstack_endpoint,
126
+ fips: cfg.use_fips_endpoint
127
+ }
128
+ )
129
+ URI(endpoint)
130
+ end
131
+
96
132
  class << self
97
133
  private
98
134
 
@@ -150,7 +186,8 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
150
186
  # that a custom endpoint has NOT been configured by the user
151
187
  cfg.override_config(:regional_endpoint, true)
152
188
 
153
- resolve_legacy_endpoint(cfg)
189
+ # a default endpoint is resolved in after_initialize
190
+ nil
154
191
  end
155
192
 
156
193
  # get a custom configured endpoint from ENV or configuration
@@ -205,24 +242,6 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
205
242
  cfg.override_config(:region, new_region)
206
243
  end
207
244
  end
208
-
209
- # set a default endpoint in config using legacy (endpoints.json) resolver
210
- def resolve_legacy_endpoint(cfg)
211
- endpoint_prefix = cfg.api.metadata['endpointPrefix']
212
- if cfg.respond_to?(:sts_regional_endpoints)
213
- sts_regional = cfg.sts_regional_endpoints
214
- end
215
-
216
- Aws::Partitions::EndpointProvider.resolve(
217
- cfg.region,
218
- endpoint_prefix,
219
- sts_regional,
220
- {
221
- dualstack: cfg.use_dualstack_endpoint,
222
- fips: cfg.use_fips_endpoint
223
- }
224
- )
225
- end
226
245
  end
227
246
  end
228
247
  end
@@ -13,9 +13,6 @@ module Aws
13
13
  option(:sigv4_region)
14
14
  option(:unsigned_operations, default: [])
15
15
 
16
- supported_auth_types = %w[sigv4 bearer sigv4-s3express sigv4a none]
17
- SUPPORTED_AUTH_TYPES = supported_auth_types.freeze
18
-
19
16
  def add_handlers(handlers, cfg)
20
17
  operations = cfg.api.operation_names - cfg.unsigned_operations
21
18
  handlers.add(Handler, step: :sign, operations: operations)
@@ -32,7 +29,7 @@ module Aws
32
29
  }
33
30
  SignatureV4.new(auth_scheme, config, sigv4_overrides)
34
31
  when 'bearer'
35
- Bearer.new
32
+ Bearer.new(config)
36
33
  else
37
34
  NullSigner.new
38
35
  end
@@ -50,11 +47,22 @@ module Aws
50
47
  )
51
48
  signer.sign(context)
52
49
  end
53
- @handler.call(context)
50
+ with_metrics(signer) { @handler.call(context) }
54
51
  end
55
52
 
56
53
  private
57
54
 
55
+ def with_metrics(signer, &block)
56
+ case signer
57
+ when SignatureV4
58
+ Aws::Plugins::UserAgent.metric(*signer.credentials.metrics, &block)
59
+ when Bearer
60
+ Aws::Plugins::UserAgent.metric(*signer.token_provider.metrics, &block)
61
+ else
62
+ block.call
63
+ end
64
+ end
65
+
58
66
  def v2_signing?(config)
59
67
  # 's3' is legacy signing, 'v4' is default
60
68
  config.respond_to?(:signature_version) &&
@@ -64,21 +72,19 @@ module Aws
64
72
 
65
73
  # @api private
66
74
  class Bearer
67
- def initialize
75
+ def initialize(config)
76
+ @token_provider = config.token_provider
68
77
  end
69
78
 
79
+ attr_reader :token_provider
80
+
70
81
  def sign(context)
71
82
  if context.http_request.endpoint.scheme != 'https'
72
- raise ArgumentError,
73
- 'Unable to use bearer authorization on non https endpoint.'
83
+ raise ArgumentError, 'Unable to use bearer authorization on non https endpoint.'
74
84
  end
85
+ raise Errors::MissingBearerTokenError unless @token_provider && @token_provider.set?
75
86
 
76
- token_provider = context.config.token_provider
77
-
78
- raise Errors::MissingBearerTokenError unless token_provider&.set?
79
-
80
- context.http_request.headers['Authorization'] =
81
- "Bearer #{token_provider.token.token}"
87
+ context.http_request.headers['Authorization'] = "Bearer #{@token_provider.token.token}"
82
88
  end
83
89
 
84
90
  def presign_url(*args)
@@ -94,12 +100,9 @@ module Aws
94
100
  class SignatureV4
95
101
  def initialize(auth_scheme, config, sigv4_overrides = {})
96
102
  scheme_name = auth_scheme['name']
97
-
98
103
  unless %w[sigv4 sigv4a sigv4-s3express].include?(scheme_name)
99
- raise ArgumentError,
100
- "Expected sigv4, sigv4a, or sigv4-s3express auth scheme, got #{scheme_name}"
104
+ raise ArgumentError, "Expected sigv4, sigv4a, or sigv4-s3express auth scheme, got #{scheme_name}"
101
105
  end
102
-
103
106
  region = if scheme_name == 'sigv4a'
104
107
  auth_scheme['signingRegionSet'].join(',')
105
108
  else
@@ -111,15 +114,17 @@ module Aws
111
114
  region: sigv4_overrides[:region] || config.sigv4_region || region,
112
115
  credentials_provider: sigv4_overrides[:credentials] || config.credentials,
113
116
  signing_algorithm: scheme_name.to_sym,
114
- uri_escape_path: !!!auth_scheme['disableDoubleEncoding'],
115
- normalize_path: !!!auth_scheme['disableNormalizePath'],
116
- unsigned_headers: %w[content-length user-agent x-amzn-trace-id]
117
+ uri_escape_path: !auth_scheme['disableDoubleEncoding'],
118
+ normalize_path: !auth_scheme['disableNormalizePath'],
119
+ unsigned_headers: %w[content-length user-agent x-amzn-trace-id expect transfer-encoding connection]
117
120
  )
118
121
  rescue Aws::Sigv4::Errors::MissingCredentialsError
119
122
  raise Aws::Errors::MissingCredentialsError
120
123
  end
121
124
  end
122
125
 
126
+ attr_reader :signer
127
+
123
128
  def sign(context)
124
129
  req = context.http_request
125
130
 
@@ -155,6 +160,10 @@ module Aws
155
160
  @signer.sign_event(*args)
156
161
  end
157
162
 
163
+ def credentials
164
+ @signer.credentials_provider
165
+ end
166
+
158
167
  private
159
168
 
160
169
  def apply_authtype(context, req)
@@ -29,8 +29,22 @@ requests are made, and retries are disabled.
29
29
  end
30
30
  end
31
31
 
32
+ option(:token_provider) do |config|
33
+ if config.stub_responses
34
+ StaticTokenProvider.new('stubbed-token')
35
+ end
36
+ end
37
+
38
+ option(:stubs) { {} }
39
+ option(:stubs_mutex) { Mutex.new }
40
+ option(:api_requests) { [] }
41
+ option(:api_requests_mutex) { Mutex.new }
42
+
32
43
  def add_handlers(handlers, config)
33
- handlers.add(Handler, step: :send) if config.stub_responses
44
+ return unless config.stub_responses
45
+
46
+ handlers.add(ApiRequestsHandler)
47
+ handlers.add(StubbingHandler, step: :send)
34
48
  end
35
49
 
36
50
  def after_initialize(client)
@@ -46,8 +60,20 @@ requests are made, and retries are disabled.
46
60
  end
47
61
  end
48
62
 
49
- class Handler < Seahorse::Client::Handler
63
+ class ApiRequestsHandler < Seahorse::Client::Handler
64
+ def call(context)
65
+ context.config.api_requests_mutex.synchronize do
66
+ context.config.api_requests << {
67
+ operation_name: context.operation_name,
68
+ params: context.params,
69
+ context: context
70
+ }
71
+ end
72
+ @handler.call(context)
73
+ end
74
+ end
50
75
 
76
+ class StubbingHandler < Seahorse::Client::Handler
51
77
  def call(context)
52
78
  span_wrapper(context) do
53
79
  stub_responses(context)
@@ -57,14 +83,10 @@ requests are made, and retries are disabled.
57
83
  private
58
84
 
59
85
  def stub_responses(context)
60
- stub = context.client.next_stub(context)
61
86
  resp = Seahorse::Client::Response.new(context: context)
62
87
  async_mode = context.client.is_a? Seahorse::Client::AsyncBase
63
- if Hash === stub && stub[:mutex]
64
- stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) }
65
- else
66
- apply_stub(stub, resp, async_mode)
67
- end
88
+ stub = context.client.next_stub(context)
89
+ stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) }
68
90
 
69
91
  if async_mode
70
92
  Seahorse::Client::AsyncResponse.new(
@@ -25,7 +25,37 @@ module Aws
25
25
  "ACCOUNT_ID_MODE_DISABLED": "Q",
26
26
  "ACCOUNT_ID_MODE_REQUIRED": "R",
27
27
  "SIGV4A_SIGNING": "S",
28
- "RESOLVED_ACCOUNT_ID": "T"
28
+ "RESOLVED_ACCOUNT_ID": "T",
29
+ "FLEXIBLE_CHECKSUMS_REQ_CRC32" : "U",
30
+ "FLEXIBLE_CHECKSUMS_REQ_CRC32C" : "V",
31
+ "FLEXIBLE_CHECKSUMS_REQ_CRC64" : "W",
32
+ "FLEXIBLE_CHECKSUMS_REQ_SHA1" : "X",
33
+ "FLEXIBLE_CHECKSUMS_REQ_SHA256" : "Y",
34
+ "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED" : "Z",
35
+ "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED" : "a",
36
+ "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED" : "b",
37
+ "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED" : "c",
38
+ "DDB_MAPPER": "d",
39
+ "CREDENTIALS_CODE" : "e",
40
+ "CREDENTIALS_ENV_VARS" : "g",
41
+ "CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN" : "h",
42
+ "CREDENTIALS_STS_ASSUME_ROLE" : "i",
43
+ "CREDENTIALS_STS_ASSUME_ROLE_WEB_ID" : "k",
44
+ "CREDENTIALS_PROFILE" : "n",
45
+ "CREDENTIALS_PROFILE_SOURCE_PROFILE" : "o",
46
+ "CREDENTIALS_PROFILE_NAMED_PROVIDER" : "p",
47
+ "CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN" : "q",
48
+ "CREDENTIALS_PROFILE_SSO" : "r",
49
+ "CREDENTIALS_SSO" : "s",
50
+ "CREDENTIALS_PROFILE_SSO_LEGACY" : "t",
51
+ "CREDENTIALS_SSO_LEGACY" : "u",
52
+ "CREDENTIALS_PROFILE_PROCESS" : "v",
53
+ "CREDENTIALS_PROCESS" : "w",
54
+ "CREDENTIALS_HTTP" : "z",
55
+ "CREDENTIALS_IMDS" : "0",
56
+ "SSO_LOGIN_DEVICE" : "1",
57
+ "SSO_LOGIN_AUTH" : "2",
58
+ "BEARER_SERVICE_ENV_VARS": "3"
29
59
  }
30
60
  METRICS
31
61
 
@@ -187,7 +217,8 @@ variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
187
217
  end
188
218
  end
189
219
 
190
- handler(Handler, step: :sign, priority: 97)
220
+ # Priority set to 5 in order to add user agent as late as possible after signing
221
+ handler(Handler, step: :sign, priority: 5)
191
222
  end
192
223
  end
193
224
  end