Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 6... Línea 6...
6
use Aws\Api\Service;
6
use Aws\Api\Service;
7
use Aws\AwsClient;
7
use Aws\AwsClient;
8
use Aws\CacheInterface;
8
use Aws\CacheInterface;
9
use Aws\ClientResolver;
9
use Aws\ClientResolver;
10
use Aws\Command;
10
use Aws\Command;
-
 
11
use Aws\CommandInterface;
-
 
12
use Aws\Configuration\ConfigurationResolver;
11
use Aws\Exception\AwsException;
13
use Aws\Exception\AwsException;
12
use Aws\HandlerList;
14
use Aws\HandlerList;
-
 
15
use Aws\Identity\S3\S3ExpressIdentityProvider;
13
use Aws\InputValidationMiddleware;
16
use Aws\InputValidationMiddleware;
14
use Aws\Middleware;
17
use Aws\Middleware;
-
 
18
use Aws\ResultInterface;
15
use Aws\Retry\QuotaManager;
19
use Aws\Retry\QuotaManager;
16
use Aws\RetryMiddleware;
20
use Aws\RetryMiddleware;
17
use Aws\ResultInterface;
-
 
18
use Aws\CommandInterface;
-
 
19
use Aws\RetryMiddlewareV2;
21
use Aws\RetryMiddlewareV2;
-
 
22
use Aws\S3\Parser\GetBucketLocationResultMutator;
-
 
23
use Aws\S3\Parser\S3Parser;
-
 
24
use Aws\S3\Parser\ValidateResponseChecksumResultMutator;
-
 
25
use Aws\S3\RegionalEndpoint\ConfigurationProvider;
20
use Aws\S3\UseArnRegion\Configuration;
26
use Aws\S3\UseArnRegion\Configuration;
21
use Aws\S3\UseArnRegion\ConfigurationInterface;
27
use Aws\S3\UseArnRegion\ConfigurationInterface;
22
use Aws\S3\UseArnRegion\ConfigurationProvider as UseArnRegionConfigurationProvider;
28
use Aws\S3\UseArnRegion\ConfigurationProvider as UseArnRegionConfigurationProvider;
23
use Aws\S3\RegionalEndpoint\ConfigurationProvider;
-
 
24
use GuzzleHttp\Exception\RequestException;
29
use GuzzleHttp\Exception\RequestException;
25
use GuzzleHttp\Promise\Promise;
-
 
26
use GuzzleHttp\Promise\PromiseInterface;
30
use GuzzleHttp\Promise\PromiseInterface;
27
use Psr\Http\Message\RequestInterface;
31
use Psr\Http\Message\RequestInterface;
Línea 28... Línea 32...
28
 
32
 
29
/**
33
/**
Línea 35... Línea 39...
35
 * @method \GuzzleHttp\Promise\Promise completeMultipartUploadAsync(array $args = [])
39
 * @method \GuzzleHttp\Promise\Promise completeMultipartUploadAsync(array $args = [])
36
 * @method \Aws\Result copyObject(array $args = [])
40
 * @method \Aws\Result copyObject(array $args = [])
37
 * @method \GuzzleHttp\Promise\Promise copyObjectAsync(array $args = [])
41
 * @method \GuzzleHttp\Promise\Promise copyObjectAsync(array $args = [])
38
 * @method \Aws\Result createBucket(array $args = [])
42
 * @method \Aws\Result createBucket(array $args = [])
39
 * @method \GuzzleHttp\Promise\Promise createBucketAsync(array $args = [])
43
 * @method \GuzzleHttp\Promise\Promise createBucketAsync(array $args = [])
-
 
44
 * @method \Aws\Result createBucketMetadataTableConfiguration(array $args = [])
-
 
45
 * @method \GuzzleHttp\Promise\Promise createBucketMetadataTableConfigurationAsync(array $args = [])
40
 * @method \Aws\Result createMultipartUpload(array $args = [])
46
 * @method \Aws\Result createMultipartUpload(array $args = [])
41
 * @method \GuzzleHttp\Promise\Promise createMultipartUploadAsync(array $args = [])
47
 * @method \GuzzleHttp\Promise\Promise createMultipartUploadAsync(array $args = [])
-
 
48
 * @method \Aws\Result createSession(array $args = [])
-
 
49
 * @method \GuzzleHttp\Promise\Promise createSessionAsync(array $args = [])
42
 * @method \Aws\Result deleteBucket(array $args = [])
50
 * @method \Aws\Result deleteBucket(array $args = [])
43
 * @method \GuzzleHttp\Promise\Promise deleteBucketAsync(array $args = [])
51
 * @method \GuzzleHttp\Promise\Promise deleteBucketAsync(array $args = [])
44
 * @method \Aws\Result deleteBucketAnalyticsConfiguration(array $args = [])
52
 * @method \Aws\Result deleteBucketAnalyticsConfiguration(array $args = [])
45
 * @method \GuzzleHttp\Promise\Promise deleteBucketAnalyticsConfigurationAsync(array $args = [])
53
 * @method \GuzzleHttp\Promise\Promise deleteBucketAnalyticsConfigurationAsync(array $args = [])
46
 * @method \Aws\Result deleteBucketCors(array $args = [])
54
 * @method \Aws\Result deleteBucketCors(array $args = [])
Línea 51... Línea 59...
51
 * @method \GuzzleHttp\Promise\Promise deleteBucketIntelligentTieringConfigurationAsync(array $args = [])
59
 * @method \GuzzleHttp\Promise\Promise deleteBucketIntelligentTieringConfigurationAsync(array $args = [])
52
 * @method \Aws\Result deleteBucketInventoryConfiguration(array $args = [])
60
 * @method \Aws\Result deleteBucketInventoryConfiguration(array $args = [])
53
 * @method \GuzzleHttp\Promise\Promise deleteBucketInventoryConfigurationAsync(array $args = [])
61
 * @method \GuzzleHttp\Promise\Promise deleteBucketInventoryConfigurationAsync(array $args = [])
54
 * @method \Aws\Result deleteBucketLifecycle(array $args = [])
62
 * @method \Aws\Result deleteBucketLifecycle(array $args = [])
55
 * @method \GuzzleHttp\Promise\Promise deleteBucketLifecycleAsync(array $args = [])
63
 * @method \GuzzleHttp\Promise\Promise deleteBucketLifecycleAsync(array $args = [])
-
 
64
 * @method \Aws\Result deleteBucketMetadataTableConfiguration(array $args = [])
-
 
65
 * @method \GuzzleHttp\Promise\Promise deleteBucketMetadataTableConfigurationAsync(array $args = [])
56
 * @method \Aws\Result deleteBucketMetricsConfiguration(array $args = [])
66
 * @method \Aws\Result deleteBucketMetricsConfiguration(array $args = [])
57
 * @method \GuzzleHttp\Promise\Promise deleteBucketMetricsConfigurationAsync(array $args = [])
67
 * @method \GuzzleHttp\Promise\Promise deleteBucketMetricsConfigurationAsync(array $args = [])
58
 * @method \Aws\Result deleteBucketOwnershipControls(array $args = [])
68
 * @method \Aws\Result deleteBucketOwnershipControls(array $args = [])
59
 * @method \GuzzleHttp\Promise\Promise deleteBucketOwnershipControlsAsync(array $args = [])
69
 * @method \GuzzleHttp\Promise\Promise deleteBucketOwnershipControlsAsync(array $args = [])
60
 * @method \Aws\Result deleteBucketPolicy(array $args = [])
70
 * @method \Aws\Result deleteBucketPolicy(array $args = [])
Línea 93... Línea 103...
93
 * @method \GuzzleHttp\Promise\Promise getBucketLifecycleConfigurationAsync(array $args = [])
103
 * @method \GuzzleHttp\Promise\Promise getBucketLifecycleConfigurationAsync(array $args = [])
94
 * @method \Aws\Result getBucketLocation(array $args = [])
104
 * @method \Aws\Result getBucketLocation(array $args = [])
95
 * @method \GuzzleHttp\Promise\Promise getBucketLocationAsync(array $args = [])
105
 * @method \GuzzleHttp\Promise\Promise getBucketLocationAsync(array $args = [])
96
 * @method \Aws\Result getBucketLogging(array $args = [])
106
 * @method \Aws\Result getBucketLogging(array $args = [])
97
 * @method \GuzzleHttp\Promise\Promise getBucketLoggingAsync(array $args = [])
107
 * @method \GuzzleHttp\Promise\Promise getBucketLoggingAsync(array $args = [])
-
 
108
 * @method \Aws\Result getBucketMetadataTableConfiguration(array $args = [])
-
 
109
 * @method \GuzzleHttp\Promise\Promise getBucketMetadataTableConfigurationAsync(array $args = [])
98
 * @method \Aws\Result getBucketMetricsConfiguration(array $args = [])
110
 * @method \Aws\Result getBucketMetricsConfiguration(array $args = [])
99
 * @method \GuzzleHttp\Promise\Promise getBucketMetricsConfigurationAsync(array $args = [])
111
 * @method \GuzzleHttp\Promise\Promise getBucketMetricsConfigurationAsync(array $args = [])
100
 * @method \Aws\Result getBucketNotification(array $args = [])
112
 * @method \Aws\Result getBucketNotification(array $args = [])
101
 * @method \GuzzleHttp\Promise\Promise getBucketNotificationAsync(array $args = [])
113
 * @method \GuzzleHttp\Promise\Promise getBucketNotificationAsync(array $args = [])
102
 * @method \Aws\Result getBucketNotificationConfiguration(array $args = [])
114
 * @method \Aws\Result getBucketNotificationConfiguration(array $args = [])
Línea 147... Línea 159...
147
 * @method \GuzzleHttp\Promise\Promise listBucketInventoryConfigurationsAsync(array $args = [])
159
 * @method \GuzzleHttp\Promise\Promise listBucketInventoryConfigurationsAsync(array $args = [])
148
 * @method \Aws\Result listBucketMetricsConfigurations(array $args = [])
160
 * @method \Aws\Result listBucketMetricsConfigurations(array $args = [])
149
 * @method \GuzzleHttp\Promise\Promise listBucketMetricsConfigurationsAsync(array $args = [])
161
 * @method \GuzzleHttp\Promise\Promise listBucketMetricsConfigurationsAsync(array $args = [])
150
 * @method \Aws\Result listBuckets(array $args = [])
162
 * @method \Aws\Result listBuckets(array $args = [])
151
 * @method \GuzzleHttp\Promise\Promise listBucketsAsync(array $args = [])
163
 * @method \GuzzleHttp\Promise\Promise listBucketsAsync(array $args = [])
-
 
164
 * @method \Aws\Result listDirectoryBuckets(array $args = [])
-
 
165
 * @method \GuzzleHttp\Promise\Promise listDirectoryBucketsAsync(array $args = [])
152
 * @method \Aws\Result listMultipartUploads(array $args = [])
166
 * @method \Aws\Result listMultipartUploads(array $args = [])
153
 * @method \GuzzleHttp\Promise\Promise listMultipartUploadsAsync(array $args = [])
167
 * @method \GuzzleHttp\Promise\Promise listMultipartUploadsAsync(array $args = [])
154
 * @method \Aws\Result listObjectVersions(array $args = [])
168
 * @method \Aws\Result listObjectVersions(array $args = [])
155
 * @method \GuzzleHttp\Promise\Promise listObjectVersionsAsync(array $args = [])
169
 * @method \GuzzleHttp\Promise\Promise listObjectVersionsAsync(array $args = [])
156
 * @method \Aws\Result listObjects(array $args = [])
170
 * @method \Aws\Result listObjects(array $args = [])
Línea 224... Línea 238...
224
 * @method \Aws\Result writeGetObjectResponse(array $args = [])
238
 * @method \Aws\Result writeGetObjectResponse(array $args = [])
225
 * @method \GuzzleHttp\Promise\Promise writeGetObjectResponseAsync(array $args = [])
239
 * @method \GuzzleHttp\Promise\Promise writeGetObjectResponseAsync(array $args = [])
226
 */
240
 */
227
class S3Client extends AwsClient implements S3ClientInterface
241
class S3Client extends AwsClient implements S3ClientInterface
228
{
242
{
-
 
243
    private const DIRECTORY_BUCKET_REGEX = '/^[a-zA-Z0-9_-]+--[a-z0-9]+-az\d+--x-s3'
-
 
244
                                            .'(?!.*(?:-s3alias|--ol-s3|\.mrap))$/';
229
    use S3ClientTrait;
245
    use S3ClientTrait;
Línea 230... Línea 246...
230
 
246
 
231
    /** @var array */
247
    /** @var array */
Línea -... Línea 248...
-
 
248
    private static $mandatoryAttributes = ['Bucket', 'Key'];
-
 
249
 
-
 
250
    /** @var array */
-
 
251
    private static $checksumOptionEnum = [
-
 
252
        'when_supported' => true,
-
 
253
        'when_required' => true
232
    private static $mandatoryAttributes = ['Bucket', 'Key'];
254
    ];
233
 
255
 
234
    public static function getArguments()
256
    public static function getArguments()
235
    {
257
    {
236
        $args = parent::getArguments();
258
        $args = parent::getArguments();
Línea 237... Línea 259...
237
        $args['retries']['fn'] = [__CLASS__, '_applyRetryConfig'];
259
        $args['retries']['fn'] = [__CLASS__, '_applyRetryConfig'];
-
 
260
        $args['api_provider']['fn'] = [__CLASS__, '_applyApiProvider'];
238
        $args['api_provider']['fn'] = [__CLASS__, '_applyApiProvider'];
261
 
239
 
262
        return
240
        return $args + [
263
            [
241
            'bucket_endpoint' => [
264
                'request_checksum_calculation' => [
242
                'type'    => 'config',
265
                    'type' => 'config',
243
                'valid'   => ['bool'],
266
                    'valid' => ['string'],
244
                'doc'     => 'Set to true to send requests to a hardcoded '
267
                    'doc' => 'Valid values are `when_supported` and `when_required`. Default is `when_supported`.'
245
                    . 'bucket endpoint rather than create an endpoint as a '
-
 
246
                    . 'result of injecting the bucket into the URL. This '
-
 
247
                    . 'option is useful for interacting with CNAME endpoints.',
-
 
248
            ],
-
 
249
            'use_arn_region' => [
-
 
250
                'type'    => 'config',
268
                        . ' `when_supported` results in checksum calculation when an operation has modeled checksum support.'
251
                'valid'   => [
269
                        . ' `when_required` results in checksum calculation when an operation has modeled checksum support and'
252
                    'bool',
-
 
253
                    Configuration::class,
270
                        . ' request checksums are modeled as required.',
-
 
271
                    'fn' => [__CLASS__, '_apply_request_checksum_calculation'],
-
 
272
                    'default' => [__CLASS__, '_default_request_checksum_calculation'],
-
 
273
                ],
-
 
274
                'response_checksum_validation' => [
-
 
275
                    'type' => 'config',
-
 
276
                    'valid' => ['string'],
-
 
277
                    'doc' => 'Valid values are `when_supported` and `when_required`. Default is `when_supported`.'
-
 
278
                        . ' `when_supported` results in checksum validation when an operation has modeled checksum support.'
-
 
279
                        . ' `when_required` results in checksum validation when an operation has modeled checksum support and'
-
 
280
                        . ' `CheckSumMode` is set to `enabled`.',
-
 
281
                    'fn' => [__CLASS__, '_apply_response_checksum_validation'],
-
 
282
                    'default' => [__CLASS__, '_default_response_checksum_validation'],
-
 
283
                ]
-
 
284
            ]
-
 
285
            + $args + [
-
 
286
                'bucket_endpoint' => [
-
 
287
                    'type'    => 'config',
-
 
288
                    'valid'   => ['bool'],
-
 
289
                    'doc'     => 'Set to true to send requests to a hardcoded '
-
 
290
                        . 'bucket endpoint rather than create an endpoint as a '
-
 
291
                        . 'result of injecting the bucket into the URL. This '
-
 
292
                        . 'option is useful for interacting with CNAME endpoints.',
-
 
293
                ],
-
 
294
                'use_arn_region' => [
-
 
295
                    'type'    => 'config',
-
 
296
                    'valid'   => [
-
 
297
                        'bool',
-
 
298
                        Configuration::class,
254
                    CacheInterface::class,
299
                        CacheInterface::class,
255
                    'callable'
300
                        'callable'
256
                ],
301
                    ],
257
                'doc'     => 'Set to true to allow passed in ARNs to override'
302
                    'doc'     => 'Set to true to allow passed in ARNs to override'
258
                    . ' client region. Accepts...',
303
                        . ' client region. Accepts...',
259
                'fn' => [__CLASS__, '_apply_use_arn_region'],
304
                    'fn' => [__CLASS__, '_apply_use_arn_region'],
260
                'default' => [UseArnRegionConfigurationProvider::class, 'defaultProvider'],
305
                    'default' => [UseArnRegionConfigurationProvider::class, 'defaultProvider'],
261
            ],
306
                ],
262
            'use_accelerate_endpoint' => [
307
                'use_accelerate_endpoint' => [
263
                'type' => 'config',
308
                    'type' => 'config',
264
                'valid' => ['bool'],
309
                    'valid' => ['bool'],
265
                'doc' => 'Set to true to send requests to an S3 Accelerate'
310
                    'doc' => 'Set to true to send requests to an S3 Accelerate'
266
                    . ' endpoint by default. Can be enabled or disabled on'
311
                        . ' endpoint by default. Can be enabled or disabled on'
267
                    . ' individual operations by setting'
312
                        . ' individual operations by setting'
268
                    . ' \'@use_accelerate_endpoint\' to true or false. Note:'
313
                        . ' \'@use_accelerate_endpoint\' to true or false. Note:'
269
                    . ' you must enable S3 Accelerate on a bucket before it can'
314
                        . ' you must enable S3 Accelerate on a bucket before it can'
270
                    . ' be accessed via an Accelerate endpoint.',
315
                        . ' be accessed via an Accelerate endpoint.',
271
                'default' => false,
316
                    'default' => false,
272
            ],
317
                ],
273
            'use_path_style_endpoint' => [
318
                'use_path_style_endpoint' => [
274
                'type' => 'config',
319
                    'type' => 'config',
275
                'valid' => ['bool'],
320
                    'valid' => ['bool'],
276
                'doc' => 'Set to true to send requests to an S3 path style'
321
                    'doc' => 'Set to true to send requests to an S3 path style'
277
                    . ' endpoint by default.'
322
                        . ' endpoint by default.'
278
                    . ' Can be enabled or disabled on individual operations by setting'
323
                        . ' Can be enabled or disabled on individual operations by setting'
279
                    . ' \'@use_path_style_endpoint\' to true or false.',
324
                        . ' \'@use_path_style_endpoint\' to true or false.',
280
                'default' => false,
325
                    'default' => false,
281
            ],
326
                ],
282
            'disable_multiregion_access_points' => [
327
                'disable_multiregion_access_points' => [
283
                'type' => 'config',
328
                    'type' => 'config',
284
                'valid' => ['bool'],
329
                    'valid' => ['bool'],
285
                'doc' => 'Set to true to disable the usage of'
330
                    'doc' => 'Set to true to disable the usage of'
286
                    . ' multi region access points. These are enabled by default.'
331
                        . ' multi region access points. These are enabled by default.'
-
 
332
                        . ' Can be enabled or disabled on individual operations by setting'
-
 
333
                        . ' \'@disable_multiregion_access_points\' to true or false.',
-
 
334
                    'default' => false,
-
 
335
                ],
-
 
336
                'disable_express_session_auth' => [
-
 
337
                    'type' => 'config',
-
 
338
                    'valid' => ['bool'],
-
 
339
                    'doc' => 'Set to true to disable the usage of'
-
 
340
                        . ' s3 express session authentication. This is enabled by default.',
-
 
341
                    'default' => [__CLASS__, '_default_disable_express_session_auth'],
-
 
342
                ],
-
 
343
                's3_express_identity_provider' => [
-
 
344
                    'type'    => 'config',
-
 
345
                    'valid'   => [
-
 
346
                        'bool',
-
 
347
                        'callable'
-
 
348
                    ],
-
 
349
                    'doc'     => 'Specifies the provider used to generate identities to sign s3 express requests.  '
287
                    . ' Can be enabled or disabled on individual operations by setting'
350
                        . 'Set to `false` to disable s3 express auth, or a callable provider used to create s3 express '
288
                    . ' \'@disable_multiregion_access_points\' to true or false.',
351
                        . 'identities or return null.',
289
                'default' => false,
352
                    'default' => [__CLASS__, '_default_s3_express_identity_provider'],
Línea 290... Línea 353...
290
            ],
353
            ],
Línea 356... Línea 419...
356
        }
419
        }
357
        $this->addBuiltIns($args);
420
        $this->addBuiltIns($args);
358
        parent::__construct($args);
421
        parent::__construct($args);
359
        $stack = $this->getHandlerList();
422
        $stack = $this->getHandlerList();
360
        $stack->appendInit(SSECMiddleware::wrap($this->getEndpoint()->getScheme()), 's3.ssec');
423
        $stack->appendInit(SSECMiddleware::wrap($this->getEndpoint()->getScheme()), 's3.ssec');
-
 
424
        $stack->appendBuild(
361
        $stack->appendBuild(ApplyChecksumMiddleware::wrap($this->getApi()), 's3.checksum');
425
            ApplyChecksumMiddleware::wrap($this->getApi(), $this->getConfig()),
-
 
426
            's3.checksum'
-
 
427
        );
362
        $stack->appendBuild(
428
        $stack->appendBuild(
363
            Middleware::contentType(['PutObject', 'UploadPart']),
429
            Middleware::contentType(['PutObject', 'UploadPart']),
364
            's3.content_type'
430
            's3.content_type'
365
        );
431
        );
Línea 395... Línea 461...
395
                    'dual_stack' =>
461
                    'dual_stack' =>
396
                        $this->getConfig('use_dual_stack_endpoint')->isUseDualStackEndpoint(),
462
                        $this->getConfig('use_dual_stack_endpoint')->isUseDualStackEndpoint(),
397
                    'use_fips_endpoint' => $this->getConfig('use_fips_endpoint'),
463
                    'use_fips_endpoint' => $this->getConfig('use_fips_endpoint'),
398
                    'disable_multiregion_access_points' =>
464
                    'disable_multiregion_access_points' =>
399
                        $this->getConfig('disable_multiregion_access_points'),
465
                        $this->getConfig('disable_multiregion_access_points'),
400
                    'endpoint' => isset($args['endpoint'])
466
                    'endpoint' => $args['endpoint'] ?? null
401
                        ? $args['endpoint']
-
 
402
                        : null
-
 
403
                ],
467
                ],
404
                $this->isUseEndpointV2()
468
                $this->isUseEndpointV2()
405
            ),
469
            ),
406
            's3.bucket_endpoint_arn'
470
            's3.bucket_endpoint_arn'
407
        );
471
        );
-
 
472
        if ($this->getConfig('disable_express_session_auth')) {
-
 
473
            $stack->prependSign(
-
 
474
                $this->getDisableExpressSessionAuthMiddleware(),
-
 
475
                's3.disable_express_session_auth'
-
 
476
            );
-
 
477
        }
Línea 408... Línea 478...
408
 
478
 
409
        $stack->appendValidate(
479
        $stack->appendValidate(
410
            InputValidationMiddleware::wrap($this->getApi(), self::$mandatoryAttributes),
480
            InputValidationMiddleware::wrap($this->getApi(), self::$mandatoryAttributes),
411
            'input_validation_middleware'
481
            'input_validation_middleware'
-
 
482
        );
412
        );
483
        $stack->appendSign(ExpiresParsingMiddleware::wrap(), 's3.expires_parsing');
413
        $stack->appendSign(PutObjectUrlMiddleware::wrap(), 's3.put_object_url');
484
        $stack->appendSign(PutObjectUrlMiddleware::wrap(), 's3.put_object_url');
414
        $stack->appendSign(PermanentRedirectMiddleware::wrap(), 's3.permanent_redirect');
485
        $stack->appendSign(PermanentRedirectMiddleware::wrap(), 's3.permanent_redirect');
415
        $stack->appendInit(Middleware::sourceFile($this->getApi()), 's3.source_file');
486
        $stack->appendInit(Middleware::sourceFile($this->getApi()), 's3.source_file');
416
        $stack->appendInit($this->getSaveAsParameter(), 's3.save_as');
487
        $stack->appendInit($this->getSaveAsParameter(), 's3.save_as');
417
        $stack->appendInit($this->getLocationConstraintMiddleware(), 's3.location');
488
        $stack->appendInit($this->getLocationConstraintMiddleware(), 's3.location');
418
        $stack->appendInit($this->getEncodingTypeMiddleware(), 's3.auto_encode');
489
        $stack->appendInit($this->getEncodingTypeMiddleware(), 's3.auto_encode');
-
 
490
        $stack->appendInit($this->getHeadObjectMiddleware(), 's3.head_object');
419
        $stack->appendInit($this->getHeadObjectMiddleware(), 's3.head_object');
491
        $this->processModel($this->isUseEndpointV2());
420
        if ($this->isUseEndpointV2()) {
-
 
421
            $this->processEndpointV2Model();
492
        if ($this->isUseEndpointV2()) {
422
            $stack->after('builderV2',
493
            $stack->after('builder',
423
                's3.check_empty_path_with_query',
494
                's3.check_empty_path_with_query',
424
                $this->getEmptyPathWithQuery());
495
                $this->getEmptyPathWithQuery());
425
        }
496
        }
Línea 466... Línea 537...
466
            // The Configuration class itself will validate other inputs
537
            // The Configuration class itself will validate other inputs
467
            $args['use_arn_region'] = new Configuration($value);
538
            $args['use_arn_region'] = new Configuration($value);
468
        }
539
        }
469
    }
540
    }
Línea -... Línea 541...
-
 
541
 
-
 
542
    public static function _default_request_checksum_calculation(array $args): string
-
 
543
    {
-
 
544
        return ConfigurationResolver::resolve(
-
 
545
            'request_checksum_calculation',
-
 
546
            ApplyChecksumMiddleware::DEFAULT_CALCULATION_MODE,
-
 
547
            'string',
-
 
548
            $args
-
 
549
        );
-
 
550
    }
-
 
551
 
-
 
552
    public static function _apply_request_checksum_calculation(
-
 
553
        string $value,
-
 
554
        array &$args
-
 
555
    ): void
-
 
556
    {
-
 
557
        $value = strtolower($value);
-
 
558
        if (array_key_exists($value, self::$checksumOptionEnum)) {
-
 
559
            $args['request_checksum_calculation'] = $value;
-
 
560
        } else {
-
 
561
            $validValues = implode(' | ', array_keys(self::$checksumOptionEnum));
-
 
562
            throw new \InvalidArgumentException(
-
 
563
                'invalid value provided for `request_checksum_calculation`.'
-
 
564
                . ' valid values are: ' . $validValues . '.'
-
 
565
            );
-
 
566
        }
-
 
567
    }
-
 
568
 
-
 
569
    public static function _default_response_checksum_validation(array $args): string
-
 
570
    {
-
 
571
        return ConfigurationResolver::resolve(
-
 
572
            'response_checksum_validation',
-
 
573
            ValidateResponseChecksumResultMutator::DEFAULT_VALIDATION_MODE,
-
 
574
            'string',
-
 
575
            $args
-
 
576
        );
-
 
577
    }
-
 
578
 
-
 
579
    public static function _apply_response_checksum_validation(
-
 
580
        $value,
-
 
581
        array &$args
-
 
582
    ): void
-
 
583
    {
-
 
584
        $value = strtolower($value);
-
 
585
        if (array_key_exists($value, self::$checksumOptionEnum)) {
-
 
586
            $args['response_checksum_validation'] = $value;
-
 
587
        } else {
-
 
588
            $validValues = implode(' | ', array_keys(self::$checksumOptionEnum));
-
 
589
            throw new \InvalidArgumentException(
-
 
590
                'invalid value provided for `response_checksum_validation`.'
-
 
591
                . ' valid values are: ' . $validValues . '.'
-
 
592
            );
-
 
593
        }
-
 
594
    }
-
 
595
 
-
 
596
    public static function _default_disable_express_session_auth(array &$args)
-
 
597
    {
-
 
598
        return ConfigurationResolver::resolve(
-
 
599
            's3_disable_express_session_auth',
-
 
600
            false,
-
 
601
            'bool',
-
 
602
            $args
-
 
603
        );
-
 
604
    }
-
 
605
 
-
 
606
    public static function _default_s3_express_identity_provider(array $args)
-
 
607
    {
-
 
608
        if ($args['config']['disable_express_session_auth']) {
-
 
609
            return false;
-
 
610
        }
-
 
611
        return new S3ExpressIdentityProvider($args['region']);
-
 
612
    }
470
 
613
 
471
    public function createPresignedRequest(CommandInterface $command, $expires, array $options = [])
614
    public function createPresignedRequest(CommandInterface $command, $expires, array $options = [])
472
    {
615
    {
-
 
616
        $command = clone $command;
473
        $command = clone $command;
617
        $list = $command->getHandlerList();
-
 
618
        $list->remove('signer');
-
 
619
 
-
 
620
        //Removes checksum calculation behavior by default
-
 
621
        if (empty($command['ChecksumAlgorithm'])
-
 
622
            && empty($command['AddContentMD5'])
-
 
623
        ) {
-
 
624
            $list->remove('s3.checksum');
-
 
625
        }
474
        $command->getHandlerList()->remove('signer');
626
 
-
 
627
        $request = \Aws\serialize($command);
-
 
628
 
-
 
629
        //Applies ContentSHA256 parameter, if provided and not applied
475
        $request = \Aws\serialize($command);
630
        // by middleware
-
 
631
        $commandName = $command->getName();
-
 
632
        if (!empty($command['ContentSHA256']
-
 
633
            && isset(ApplyChecksumMiddleware::$sha256[$commandName])
-
 
634
            && !$request->hasHeader('X-Amz-Content-Sha256')
476
        $signing_name = empty($command->getAuthSchemes())
635
        )) {
-
 
636
            $request = $request->withHeader(
477
            ? $this->getSigningName($request->getUri()->getHost())
637
                'X-Amz-Content-Sha256',
-
 
638
                $command['ContentSHA256']
-
 
639
            );
-
 
640
        }
478
            : $command->getAuthSchemes()['name'];
641
 
479
        $signature_version = empty($command->getAuthSchemes())
642
        $signing_name = $command['@context']['signing_service']
480
            ? $this->getConfig('signature_version')
643
            ?? $this->getSigningName($request->getUri()->getHost());
Línea 481... Línea 644...
481
            : $command->getAuthSchemes()['version'];
644
        $signature_version = $this->getSignatureVersionFromCommand($command);
482
 
645
 
483
        /** @var \Aws\Signature\SignatureInterface $signer */
646
        /** @var \Aws\Signature\SignatureInterface $signer */
484
        $signer = call_user_func(
647
        $signer = call_user_func(
485
            $this->getSignatureProvider(),
648
            $this->getSignatureProvider(),
486
            $signature_version,
649
            $signature_version,
487
            $signing_name,
650
            $signing_name,
-
 
651
            $this->getConfig('signing_region')
-
 
652
        );
-
 
653
        if ($signature_version == 'v4-s3express') {
-
 
654
            $provider = $this->getConfig('s3_express_identity_provider');
-
 
655
            $credentials = $provider($command)->wait();
488
            $this->getConfig('signing_region')
656
        } else {
489
        );
657
            $credentials = $this->getCredentials()->wait();
490
 
658
        }
491
        return $signer->presign(
659
        return $signer->presign(
492
            $request,
660
            $request,
493
            $this->getCredentials()->wait(),
661
            $credentials,
494
            $expires,
662
            $expires,
495
            $options
663
            $options
Línea 539... Línea 707...
539
    private function getLocationConstraintMiddleware()
707
    private function getLocationConstraintMiddleware()
540
    {
708
    {
541
        $region = $this->getRegion();
709
        $region = $this->getRegion();
542
        return static function (callable $handler) use ($region) {
710
        return static function (callable $handler) use ($region) {
543
            return function (Command $command, $request = null) use ($handler, $region) {
711
            return function (Command $command, $request = null) use ($handler, $region) {
544
                if ($command->getName() === 'CreateBucket') {
712
                if ($command->getName() === 'CreateBucket'
545
                    $locationConstraint = isset($command['CreateBucketConfiguration']['LocationConstraint'])
713
                    && !self::isDirectoryBucket($command['Bucket'])
-
 
714
                ) {
546
                        ? $command['CreateBucketConfiguration']['LocationConstraint']
715
                    $locationConstraint = $command['CreateBucketConfiguration']['LocationConstraint']
547
                        : null;
716
                        ?? null;
Línea 548... Línea 717...
548
 
717
 
549
                    if ($locationConstraint === 'us-east-1') {
718
                    if ($locationConstraint === 'us-east-1') {
550
                        unset($command['CreateBucketConfiguration']);
719
                        unset($command['CreateBucketConfiguration']);
-
 
720
                    } elseif ('us-east-1' !== $region && empty($locationConstraint)) {
-
 
721
                        if (isset($command['CreateBucketConfiguration'])) {
-
 
722
                            $command['CreateBucketConfiguration']['LocationConstraint'] = $region;
551
                    } elseif ('us-east-1' !== $region && empty($locationConstraint)) {
723
                        } else {
-
 
724
                            $command['CreateBucketConfiguration'] = ['LocationConstraint' => $region];
552
                        $command['CreateBucketConfiguration'] = ['LocationConstraint' => $region];
725
                        }
553
                    }
726
                    }
Línea 554... Línea 727...
554
                }
727
                }
555
 
728
 
Línea 586... Línea 759...
586
    private function getHeadObjectMiddleware()
759
    private function getHeadObjectMiddleware()
587
    {
760
    {
588
        return static function (callable $handler) {
761
        return static function (callable $handler) {
589
            return function (
762
            return function (
590
                CommandInterface $command,
763
                CommandInterface $command,
591
                RequestInterface $request = null
764
                ?RequestInterface $request = null
592
            ) use ($handler) {
765
            ) use ($handler) {
593
                if ($command->getName() === 'HeadObject'
766
                if ($command->getName() === 'HeadObject'
594
                    && !isset($command['@http']['decode_content'])
767
                    && !isset($command['@http']['decode_content'])
595
                ) {
768
                ) {
596
                    $command['@http']['decode_content'] = false;
769
                    $command['@http']['decode_content'] = false;
Línea 677... Línea 850...
677
            };
850
            };
678
        };
851
        };
679
    }
852
    }
Línea 680... Línea 853...
680
 
853
 
-
 
854
    /**
-
 
855
     * Provides a middleware that disables express session auth when
-
 
856
     * customers opt out of it.
-
 
857
     *
-
 
858
     * @return \Closure
-
 
859
     */
-
 
860
    private function getDisableExpressSessionAuthMiddleware()
-
 
861
    {
-
 
862
        return function (callable $handler) {
-
 
863
            return function (
-
 
864
                CommandInterface $command,
-
 
865
                ?RequestInterface $request = null
-
 
866
            ) use ($handler) {
-
 
867
                if (!empty($command['@context']['signature_version'])
-
 
868
                    && $command['@context']['signature_version'] === 'v4-s3express'
-
 
869
                ) {
-
 
870
                    $command['@context']['signature_version'] = 's3v4';
-
 
871
                }
-
 
872
                return $handler($command, $request);
-
 
873
            };
-
 
874
        };
-
 
875
    }
-
 
876
 
681
    /**
877
    /**
682
     * Special handling for when the service name is s3-object-lambda.
878
     * Special handling for when the service name is s3-object-lambda.
683
     * So, if the host contains s3-object-lambda, then the service name
879
     * So, if the host contains s3-object-lambda, then the service name
684
     * returned is s3-object-lambda, otherwise the default signing service is returned.
880
     * returned is s3-object-lambda, otherwise the default signing service is returned.
685
     * @param string $host The host to validate if is a s3-object-lambda URL.
881
     * @param string $host The host to validate if is a s3-object-lambda URL.
Línea 693... Línea 889...
693
 
889
 
694
        return $this->getConfig('signing_name');
890
        return $this->getConfig('signing_name');
Línea 695... Línea 891...
695
    }
891
    }
696
 
892
 
697
    /**
893
    /**
698
     * Modifies API definition to remove `Bucket` from request URIs.
894
     * If EndpointProviderV2 is used, removes `Bucket` from request URIs.
-
 
895
     * This is now handled by the endpoint ruleset.
-
 
896
     *
-
 
897
     * Additionally adds a synthetic shape `ExpiresString` and modifies
-
 
898
     * `Expires` type to ensure it remains set to `timestamp`.
699
     * This is now handled by the endpoint ruleset.
899
     *
700
     *
900
     * @param array $args
701
     * @return void
901
     * @return void
702
     *
902
     *
703
     * @internal
903
     * @internal
704
     */
904
     */
705
    private function processEndpointV2Model()
905
    private function processModel(bool $isUseEndpointV2): void
Línea -... Línea 906...
-
 
906
    {
706
    {
907
        $definition = $this->getApi()->getDefinition();
707
        $definition = $this->getApi()->getDefinition();
908
 
708
 
909
        if ($isUseEndpointV2) {
709
        foreach($definition['operations'] as &$operation) {
910
            foreach($definition['operations'] as &$operation) {
710
            if (isset($operation['http']['requestUri'])) {
911
                if (isset($operation['http']['requestUri'])) {
711
                $requestUri = $operation['http']['requestUri'];
912
                    $requestUri = $operation['http']['requestUri'];
712
                if ($requestUri === "/{Bucket}") {
913
                    if ($requestUri === "/{Bucket}") {
-
 
914
                        $requestUri = str_replace('/{Bucket}', '/', $requestUri);
-
 
915
                    } else {
-
 
916
                        $requestUri = str_replace('/{Bucket}', '', $requestUri);
-
 
917
                    }
-
 
918
                    $operation['http']['requestUri'] = $requestUri;
-
 
919
                }
-
 
920
            }
-
 
921
        }
-
 
922
 
-
 
923
        foreach ($definition['shapes'] as $key => &$value) {
-
 
924
            $suffix = 'Output';
-
 
925
            if (substr($key, -strlen($suffix)) === $suffix) {
-
 
926
                if (isset($value['members']['Expires'])) {
-
 
927
                    $value['members']['Expires']['deprecated'] = true;
-
 
928
                    $value['members']['ExpiresString'] = [
-
 
929
                        'shape' => 'ExpiresString',
713
                    $requestUri = str_replace('/{Bucket}', '/', $requestUri);
930
                        'location' => 'header',
714
                } else {
-
 
715
                    $requestUri = str_replace('/{Bucket}', '', $requestUri);
931
                        'locationName' => 'Expires'
716
                }
932
                    ];
-
 
933
                }
-
 
934
            }
-
 
935
        }
717
                $operation['http']['requestUri'] = $requestUri;
936
        $definition['shapes']['ExpiresString']['type'] = 'string';
718
            }
937
        $definition['shapes']['Expires']['type'] = 'timestamp';
Línea 719... Línea 938...
719
        }
938
 
720
        $this->getApi()->setDefinition($definition);
939
        $this->getApi()->setDefinition($definition);
721
    }
940
    }
722
 
941
 
723
    /**
942
    /**
724
     * Adds service-specific client built-in values
943
     * Adds service-specific client built-in values
725
     *
944
     *
-
 
945
     * @return void
726
     * @return void
946
     */
-
 
947
    private function addBuiltIns($args)
-
 
948
    {
-
 
949
        if (isset($args['region'])
-
 
950
            && $args['region'] !== 'us-east-1'
-
 
951
        ) {
-
 
952
            return false;
-
 
953
        }
727
     */
954
 
728
    private function addBuiltIns($args)
955
        if (!isset($args['region'])
-
 
956
            && ConfigurationResolver::resolve('region', '', 'string') !== 'us-east-1'
729
    {
957
        ) {
730
        if ($args['region'] !== 'us-east-1') {
958
            return false;
731
            return false;
959
        }
Línea 732... Línea 960...
732
        }
960
 
Línea 752... Línea 980...
752
            }
980
            }
753
        }
981
        }
754
        $this->clientBuiltIns[$key] = $value;
982
        $this->clientBuiltIns[$key] = $value;
755
    }
983
    }
Línea -... Línea 984...
-
 
984
 
-
 
985
    /**
-
 
986
     * Determines whether a bucket is a directory bucket.
-
 
987
     * Only considers the availability zone/suffix format
-
 
988
     *
-
 
989
     * @param string $bucket
-
 
990
     * @return bool
-
 
991
     */
-
 
992
    public static function isDirectoryBucket(string $bucket): bool
-
 
993
    {
-
 
994
        return preg_match(self::DIRECTORY_BUCKET_REGEX, $bucket) === 1;
-
 
995
    }
756
 
996
 
757
    /** @internal */
997
    /** @internal */
758
    public static function _applyRetryConfig($value, $args, HandlerList $list)
998
    public static function _applyRetryConfig($value, $args, HandlerList $list)
759
    {
999
    {
760
        if ($value) {
1000
        if ($value) {
Línea 761... Línea 1001...
761
            $config = \Aws\Retry\ConfigurationProvider::unwrap($value);
1001
            $config = \Aws\Retry\ConfigurationProvider::unwrap($value);
762
 
1002
 
763
            if ($config->getMode() === 'legacy') {
1003
            if ($config->getMode() === 'legacy') {
764
                $maxRetries = $config->getMaxAttempts() - 1;
1004
                $maxRetries = $config->getMaxAttempts() - 1;
765
                $decider = RetryMiddleware::createDefaultDecider($maxRetries);
1005
                $decider = RetryMiddleware::createDefaultDecider($maxRetries);
766
                $decider = function ($retries, $command, $request, $result, $error) use ($decider, $maxRetries) {
-
 
767
                    $maxRetries = null !== $command['@retries']
-
 
Línea 768... Línea 1006...
768
                        ? $command['@retries']
1006
                $decider = function ($retries, $command, $request, $result, $error) use ($decider, $maxRetries) {
769
                        : $maxRetries;
1007
                    $maxRetries = $command['@retries'] ?? $maxRetries;
770
 
1008
 
Línea 846... Línea 1084...
846
 
1084
 
847
    /** @internal */
1085
    /** @internal */
848
    public static function _applyApiProvider($value, array &$args, HandlerList $list)
1086
    public static function _applyApiProvider($value, array &$args, HandlerList $list)
849
    {
1087
    {
850
        ClientResolver::_apply_api_provider($value, $args);
1088
        ClientResolver::_apply_api_provider($value, $args);
851
        $args['parser'] = new GetBucketLocationParser(
1089
        $s3Parser = new S3Parser(
852
            new ValidateResponseChecksumParser(
1090
            $args['parser'],
853
                new AmbiguousSuccessParser(
-
 
854
                    new RetryableMalformedResponseParser(
1091
            $args['error_parser'],
855
                        $args['parser'],
1092
            $args['api'],
856
                        $args['exception_class']
1093
            $args['exception_class']
-
 
1094
        );
857
                    ),
1095
        $s3Parser->addS3ResultMutator(
858
                    $args['error_parser'],
1096
            'get-bucket-location',
859
                    $args['exception_class']
1097
            new GetBucketLocationResultMutator()
-
 
1098
        );
-
 
1099
        $s3Parser->addS3ResultMutator(
-
 
1100
            'validate-response-checksum',
860
                ),
1101
            new ValidateResponseChecksumResultMutator(
-
 
1102
                $args['api'],
861
                $args['api']
1103
                ['response_checksum_validation' => $args['response_checksum_validation']]
862
            )
1104
            )
-
 
1105
        );
863
        );
1106
        $args['parser'] = $s3Parser;
Línea 864... Línea 1107...
864
    }
1107
    }
865
 
1108
 
866
    /**
1109
    /**
Línea 958... Línea 1201...
958
        $docs['shapes']['ContentMD5']['appendOnly'] = [
1201
        $docs['shapes']['ContentMD5']['appendOnly'] = [
959
            'message' => $objectLock,
1202
            'message' => $objectLock,
960
            'shapes' => ['PutObjectRequest', 'UploadPartRequest']
1203
            'shapes' => ['PutObjectRequest', 'UploadPartRequest']
961
        ];
1204
        ];
Línea -... Línea 1205...
-
 
1205
 
-
 
1206
        // Add `ExpiresString` shape to output structures which contain `Expires`
-
 
1207
        // Deprecate existing `Expires` shapes in output structures
-
 
1208
        // Add/Update documentation for both `ExpiresString` and `Expires`
-
 
1209
        // Ensure `Expires` type remains timestamp
-
 
1210
        foreach ($api['shapes'] as $key => &$value) {
-
 
1211
            $suffix = 'Output';
-
 
1212
            if (substr($key, -strlen($suffix)) === $suffix) {
-
 
1213
                if (isset($value['members']['Expires'])) {
-
 
1214
                    $value['members']['Expires']['deprecated'] = true;
-
 
1215
                    $value['members']['ExpiresString'] = [
-
 
1216
                        'shape' => 'ExpiresString',
-
 
1217
                        'location' => 'header',
-
 
1218
                        'locationName' => 'Expires'
-
 
1219
                    ];
-
 
1220
                    $docs['shapes']['Expires']['refs'][$key . '$Expires']
-
 
1221
                        .= '<p>This output shape has been deprecated. Please refer to <code>ExpiresString</code> instead.</p>.';
-
 
1222
                }
-
 
1223
            }
-
 
1224
        }
-
 
1225
        $api['shapes']['ExpiresString']['type'] = 'string';
-
 
1226
        $docs['shapes']['ExpiresString']['base'] = 'The unparsed string value of the <code>Expires</code> output member.';
-
 
1227
        $api['shapes']['Expires']['type'] = 'timestamp';
962
 
1228
 
963
        return [
1229
        return [
964
            new Service($api, ApiProvider::defaultProvider()),
1230
            new Service($api, ApiProvider::defaultProvider()),
965
            new DocModel($docs)
1231
            new DocModel($docs)
966
        ];
1232
        ];
Línea 1019... Línea 1285...
1019
            $examples['PutObject'] = [$putObjectExample];
1285
            $examples['PutObject'] = [$putObjectExample];
1020
        }
1286
        }
Línea 1021... Línea 1287...
1021
 
1287
 
1022
        return $examples;
1288
        return $examples;
-
 
1289
    }
-
 
1290
 
-
 
1291
    /**
-
 
1292
     * @param CommandInterface $command
-
 
1293
     * @return array|mixed|null
-
 
1294
     */
-
 
1295
    private function getSignatureVersionFromCommand(CommandInterface $command)
-
 
1296
    {
-
 
1297
        return $command['@context']['signature_version']
-
 
1298
            ?? $this->getConfig('signature_version');
1023
    }
1299
    }