| 1 |
<?php |
| 2 |
namespace Aws; |
| 3 |
|
| 4 |
use Aws\Api\ApiProvider; |
| 5 |
use Aws\Api\Service; |
| 6 |
use Aws\Api\Validator; |
| 7 |
use Aws\Auth\AuthResolver; |
| 8 |
use Aws\Auth\AuthSchemeResolver; |
| 9 |
use Aws\Auth\AuthSchemeResolverInterface; |
| 10 |
use Aws\ClientSideMonitoring\ApiCallAttemptMonitoringMiddleware; |
| 11 |
use Aws\ClientSideMonitoring\ApiCallMonitoringMiddleware; |
| 12 |
use Aws\ClientSideMonitoring\Configuration; |
| 13 |
use Aws\Configuration\ConfigurationResolver; |
| 14 |
use Aws\Credentials\CredentialProvider; |
| 15 |
use Aws\Credentials\Credentials; |
| 16 |
use Aws\Credentials\CredentialsInterface; |
| 17 |
use Aws\DefaultsMode\ConfigurationInterface as ConfigModeInterface; |
| 18 |
use Aws\DefaultsMode\ConfigurationProvider as ConfigModeProvider; |
| 19 |
use Aws\Endpoint\EndpointProvider; |
| 20 |
use Aws\Endpoint\PartitionEndpointProvider; |
| 21 |
use Aws\Endpoint\UseDualstackEndpoint\Configuration as UseDualStackEndpointConfiguration; |
| 22 |
use Aws\Endpoint\UseDualstackEndpoint\ConfigurationInterface as UseDualStackEndpointConfigurationInterface; |
| 23 |
use Aws\Endpoint\UseDualstackEndpoint\ConfigurationProvider as UseDualStackConfigProvider; |
| 24 |
use Aws\Endpoint\UseFipsEndpoint\Configuration as UseFipsEndpointConfiguration; |
| 25 |
use Aws\Endpoint\UseFipsEndpoint\ConfigurationInterface as UseFipsEndpointConfigurationInterface; |
| 26 |
use Aws\Endpoint\UseFipsEndpoint\ConfigurationProvider as UseFipsConfigProvider; |
| 27 |
use Aws\EndpointDiscovery\ConfigurationInterface; |
| 28 |
use Aws\EndpointDiscovery\ConfigurationProvider; |
| 29 |
use Aws\EndpointV2\EndpointDefinitionProvider; |
| 30 |
use Aws\EndpointV2\EndpointProviderV2; |
| 31 |
use Aws\Exception\AwsException; |
| 32 |
use Aws\Exception\InvalidRegionException; |
| 33 |
use Aws\Retry\ConfigurationInterface as RetryConfigInterface; |
| 34 |
use Aws\Retry\ConfigurationProvider as RetryConfigProvider; |
| 35 |
use Aws\Retry\V3\OptIn as NewRetriesOptIn; |
| 36 |
use Aws\Retry\V3\RetryMiddleware as RetryV3Middleware; |
| 37 |
use Aws\Signature\SignatureProvider; |
| 38 |
use Aws\Token\Token; |
| 39 |
use Aws\Token\TokenInterface; |
| 40 |
use Aws\Token\BedrockTokenProvider; |
| 41 |
use Aws\Token\TokenProvider; |
| 42 |
use GuzzleHttp\Promise\PromiseInterface; |
| 43 |
use InvalidArgumentException as IAE; |
| 44 |
use Psr\Http\Message\RequestInterface; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
class ClientResolver |
| 50 |
{ |
| 51 |
|
| 52 |
private $argDefinitions; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
const DEFAULT_FROM_ENV_INI = [ |
| 64 |
__CLASS__, |
| 65 |
'_resolve_from_env_ini' |
| 66 |
]; |
| 67 |
private const ANONYMOUS_SIGNATURE = 'anonymous'; |
| 68 |
private const DPOP_SIGNATURE = 'dpop'; |
| 69 |
|
| 70 |
|
| 71 |
private static $typeMap = [ |
| 72 |
'resource' => 'is_resource', |
| 73 |
'callable' => 'is_callable', |
| 74 |
'int' => 'is_int', |
| 75 |
'bool' => 'is_bool', |
| 76 |
'boolean' => 'is_bool', |
| 77 |
'string' => 'is_string', |
| 78 |
'object' => 'is_object', |
| 79 |
'array' => 'is_array', |
| 80 |
]; |
| 81 |
|
| 82 |
private static $defaultArgs = [ |
| 83 |
'service' => [ |
| 84 |
'type' => 'value', |
| 85 |
'valid' => ['string'], |
| 86 |
'doc' => 'Name of the service to utilize. This value will be supplied by default when using one of the SDK clients (e.g., Aws\\S3\\S3Client).', |
| 87 |
'required' => true, |
| 88 |
'internal' => true |
| 89 |
], |
| 90 |
'exception_class' => [ |
| 91 |
'type' => 'value', |
| 92 |
'valid' => ['string'], |
| 93 |
'doc' => 'Exception class to create when an error occurs.', |
| 94 |
'default' => AwsException::class, |
| 95 |
'internal' => true |
| 96 |
], |
| 97 |
'scheme' => [ |
| 98 |
'type' => 'value', |
| 99 |
'valid' => ['string'], |
| 100 |
'default' => 'https', |
| 101 |
'doc' => 'URI scheme to use when connecting connect. The SDK will utilize "https" endpoints (i.e., utilize SSL/TLS connections) by default. You can attempt to connect to a service over an unencrypted "http" endpoint by setting ``scheme`` to "http".', |
| 102 |
], |
| 103 |
'disable_host_prefix_injection' => [ |
| 104 |
'type' => 'value', |
| 105 |
'valid' => ['bool'], |
| 106 |
'doc' => 'Set to true to disable host prefix injection logic for services that use it. This disables the entire prefix injection, including the portions supplied by user-defined parameters. Setting this flag will have no effect on services that do not use host prefix injection.', |
| 107 |
'default' => false, |
| 108 |
], |
| 109 |
'ignore_configured_endpoint_urls' => [ |
| 110 |
'type' => 'value', |
| 111 |
'valid' => ['bool'], |
| 112 |
'doc' => 'Set to true to disable endpoint urls configured using `AWS_ENDPOINT_URL` and `endpoint_url` shared config option.', |
| 113 |
'fn' => [__CLASS__, '_apply_ignore_configured_endpoint_urls'], |
| 114 |
'default' => self::DEFAULT_FROM_ENV_INI, |
| 115 |
], |
| 116 |
'endpoint' => [ |
| 117 |
'type' => 'value', |
| 118 |
'valid' => ['string'], |
| 119 |
'doc' => 'The full URI of the webservice. This is only required when connecting to a custom endpoint (e.g., a local version of S3).', |
| 120 |
'fn' => [__CLASS__, '_apply_endpoint'], |
| 121 |
'default' => [__CLASS__, '_default_endpoint'] |
| 122 |
], |
| 123 |
'region' => [ |
| 124 |
'type' => 'value', |
| 125 |
'valid' => ['string'], |
| 126 |
'doc' => 'Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions.', |
| 127 |
'fn' => [__CLASS__, '_apply_region'], |
| 128 |
'default' => self::DEFAULT_FROM_ENV_INI |
| 129 |
], |
| 130 |
'version' => [ |
| 131 |
'type' => 'value', |
| 132 |
'valid' => ['string'], |
| 133 |
'doc' => 'The version of the webservice to utilize (e.g., 2006-03-01).', |
| 134 |
'default' => 'latest', |
| 135 |
], |
| 136 |
'signature_provider' => [ |
| 137 |
'type' => 'value', |
| 138 |
'valid' => ['callable'], |
| 139 |
'doc' => 'A callable that accepts a signature version name (e.g., "v4"), a service name, and region, and returns a SignatureInterface object or null. This provider is used to create signers utilized by the client. See Aws\\Signature\\SignatureProvider for a list of built-in providers', |
| 140 |
'default' => [__CLASS__, '_default_signature_provider'], |
| 141 |
], |
| 142 |
'api_provider' => [ |
| 143 |
'type' => 'value', |
| 144 |
'valid' => ['callable'], |
| 145 |
'doc' => 'An optional PHP callable that accepts a type, service, and version argument, and returns an array of corresponding configuration data. The type value can be one of api, waiter, or paginator.', |
| 146 |
'fn' => [__CLASS__, '_apply_api_provider'], |
| 147 |
'default' => [ApiProvider::class, 'defaultProvider'], |
| 148 |
], |
| 149 |
'configuration_mode' => [ |
| 150 |
'type' => 'value', |
| 151 |
'valid' => [ConfigModeInterface::class, CacheInterface::class, 'string', 'closure'], |
| 152 |
'doc' => "Sets the default configuration mode. Otherwise provide an instance of Aws\DefaultsMode\ConfigurationInterface, an instance of Aws\CacheInterface, or a string containing a valid mode", |
| 153 |
'fn' => [__CLASS__, '_apply_defaults'], |
| 154 |
'default' => [ConfigModeProvider::class, 'defaultProvider'] |
| 155 |
], |
| 156 |
'use_fips_endpoint' => [ |
| 157 |
'type' => 'value', |
| 158 |
'valid' => ['bool', UseFipsEndpointConfiguration::class, CacheInterface::class, 'callable'], |
| 159 |
'doc' => 'Set to true to enable the use of FIPS pseudo regions', |
| 160 |
'fn' => [__CLASS__, '_apply_use_fips_endpoint'], |
| 161 |
'default' => [__CLASS__, '_default_use_fips_endpoint'], |
| 162 |
], |
| 163 |
'use_dual_stack_endpoint' => [ |
| 164 |
'type' => 'value', |
| 165 |
'valid' => ['bool', UseDualStackEndpointConfiguration::class, CacheInterface::class, 'callable'], |
| 166 |
'doc' => 'Set to true to enable the use of dual-stack endpoints', |
| 167 |
'fn' => [__CLASS__, '_apply_use_dual_stack_endpoint'], |
| 168 |
'default' => [__CLASS__, '_default_use_dual_stack_endpoint'], |
| 169 |
], |
| 170 |
'endpoint_provider' => [ |
| 171 |
'type' => 'value', |
| 172 |
'valid' => ['callable', EndpointV2\EndpointProviderV2::class], |
| 173 |
'fn' => [__CLASS__, '_apply_endpoint_provider'], |
| 174 |
'doc' => 'An optional PHP callable that accepts a hash of options including a "service" and "region" key and returns NULL or a hash of endpoint data, of which the "endpoint" key is required. See Aws\\Endpoint\\EndpointProvider for a list of built-in providers.', |
| 175 |
'default' => [__CLASS__, '_default_endpoint_provider'], |
| 176 |
], |
| 177 |
'serializer' => [ |
| 178 |
'default' => [__CLASS__, '_default_serializer'], |
| 179 |
'fn' => [__CLASS__, '_apply_serializer'], |
| 180 |
'internal' => true, |
| 181 |
'type' => 'value', |
| 182 |
'valid' => ['callable'], |
| 183 |
], |
| 184 |
'signature_version' => [ |
| 185 |
'type' => 'config', |
| 186 |
'valid' => ['string'], |
| 187 |
'doc' => 'A string representing a custom signature version to use with a service (e.g., v4). Note that per/operation signature version MAY override this requested signature version.', |
| 188 |
'default' => [__CLASS__, '_default_signature_version'], |
| 189 |
], |
| 190 |
'signing_name' => [ |
| 191 |
'type' => 'config', |
| 192 |
'valid' => ['string'], |
| 193 |
'doc' => 'A string representing a custom service name to be used when calculating a request signature.', |
| 194 |
'default' => [__CLASS__, '_default_signing_name'], |
| 195 |
], |
| 196 |
'signing_region' => [ |
| 197 |
'type' => 'config', |
| 198 |
'valid' => ['string'], |
| 199 |
'doc' => 'A string representing a custom region name to be used when calculating a request signature.', |
| 200 |
'default' => [__CLASS__, '_default_signing_region'], |
| 201 |
], |
| 202 |
'profile' => [ |
| 203 |
'type' => 'config', |
| 204 |
'valid' => ['string'], |
| 205 |
'doc' => 'Allows you to specify which profile to use when credentials are created from the AWS credentials file in your HOME directory. This setting overrides the AWS_PROFILE environment variable. Note: Specifying "profile" will cause the "credentials" and "use_aws_shared_config_files" keys to be ignored.', |
| 206 |
'fn' => [__CLASS__, '_apply_profile'], |
| 207 |
], |
| 208 |
'credentials' => [ |
| 209 |
'type' => 'value', |
| 210 |
'valid' => [CredentialsInterface::class, CacheInterface::class, 'array', 'bool', 'callable'], |
| 211 |
'doc' => 'Specifies the credentials used to sign requests. Provide an Aws\Credentials\CredentialsInterface object, an associative array of "key", "secret", and an optional "token" key, `false` to use null credentials, or a callable credentials provider used to create credentials or return null. See Aws\\Credentials\\CredentialProvider for a list of built-in credentials providers. If no credentials are provided, the SDK will attempt to load them from the environment.', |
| 212 |
'fn' => [__CLASS__, '_apply_credentials'], |
| 213 |
'default' => [__CLASS__, '_default_credential_provider'], |
| 214 |
], |
| 215 |
'auth_scheme_preference' => [ |
| 216 |
'type' => 'value', |
| 217 |
'valid' => ['string', 'array'], |
| 218 |
'doc' => 'Comma-separated list of authentication scheme preferences in priority order. Configure via environment variable `AWS_AUTH_SCHEME_PREFERENCE`, INI config file `auth_scheme_preference`, or client constructor parameter `auth_scheme_preference` (string or array).\nExample: `AWS_AUTH_SCHEME_PREFERENCE=aws.auth#sigv4a,aws.auth#sigv4,smithy.api#httpBearerAuth`', |
| 219 |
'default' => self::DEFAULT_FROM_ENV_INI, |
| 220 |
'fn' => [__CLASS__, '_apply_auth_scheme_preference'], |
| 221 |
], |
| 222 |
'token' => [ |
| 223 |
'type' => 'value', |
| 224 |
'valid' => [TokenInterface::class, CacheInterface::class, 'array', 'bool', 'callable'], |
| 225 |
'doc' => 'Specifies the token used to authorize requests. Provide an Aws\Token\TokenInterface object, an associative array of "token", and an optional "expiration" key, `false` to use a null token, or a callable token provider used to fetch a token or return null. See Aws\\Token\\TokenProvider for a list of built-in credentials providers. If no token is provided, the SDK will attempt to load one from the environment.', |
| 226 |
'fn' => [__CLASS__, '_apply_token'], |
| 227 |
'default' => [__CLASS__, '_default_token_provider'], |
| 228 |
], |
| 229 |
'auth_scheme_resolver' => [ |
| 230 |
'type' => 'value', |
| 231 |
'valid' => [AuthSchemeResolverInterface::class], |
| 232 |
'doc' => 'An instance of Aws\Auth\AuthSchemeResolverInterface which selects a modeled auth scheme and returns a signature version', |
| 233 |
'default' => [__CLASS__, '_default_auth_scheme_resolver'], |
| 234 |
], |
| 235 |
'endpoint_discovery' => [ |
| 236 |
'type' => 'value', |
| 237 |
'valid' => [ConfigurationInterface::class, CacheInterface::class, 'array', 'callable'], |
| 238 |
'doc' => 'Specifies settings for endpoint discovery. Provide an instance of Aws\EndpointDiscovery\ConfigurationInterface, an instance Aws\CacheInterface, a callable that provides a promise for a Configuration object, or an associative array with the following keys: enabled: (bool) Set to true to enable endpoint discovery, false to explicitly disable it. Defaults to false; cache_limit: (int) The maximum number of keys in the endpoints cache. Defaults to 1000.', |
| 239 |
'fn' => [__CLASS__, '_apply_endpoint_discovery'], |
| 240 |
'default' => [__CLASS__, '_default_endpoint_discovery_provider'] |
| 241 |
], |
| 242 |
'stats' => [ |
| 243 |
'type' => 'value', |
| 244 |
'valid' => ['bool', 'array'], |
| 245 |
'default' => false, |
| 246 |
'doc' => 'Set to true to gather transfer statistics on requests sent. Alternatively, you can provide an associative array with the following keys: retries: (bool) Set to false to disable reporting on retries attempted; http: (bool) Set to true to enable collecting statistics from lower level HTTP adapters (e.g., values returned in GuzzleHttp\TransferStats). HTTP handlers must support an http_stats_receiver option for this to have an effect; timer: (bool) Set to true to enable a command timer that reports the total wall clock time spent on an operation in seconds.', |
| 247 |
'fn' => [__CLASS__, '_apply_stats'], |
| 248 |
], |
| 249 |
'retries' => [ |
| 250 |
'type' => 'value', |
| 251 |
'valid' => ['int', RetryConfigInterface::class, CacheInterface::class, 'callable', 'array'], |
| 252 |
'doc' => "Configures the retry mode and maximum number of allowed retries for a client (pass 0 to disable retries). Provide an integer for 'legacy' mode with the specified number of retries. Otherwise provide an instance of Aws\Retry\ConfigurationInterface, an instance of Aws\CacheInterface, a callable function, or an array with the following keys: mode: (string) Set to 'legacy', 'standard' (uses retry quota management), or 'adapative' (an experimental mode that adds client-side rate limiting to standard mode); max_attempts: (int) The maximum number of attempts for a given request. ", |
| 253 |
'fn' => [__CLASS__, '_apply_retries'], |
| 254 |
'default' => [RetryConfigProvider::class, 'defaultProvider'] |
| 255 |
], |
| 256 |
'validate' => [ |
| 257 |
'type' => 'value', |
| 258 |
'valid' => ['bool', 'array'], |
| 259 |
'default' => true, |
| 260 |
'doc' => 'Set to false to disable client-side parameter validation. Set to true to utilize default validation constraints. Set to an associative array of validation options to enable specific validation constraints.', |
| 261 |
'fn' => [__CLASS__, '_apply_validate'], |
| 262 |
], |
| 263 |
'debug' => [ |
| 264 |
'type' => 'value', |
| 265 |
'valid' => ['bool', 'array'], |
| 266 |
'doc' => 'Set to true to display debug information when sending requests. Alternatively, you can provide an associative array with the following keys: logfn: (callable) Function that is invoked with log messages; stream_size: (int) When the size of a stream is greater than this number, the stream data will not be logged (set to "0" to not log any stream data); scrub_auth: (bool) Set to false to disable the scrubbing of auth data from the logged messages; http: (bool) Set to false to disable the "debug" feature of lower level HTTP adapters (e.g., verbose curl output).', |
| 267 |
'fn' => [__CLASS__, '_apply_debug'], |
| 268 |
], |
| 269 |
'disable_request_compression' => [ |
| 270 |
'type' => 'value', |
| 271 |
'valid' => ['bool', 'callable'], |
| 272 |
'doc' => 'Set to true to disable request compression for supported operations', |
| 273 |
'fn' => [__CLASS__, '_apply_disable_request_compression'], |
| 274 |
'default' => self::DEFAULT_FROM_ENV_INI, |
| 275 |
], |
| 276 |
'request_min_compression_size_bytes' => [ |
| 277 |
'type' => 'value', |
| 278 |
'valid' => ['int', 'callable'], |
| 279 |
'doc' => 'Set to a value between between 0 and 10485760 bytes, inclusive. This value will be ignored if `disable_request_compression` is set to `true`', |
| 280 |
'fn' => [__CLASS__, '_apply_min_compression_size'], |
| 281 |
'default' => [__CLASS__, '_default_min_compression_size'], |
| 282 |
], |
| 283 |
'csm' => [ |
| 284 |
'type' => 'value', |
| 285 |
'valid' => [\Aws\ClientSideMonitoring\ConfigurationInterface::class, 'callable', 'array', 'bool'], |
| 286 |
'doc' => 'CSM options for the client. Provides a callable wrapping a promise, a boolean "false", an instance of ConfigurationInterface, or an associative array of "enabled", "host", "port", and "client_id".', |
| 287 |
'fn' => [__CLASS__, '_apply_csm'], |
| 288 |
'default' => [\Aws\ClientSideMonitoring\ConfigurationProvider::class, 'defaultProvider'] |
| 289 |
], |
| 290 |
'http' => [ |
| 291 |
'type' => 'value', |
| 292 |
'valid' => ['array'], |
| 293 |
'default' => [], |
| 294 |
'doc' => 'Set to an array of SDK request options to apply to each request (e.g., proxy, verify, etc.).', |
| 295 |
], |
| 296 |
'http_handler' => [ |
| 297 |
'type' => 'value', |
| 298 |
'valid' => ['callable'], |
| 299 |
'doc' => 'An HTTP handler is a function that accepts a PSR-7 request object and returns a promise that is fulfilled with a PSR-7 response object or rejected with an array of exception data. NOTE: This option supersedes any provided "handler" option.', |
| 300 |
'fn' => [__CLASS__, '_apply_http_handler'] |
| 301 |
], |
| 302 |
'handler' => [ |
| 303 |
'type' => 'value', |
| 304 |
'valid' => ['callable'], |
| 305 |
'doc' => 'A handler that accepts a command object, request object and returns a promise that is fulfilled with an Aws\ResultInterface object or rejected with an Aws\Exception\AwsException. A handler does not accept a next handler as it is terminal and expected to fulfill a command. If no handler is provided, a default Guzzle handler will be utilized.', |
| 306 |
'fn' => [__CLASS__, '_apply_handler'], |
| 307 |
'default' => [__CLASS__, '_default_handler'] |
| 308 |
], |
| 309 |
'app_id' => [ |
| 310 |
'type' => 'value', |
| 311 |
'valid' => ['string'], |
| 312 |
'doc' => 'app_id(AppId) is an optional application specific identifier that can be set. |
| 313 |
When set it will be appended to the User-Agent header of every request in the form of App/{AppId}. |
| 314 |
This value is also sourced from environment variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.', |
| 315 |
'fn' => [__CLASS__, '_apply_app_id'], |
| 316 |
'default' => [__CLASS__, '_default_app_id'] |
| 317 |
], |
| 318 |
'ua_append' => [ |
| 319 |
'type' => 'value', |
| 320 |
'valid' => ['string', 'array'], |
| 321 |
'doc' => 'Provide a string or array of strings to send in the User-Agent header.', |
| 322 |
'fn' => [__CLASS__, '_apply_user_agent'], |
| 323 |
'default' => [], |
| 324 |
], |
| 325 |
'idempotency_auto_fill' => [ |
| 326 |
'type' => 'value', |
| 327 |
'valid' => ['bool', 'callable'], |
| 328 |
'doc' => 'Set to false to disable SDK to populate parameters that enabled \'idempotencyToken\' trait with a random UUID v4 value on your behalf. Using default value \'true\' still allows parameter value to be overwritten when provided. Note: auto-fill only works when cryptographically secure random bytes generator functions(random_bytes, openssl_random_pseudo_bytes or mcrypt_create_iv) can be found. You may also provide a callable source of random bytes.', |
| 329 |
'default' => true, |
| 330 |
'fn' => [__CLASS__, '_apply_idempotency_auto_fill'] |
| 331 |
], |
| 332 |
'use_aws_shared_config_files' => [ |
| 333 |
'type' => 'value', |
| 334 |
'valid' => ['bool'], |
| 335 |
'doc' => 'Set to false to disable checking for shared aws config files usually located in \'~/.aws/config\' and \'~/.aws/credentials\'. This will be ignored if you set the \'profile\' setting.', |
| 336 |
'default' => true, |
| 337 |
], |
| 338 |
'suppress_php_deprecation_warning' => [ |
| 339 |
'type' => 'value', |
| 340 |
'valid' => ['bool'], |
| 341 |
'doc' => 'Set to true to suppress PHP runtime deprecation warnings. The current deprecation campaign is PHP versions 8.0.x and below, taking effect on 1/13/2025.', |
| 342 |
'default' => false, |
| 343 |
'fn' => [__CLASS__, '_apply_suppress_php_deprecation_warning'] |
| 344 |
], |
| 345 |
'account_id_endpoint_mode' => [ |
| 346 |
'type' => 'value', |
| 347 |
'valid' => ['string'], |
| 348 |
'doc' => 'Decides whether account_id must a be a required resolved credentials property. If this configuration is set to disabled, then account_id is not required. If set to preferred a warning will be logged when account_id is not resolved, and when set to required an exception will be thrown if account_id is not resolved.', |
| 349 |
'default' => [__CLASS__, '_default_account_id_endpoint_mode'], |
| 350 |
'fn' => [__CLASS__, '_apply_account_id_endpoint_mode'] |
| 351 |
], |
| 352 |
'sigv4a_signing_region_set' => [ |
| 353 |
'type' => 'value', |
| 354 |
'valid' => ['string', 'array'], |
| 355 |
'doc' => 'A comma-delimited list of supported regions sent in sigv4a requests.', |
| 356 |
'fn' => [__CLASS__, '_apply_sigv4a_signing_region_set'], |
| 357 |
'default' => self::DEFAULT_FROM_ENV_INI |
| 358 |
] |
| 359 |
]; |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
public static function getDefaultArguments() |
| 390 |
{ |
| 391 |
return self::$defaultArgs; |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
public function __construct(array $argDefinitions) |
| 398 |
{ |
| 399 |
$this->argDefinitions = $argDefinitions; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
public function resolve(array $args, HandlerList $list) |
| 414 |
{ |
| 415 |
$args['config'] = []; |
| 416 |
foreach ($this->argDefinitions as $key => $a) { |
| 417 |
|
| 418 |
if (!isset($args[$key])) { |
| 419 |
if (isset($a['default'])) { |
| 420 |
|
| 421 |
if (is_callable($a['default']) |
| 422 |
&& ( |
| 423 |
is_array($a['default']) |
| 424 |
|| $a['default'] instanceof \Closure |
| 425 |
) |
| 426 |
) { |
| 427 |
if ($a['default'] === self::DEFAULT_FROM_ENV_INI) { |
| 428 |
$args[$key] = $a['default']( |
| 429 |
$key, |
| 430 |
$a['valid'][0] ?? 'string', |
| 431 |
$args |
| 432 |
); |
| 433 |
} else { |
| 434 |
$args[$key] = $a['default']($args); |
| 435 |
} |
| 436 |
} else { |
| 437 |
$args[$key] = $a['default']; |
| 438 |
} |
| 439 |
} elseif (empty($a['required'])) { |
| 440 |
continue; |
| 441 |
} else { |
| 442 |
$this->throwRequired($args); |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
foreach ($a['valid'] as $check) { |
| 448 |
if (isset(self::$typeMap[$check])) { |
| 449 |
$fn = self::$typeMap[$check]; |
| 450 |
if ($fn($args[$key])) { |
| 451 |
goto is_valid; |
| 452 |
} |
| 453 |
} elseif ($args[$key] instanceof $check) { |
| 454 |
goto is_valid; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
$this->invalidType($key, $args[$key]); |
| 459 |
|
| 460 |
|
| 461 |
is_valid: |
| 462 |
if (isset($a['fn'])) { |
| 463 |
$a['fn']($args[$key], $args, $list); |
| 464 |
} |
| 465 |
|
| 466 |
if ($a['type'] === 'config') { |
| 467 |
$args['config'][$key] = $args[$key]; |
| 468 |
} |
| 469 |
} |
| 470 |
$this->_apply_client_context_params($args); |
| 471 |
|
| 472 |
return $args; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
private function getArgMessage($name, $args = [], $useRequired = false) |
| 485 |
{ |
| 486 |
$arg = $this->argDefinitions[$name]; |
| 487 |
$msg = ''; |
| 488 |
$modifiers = []; |
| 489 |
if (isset($arg['valid'])) { |
| 490 |
$modifiers[] = implode('|', $arg['valid']); |
| 491 |
} |
| 492 |
if (isset($arg['choice'])) { |
| 493 |
$modifiers[] = 'One of ' . implode(', ', $arg['choice']); |
| 494 |
} |
| 495 |
if ($modifiers) { |
| 496 |
$msg .= '(' . implode('; ', $modifiers) . ')'; |
| 497 |
} |
| 498 |
$msg = wordwrap("{$name}: {$msg}", 75, "\n "); |
| 499 |
|
| 500 |
if ($useRequired && is_callable($arg['required'])) { |
| 501 |
$msg .= "\n\n "; |
| 502 |
$msg .= str_replace("\n", "\n ", call_user_func($arg['required'], $args)); |
| 503 |
} elseif (isset($arg['doc'])) { |
| 504 |
$msg .= wordwrap("\n\n {$arg['doc']}", 75, "\n "); |
| 505 |
} |
| 506 |
|
| 507 |
return $msg; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
private function invalidType($name, $provided) |
| 518 |
{ |
| 519 |
$expected = implode('|', $this->argDefinitions[$name]['valid']); |
| 520 |
$msg = "Invalid configuration value " |
| 521 |
. "provided for \"{$name}\". Expected {$expected}, but got " |
| 522 |
. describe_type($provided) . "\n\n" |
| 523 |
. $this->getArgMessage($name); |
| 524 |
throw new IAE($msg); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
private function throwRequired(array $args) |
| 534 |
{ |
| 535 |
$missing = []; |
| 536 |
foreach ($this->argDefinitions as $k => $a) { |
| 537 |
if (empty($a['required']) |
| 538 |
|| isset($a['default']) |
| 539 |
|| isset($args[$k]) |
| 540 |
) { |
| 541 |
continue; |
| 542 |
} |
| 543 |
$missing[] = $this->getArgMessage($k, $args, true); |
| 544 |
} |
| 545 |
$msg = "Missing required client configuration options: \n\n"; |
| 546 |
$msg .= implode("\n\n", $missing); |
| 547 |
throw new IAE($msg); |
| 548 |
} |
| 549 |
|
| 550 |
public static function _apply_retries($value, array &$args, HandlerList $list) |
| 551 |
{ |
| 552 |
|
| 553 |
if (!$value) { |
| 554 |
return; |
| 555 |
} |
| 556 |
|
| 557 |
$config = RetryConfigProvider::unwrap($value); |
| 558 |
|
| 559 |
if ($config->getMode() === 'legacy') { |
| 560 |
|
| 561 |
$decider = RetryMiddleware::createDefaultDecider( |
| 562 |
$config->getMaxAttempts() - 1 |
| 563 |
); |
| 564 |
$list->appendSign( |
| 565 |
Middleware::retry($decider, null, $args['stats']['retries']), |
| 566 |
'retry' |
| 567 |
); |
| 568 |
return; |
| 569 |
} |
| 570 |
|
| 571 |
if (NewRetriesOptIn::isEnabled()) { |
| 572 |
$list->appendSign( |
| 573 |
RetryV3Middleware::wrap($config, [ |
| 574 |
'collect_stats' => $args['stats']['retries'], |
| 575 |
'service' => $args['service'], |
| 576 |
]), |
| 577 |
'retry' |
| 578 |
); |
| 579 |
return; |
| 580 |
} |
| 581 |
|
| 582 |
$list->appendSign( |
| 583 |
RetryMiddlewareV2::wrap( |
| 584 |
$config, |
| 585 |
['collect_stats' => $args['stats']['retries']] |
| 586 |
), |
| 587 |
'retry' |
| 588 |
); |
| 589 |
} |
| 590 |
|
| 591 |
public static function _apply_defaults($value, array &$args, HandlerList $list) |
| 592 |
{ |
| 593 |
$config = ConfigModeProvider::unwrap($value); |
| 594 |
if ($config->getMode() !== 'legacy') { |
| 595 |
if (!isset($args['retries']) && !is_null($config->getRetryMode())) { |
| 596 |
$args['retries'] = ['mode' => $config->getRetryMode()]; |
| 597 |
} |
| 598 |
if ( |
| 599 |
!isset($args['sts_regional_endpoints']) |
| 600 |
&& !is_null($config->getStsRegionalEndpoints()) |
| 601 |
) { |
| 602 |
$args['sts_regional_endpoints'] = ['mode' => $config->getStsRegionalEndpoints()]; |
| 603 |
} |
| 604 |
if ( |
| 605 |
!isset($args['s3_us_east_1_regional_endpoint']) |
| 606 |
&& !is_null($config->getS3UsEast1RegionalEndpoints()) |
| 607 |
) { |
| 608 |
$args['s3_us_east_1_regional_endpoint'] = ['mode' => $config->getS3UsEast1RegionalEndpoints()]; |
| 609 |
} |
| 610 |
|
| 611 |
if (!isset($args['http'])) { |
| 612 |
$args['http'] = []; |
| 613 |
} |
| 614 |
if ( |
| 615 |
!isset($args['http']['connect_timeout']) |
| 616 |
&& !is_null($config->getConnectTimeoutInMillis()) |
| 617 |
) { |
| 618 |
$args['http']['connect_timeout'] = $config->getConnectTimeoutInMillis() / 1000; |
| 619 |
} |
| 620 |
if ( |
| 621 |
!isset($args['http']['timeout']) |
| 622 |
&& !is_null($config->getHttpRequestTimeoutInMillis()) |
| 623 |
) { |
| 624 |
$args['http']['timeout'] = $config->getHttpRequestTimeoutInMillis() / 1000; |
| 625 |
} |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
public static function _apply_disable_request_compression($value, array &$args) { |
| 630 |
if (is_callable($value)) { |
| 631 |
$value = $value(); |
| 632 |
} |
| 633 |
if (!is_bool($value)) { |
| 634 |
throw new IAE( |
| 635 |
"Invalid configuration value provided for 'disable_request_compression'." |
| 636 |
. " value must be a bool." |
| 637 |
); |
| 638 |
} |
| 639 |
$args['config']['disable_request_compression'] = $value; |
| 640 |
} |
| 641 |
|
| 642 |
public static function _apply_min_compression_size($value, array &$args) { |
| 643 |
if (is_callable($value)) { |
| 644 |
$value = $value(); |
| 645 |
} |
| 646 |
if (!is_int($value) |
| 647 |
|| (is_int($value) |
| 648 |
&& ($value < 0 || $value > 10485760)) |
| 649 |
) { |
| 650 |
throw new IAE(" Invalid configuration value provided for 'min_compression_size_bytes'." |
| 651 |
. " value must be an integer between 0 and 10485760, inclusive."); |
| 652 |
} |
| 653 |
$args['config']['request_min_compression_size_bytes'] = $value; |
| 654 |
} |
| 655 |
|
| 656 |
public static function _default_min_compression_size(array &$args) { |
| 657 |
return ConfigurationResolver::resolve( |
| 658 |
'request_min_compression_size_bytes', |
| 659 |
10240, |
| 660 |
'int', |
| 661 |
$args |
| 662 |
); |
| 663 |
} |
| 664 |
|
| 665 |
public static function _apply_credentials($value, array &$args) |
| 666 |
{ |
| 667 |
if (is_callable($value)) { |
| 668 |
return; |
| 669 |
} |
| 670 |
|
| 671 |
if ($value instanceof CredentialsInterface) { |
| 672 |
$args['credentials'] = CredentialProvider::fromCredentials($value); |
| 673 |
} elseif (is_array($value) |
| 674 |
&& isset($value['key']) |
| 675 |
&& isset($value['secret']) |
| 676 |
) { |
| 677 |
$args['credentials'] = CredentialProvider::fromCredentials( |
| 678 |
new Credentials( |
| 679 |
$value['key'], |
| 680 |
$value['secret'], |
| 681 |
$value['token'] ?? null, |
| 682 |
$value['expires'] ?? null, |
| 683 |
$value['accountId'] ?? null |
| 684 |
) |
| 685 |
); |
| 686 |
} elseif ($value === false) { |
| 687 |
$args['credentials'] = CredentialProvider::fromCredentials( |
| 688 |
new Credentials('', '') |
| 689 |
); |
| 690 |
if ($args['config']['signature_version'] !== self::DPOP_SIGNATURE) { |
| 691 |
$args['config']['signature_version'] = self::ANONYMOUS_SIGNATURE; |
| 692 |
} |
| 693 |
|
| 694 |
$args['config']['configured_signature_version'] = true; |
| 695 |
} elseif ($value instanceof CacheInterface) { |
| 696 |
$args['credentials'] = CredentialProvider::defaultProvider($args); |
| 697 |
} else { |
| 698 |
throw new IAE('Credentials must be an instance of ' |
| 699 |
. "'" . CredentialsInterface::class . ', an associative ' |
| 700 |
. 'array that contains "key", "secret", and an optional "token" ' |
| 701 |
. 'key-value pairs, a credentials provider function, or false.'); |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
public static function _default_credential_provider(array $args) |
| 706 |
{ |
| 707 |
return CredentialProvider::defaultProvider($args); |
| 708 |
} |
| 709 |
|
| 710 |
public static function _apply_token($value, array &$args) |
| 711 |
{ |
| 712 |
if (is_callable($value)) { |
| 713 |
return; |
| 714 |
} |
| 715 |
|
| 716 |
if ($value instanceof Token) { |
| 717 |
$args['token'] = TokenProvider::fromToken($value); |
| 718 |
} elseif (is_array($value) |
| 719 |
&& isset($value['token']) |
| 720 |
) { |
| 721 |
$args['token'] = TokenProvider::fromToken( |
| 722 |
new Token( |
| 723 |
$value['token'], |
| 724 |
$value['expires'] ?? null |
| 725 |
) |
| 726 |
); |
| 727 |
} elseif ($value instanceof CacheInterface) { |
| 728 |
$args['token'] = TokenProvider::defaultProvider($args); |
| 729 |
} else { |
| 730 |
throw new IAE('Token must be an instance of ' |
| 731 |
. TokenInterface::class . ', an associative ' |
| 732 |
. 'array that contains "token" and an optional "expires" ' |
| 733 |
. 'key-value pairs, a token provider function, or false.'); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
public static function _default_token_provider(array &$args) |
| 738 |
{ |
| 739 |
if (($args['config']['signing_name'] ?? '') === 'bedrock') { |
| 740 |
|
| 741 |
|
| 742 |
$provider = BedrockTokenProvider::createIfAvailable($args); |
| 743 |
if (!is_null($provider)) { |
| 744 |
return $provider; |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
return TokenProvider::defaultProvider($args); |
| 749 |
} |
| 750 |
|
| 751 |
public static function _apply_csm($value, array &$args, HandlerList $list) |
| 752 |
{ |
| 753 |
if ($value === false) { |
| 754 |
$value = new Configuration( |
| 755 |
false, |
| 756 |
\Aws\ClientSideMonitoring\ConfigurationProvider::DEFAULT_HOST, |
| 757 |
\Aws\ClientSideMonitoring\ConfigurationProvider::DEFAULT_PORT, |
| 758 |
\Aws\ClientSideMonitoring\ConfigurationProvider::DEFAULT_CLIENT_ID |
| 759 |
); |
| 760 |
$args['csm'] = $value; |
| 761 |
} |
| 762 |
|
| 763 |
$list->appendBuild( |
| 764 |
ApiCallMonitoringMiddleware::wrap( |
| 765 |
$args['credentials'], |
| 766 |
$value, |
| 767 |
$args['region'], |
| 768 |
$args['api']->getServiceId() |
| 769 |
), |
| 770 |
'ApiCallMonitoringMiddleware' |
| 771 |
); |
| 772 |
|
| 773 |
$list->appendAttempt( |
| 774 |
ApiCallAttemptMonitoringMiddleware::wrap( |
| 775 |
$args['credentials'], |
| 776 |
$value, |
| 777 |
$args['region'], |
| 778 |
$args['api']->getServiceId() |
| 779 |
), |
| 780 |
'ApiCallAttemptMonitoringMiddleware' |
| 781 |
); |
| 782 |
} |
| 783 |
|
| 784 |
public static function _apply_api_provider(callable $value, array &$args) |
| 785 |
{ |
| 786 |
$api = new Service( |
| 787 |
ApiProvider::resolve( |
| 788 |
$value, |
| 789 |
'api', |
| 790 |
$args['service'], |
| 791 |
$args['version'] |
| 792 |
), |
| 793 |
$value |
| 794 |
); |
| 795 |
|
| 796 |
if ( |
| 797 |
empty($args['config']['signing_name']) |
| 798 |
&& isset($api['metadata']['signingName']) |
| 799 |
) { |
| 800 |
$args['config']['signing_name'] = $api['metadata']['signingName']; |
| 801 |
} |
| 802 |
|
| 803 |
$args['api'] = $api; |
| 804 |
$args['parser'] = Service::createParser($api); |
| 805 |
$args['error_parser'] = Service::createErrorParser($api->getProtocol(), $api); |
| 806 |
} |
| 807 |
|
| 808 |
public static function _apply_endpoint_provider($value, array &$args) |
| 809 |
{ |
| 810 |
if (!isset($args['endpoint'])) { |
| 811 |
if ($value instanceof EndpointProviderV2) { |
| 812 |
$options = self::getEndpointProviderOptions($args); |
| 813 |
$value = PartitionEndpointProvider::defaultProvider($options) |
| 814 |
->getPartition($args['region'], $args['service']); |
| 815 |
} |
| 816 |
|
| 817 |
$endpointPrefix = $args['api']['metadata']['endpointPrefix'] ?? $args['service']; |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
if (!self::isValidRegion($args['region'])) { |
| 822 |
throw new InvalidRegionException('Region must be a valid RFC' |
| 823 |
. ' host label.'); |
| 824 |
} |
| 825 |
$serviceEndpoints = |
| 826 |
is_array($value) && isset($value['services'][$args['service']]['endpoints']) |
| 827 |
? $value['services'][$args['service']]['endpoints'] |
| 828 |
: null; |
| 829 |
if (isset($serviceEndpoints[$args['region']]['deprecated'])) { |
| 830 |
trigger_error("The service " . $args['service'] . "has " |
| 831 |
. " deprecated the region " . $args['region'] . ".", |
| 832 |
E_USER_WARNING |
| 833 |
); |
| 834 |
} |
| 835 |
|
| 836 |
$args['region'] = \Aws\strip_fips_pseudo_regions($args['region']); |
| 837 |
|
| 838 |
|
| 839 |
$result = EndpointProvider::resolve($value, [ |
| 840 |
'service' => $endpointPrefix, |
| 841 |
'region' => $args['region'], |
| 842 |
'scheme' => $args['scheme'], |
| 843 |
'options' => self::getEndpointProviderOptions($args), |
| 844 |
]); |
| 845 |
|
| 846 |
$args['endpoint'] = $result['endpoint']; |
| 847 |
|
| 848 |
if (empty($args['config']['signature_version'])) { |
| 849 |
if ( |
| 850 |
isset($args['api']) |
| 851 |
&& $args['api']->getSignatureVersion() == 'bearer' |
| 852 |
) { |
| 853 |
$args['config']['signature_version'] = 'bearer'; |
| 854 |
} elseif (isset($result['signatureVersion'])) { |
| 855 |
$args['config']['signature_version'] = $result['signatureVersion']; |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
if ( |
| 860 |
empty($args['config']['signing_region']) |
| 861 |
&& isset($result['signingRegion']) |
| 862 |
) { |
| 863 |
$args['config']['signing_region'] = $result['signingRegion']; |
| 864 |
} |
| 865 |
|
| 866 |
if ( |
| 867 |
empty($args['config']['signing_name']) |
| 868 |
&& isset($result['signingName']) |
| 869 |
) { |
| 870 |
$args['config']['signing_name'] = $result['signingName']; |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
public static function _apply_endpoint_discovery($value, array &$args) { |
| 876 |
$args['endpoint_discovery'] = $value; |
| 877 |
} |
| 878 |
|
| 879 |
public static function _default_endpoint_discovery_provider(array $args) |
| 880 |
{ |
| 881 |
return ConfigurationProvider::defaultProvider($args); |
| 882 |
} |
| 883 |
|
| 884 |
public static function _apply_use_fips_endpoint($value, array &$args) { |
| 885 |
if ($value instanceof CacheInterface) { |
| 886 |
$value = UseFipsConfigProvider::defaultProvider($args); |
| 887 |
} |
| 888 |
if (is_callable($value)) { |
| 889 |
$value = $value(); |
| 890 |
} |
| 891 |
if ($value instanceof PromiseInterface) { |
| 892 |
$value = $value->wait(); |
| 893 |
} |
| 894 |
if ($value instanceof UseFipsEndpointConfigurationInterface) { |
| 895 |
$args['config']['use_fips_endpoint'] = $value; |
| 896 |
} else { |
| 897 |
|
| 898 |
$args['config']['use_fips_endpoint'] = new UseFipsEndpointConfiguration($value); |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
public static function _default_use_fips_endpoint(array &$args) { |
| 903 |
return UseFipsConfigProvider::defaultProvider($args); |
| 904 |
} |
| 905 |
|
| 906 |
public static function _apply_use_dual_stack_endpoint($value, array &$args) { |
| 907 |
if ($value instanceof CacheInterface) { |
| 908 |
$value = UseDualStackConfigProvider::defaultProvider($args); |
| 909 |
} |
| 910 |
if (is_callable($value)) { |
| 911 |
$value = $value(); |
| 912 |
} |
| 913 |
if ($value instanceof PromiseInterface) { |
| 914 |
$value = $value->wait(); |
| 915 |
} |
| 916 |
if ($value instanceof UseDualStackEndpointConfigurationInterface) { |
| 917 |
$args['config']['use_dual_stack_endpoint'] = $value; |
| 918 |
} else { |
| 919 |
|
| 920 |
$args['config']['use_dual_stack_endpoint'] = |
| 921 |
new UseDualStackEndpointConfiguration($value, $args['region']); |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
public static function _default_use_dual_stack_endpoint(array &$args) { |
| 926 |
return UseDualStackConfigProvider::defaultProvider($args); |
| 927 |
} |
| 928 |
|
| 929 |
public static function _apply_serializer($value, array &$args, HandlerList $list) |
| 930 |
{ |
| 931 |
$list->prependBuild(Middleware::requestBuilder($value), 'builder'); |
| 932 |
} |
| 933 |
|
| 934 |
public static function _apply_debug($value, array &$args, HandlerList $list) |
| 935 |
{ |
| 936 |
if ($value !== false) { |
| 937 |
$list->interpose( |
| 938 |
new TraceMiddleware( |
| 939 |
$value === true ? [] : $value, |
| 940 |
$args['api']) |
| 941 |
); |
| 942 |
} |
| 943 |
} |
| 944 |
|
| 945 |
public static function _apply_stats($value, array &$args, HandlerList $list) |
| 946 |
{ |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
$defaults = array_fill_keys( |
| 951 |
['http', 'retries', 'timer'], |
| 952 |
$value === true |
| 953 |
); |
| 954 |
$args['stats'] = is_array($value) |
| 955 |
? array_replace($defaults, $value) |
| 956 |
: $defaults; |
| 957 |
|
| 958 |
if ($args['stats']['timer']) { |
| 959 |
$list->prependInit(Middleware::timer(), 'timer'); |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
public static function _apply_profile($_, array &$args) |
| 964 |
{ |
| 965 |
$args['credentials'] = CredentialProvider::ini($args['profile']); |
| 966 |
} |
| 967 |
|
| 968 |
public static function _apply_validate($value, array &$args, HandlerList $list) |
| 969 |
{ |
| 970 |
if ($value === false) { |
| 971 |
return; |
| 972 |
} |
| 973 |
|
| 974 |
$validator = $value === true |
| 975 |
? new Validator() |
| 976 |
: new Validator($value); |
| 977 |
$list->appendValidate( |
| 978 |
Middleware::validation($args['api'], $validator), |
| 979 |
'validation' |
| 980 |
); |
| 981 |
} |
| 982 |
|
| 983 |
public static function _apply_handler($value, array &$args, HandlerList $list) |
| 984 |
{ |
| 985 |
$list->setHandler($value); |
| 986 |
} |
| 987 |
|
| 988 |
public static function _default_handler(array &$args) |
| 989 |
{ |
| 990 |
return new WrappedHttpHandler( |
| 991 |
default_http_handler(), |
| 992 |
$args['parser'], |
| 993 |
$args['error_parser'], |
| 994 |
$args['exception_class'], |
| 995 |
$args['stats']['http'] |
| 996 |
); |
| 997 |
} |
| 998 |
|
| 999 |
public static function _apply_http_handler($value, array &$args, HandlerList $list) |
| 1000 |
{ |
| 1001 |
$args['handler'] = new WrappedHttpHandler( |
| 1002 |
$value, |
| 1003 |
$args['parser'], |
| 1004 |
$args['error_parser'], |
| 1005 |
$args['exception_class'], |
| 1006 |
$args['stats']['http'] |
| 1007 |
); |
| 1008 |
} |
| 1009 |
|
| 1010 |
public static function _apply_app_id($value, array &$args) |
| 1011 |
{ |
| 1012 |
|
| 1013 |
static $MAX_APP_ID_LENGTH = 50; |
| 1014 |
if (strlen($value) > $MAX_APP_ID_LENGTH) { |
| 1015 |
trigger_error("The provided or configured value for `AppId`, " |
| 1016 |
."which is an user agent parameter, exceeds the maximum length of " |
| 1017 |
."$MAX_APP_ID_LENGTH characters.", E_USER_WARNING); |
| 1018 |
} |
| 1019 |
|
| 1020 |
$args['app_id'] = $value; |
| 1021 |
} |
| 1022 |
|
| 1023 |
public static function _default_app_id(array $args) |
| 1024 |
{ |
| 1025 |
return ConfigurationResolver::resolve( |
| 1026 |
'sdk_ua_app_id', |
| 1027 |
'', |
| 1028 |
'string', |
| 1029 |
$args |
| 1030 |
); |
| 1031 |
} |
| 1032 |
|
| 1033 |
public static function _apply_user_agent( |
| 1034 |
$inputUserAgent, |
| 1035 |
array &$args, |
| 1036 |
HandlerList $list |
| 1037 |
): void |
| 1038 |
{ |
| 1039 |
|
| 1040 |
$userAgent = []; |
| 1041 |
|
| 1042 |
if ($inputUserAgent){ |
| 1043 |
if (!is_array($inputUserAgent)) { |
| 1044 |
$inputUserAgent = [$inputUserAgent]; |
| 1045 |
} |
| 1046 |
$inputUserAgent = array_map('strval', $inputUserAgent); |
| 1047 |
$userAgent = array_merge($userAgent, $inputUserAgent); |
| 1048 |
} |
| 1049 |
|
| 1050 |
$args['ua_append'] = $userAgent; |
| 1051 |
|
| 1052 |
$list->appendBuild( |
| 1053 |
Middleware::mapRequest(function (RequestInterface $request) use ($userAgent) { |
| 1054 |
return $request->withHeader( |
| 1055 |
'X-Amz-User-Agent', |
| 1056 |
implode(' ', array_merge( |
| 1057 |
$userAgent, |
| 1058 |
$request->getHeader('X-Amz-User-Agent') |
| 1059 |
)) |
| 1060 |
); |
| 1061 |
}) |
| 1062 |
); |
| 1063 |
} |
| 1064 |
|
| 1065 |
public static function _apply_endpoint($value, array &$args, HandlerList $list) |
| 1066 |
{ |
| 1067 |
if (empty($value)) { |
| 1068 |
unset($args['endpoint']); |
| 1069 |
return; |
| 1070 |
} |
| 1071 |
|
| 1072 |
$args['endpoint_override'] = true; |
| 1073 |
$args['endpoint'] = $value; |
| 1074 |
} |
| 1075 |
|
| 1076 |
public static function _apply_idempotency_auto_fill( |
| 1077 |
$value, |
| 1078 |
array &$args, |
| 1079 |
HandlerList $list |
| 1080 |
) { |
| 1081 |
$enabled = false; |
| 1082 |
$generator = null; |
| 1083 |
|
| 1084 |
|
| 1085 |
if (is_bool($value)) { |
| 1086 |
$enabled = $value; |
| 1087 |
} elseif (is_callable($value)) { |
| 1088 |
$enabled = true; |
| 1089 |
$generator = $value; |
| 1090 |
} |
| 1091 |
|
| 1092 |
if ($enabled) { |
| 1093 |
$list->prependInit( |
| 1094 |
IdempotencyTokenMiddleware::wrap($args['api'], $generator), |
| 1095 |
'idempotency_auto_fill' |
| 1096 |
); |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
public static function _default_account_id_endpoint_mode($args) |
| 1101 |
{ |
| 1102 |
return ConfigurationResolver::resolve( |
| 1103 |
'account_id_endpoint_mode', |
| 1104 |
'preferred', |
| 1105 |
'string', |
| 1106 |
$args |
| 1107 |
); |
| 1108 |
} |
| 1109 |
|
| 1110 |
public static function _apply_account_id_endpoint_mode($value, array &$args) |
| 1111 |
{ |
| 1112 |
static $accountIdEndpointModes = ['disabled', 'required', 'preferred']; |
| 1113 |
if (!in_array($value, $accountIdEndpointModes)) { |
| 1114 |
throw new IAE( |
| 1115 |
"The value provided for the config account_id_endpoint_mode is invalid." |
| 1116 |
."Valid values are: " . implode(", ", $accountIdEndpointModes) |
| 1117 |
); |
| 1118 |
} |
| 1119 |
|
| 1120 |
$args['account_id_endpoint_mode'] = $value; |
| 1121 |
} |
| 1122 |
|
| 1123 |
public static function _default_endpoint_provider(array $args) |
| 1124 |
{ |
| 1125 |
$service = $args['api'] ?? null; |
| 1126 |
$serviceName = isset($service) ? $service->getServiceName() : null; |
| 1127 |
$apiVersion = isset($service) ? $service->getApiVersion() : null; |
| 1128 |
|
| 1129 |
if (self::isValidService($serviceName) |
| 1130 |
&& self::isValidApiVersion($serviceName, $apiVersion) |
| 1131 |
) { |
| 1132 |
$partitions = EndpointDefinitionProvider::getPartitions(); |
| 1133 |
$parsed = EndpointDefinitionProvider::getParsedRuleset( |
| 1134 |
$service->getServiceName(), |
| 1135 |
$service->getApiVersion(), |
| 1136 |
$partitions |
| 1137 |
); |
| 1138 |
return new EndpointProviderV2($parsed, $partitions); |
| 1139 |
} |
| 1140 |
$options = self::getEndpointProviderOptions($args); |
| 1141 |
return PartitionEndpointProvider::defaultProvider($options) |
| 1142 |
->getPartition($args['region'], $args['service']); |
| 1143 |
} |
| 1144 |
|
| 1145 |
public static function _default_serializer(array $args) |
| 1146 |
{ |
| 1147 |
return Service::createSerializer( |
| 1148 |
$args['api'], |
| 1149 |
$args['endpoint'] |
| 1150 |
); |
| 1151 |
} |
| 1152 |
|
| 1153 |
public static function _default_signature_provider() |
| 1154 |
{ |
| 1155 |
return SignatureProvider::defaultProvider(); |
| 1156 |
} |
| 1157 |
|
| 1158 |
public static function _default_auth_scheme_resolver(array $args) |
| 1159 |
{ |
| 1160 |
return new AuthSchemeResolver($args['credentials'], $args['token']); |
| 1161 |
} |
| 1162 |
|
| 1163 |
public static function _apply_auth_scheme_preference( |
| 1164 |
string|array|null &$value, |
| 1165 |
array &$args |
| 1166 |
): void |
| 1167 |
{ |
| 1168 |
|
| 1169 |
if (empty($value)) { |
| 1170 |
$value = null; |
| 1171 |
$args['config']['auth_scheme_preference'] = $value; |
| 1172 |
return; |
| 1173 |
} |
| 1174 |
|
| 1175 |
|
| 1176 |
if (is_string($value)) { |
| 1177 |
$value = explode(',', $value); |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
foreach ($value as &$val) { |
| 1182 |
$val = trim($val); |
| 1183 |
} |
| 1184 |
|
| 1185 |
|
| 1186 |
$args['config']['auth_scheme_preference'] = $value; |
| 1187 |
} |
| 1188 |
|
| 1189 |
public static function _default_signature_version(array &$args) |
| 1190 |
{ |
| 1191 |
if (isset($args['config']['signature_version'])) { |
| 1192 |
return $args['config']['signature_version']; |
| 1193 |
} |
| 1194 |
|
| 1195 |
$args['__partition_result'] = isset($args['__partition_result']) |
| 1196 |
? isset($args['__partition_result']) |
| 1197 |
: call_user_func(PartitionEndpointProvider::defaultProvider(), [ |
| 1198 |
'service' => $args['service'], |
| 1199 |
'region' => $args['region'], |
| 1200 |
]); |
| 1201 |
|
| 1202 |
return isset($args['__partition_result']['signatureVersion']) |
| 1203 |
? $args['__partition_result']['signatureVersion'] |
| 1204 |
: $args['api']->getSignatureVersion(); |
| 1205 |
} |
| 1206 |
|
| 1207 |
public static function _default_signing_name(array &$args) |
| 1208 |
{ |
| 1209 |
if (isset($args['config']['signing_name'])) { |
| 1210 |
return $args['config']['signing_name']; |
| 1211 |
} |
| 1212 |
|
| 1213 |
$args['__partition_result'] = isset($args['__partition_result']) |
| 1214 |
? isset($args['__partition_result']) |
| 1215 |
: call_user_func(PartitionEndpointProvider::defaultProvider(), [ |
| 1216 |
'service' => $args['service'], |
| 1217 |
'region' => $args['region'], |
| 1218 |
]); |
| 1219 |
|
| 1220 |
if (isset($args['__partition_result']['signingName'])) { |
| 1221 |
return $args['__partition_result']['signingName']; |
| 1222 |
} |
| 1223 |
|
| 1224 |
if ($signingName = $args['api']->getSigningName()) { |
| 1225 |
return $signingName; |
| 1226 |
} |
| 1227 |
|
| 1228 |
return $args['service']; |
| 1229 |
} |
| 1230 |
|
| 1231 |
public static function _default_signing_region(array &$args) |
| 1232 |
{ |
| 1233 |
if (isset($args['config']['signing_region'])) { |
| 1234 |
return $args['config']['signing_region']; |
| 1235 |
} |
| 1236 |
|
| 1237 |
$args['__partition_result'] = isset($args['__partition_result']) |
| 1238 |
? isset($args['__partition_result']) |
| 1239 |
: call_user_func(PartitionEndpointProvider::defaultProvider(), [ |
| 1240 |
'service' => $args['service'], |
| 1241 |
'region' => $args['region'], |
| 1242 |
]); |
| 1243 |
|
| 1244 |
return $args['__partition_result']['signingRegion'] ?? $args['region']; |
| 1245 |
} |
| 1246 |
|
| 1247 |
public static function _apply_ignore_configured_endpoint_urls($value, array &$args) |
| 1248 |
{ |
| 1249 |
$args['config']['ignore_configured_endpoint_urls'] = $value; |
| 1250 |
} |
| 1251 |
|
| 1252 |
public static function _apply_suppress_php_deprecation_warning($value, &$args) |
| 1253 |
{ |
| 1254 |
if ($value) { |
| 1255 |
$args['suppress_php_deprecation_warning'] = true; |
| 1256 |
} elseif (!empty(getenv("AWS_SUPPRESS_PHP_DEPRECATION_WARNING"))) { |
| 1257 |
$args['suppress_php_deprecation_warning'] |
| 1258 |
= \Aws\boolean_value(getenv("AWS_SUPPRESS_PHP_DEPRECATION_WARNING")); |
| 1259 |
} elseif (!empty($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"])) { |
| 1260 |
$args['suppress_php_deprecation_warning'] = |
| 1261 |
\Aws\boolean_value($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"]); |
| 1262 |
} elseif (!empty($_ENV["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"])) { |
| 1263 |
$args['suppress_php_deprecation_warning'] = |
| 1264 |
\Aws\boolean_value($_ENV["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"]); |
| 1265 |
} |
| 1266 |
} |
| 1267 |
|
| 1268 |
public static function _default_endpoint(array &$args) |
| 1269 |
{ |
| 1270 |
if ($args['config']['ignore_configured_endpoint_urls'] |
| 1271 |
|| !self::isValidService($args['service']) |
| 1272 |
) { |
| 1273 |
return ''; |
| 1274 |
} |
| 1275 |
|
| 1276 |
$serviceIdentifier = \Aws\manifest($args['service'])['serviceIdentifier']; |
| 1277 |
$value = ConfigurationResolver::resolve( |
| 1278 |
'endpoint_url_' . $serviceIdentifier, |
| 1279 |
'', |
| 1280 |
'string', |
| 1281 |
$args + [ |
| 1282 |
'ini_resolver_options' => [ |
| 1283 |
'section' => 'services', |
| 1284 |
'subsection' => $serviceIdentifier, |
| 1285 |
'key' => 'endpoint_url' |
| 1286 |
] |
| 1287 |
] |
| 1288 |
); |
| 1289 |
|
| 1290 |
if (empty($value)) { |
| 1291 |
$value = ConfigurationResolver::resolve( |
| 1292 |
'endpoint_url', |
| 1293 |
'', |
| 1294 |
'string', |
| 1295 |
$args |
| 1296 |
); |
| 1297 |
} |
| 1298 |
|
| 1299 |
if (!empty($value)) { |
| 1300 |
$args['config']['configured_endpoint_url'] = true; |
| 1301 |
} |
| 1302 |
|
| 1303 |
return $value; |
| 1304 |
} |
| 1305 |
|
| 1306 |
public static function _apply_sigv4a_signing_region_set($value, array &$args) |
| 1307 |
{ |
| 1308 |
if (empty($value)) { |
| 1309 |
$args['sigv4a_signing_region_set'] = null; |
| 1310 |
} elseif (is_array($value)) { |
| 1311 |
$args['sigv4a_signing_region_set'] = implode(', ', $value); |
| 1312 |
} else { |
| 1313 |
$args['sigv4a_signing_region_set'] = $value; |
| 1314 |
} |
| 1315 |
} |
| 1316 |
|
| 1317 |
public static function _apply_region($value, array &$args) |
| 1318 |
{ |
| 1319 |
if (empty($value)) { |
| 1320 |
self::_missing_region($args); |
| 1321 |
} |
| 1322 |
$args['region'] = $value; |
| 1323 |
} |
| 1324 |
|
| 1325 |
public static function _missing_region(array $args) |
| 1326 |
{ |
| 1327 |
$service = $args['service'] ?? ''; |
| 1328 |
|
| 1329 |
$msg = <<<EOT |
| 1330 |
Missing required client configuration options: |
| 1331 |
|
| 1332 |
region: (string) |
| 1333 |
|
| 1334 |
A "region" configuration value is required for the "{$service}" service |
| 1335 |
(e.g., "us-west-2"). A list of available public regions and endpoints can be |
| 1336 |
found at http://docs.aws.amazon.com/general/latest/gr/rande.html. |
| 1337 |
EOT; |
| 1338 |
throw new IAE($msg); |
| 1339 |
} |
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
private static function _resolve_from_env_ini( |
| 1351 |
string $key, |
| 1352 |
string $expectedType, |
| 1353 |
array $args |
| 1354 |
) { |
| 1355 |
static $typeDefaultMap = [ |
| 1356 |
'int' => 0, |
| 1357 |
'bool' => false, |
| 1358 |
'boolean' => false, |
| 1359 |
'string' => '', |
| 1360 |
]; |
| 1361 |
|
| 1362 |
return ConfigurationResolver::resolve( |
| 1363 |
$key, |
| 1364 |
$typeDefaultMap[$expectedType] ?? '', |
| 1365 |
$expectedType, |
| 1366 |
$args |
| 1367 |
); |
| 1368 |
} |
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
private static function getEndpointProviderOptions(array $args) |
| 1377 |
{ |
| 1378 |
$options = []; |
| 1379 |
$optionKeys = [ |
| 1380 |
'sts_regional_endpoints', |
| 1381 |
's3_us_east_1_regional_endpoint', |
| 1382 |
]; |
| 1383 |
$configKeys = [ |
| 1384 |
'use_dual_stack_endpoint', |
| 1385 |
'use_fips_endpoint', |
| 1386 |
]; |
| 1387 |
foreach ($optionKeys as $key) { |
| 1388 |
if (isset($args[$key])) { |
| 1389 |
$options[$key] = $args[$key]; |
| 1390 |
} |
| 1391 |
} |
| 1392 |
foreach ($configKeys as $key) { |
| 1393 |
if (isset($args['config'][$key])) { |
| 1394 |
$options[$key] = $args['config'][$key]; |
| 1395 |
} |
| 1396 |
} |
| 1397 |
return $options; |
| 1398 |
} |
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
private static function isValidRegion($region) |
| 1407 |
{ |
| 1408 |
return is_valid_hostlabel($region); |
| 1409 |
} |
| 1410 |
|
| 1411 |
private function _apply_client_context_params(array $args) |
| 1412 |
{ |
| 1413 |
if (isset($args['api']) |
| 1414 |
&& !empty($args['api']->getClientContextParams())) |
| 1415 |
{ |
| 1416 |
$clientContextParams = $args['api']->getClientContextParams(); |
| 1417 |
foreach($clientContextParams as $paramName => $paramDefinition) { |
| 1418 |
$definition = [ |
| 1419 |
'type' => 'value', |
| 1420 |
'valid' => [$paramDefinition['type']], |
| 1421 |
'doc' => $paramDefinition['documentation'] ?? null |
| 1422 |
]; |
| 1423 |
$this->argDefinitions[$paramName] = $definition; |
| 1424 |
|
| 1425 |
if (isset($args[$paramName])) { |
| 1426 |
$fn = self::$typeMap[$paramDefinition['type']]; |
| 1427 |
if (!$fn($args[$paramName])) { |
| 1428 |
$this->invalidType($paramName, $args[$paramName]); |
| 1429 |
} |
| 1430 |
} |
| 1431 |
} |
| 1432 |
} |
| 1433 |
} |
| 1434 |
|
| 1435 |
private static function isValidService($service) |
| 1436 |
{ |
| 1437 |
if (is_null($service)) { |
| 1438 |
return false; |
| 1439 |
} |
| 1440 |
$services = \Aws\manifest(); |
| 1441 |
return isset($services[$service]); |
| 1442 |
} |
| 1443 |
|
| 1444 |
private static function isValidApiVersion($service, $apiVersion) |
| 1445 |
{ |
| 1446 |
if (is_null($apiVersion)) { |
| 1447 |
return false; |
| 1448 |
} |
| 1449 |
return is_dir( |
| 1450 |
__DIR__ . "/data/{$service}/$apiVersion" |
| 1451 |
); |
| 1452 |
} |
| 1453 |
} |