Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/AwsClient.php

raw symbols SCIP
1 <?php
2 namespace Aws;
3
4 use Aws\Api\ApiProvider;
5 use Aws\Api\DocModel;
6 use Aws\Api\Service;
7 use Aws\Auth\AuthSelectionMiddleware;
8 use Aws\Auth\AuthSchemeResolverInterface;
9 use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
10 use Aws\EndpointV2\EndpointProviderV2;
11 use Aws\EndpointV2\EndpointV2Middleware;
12 use Aws\Exception\AwsException;
13 use Aws\Signature\SignatureProvider;
14 use GuzzleHttp\Psr7\Uri;
15 use Psr\Http\Message\RequestInterface;
16
17 /**
18 * Default AWS client implementation
19 */
20 class AwsClient implements AwsClientInterface
21 {
22 use AwsClientTrait;
23
24 /** @var array */
25 private $aliases;
26
27 /** @var array */
28 private $config;
29
30 /** @var string */
31 private $region;
32
33 /** @var string */
34 private $signingRegionSet;
35
36 /** @var string */
37 private $endpoint;
38
39 /** @var Service */
40 private $api;
41
42 /** @var callable */
43 private $signatureProvider;
44
45 /** @var AuthSchemeResolverInterface */
46 private $authSchemeResolver;
47
48 /** @var callable */
49 private $credentialProvider;
50
51 /** @var callable */
52 private $tokenProvider;
53
54 /** @var HandlerList */
55 private $handlerList;
56
57 /** @var array*/
58 private $defaultRequestOptions;
59
60 /** @var array*/
61 private $clientContextParams = [];
62
63 /** @var array*/
64 protected $clientBuiltIns = [];
65
66 /** @var EndpointProviderV2 | callable */
67 protected $endpointProvider;
68
69 /** @var callable */
70 protected $serializer;
71
72 /**
73 * Get an array of client constructor arguments used by the client.
74 *
75 * @return array
76 */
77 public static function getArguments()
78 {
79 return ClientResolver::getDefaultArguments();
80 }
81
82 /**
83 * The client constructor accepts the following options:
84 *
85 * - api_provider: (callable) An optional PHP callable that accepts a
86 * type, service, and version argument, and returns an array of
87 * corresponding configuration data. The type value can be one of api,
88 * waiter, or paginator.
89 * - credentials:
90 * (Aws\Credentials\CredentialsInterface|array|bool|callable) Specifies
91 * the credentials used to sign requests. Provide an
92 * Aws\Credentials\CredentialsInterface object, an associative array of
93 * "key", "secret", and an optional "token" key, `false` to use null
94 * credentials, or a callable credentials provider used to create
95 * credentials or return null. See Aws\Credentials\CredentialProvider for
96 * a list of built-in credentials providers. If no credentials are
97 * provided, the SDK will attempt to load them from the environment.
98 * - token:
99 * (Aws\Token\TokenInterface|array|bool|callable) Specifies
100 * the token used to authorize requests. Provide an
101 * Aws\Token\TokenInterface object, an associative array of
102 * "token" and an optional "expires" key, `false` to use no
103 * token, or a callable token provider used to create a
104 * token or return null. See Aws\Token\TokenProvider for
105 * a list of built-in token providers. If no token is
106 * provided, the SDK will attempt to load one from the environment.
107 * - csm:
108 * (Aws\ClientSideMonitoring\ConfigurationInterface|array|callable) Specifies
109 * the credentials used to sign requests. Provide an
110 * Aws\ClientSideMonitoring\ConfigurationInterface object, a callable
111 * configuration provider used to create client-side monitoring configuration,
112 * `false` to disable csm, or an associative array with the following keys:
113 * enabled: (bool) Set to true to enable client-side monitoring, defaults
114 * to false; host: (string) the host location to send monitoring events to,
115 * defaults to 127.0.0.1; port: (int) The port used for the host connection,
116 * defaults to 31000; client_id: (string) An identifier for this project
117 * - debug: (bool|array) Set to true to display debug information when
118 * sending requests. Alternatively, you can provide an associative array
119 * with the following keys: logfn: (callable) Function that is invoked
120 * with log messages; stream_size: (int) When the size of a stream is
121 * greater than this number, the stream data will not be logged (set to
122 * "0" to not log any stream data); scrub_auth: (bool) Set to false to
123 * disable the scrubbing of auth data from the logged messages; http:
124 * (bool) Set to false to disable the "debug" feature of lower level HTTP
125 * adapters (e.g., verbose curl output).
126 * - stats: (bool|array) Set to true to gather transfer statistics on
127 * requests sent. Alternatively, you can provide an associative array with
128 * the following keys: retries: (bool) Set to false to disable reporting
129 * on retries attempted; http: (bool) Set to true to enable collecting
130 * statistics from lower level HTTP adapters (e.g., values returned in
131 * GuzzleHttp\TransferStats). HTTP handlers must support an
132 * `http_stats_receiver` option for this to have an effect; timer: (bool)
133 * Set to true to enable a command timer that reports the total wall clock
134 * time spent on an operation in seconds.
135 * - disable_host_prefix_injection: (bool) Set to true to disable host prefix
136 * injection logic for services that use it. This disables the entire
137 * prefix injection, including the portions supplied by user-defined
138 * parameters. Setting this flag will have no effect on services that do
139 * not use host prefix injection.
140 * - endpoint: (string) The full URI of the webservice. This is only
141 * required when connecting to a custom endpoint (e.g., a local version
142 * of S3).
143 * - endpoint_discovery: (Aws\EndpointDiscovery\ConfigurationInterface,
144 * Aws\CacheInterface, array, callable) Settings for endpoint discovery.
145 * Provide an instance of Aws\EndpointDiscovery\ConfigurationInterface,
146 * an instance Aws\CacheInterface, a callable that provides a promise for
147 * a Configuration object, or an associative array with the following
148 * keys: enabled: (bool) Set to true to enable endpoint discovery, false
149 * to explicitly disable it, defaults to false; cache_limit: (int) The
150 * maximum number of keys in the endpoints cache, defaults to 1000.
151 * - endpoint_provider: (callable) An optional PHP callable that
152 * accepts a hash of options including a "service" and "region" key and
153 * returns NULL or a hash of endpoint data, of which the "endpoint" key
154 * is required. See Aws\Endpoint\EndpointProvider for a list of built-in
155 * providers.
156 * - handler: (callable) A handler that accepts a command object,
157 * request object and returns a promise that is fulfilled with an
158 * Aws\ResultInterface object or rejected with an
159 * Aws\Exception\AwsException. A handler does not accept a next handler
160 * as it is terminal and expected to fulfill a command. If no handler is
161 * provided, a default Guzzle handler will be utilized.
162 * - http: (array, default=array(0)) Set to an array of SDK request
163 * options to apply to each request (e.g., proxy, verify, etc.).
164 * - http_handler: (callable) An HTTP handler is a function that
165 * accepts a PSR-7 request object and returns a promise that is fulfilled
166 * with a PSR-7 response object or rejected with an array of exception
167 * data. NOTE: This option supersedes any provided "handler" option.
168 * - idempotency_auto_fill: (bool|callable) Set to false to disable SDK to
169 * populate parameters that enabled 'idempotencyToken' trait with a random
170 * UUID v4 value on your behalf. Using default value 'true' still allows
171 * parameter value to be overwritten when provided. Note: auto-fill only
172 * works when cryptographically secure random bytes generator functions
173 * (random_bytes, openssl_random_pseudo_bytes or mcrypt_create_iv) can be
174 * found. You may also provide a callable source of random bytes.
175 * - profile: (string) Allows you to specify which profile to use when
176 * credentials are created from the AWS credentials file in your HOME
177 * directory. This setting overrides the AWS_PROFILE environment
178 * variable. Note: Specifying "profile" will cause the "credentials" key
179 * to be ignored.
180 * - region: (string, required) Region to connect to. See
181 * http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of
182 * available regions.
183 * - retries: (int, Aws\Retry\ConfigurationInterface, Aws\CacheInterface,
184 * array, callable) Configures the retry mode and maximum number of
185 * allowed retries for a client (pass 0 to disable retries). Provide an
186 * integer for 'legacy' mode with the specified number of retries.
187 * Otherwise provide an instance of Aws\Retry\ConfigurationInterface, an
188 * instance of Aws\CacheInterface, a callable function, or an array with
189 * the following keys: mode: (string) Set to 'legacy', 'standard' (uses
190 * retry quota management), or 'adapative' (an experimental mode that adds
191 * client-side rate limiting to standard mode); max_attempts (int) The
192 * maximum number of attempts for a given request.
193 * - scheme: (string, default=string(5) "https") URI scheme to use when
194 * connecting connect. The SDK will utilize "https" endpoints (i.e.,
195 * utilize SSL/TLS connections) by default. You can attempt to connect to
196 * a service over an unencrypted "http" endpoint by setting ``scheme`` to
197 * "http".
198 * - signature_provider: (callable) A callable that accepts a signature
199 * version name (e.g., "v4"), a service name, and region, and
200 * returns a SignatureInterface object or null. This provider is used to
201 * create signers utilized by the client. See
202 * Aws\Signature\SignatureProvider for a list of built-in providers
203 * - signature_version: (string) A string representing a custom
204 * signature version to use with a service (e.g., v4). Note that
205 * per/operation signature version MAY override this requested signature
206 * version.
207 * - use_aws_shared_config_files: (bool, default=bool(true)) Set to false to
208 * disable checking for shared config file in '~/.aws/config' and
209 * '~/.aws/credentials'. This will override the AWS_CONFIG_FILE
210 * environment variable.
211 * - validate: (bool, default=bool(true)) Set to false to disable
212 * client-side parameter validation.
213 * - version: (string, required) The version of the webservice to
214 * utilize (e.g., 2006-03-01).
215 * - account_id_endpoint_mode: (string, default(preferred)) this option
216 * decides whether credentials should resolve an accountId value,
217 * which is going to be used as part of the endpoint resolution.
218 * The valid values for this option are:
219 * - preferred: when this value is set then, a warning is logged when
220 * accountId is empty in the resolved identity.
221 * - required: when this value is set then, an exception is thrown when
222 * accountId is empty in the resolved identity.
223 * - disabled: when this value is set then, the validation for if accountId
224 * was resolved or not, is ignored.
225 * - ua_append: (string, array) To pass custom user agent parameters.
226 * - app_id: (string) an optional application specific identifier that can be set.
227 * When set it will be appended to the User-Agent header of every request
228 * in the form of App/{AppId}. This variable is sourced from environment
229 * variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
230 * See https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html for
231 * more information on environment variables and shared config settings.
232 *
233 * @param array $args Client configuration arguments.
234 *
235 * @throws \InvalidArgumentException if any required options are missing or
236 * the service is not supported.
237 */
238 public function __construct(array $args)
239 {
240 list($service, $exceptionClass) = $this->parseClass();
241 if (!isset($args['service'])) {
242 $args['service'] = manifest($service)['endpoint'];
243 }
244 if (!isset($args['exception_class'])) {
245 $args['exception_class'] = $exceptionClass;
246 }
247 $this->handlerList = new HandlerList();
248 $resolver = new ClientResolver(static::getArguments());
249 $config = $resolver->resolve($args, $this->handlerList);
250 $this->api = $config['api'];
251 $this->signatureProvider = $config['signature_provider'];
252 $this->authSchemeResolver = $config['auth_scheme_resolver'];
253 $this->endpoint = new Uri($config['endpoint']);
254 $this->credentialProvider = $config['credentials'];
255 $this->tokenProvider = $config['token'];
256 $this->region = $config['region'] ?? null;
257 $this->signingRegionSet = $config['sigv4a_signing_region_set'] ?? null;
258 $this->config = $config['config'];
259 $this->setClientBuiltIns($args, $config);
260 $this->clientContextParams = $this->setClientContextParams($args);
261 $this->defaultRequestOptions = $config['http'];
262 $this->endpointProvider = $config['endpoint_provider'];
263 $this->serializer = $config['serializer'];
264 $this->addSignatureMiddleware($args);
265 $this->addInvocationId();
266 $this->addEndpointParameterMiddleware($args);
267 $this->addEndpointDiscoveryMiddleware($config, $args);
268 $this->addRequestCompressionMiddleware($config);
269 $this->loadAliases();
270 $this->addStreamRequestPayload();
271 $this->addRecursionDetection();
272 if ($this->isUseEndpointV2()) {
273 $this->addEndpointV2Middleware();
274 }
275 $this->addAuthSelectionMiddleware($config['config']);
276
277 if (!is_null($this->api->getMetadata('awsQueryCompatible'))) {
278 $this->addQueryCompatibleInputMiddleware($this->api);
279 $this->addQueryModeHeader();
280 }
281
282 if (isset($args['with_resolved'])) {
283 $args['with_resolved']($config);
284 }
285 $this->addUserAgentMiddleware($config);
286 $this->addEventStreamHttpFlagMiddleware();
287 }
288
289 public function getHandlerList()
290 {
291 return $this->handlerList;
292 }
293
294 public function getConfig($option = null)
295 {
296 return $option === null
297 ? $this->config
298 : $this->config[$option] ?? null;
299 }
300
301 public function getCredentials()
302 {
303 $fn = $this->credentialProvider;
304 return $fn();
305 }
306
307 public function getToken()
308 {
309 $fn = $this->tokenProvider;
310 return $fn();
311 }
312
313
314 public function getEndpoint()
315 {
316 return $this->endpoint;
317 }
318
319 public function getRegion()
320 {
321 return $this->region;
322 }
323
324 public function getApi()
325 {
326 return $this->api;
327 }
328
329 public function getCommand($name, array $args = [])
330 {
331 // Fail fast if the command cannot be found in the description.
332 if (!isset($this->getApi()['operations'][$name])) {
333 $name = ucfirst($name);
334 if (!isset($this->getApi()['operations'][$name])) {
335 throw new \InvalidArgumentException("Operation not found: $name");
336 }
337 }
338
339 if (!isset($args['@http'])) {
340 $args['@http'] = $this->defaultRequestOptions;
341 } else {
342 $args['@http'] += $this->defaultRequestOptions;
343 }
344
345 return new Command($name, $args, clone $this->getHandlerList());
346 }
347
348 public function getEndpointProvider()
349 {
350 return $this->endpointProvider;
351 }
352
353 /**
354 * Provides the set of service context parameter
355 * key-value pairs used for endpoint resolution.
356 *
357 * @return array
358 */
359 public function getClientContextParams()
360 {
361 return $this->clientContextParams;
362 }
363
364 /**
365 * Provides the set of built-in keys and values
366 * used for endpoint resolution
367 *
368 * @return array
369 */
370 public function getClientBuiltIns()
371 {
372 return $this->clientBuiltIns;
373 }
374
375 public function __sleep()
376 {
377 throw new \RuntimeException('Instances of ' . static::class
378 . ' cannot be serialized');
379 }
380
381 /**
382 * Get the signature_provider function of the client.
383 *
384 * @return callable
385 */
386 final public function getSignatureProvider()
387 {
388 return $this->signatureProvider;
389 }
390
391 /**
392 * Parse the class name and setup the custom exception class of the client
393 * and return the "service" name of the client and "exception_class".
394 *
395 * @return array
396 */
397 private function parseClass()
398 {
399 $klass = get_class($this);
400
401 if ($klass === __CLASS__) {
402 return ['', AwsException::class];
403 }
404
405 $service = substr($klass, strrpos($klass, '\\') + 1, -6);
406
407 return [
408 strtolower($service),
409 "Aws\\{$service}\\Exception\\{$service}Exception"
410 ];
411 }
412
413 private function addEndpointParameterMiddleware($args)
414 {
415 if (empty($args['disable_host_prefix_injection'])) {
416 $list = $this->getHandlerList();
417 $list->appendBuild(
418 EndpointParameterMiddleware::wrap(
419 $this->api
420 ),
421 'endpoint_parameter'
422 );
423 }
424 }
425
426 private function addEndpointDiscoveryMiddleware($config, $args)
427 {
428 $list = $this->getHandlerList();
429
430 if (!isset($args['endpoint'])) {
431 $list->appendBuild(
432 EndpointDiscoveryMiddleware::wrap(
433 $this,
434 $args,
435 $config['endpoint_discovery']
436 ),
437 'EndpointDiscoveryMiddleware'
438 );
439 }
440 }
441
442 private function addSignatureMiddleware(array $args)
443 {
444 $api = $this->getApi();
445 $provider = $this->signatureProvider;
446 $signatureVersion = $this->config['signature_version'];
447 $name = $this->config['signing_name'];
448 $region = $this->config['signing_region'];
449 $signingRegionSet = $this->signingRegionSet;
450
451 if (isset($args['signature_version'])
452 || isset($this->config['configured_signature_version'])
453 ) {
454 $configuredSignatureVersion = true;
455 } else {
456 $configuredSignatureVersion = false;
457 }
458
459 $resolver = static function (
460 CommandInterface $command
461 ) use (
462 $api,
463 $provider,
464 $name,
465 $region,
466 $signatureVersion,
467 $configuredSignatureVersion,
468 $signingRegionSet
469 ) {
470 if (!$configuredSignatureVersion) {
471 if (!empty($command['@context']['signing_region'])) {
472 $region = $command['@context']['signing_region'];
473 }
474 if (!empty($command['@context']['signing_service'])) {
475 $name = $command['@context']['signing_service'];
476 }
477 if (!empty($command['@context']['signature_version'])) {
478 $signatureVersion = $command['@context']['signature_version'];
479 }
480
481 $authType = $api->getOperation($command->getName())['authtype'];
482 switch ($authType){
483 case 'none':
484 $signatureVersion = 'anonymous';
485 break;
486 case 'v4-unsigned-body':
487 $signatureVersion = 'v4-unsigned-body';
488 break;
489 case 'bearer':
490 $signatureVersion = 'bearer';
491 break;
492 }
493 }
494
495 if ($signatureVersion === 'v4a') {
496 $commandSigningRegionSet = !empty($command['@context']['signing_region_set'])
497 ? implode(', ', $command['@context']['signing_region_set'])
498 : null;
499
500 $region = $signingRegionSet
501 ?? $commandSigningRegionSet
502 ?? $region;
503 }
504
505 // Capture signature metric
506 $command->getMetricsBuilder()->identifyMetricByValueAndAppend(
507 'signature',
508 $signatureVersion
509 );
510
511 return SignatureProvider::resolve($provider, $signatureVersion, $name, $region);
512 };
513 $this->handlerList->appendSign(
514 Middleware::signer($this->credentialProvider,
515 $resolver,
516 $this->tokenProvider,
517 $this->getConfig()
518 ),
519 'signer'
520 );
521 }
522
523 private function addRequestCompressionMiddleware($config)
524 {
525 if (empty($config['disable_request_compression'])) {
526 $list = $this->getHandlerList();
527 $list->appendBuild(
528 RequestCompressionMiddleware::wrap($config),
529 'request-compression'
530 );
531 }
532 }
533
534 private function addQueryCompatibleInputMiddleware(Service $api)
535 {
536 $list = $this->getHandlerList();
537 $list->appendValidate(
538 QueryCompatibleInputMiddleware::wrap($api),
539 'query-compatible-input'
540 );
541 }
542
543 private function addQueryModeHeader(): void
544 {
545 $list = $this->getHandlerList();
546 $list->appendBuild(
547 Middleware::mapRequest(static function (RequestInterface $r) {
548 return $r->withHeader(
549 'x-amzn-query-mode',
550 "true"
551 );
552 }),
553 'x-amzn-query-mode-header'
554 );
555 }
556
557 private function addInvocationId()
558 {
559 // Add invocation id to each request
560 $this->handlerList->prependSign(Middleware::invocationId(), 'invocation-id');
561 }
562
563 private function loadAliases($file = null)
564 {
565 if (!isset($this->aliases)) {
566 if (is_null($file)) {
567 $file = __DIR__ . '/data/aliases.json';
568 }
569 $aliases = \Aws\load_compiled_json($file);
570 $serviceId = $this->api->getServiceId();
571 $version = $this->getApi()->getApiVersion();
572 $serviceAliases = null;
573
574 if (!is_null($serviceId) && isset($aliases['operations'][$serviceId])) {
575 $serviceAliases = $aliases['operations'][$serviceId];
576 }
577
578 if ($serviceAliases && isset($serviceAliases[$version])) {
579 $this->aliases = array_flip($serviceAliases[$version]);
580 }
581 }
582 }
583
584 private function addStreamRequestPayload()
585 {
586 $streamRequestPayloadMiddleware = StreamRequestPayloadMiddleware::wrap(
587 $this->api
588 );
589
590 $this->handlerList->prependSign(
591 $streamRequestPayloadMiddleware,
592 'StreamRequestPayloadMiddleware'
593 );
594 }
595
596 private function addRecursionDetection()
597 {
598 // Add recursion detection header to requests
599 // originating in supported Lambda runtimes
600 $this->handlerList->appendBuild(
601 Middleware::recursionDetection(), 'recursion-detection'
602 );
603 }
604
605 private function addAuthSelectionMiddleware(array $args)
606 {
607 $list = $this->getHandlerList();
608
609 $list->prependBuild(
610 AuthSelectionMiddleware::wrap(
611 $this->authSchemeResolver,
612 $this->getApi(),
613 $args['auth_scheme_preference'] ?? null
614 ),
615 'auth-selection'
616 );
617 }
618
619 private function addEndpointV2Middleware()
620 {
621 $list = $this->getHandlerList();
622 $endpointArgs = $this->getEndpointProviderArgs();
623
624 $list->prependBuild(
625 EndpointV2Middleware::wrap(
626 $this->endpointProvider,
627 $this->getApi(),
628 $endpointArgs,
629 $this->credentialProvider
630 ),
631 'endpoint-resolution'
632 );
633 }
634
635 /**
636 * Appends the user agent middleware.
637 * This middleware MUST be appended after the
638 * signature middleware `addSignatureMiddleware`,
639 * so that metrics around signatures are properly
640 * captured.
641 *
642 * @param $args
643 * @return void
644 */
645 private function addUserAgentMiddleware($args)
646 {
647 $this->getHandlerList()->appendSign(
648 UserAgentMiddleware::wrap($args),
649 'user-agent'
650 );
651 }
652
653 /**
654 * Enables streaming the response by using the stream flag.
655 *
656 * @return void
657 */
658 private function addEventStreamHttpFlagMiddleware(): void
659 {
660 $api = $this->getApi();
661 $this->getHandlerList()
662 -> appendInit(
663 static function (callable $handler) use ($api) {
664 return static function (CommandInterface $command, $request = null) use ($handler, $api) {
665 $operation = $api->getOperation($command->getName());
666 $output = $operation->getOutput();
667 foreach ($output->getMembers() as $memberProps) {
668 if (!empty($memberProps['eventstream'])) {
669 $command['@http']['stream'] = true;
670 break;
671 }
672 }
673
674 return $handler($command, $request);
675 };
676 },
677 'event-streaming-flag-middleware'
678 );
679 }
680
681 /**
682 * Retrieves client context param definition from service model,
683 * creates mapping of client context param names with client-provided
684 * values.
685 *
686 * @return array
687 */
688 private function setClientContextParams($args)
689 {
690 $api = $this->getApi();
691 $resolvedParams = [];
692 if (!empty($paramDefinitions = $api->getClientContextParams())) {
693 foreach($paramDefinitions as $paramName => $paramValue) {
694 if (isset($args[$paramName])) {
695 $resolvedParams[$paramName] = $args[$paramName];
696 }
697 }
698 }
699 return $resolvedParams;
700 }
701
702 /**
703 * Retrieves and sets default values used for endpoint resolution.
704 */
705 private function setClientBuiltIns($args, $resolvedConfig)
706 {
707 $builtIns = [];
708 $config = $resolvedConfig['config'];
709 $service = $args['service'];
710
711 $builtIns['SDK::Endpoint'] = null;
712 if (!empty($args['endpoint'])) {
713 $builtIns['SDK::Endpoint'] = $args['endpoint'];
714 } elseif (isset($config['configured_endpoint_url'])) {
715 $builtIns['SDK::Endpoint'] = (string) $this->getEndpoint();
716 }
717 $builtIns['AWS::Region'] = $this->getRegion();
718 $builtIns['AWS::UseFIPS'] = $config['use_fips_endpoint']->isUseFipsEndpoint();
719 $builtIns['AWS::UseDualStack'] = $config['use_dual_stack_endpoint']->isUseDualstackEndpoint();
720 if ($service === 's3' || $service === 's3control'){
721 $builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
722 }
723 if ($service === 's3') {
724 $builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
725 $builtIns['AWS::S3::Accelerate'] = $config['use_accelerate_endpoint'];
726 $builtIns['AWS::S3::ForcePathStyle'] = $config['use_path_style_endpoint'];
727 $builtIns['AWS::S3::DisableMultiRegionAccessPoints'] = $config['disable_multiregion_access_points'];
728 }
729 $builtIns['AWS::Auth::AccountIdEndpointMode'] = $resolvedConfig['account_id_endpoint_mode'];
730
731 $this->clientBuiltIns += $builtIns;
732 }
733
734 /**
735 * Retrieves arguments to be used in endpoint resolution.
736 *
737 * @return array
738 */
739 public function getEndpointProviderArgs()
740 {
741 return $this->normalizeEndpointProviderArgs();
742 }
743
744 /**
745 * Combines built-in and client context parameter values in
746 * order of specificity. Client context parameter values supersede
747 * built-in values.
748 *
749 * @return array
750 */
751 private function normalizeEndpointProviderArgs()
752 {
753 $normalizedBuiltIns = [];
754
755 foreach($this->clientBuiltIns as $name => $value) {
756 $normalizedName = explode('::', $name);
757 $normalizedName = $normalizedName[count($normalizedName) - 1];
758 $normalizedBuiltIns[$normalizedName] = $value;
759 }
760
761 return array_merge($normalizedBuiltIns, $this->getClientContextParams());
762 }
763
764 protected function isUseEndpointV2()
765 {
766 return $this->endpointProvider instanceof EndpointProviderV2;
767 }
768
769
770 /**
771 * Returns a service model and doc model with any necessary changes
772 * applied.
773 *
774 * @param array $api Array of service data being documented.
775 * @param array $docs Array of doc model data.
776 *
777 * @return array Tuple containing a [Service, DocModel]
778 *
779 * @internal This should only used to document the service API.
780 * @codeCoverageIgnore
781 */
782 public static function applyDocFilters(array $api, array $docs)
783 {
784 $aliases = \Aws\load_compiled_json(__DIR__ . '/data/aliases.json');
785 $serviceId = $api['metadata']['serviceId'] ?? '';
786 $version = $api['metadata']['apiVersion'];
787
788 // Replace names for any operations with SDK aliases
789 if (!empty($aliases['operations'][$serviceId][$version])) {
790 foreach ($aliases['operations'][$serviceId][$version] as $op => $alias) {
791 $api['operations'][$alias] = $api['operations'][$op];
792 $docs['operations'][$alias] = $docs['operations'][$op];
793 unset($api['operations'][$op], $docs['operations'][$op]);
794 }
795 }
796 ksort($api['operations']);
797
798 return [
799 new Service($api, ApiProvider::defaultProvider()),
800 new DocModel($docs)
801 ];
802 }
803
804 /**
805 * @deprecated
806 * @return static
807 */
808 public static function factory(array $config = [])
809 {
810 return new static($config);
811 }
812 }