| 1 |
efrain |
1 |
<?php
|
|
|
2 |
namespace Aws;
|
|
|
3 |
|
|
|
4 |
use Aws\Api\ApiProvider;
|
|
|
5 |
use Aws\Api\DocModel;
|
|
|
6 |
use Aws\Api\Service;
|
| 1441 |
ariadna |
7 |
use Aws\Auth\AuthSelectionMiddleware;
|
|
|
8 |
use Aws\Auth\AuthSchemeResolverInterface;
|
| 1 |
efrain |
9 |
use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
|
|
|
10 |
use Aws\EndpointV2\EndpointProviderV2;
|
| 1441 |
ariadna |
11 |
use Aws\EndpointV2\EndpointV2Middleware;
|
| 1 |
efrain |
12 |
use Aws\Exception\AwsException;
|
|
|
13 |
use Aws\Signature\SignatureProvider;
|
|
|
14 |
use GuzzleHttp\Psr7\Uri;
|
| 1441 |
ariadna |
15 |
use Psr\Http\Message\RequestInterface;
|
| 1 |
efrain |
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 */
|
| 1441 |
ariadna |
34 |
private $signingRegionSet;
|
|
|
35 |
|
|
|
36 |
/** @var string */
|
| 1 |
efrain |
37 |
private $endpoint;
|
|
|
38 |
|
|
|
39 |
/** @var Service */
|
|
|
40 |
private $api;
|
|
|
41 |
|
|
|
42 |
/** @var callable */
|
|
|
43 |
private $signatureProvider;
|
|
|
44 |
|
| 1441 |
ariadna |
45 |
/** @var AuthSchemeResolverInterface */
|
|
|
46 |
private $authSchemeResolver;
|
|
|
47 |
|
| 1 |
efrain |
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).
|
| 1441 |
ariadna |
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.
|
| 1 |
efrain |
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'];
|
| 1441 |
ariadna |
252 |
$this->authSchemeResolver = $config['auth_scheme_resolver'];
|
| 1 |
efrain |
253 |
$this->endpoint = new Uri($config['endpoint']);
|
|
|
254 |
$this->credentialProvider = $config['credentials'];
|
|
|
255 |
$this->tokenProvider = $config['token'];
|
| 1441 |
ariadna |
256 |
$this->region = $config['region'] ?? null;
|
|
|
257 |
$this->signingRegionSet = $config['sigv4a_signing_region_set'] ?? null;
|
| 1 |
efrain |
258 |
$this->config = $config['config'];
|
| 1441 |
ariadna |
259 |
$this->setClientBuiltIns($args, $config);
|
| 1 |
efrain |
260 |
$this->clientContextParams = $this->setClientContextParams($args);
|
|
|
261 |
$this->defaultRequestOptions = $config['http'];
|
|
|
262 |
$this->endpointProvider = $config['endpoint_provider'];
|
|
|
263 |
$this->serializer = $config['serializer'];
|
| 1441 |
ariadna |
264 |
$this->addSignatureMiddleware($args);
|
| 1 |
efrain |
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();
|
| 1441 |
ariadna |
272 |
if ($this->isUseEndpointV2()) {
|
|
|
273 |
$this->addEndpointV2Middleware();
|
|
|
274 |
}
|
|
|
275 |
$this->addAuthSelectionMiddleware();
|
| 1 |
efrain |
276 |
|
| 1441 |
ariadna |
277 |
if (!is_null($this->api->getMetadata('awsQueryCompatible'))) {
|
|
|
278 |
$this->addQueryCompatibleInputMiddleware($this->api);
|
|
|
279 |
$this->addQueryModeHeader();
|
| 1 |
efrain |
280 |
}
|
|
|
281 |
|
|
|
282 |
if (isset($args['with_resolved'])) {
|
|
|
283 |
$args['with_resolved']($config);
|
|
|
284 |
}
|
| 1441 |
ariadna |
285 |
$this->addUserAgentMiddleware($config);
|
| 1 |
efrain |
286 |
}
|
|
|
287 |
|
|
|
288 |
public function getHandlerList()
|
|
|
289 |
{
|
|
|
290 |
return $this->handlerList;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
public function getConfig($option = null)
|
|
|
294 |
{
|
|
|
295 |
return $option === null
|
|
|
296 |
? $this->config
|
| 1441 |
ariadna |
297 |
: $this->config[$option] ?? null;
|
| 1 |
efrain |
298 |
}
|
|
|
299 |
|
|
|
300 |
public function getCredentials()
|
|
|
301 |
{
|
|
|
302 |
$fn = $this->credentialProvider;
|
|
|
303 |
return $fn();
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
public function getEndpoint()
|
|
|
308 |
{
|
|
|
309 |
return $this->endpoint;
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
public function getRegion()
|
|
|
313 |
{
|
|
|
314 |
return $this->region;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
public function getApi()
|
|
|
318 |
{
|
|
|
319 |
return $this->api;
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
public function getCommand($name, array $args = [])
|
|
|
323 |
{
|
|
|
324 |
// Fail fast if the command cannot be found in the description.
|
|
|
325 |
if (!isset($this->getApi()['operations'][$name])) {
|
|
|
326 |
$name = ucfirst($name);
|
|
|
327 |
if (!isset($this->getApi()['operations'][$name])) {
|
|
|
328 |
throw new \InvalidArgumentException("Operation not found: $name");
|
|
|
329 |
}
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
if (!isset($args['@http'])) {
|
|
|
333 |
$args['@http'] = $this->defaultRequestOptions;
|
|
|
334 |
} else {
|
|
|
335 |
$args['@http'] += $this->defaultRequestOptions;
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
return new Command($name, $args, clone $this->getHandlerList());
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
public function getEndpointProvider()
|
|
|
342 |
{
|
|
|
343 |
return $this->endpointProvider;
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
/**
|
|
|
347 |
* Provides the set of service context parameter
|
|
|
348 |
* key-value pairs used for endpoint resolution.
|
|
|
349 |
*
|
|
|
350 |
* @return array
|
|
|
351 |
*/
|
|
|
352 |
public function getClientContextParams()
|
|
|
353 |
{
|
|
|
354 |
return $this->clientContextParams;
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
/**
|
|
|
358 |
* Provides the set of built-in keys and values
|
|
|
359 |
* used for endpoint resolution
|
|
|
360 |
*
|
|
|
361 |
* @return array
|
|
|
362 |
*/
|
|
|
363 |
public function getClientBuiltIns()
|
|
|
364 |
{
|
|
|
365 |
return $this->clientBuiltIns;
|
|
|
366 |
}
|
|
|
367 |
|
|
|
368 |
public function __sleep()
|
|
|
369 |
{
|
|
|
370 |
throw new \RuntimeException('Instances of ' . static::class
|
|
|
371 |
. ' cannot be serialized');
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
/**
|
|
|
375 |
* Get the signature_provider function of the client.
|
|
|
376 |
*
|
|
|
377 |
* @return callable
|
|
|
378 |
*/
|
|
|
379 |
final public function getSignatureProvider()
|
|
|
380 |
{
|
|
|
381 |
return $this->signatureProvider;
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
/**
|
|
|
385 |
* Parse the class name and setup the custom exception class of the client
|
|
|
386 |
* and return the "service" name of the client and "exception_class".
|
|
|
387 |
*
|
|
|
388 |
* @return array
|
|
|
389 |
*/
|
|
|
390 |
private function parseClass()
|
|
|
391 |
{
|
|
|
392 |
$klass = get_class($this);
|
|
|
393 |
|
|
|
394 |
if ($klass === __CLASS__) {
|
|
|
395 |
return ['', AwsException::class];
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
$service = substr($klass, strrpos($klass, '\\') + 1, -6);
|
|
|
399 |
|
|
|
400 |
return [
|
|
|
401 |
strtolower($service),
|
|
|
402 |
"Aws\\{$service}\\Exception\\{$service}Exception"
|
|
|
403 |
];
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
private function addEndpointParameterMiddleware($args)
|
|
|
407 |
{
|
|
|
408 |
if (empty($args['disable_host_prefix_injection'])) {
|
|
|
409 |
$list = $this->getHandlerList();
|
|
|
410 |
$list->appendBuild(
|
|
|
411 |
EndpointParameterMiddleware::wrap(
|
|
|
412 |
$this->api
|
|
|
413 |
),
|
|
|
414 |
'endpoint_parameter'
|
|
|
415 |
);
|
|
|
416 |
}
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
private function addEndpointDiscoveryMiddleware($config, $args)
|
|
|
420 |
{
|
|
|
421 |
$list = $this->getHandlerList();
|
|
|
422 |
|
|
|
423 |
if (!isset($args['endpoint'])) {
|
|
|
424 |
$list->appendBuild(
|
|
|
425 |
EndpointDiscoveryMiddleware::wrap(
|
|
|
426 |
$this,
|
|
|
427 |
$args,
|
|
|
428 |
$config['endpoint_discovery']
|
|
|
429 |
),
|
|
|
430 |
'EndpointDiscoveryMiddleware'
|
|
|
431 |
);
|
|
|
432 |
}
|
|
|
433 |
}
|
|
|
434 |
|
| 1441 |
ariadna |
435 |
private function addSignatureMiddleware(array $args)
|
| 1 |
efrain |
436 |
{
|
|
|
437 |
$api = $this->getApi();
|
|
|
438 |
$provider = $this->signatureProvider;
|
| 1441 |
ariadna |
439 |
$signatureVersion = $this->config['signature_version'];
|
| 1 |
efrain |
440 |
$name = $this->config['signing_name'];
|
|
|
441 |
$region = $this->config['signing_region'];
|
| 1441 |
ariadna |
442 |
$signingRegionSet = $this->signingRegionSet;
|
| 1 |
efrain |
443 |
|
| 1441 |
ariadna |
444 |
if (isset($args['signature_version'])
|
|
|
445 |
|| isset($this->config['configured_signature_version'])
|
|
|
446 |
) {
|
|
|
447 |
$configuredSignatureVersion = true;
|
|
|
448 |
} else {
|
|
|
449 |
$configuredSignatureVersion = false;
|
|
|
450 |
}
|
|
|
451 |
|
| 1 |
efrain |
452 |
$resolver = static function (
|
| 1441 |
ariadna |
453 |
CommandInterface $command
|
|
|
454 |
) use (
|
|
|
455 |
$api,
|
|
|
456 |
$provider,
|
|
|
457 |
$name,
|
|
|
458 |
$region,
|
|
|
459 |
$signatureVersion,
|
|
|
460 |
$configuredSignatureVersion,
|
|
|
461 |
$signingRegionSet
|
|
|
462 |
) {
|
|
|
463 |
if (!$configuredSignatureVersion) {
|
|
|
464 |
if (!empty($command['@context']['signing_region'])) {
|
|
|
465 |
$region = $command['@context']['signing_region'];
|
|
|
466 |
}
|
|
|
467 |
if (!empty($command['@context']['signing_service'])) {
|
|
|
468 |
$name = $command['@context']['signing_service'];
|
|
|
469 |
}
|
|
|
470 |
if (!empty($command['@context']['signature_version'])) {
|
|
|
471 |
$signatureVersion = $command['@context']['signature_version'];
|
|
|
472 |
}
|
| 1 |
efrain |
473 |
|
| 1441 |
ariadna |
474 |
$authType = $api->getOperation($command->getName())['authtype'];
|
|
|
475 |
switch ($authType){
|
|
|
476 |
case 'none':
|
|
|
477 |
$signatureVersion = 'anonymous';
|
|
|
478 |
break;
|
|
|
479 |
case 'v4-unsigned-body':
|
|
|
480 |
$signatureVersion = 'v4-unsigned-body';
|
|
|
481 |
break;
|
|
|
482 |
case 'bearer':
|
|
|
483 |
$signatureVersion = 'bearer';
|
|
|
484 |
break;
|
| 1 |
efrain |
485 |
}
|
|
|
486 |
}
|
| 1441 |
ariadna |
487 |
|
|
|
488 |
if ($signatureVersion === 'v4a') {
|
|
|
489 |
$commandSigningRegionSet = !empty($command['@context']['signing_region_set'])
|
|
|
490 |
? implode(', ', $command['@context']['signing_region_set'])
|
|
|
491 |
: null;
|
|
|
492 |
|
|
|
493 |
$region = $signingRegionSet
|
|
|
494 |
?? $commandSigningRegionSet
|
|
|
495 |
?? $region;
|
| 1 |
efrain |
496 |
}
|
| 1441 |
ariadna |
497 |
|
|
|
498 |
// Capture signature metric
|
|
|
499 |
$command->getMetricsBuilder()->identifyMetricByValueAndAppend(
|
|
|
500 |
'signature',
|
|
|
501 |
$signatureVersion
|
|
|
502 |
);
|
|
|
503 |
|
|
|
504 |
return SignatureProvider::resolve($provider, $signatureVersion, $name, $region);
|
| 1 |
efrain |
505 |
};
|
|
|
506 |
$this->handlerList->appendSign(
|
| 1441 |
ariadna |
507 |
Middleware::signer($this->credentialProvider,
|
|
|
508 |
$resolver,
|
|
|
509 |
$this->tokenProvider,
|
|
|
510 |
$this->getConfig()
|
|
|
511 |
),
|
| 1 |
efrain |
512 |
'signer'
|
|
|
513 |
);
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
private function addRequestCompressionMiddleware($config)
|
|
|
517 |
{
|
|
|
518 |
if (empty($config['disable_request_compression'])) {
|
|
|
519 |
$list = $this->getHandlerList();
|
|
|
520 |
$list->appendBuild(
|
|
|
521 |
RequestCompressionMiddleware::wrap($config),
|
|
|
522 |
'request-compression'
|
|
|
523 |
);
|
|
|
524 |
}
|
|
|
525 |
}
|
|
|
526 |
|
| 1441 |
ariadna |
527 |
private function addQueryCompatibleInputMiddleware(Service $api)
|
|
|
528 |
{
|
|
|
529 |
$list = $this->getHandlerList();
|
|
|
530 |
$list->appendValidate(
|
|
|
531 |
QueryCompatibleInputMiddleware::wrap($api),
|
|
|
532 |
'query-compatible-input'
|
|
|
533 |
);
|
|
|
534 |
}
|
|
|
535 |
|
|
|
536 |
private function addQueryModeHeader(): void
|
|
|
537 |
{
|
|
|
538 |
$list = $this->getHandlerList();
|
|
|
539 |
$list->appendBuild(
|
|
|
540 |
Middleware::mapRequest(function (RequestInterface $r) {
|
|
|
541 |
return $r->withHeader(
|
|
|
542 |
'x-amzn-query-mode',
|
|
|
543 |
true
|
|
|
544 |
);
|
|
|
545 |
}),
|
|
|
546 |
'x-amzn-query-mode-header'
|
|
|
547 |
);
|
|
|
548 |
}
|
|
|
549 |
|
| 1 |
efrain |
550 |
private function addInvocationId()
|
|
|
551 |
{
|
|
|
552 |
// Add invocation id to each request
|
|
|
553 |
$this->handlerList->prependSign(Middleware::invocationId(), 'invocation-id');
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
private function loadAliases($file = null)
|
|
|
557 |
{
|
|
|
558 |
if (!isset($this->aliases)) {
|
|
|
559 |
if (is_null($file)) {
|
|
|
560 |
$file = __DIR__ . '/data/aliases.json';
|
|
|
561 |
}
|
|
|
562 |
$aliases = \Aws\load_compiled_json($file);
|
|
|
563 |
$serviceId = $this->api->getServiceId();
|
|
|
564 |
$version = $this->getApi()->getApiVersion();
|
|
|
565 |
if (!empty($aliases['operations'][$serviceId][$version])) {
|
|
|
566 |
$this->aliases = array_flip($aliases['operations'][$serviceId][$version]);
|
|
|
567 |
}
|
|
|
568 |
}
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
private function addStreamRequestPayload()
|
|
|
572 |
{
|
|
|
573 |
$streamRequestPayloadMiddleware = StreamRequestPayloadMiddleware::wrap(
|
|
|
574 |
$this->api
|
|
|
575 |
);
|
|
|
576 |
|
|
|
577 |
$this->handlerList->prependSign(
|
|
|
578 |
$streamRequestPayloadMiddleware,
|
|
|
579 |
'StreamRequestPayloadMiddleware'
|
|
|
580 |
);
|
|
|
581 |
}
|
|
|
582 |
|
|
|
583 |
private function addRecursionDetection()
|
|
|
584 |
{
|
|
|
585 |
// Add recursion detection header to requests
|
|
|
586 |
// originating in supported Lambda runtimes
|
|
|
587 |
$this->handlerList->appendBuild(
|
|
|
588 |
Middleware::recursionDetection(), 'recursion-detection'
|
|
|
589 |
);
|
|
|
590 |
}
|
|
|
591 |
|
| 1441 |
ariadna |
592 |
private function addAuthSelectionMiddleware()
|
| 1 |
efrain |
593 |
{
|
| 1441 |
ariadna |
594 |
$list = $this->getHandlerList();
|
|
|
595 |
|
|
|
596 |
$list->prependBuild(
|
|
|
597 |
AuthSelectionMiddleware::wrap(
|
|
|
598 |
$this->authSchemeResolver,
|
|
|
599 |
$this->getApi()
|
|
|
600 |
),
|
|
|
601 |
'auth-selection'
|
|
|
602 |
);
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
private function addEndpointV2Middleware()
|
|
|
606 |
{
|
|
|
607 |
$list = $this->getHandlerList();
|
| 1 |
efrain |
608 |
$endpointArgs = $this->getEndpointProviderArgs();
|
|
|
609 |
|
| 1441 |
ariadna |
610 |
$list->prependBuild(
|
|
|
611 |
EndpointV2Middleware::wrap(
|
|
|
612 |
$this->endpointProvider,
|
|
|
613 |
$this->getApi(),
|
|
|
614 |
$endpointArgs,
|
|
|
615 |
$this->credentialProvider
|
| 1 |
efrain |
616 |
),
|
| 1441 |
ariadna |
617 |
'endpoint-resolution'
|
| 1 |
efrain |
618 |
);
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
/**
|
| 1441 |
ariadna |
622 |
* Appends the user agent middleware.
|
|
|
623 |
* This middleware MUST be appended after the
|
|
|
624 |
* signature middleware `addSignatureMiddleware`,
|
|
|
625 |
* so that metrics around signatures are properly
|
|
|
626 |
* captured.
|
|
|
627 |
*
|
|
|
628 |
* @param $args
|
|
|
629 |
* @return void
|
|
|
630 |
*/
|
|
|
631 |
private function addUserAgentMiddleware($args)
|
|
|
632 |
{
|
|
|
633 |
$this->getHandlerList()->appendSign(
|
|
|
634 |
UserAgentMiddleware::wrap($args),
|
|
|
635 |
'user-agent'
|
|
|
636 |
);
|
|
|
637 |
}
|
|
|
638 |
|
|
|
639 |
/**
|
| 1 |
efrain |
640 |
* Retrieves client context param definition from service model,
|
|
|
641 |
* creates mapping of client context param names with client-provided
|
|
|
642 |
* values.
|
|
|
643 |
*
|
|
|
644 |
* @return array
|
|
|
645 |
*/
|
|
|
646 |
private function setClientContextParams($args)
|
|
|
647 |
{
|
|
|
648 |
$api = $this->getApi();
|
|
|
649 |
$resolvedParams = [];
|
|
|
650 |
if (!empty($paramDefinitions = $api->getClientContextParams())) {
|
|
|
651 |
foreach($paramDefinitions as $paramName => $paramValue) {
|
|
|
652 |
if (isset($args[$paramName])) {
|
| 1441 |
ariadna |
653 |
$resolvedParams[$paramName] = $args[$paramName];
|
| 1 |
efrain |
654 |
}
|
|
|
655 |
}
|
|
|
656 |
}
|
|
|
657 |
return $resolvedParams;
|
|
|
658 |
}
|
|
|
659 |
|
|
|
660 |
/**
|
|
|
661 |
* Retrieves and sets default values used for endpoint resolution.
|
|
|
662 |
*/
|
| 1441 |
ariadna |
663 |
private function setClientBuiltIns($args, $resolvedConfig)
|
| 1 |
efrain |
664 |
{
|
|
|
665 |
$builtIns = [];
|
| 1441 |
ariadna |
666 |
$config = $resolvedConfig['config'];
|
| 1 |
efrain |
667 |
$service = $args['service'];
|
|
|
668 |
|
| 1441 |
ariadna |
669 |
$builtIns['SDK::Endpoint'] = null;
|
|
|
670 |
if (!empty($args['endpoint'])) {
|
|
|
671 |
$builtIns['SDK::Endpoint'] = $args['endpoint'];
|
|
|
672 |
} elseif (isset($config['configured_endpoint_url'])) {
|
|
|
673 |
$builtIns['SDK::Endpoint'] = (string) $this->getEndpoint();
|
|
|
674 |
}
|
| 1 |
efrain |
675 |
$builtIns['AWS::Region'] = $this->getRegion();
|
|
|
676 |
$builtIns['AWS::UseFIPS'] = $config['use_fips_endpoint']->isUseFipsEndpoint();
|
|
|
677 |
$builtIns['AWS::UseDualStack'] = $config['use_dual_stack_endpoint']->isUseDualstackEndpoint();
|
|
|
678 |
if ($service === 's3' || $service === 's3control'){
|
|
|
679 |
$builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
|
|
|
680 |
}
|
|
|
681 |
if ($service === 's3') {
|
|
|
682 |
$builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
|
|
|
683 |
$builtIns['AWS::S3::Accelerate'] = $config['use_accelerate_endpoint'];
|
|
|
684 |
$builtIns['AWS::S3::ForcePathStyle'] = $config['use_path_style_endpoint'];
|
|
|
685 |
$builtIns['AWS::S3::DisableMultiRegionAccessPoints'] = $config['disable_multiregion_access_points'];
|
|
|
686 |
}
|
| 1441 |
ariadna |
687 |
$builtIns['AWS::Auth::AccountIdEndpointMode'] = $resolvedConfig['account_id_endpoint_mode'];
|
|
|
688 |
|
| 1 |
efrain |
689 |
$this->clientBuiltIns += $builtIns;
|
|
|
690 |
}
|
|
|
691 |
|
|
|
692 |
/**
|
|
|
693 |
* Retrieves arguments to be used in endpoint resolution.
|
|
|
694 |
*
|
|
|
695 |
* @return array
|
|
|
696 |
*/
|
|
|
697 |
public function getEndpointProviderArgs()
|
|
|
698 |
{
|
|
|
699 |
return $this->normalizeEndpointProviderArgs();
|
|
|
700 |
}
|
|
|
701 |
|
|
|
702 |
/**
|
|
|
703 |
* Combines built-in and client context parameter values in
|
|
|
704 |
* order of specificity. Client context parameter values supersede
|
|
|
705 |
* built-in values.
|
|
|
706 |
*
|
|
|
707 |
* @return array
|
|
|
708 |
*/
|
|
|
709 |
private function normalizeEndpointProviderArgs()
|
|
|
710 |
{
|
|
|
711 |
$normalizedBuiltIns = [];
|
|
|
712 |
|
|
|
713 |
foreach($this->clientBuiltIns as $name => $value) {
|
|
|
714 |
$normalizedName = explode('::', $name);
|
|
|
715 |
$normalizedName = $normalizedName[count($normalizedName) - 1];
|
|
|
716 |
$normalizedBuiltIns[$normalizedName] = $value;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
return array_merge($normalizedBuiltIns, $this->getClientContextParams());
|
|
|
720 |
}
|
|
|
721 |
|
|
|
722 |
protected function isUseEndpointV2()
|
|
|
723 |
{
|
|
|
724 |
return $this->endpointProvider instanceof EndpointProviderV2;
|
|
|
725 |
}
|
|
|
726 |
|
|
|
727 |
public static function emitDeprecationWarning() {
|
| 1441 |
ariadna |
728 |
trigger_error(
|
|
|
729 |
"This method is deprecated. It will be removed in an upcoming release."
|
|
|
730 |
, E_USER_DEPRECATED
|
|
|
731 |
);
|
|
|
732 |
|
| 1 |
efrain |
733 |
$phpVersion = PHP_VERSION_ID;
|
|
|
734 |
if ($phpVersion < 70205) {
|
|
|
735 |
$phpVersionString = phpversion();
|
|
|
736 |
@trigger_error(
|
|
|
737 |
"This installation of the SDK is using PHP version"
|
|
|
738 |
. " {$phpVersionString}, which will be deprecated on August"
|
|
|
739 |
. " 15th, 2023. Please upgrade your PHP version to a minimum of"
|
|
|
740 |
. " 7.2.5 before then to continue receiving updates to the AWS"
|
|
|
741 |
. " SDK for PHP. To disable this warning, set"
|
|
|
742 |
. " suppress_php_deprecation_warning to true on the client constructor"
|
|
|
743 |
. " or set the environment variable AWS_SUPPRESS_PHP_DEPRECATION_WARNING"
|
|
|
744 |
. " to true.",
|
|
|
745 |
E_USER_DEPRECATED
|
|
|
746 |
);
|
|
|
747 |
}
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
|
|
|
751 |
/**
|
|
|
752 |
* Returns a service model and doc model with any necessary changes
|
|
|
753 |
* applied.
|
|
|
754 |
*
|
|
|
755 |
* @param array $api Array of service data being documented.
|
|
|
756 |
* @param array $docs Array of doc model data.
|
|
|
757 |
*
|
|
|
758 |
* @return array Tuple containing a [Service, DocModel]
|
|
|
759 |
*
|
|
|
760 |
* @internal This should only used to document the service API.
|
|
|
761 |
* @codeCoverageIgnore
|
|
|
762 |
*/
|
|
|
763 |
public static function applyDocFilters(array $api, array $docs)
|
|
|
764 |
{
|
|
|
765 |
$aliases = \Aws\load_compiled_json(__DIR__ . '/data/aliases.json');
|
| 1441 |
ariadna |
766 |
$serviceId = $api['metadata']['serviceId'] ?? '';
|
| 1 |
efrain |
767 |
$version = $api['metadata']['apiVersion'];
|
|
|
768 |
|
|
|
769 |
// Replace names for any operations with SDK aliases
|
|
|
770 |
if (!empty($aliases['operations'][$serviceId][$version])) {
|
|
|
771 |
foreach ($aliases['operations'][$serviceId][$version] as $op => $alias) {
|
|
|
772 |
$api['operations'][$alias] = $api['operations'][$op];
|
|
|
773 |
$docs['operations'][$alias] = $docs['operations'][$op];
|
|
|
774 |
unset($api['operations'][$op], $docs['operations'][$op]);
|
|
|
775 |
}
|
|
|
776 |
}
|
|
|
777 |
ksort($api['operations']);
|
|
|
778 |
|
|
|
779 |
return [
|
|
|
780 |
new Service($api, ApiProvider::defaultProvider()),
|
|
|
781 |
new DocModel($docs)
|
|
|
782 |
];
|
|
|
783 |
}
|
|
|
784 |
|
|
|
785 |
/**
|
|
|
786 |
* @deprecated
|
|
|
787 |
* @return static
|
|
|
788 |
*/
|
|
|
789 |
public static function factory(array $config = [])
|
|
|
790 |
{
|
|
|
791 |
return new static($config);
|
|
|
792 |
}
|
|
|
793 |
}
|