Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 2... Línea 2...
2
namespace Aws;
2
namespace Aws;
Línea 3... Línea 3...
3
 
3
 
4
use Aws\Api\ApiProvider;
4
use Aws\Api\ApiProvider;
5
use Aws\Api\DocModel;
5
use Aws\Api\DocModel;
-
 
6
use Aws\Api\Service;
-
 
7
use Aws\Auth\AuthSelectionMiddleware;
6
use Aws\Api\Service;
8
use Aws\Auth\AuthSchemeResolverInterface;
7
use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
9
use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
-
 
10
use Aws\EndpointV2\EndpointProviderV2;
8
use Aws\EndpointV2\EndpointProviderV2;
11
use Aws\EndpointV2\EndpointV2Middleware;
9
use Aws\Exception\AwsException;
12
use Aws\Exception\AwsException;
10
use Aws\Signature\SignatureProvider;
13
use Aws\Signature\SignatureProvider;
-
 
14
use GuzzleHttp\Psr7\Uri;
Línea 11... Línea 15...
11
use GuzzleHttp\Psr7\Uri;
15
use Psr\Http\Message\RequestInterface;
12
 
16
 
13
/**
17
/**
14
 * Default AWS client implementation
18
 * Default AWS client implementation
Línea 25... Línea 29...
25
 
29
 
26
    /** @var string */
30
    /** @var string */
Línea 27... Línea 31...
27
    private $region;
31
    private $region;
-
 
32
 
-
 
33
    /** @var string */
-
 
34
    private $signingRegionSet;
28
 
35
 
Línea 29... Línea 36...
29
    /** @var string */
36
    /** @var string */
30
    private $endpoint;
37
    private $endpoint;
Línea 31... Línea 38...
31
 
38
 
32
    /** @var Service */
39
    /** @var Service */
Línea -... Línea 40...
-
 
40
    private $api;
-
 
41
 
-
 
42
    /** @var callable */
33
    private $api;
43
    private $signatureProvider;
34
 
44
 
Línea 35... Línea 45...
35
    /** @var callable */
45
    /** @var AuthSchemeResolverInterface */
36
    private $signatureProvider;
46
    private $authSchemeResolver;
Línea 200... Línea 210...
200
     *   environment variable.
210
     *   environment variable.
201
     * - validate: (bool, default=bool(true)) Set to false to disable
211
     * - validate: (bool, default=bool(true)) Set to false to disable
202
     *   client-side parameter validation.
212
     *   client-side parameter validation.
203
     * - version: (string, required) The version of the webservice to
213
     * - version: (string, required) The version of the webservice to
204
     *   utilize (e.g., 2006-03-01).
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.
205
     *
232
     *
206
     * @param array $args Client configuration arguments.
233
     * @param array $args Client configuration arguments.
207
     *
234
     *
208
     * @throws \InvalidArgumentException if any required options are missing or
235
     * @throws \InvalidArgumentException if any required options are missing or
209
     *                                   the service is not supported.
236
     *                                   the service is not supported.
Línea 220... Línea 247...
220
        $this->handlerList = new HandlerList();
247
        $this->handlerList = new HandlerList();
221
        $resolver = new ClientResolver(static::getArguments());
248
        $resolver = new ClientResolver(static::getArguments());
222
        $config = $resolver->resolve($args, $this->handlerList);
249
        $config = $resolver->resolve($args, $this->handlerList);
223
        $this->api = $config['api'];
250
        $this->api = $config['api'];
224
        $this->signatureProvider = $config['signature_provider'];
251
        $this->signatureProvider = $config['signature_provider'];
-
 
252
        $this->authSchemeResolver = $config['auth_scheme_resolver'];
225
        $this->endpoint = new Uri($config['endpoint']);
253
        $this->endpoint = new Uri($config['endpoint']);
226
        $this->credentialProvider = $config['credentials'];
254
        $this->credentialProvider = $config['credentials'];
227
        $this->tokenProvider = $config['token'];
255
        $this->tokenProvider = $config['token'];
228
        $this->region = isset($config['region']) ? $config['region'] : null;
256
        $this->region = $config['region'] ?? null;
-
 
257
        $this->signingRegionSet = $config['sigv4a_signing_region_set'] ?? null;
229
        $this->config = $config['config'];
258
        $this->config = $config['config'];
230
        $this->setClientBuiltIns($args);
259
        $this->setClientBuiltIns($args, $config);
231
        $this->clientContextParams = $this->setClientContextParams($args);
260
        $this->clientContextParams = $this->setClientContextParams($args);
232
        $this->defaultRequestOptions = $config['http'];
261
        $this->defaultRequestOptions = $config['http'];
233
        $this->endpointProvider = $config['endpoint_provider'];
262
        $this->endpointProvider = $config['endpoint_provider'];
234
        $this->serializer = $config['serializer'];
263
        $this->serializer = $config['serializer'];
235
        $this->addSignatureMiddleware();
264
        $this->addSignatureMiddleware($args);
236
        $this->addInvocationId();
265
        $this->addInvocationId();
237
        $this->addEndpointParameterMiddleware($args);
266
        $this->addEndpointParameterMiddleware($args);
238
        $this->addEndpointDiscoveryMiddleware($config, $args);
267
        $this->addEndpointDiscoveryMiddleware($config, $args);
239
        $this->addRequestCompressionMiddleware($config);
268
        $this->addRequestCompressionMiddleware($config);
240
        $this->loadAliases();
269
        $this->loadAliases();
241
        $this->addStreamRequestPayload();
270
        $this->addStreamRequestPayload();
242
        $this->addRecursionDetection();
271
        $this->addRecursionDetection();
-
 
272
        if ($this->isUseEndpointV2()) {
-
 
273
            $this->addEndpointV2Middleware();
-
 
274
        }
243
        $this->addRequestBuilder();
275
        $this->addAuthSelectionMiddleware();
Línea 244... Línea 276...
244
 
276
 
-
 
277
        if (!is_null($this->api->getMetadata('awsQueryCompatible'))) {
245
        if (!$config['suppress_php_deprecation_warning']) {
278
            $this->addQueryCompatibleInputMiddleware($this->api);
246
            $this->emitDeprecationWarning();
279
            $this->addQueryModeHeader();
Línea 247... Línea 280...
247
        }
280
        }
248
 
281
 
249
        if (isset($args['with_resolved'])) {
282
        if (isset($args['with_resolved'])) {
-
 
283
            $args['with_resolved']($config);
250
            $args['with_resolved']($config);
284
        }
Línea 251... Línea 285...
251
        }
285
        $this->addUserAgentMiddleware($config);
252
    }
286
    }
253
 
287
 
Línea 258... Línea 292...
258
 
292
 
259
    public function getConfig($option = null)
293
    public function getConfig($option = null)
260
    {
294
    {
261
        return $option === null
295
        return $option === null
262
            ? $this->config
-
 
263
            : (isset($this->config[$option])
296
            ? $this->config
264
                ? $this->config[$option]
-
 
265
                : null);
297
            : $this->config[$option] ?? null;
Línea 266... Línea 298...
266
    }
298
    }
267
 
299
 
268
    public function getCredentials()
300
    public function getCredentials()
Línea 398... Línea 430...
398
                'EndpointDiscoveryMiddleware'
430
                'EndpointDiscoveryMiddleware'
399
            );
431
            );
400
        }
432
        }
401
    }
433
    }
Línea 402... Línea 434...
402
 
434
 
403
    private function addSignatureMiddleware()
435
    private function addSignatureMiddleware(array $args)
404
    {
436
    {
405
        $api = $this->getApi();
437
        $api = $this->getApi();
406
        $provider = $this->signatureProvider;
438
        $provider = $this->signatureProvider;
407
        $version = $this->config['signature_version'];
439
        $signatureVersion = $this->config['signature_version'];
408
        $name = $this->config['signing_name'];
440
        $name = $this->config['signing_name'];
-
 
441
        $region = $this->config['signing_region'];
-
 
442
        $signingRegionSet = $this->signingRegionSet;
-
 
443
 
-
 
444
        if (isset($args['signature_version'])
-
 
445
         || isset($this->config['configured_signature_version'])
-
 
446
        ) {
-
 
447
            $configuredSignatureVersion = true;
-
 
448
        } else {
-
 
449
            $configuredSignatureVersion = false;
Línea 409... Línea 450...
409
        $region = $this->config['signing_region'];
450
        }
410
 
451
 
-
 
452
        $resolver = static function (
-
 
453
            CommandInterface $command
-
 
454
        ) use (
-
 
455
                $api,
-
 
456
                $provider,
-
 
457
                $name,
-
 
458
                $region,
-
 
459
                $signatureVersion,
-
 
460
                $configuredSignatureVersion,
411
        $resolver = static function (
461
                $signingRegionSet
412
            CommandInterface $c
462
        ) {
413
        ) use ($api, $provider, $name, $region, $version) {
463
            if (!$configuredSignatureVersion) {
414
            if (!empty($c['@context']['signing_region'])) {
464
                if (!empty($command['@context']['signing_region'])) {
415
                $region = $c['@context']['signing_region'];
465
                    $region = $command['@context']['signing_region'];
416
            }
466
                }
-
 
467
                if (!empty($command['@context']['signing_service'])) {
-
 
468
                    $name = $command['@context']['signing_service'];
-
 
469
                }
417
            if (!empty($c['@context']['signing_service'])) {
470
                if (!empty($command['@context']['signature_version'])) {
Línea 418... Línea 471...
418
                $name = $c['@context']['signing_service'];
471
                    $signatureVersion = $command['@context']['signature_version'];
419
            }
472
                }
420
 
473
 
421
            $authType = $api->getOperation($c->getName())['authtype'];
474
                $authType = $api->getOperation($command->getName())['authtype'];
422
            switch ($authType){
475
                switch ($authType){
423
                case 'none':
476
                    case 'none':
424
                    $version = 'anonymous';
477
                        $signatureVersion = 'anonymous';
425
                    break;
478
                        break;
426
                case 'v4-unsigned-body':
479
                    case 'v4-unsigned-body':
427
                    $version = 'v4-unsigned-body';
480
                        $signatureVersion = 'v4-unsigned-body';
428
                    break;
481
                        break;
429
                case 'bearer':
-
 
430
                    $version = 'bearer';
-
 
431
                    break;
-
 
432
            }
-
 
433
            if (isset($c['@context']['signature_version'])) {
482
                    case 'bearer':
434
                if ($c['@context']['signature_version'] == 'v4a') {
483
                        $signatureVersion = 'bearer';
-
 
484
                        break;
435
                    $version = 'v4a';
485
                }
436
                }
486
            }
437
            }
487
 
438
            if (!empty($endpointAuthSchemes = $c->getAuthSchemes())) {
488
            if ($signatureVersion === 'v4a') {
-
 
489
                $commandSigningRegionSet = !empty($command['@context']['signing_region_set'])
439
                $version = $endpointAuthSchemes['version'];
490
                    ? implode(', ', $command['@context']['signing_region_set'])
440
                $name = isset($endpointAuthSchemes['name']) ?
491
                    : null;
-
 
492
 
441
                    $endpointAuthSchemes['name'] : $name;
493
                $region = $signingRegionSet
-
 
494
                    ?? $commandSigningRegionSet
-
 
495
                    ?? $region;
-
 
496
            }
-
 
497
 
-
 
498
            // Capture signature metric
-
 
499
            $command->getMetricsBuilder()->identifyMetricByValueAndAppend(
-
 
500
                'signature',
442
                $region = isset($endpointAuthSchemes['region']) ?
501
                $signatureVersion
443
                    $endpointAuthSchemes['region'] : $region;
502
            );
444
            }
503
 
445
            return SignatureProvider::resolve($provider, $version, $name, $region);
504
            return SignatureProvider::resolve($provider, $signatureVersion, $name, $region);
-
 
505
        };
-
 
506
        $this->handlerList->appendSign(
-
 
507
            Middleware::signer($this->credentialProvider,
-
 
508
                $resolver,
446
        };
509
                $this->tokenProvider,
447
        $this->handlerList->appendSign(
510
                $this->getConfig()
448
            Middleware::signer($this->credentialProvider, $resolver, $this->tokenProvider),
511
            ),
Línea 449... Línea 512...
449
            'signer'
512
            'signer'
Línea 459... Línea 522...
459
                'request-compression'
522
                'request-compression'
460
            );
523
            );
461
        }
524
        }
462
    }
525
    }
Línea -... Línea 526...
-
 
526
 
-
 
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
    }
463
 
549
 
464
    private function addInvocationId()
550
    private function addInvocationId()
465
    {
551
    {
466
        // Add invocation id to each request
552
        // Add invocation id to each request
467
        $this->handlerList->prependSign(Middleware::invocationId(), 'invocation-id');
553
        $this->handlerList->prependSign(Middleware::invocationId(), 'invocation-id');
Línea 501... Línea 587...
501
        $this->handlerList->appendBuild(
587
        $this->handlerList->appendBuild(
502
            Middleware::recursionDetection(), 'recursion-detection'
588
            Middleware::recursionDetection(), 'recursion-detection'
503
        );
589
        );
504
    }
590
    }
Línea 505... Línea -...
505
 
-
 
506
    /**
-
 
507
     * Adds the `builder` middleware such that a client's endpoint
-
 
508
     * provider and endpoint resolution arguments can be passed.
-
 
509
     */
591
 
510
    private function addRequestBuilder()
592
    private function addAuthSelectionMiddleware()
511
    {
593
    {
-
 
594
        $list = $this->getHandlerList();
-
 
595
 
-
 
596
        $list->prependBuild(
-
 
597
            AuthSelectionMiddleware::wrap(
512
        $handlerList = $this->getHandlerList();
598
                $this->authSchemeResolver,
-
 
599
                $this->getApi()
-
 
600
            ),
-
 
601
            'auth-selection'
-
 
602
        );
-
 
603
    }
-
 
604
 
-
 
605
    private function addEndpointV2Middleware()
513
        $serializer = $this->serializer;
606
    {
514
        $endpointProvider = $this->endpointProvider;
607
        $list = $this->getHandlerList();
Línea 515... Línea 608...
515
        $endpointArgs = $this->getEndpointProviderArgs();
608
        $endpointArgs = $this->getEndpointProviderArgs();
516
 
609
 
517
        $handlerList->prependBuild(
610
        $list->prependBuild(
518
            Middleware::requestBuilder(
611
            EndpointV2Middleware::wrap(
519
                $serializer,
612
                $this->endpointProvider,
-
 
613
                $this->getApi(),
520
                $endpointProvider,
614
                $endpointArgs,
-
 
615
                $this->credentialProvider
-
 
616
            ),
-
 
617
            'endpoint-resolution'
-
 
618
        );
-
 
619
    }
-
 
620
 
-
 
621
    /**
-
 
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
    {
521
                $endpointArgs
633
        $this->getHandlerList()->appendSign(
522
            ),
634
            UserAgentMiddleware::wrap($args),
523
            'builderV2'
635
            'user-agent'
Línea 524... Línea 636...
524
        );
636
        );
525
    }
637
    }
Línea 536... Línea 648...
536
        $api = $this->getApi();
648
        $api = $this->getApi();
537
        $resolvedParams = [];
649
        $resolvedParams = [];
538
        if (!empty($paramDefinitions = $api->getClientContextParams())) {
650
        if (!empty($paramDefinitions = $api->getClientContextParams())) {
539
            foreach($paramDefinitions as $paramName => $paramValue) {
651
            foreach($paramDefinitions as $paramName => $paramValue) {
540
                if (isset($args[$paramName])) {
652
                if (isset($args[$paramName])) {
541
                   $result[$paramName] = $args[$paramName];
653
                   $resolvedParams[$paramName] = $args[$paramName];
542
               }
654
               }
543
            }
655
            }
544
        }
656
        }
545
        return $resolvedParams;
657
        return $resolvedParams;
546
    }
658
    }
Línea 547... Línea 659...
547
 
659
 
548
    /**
660
    /**
549
     * Retrieves and sets default values used for endpoint resolution.
661
     * Retrieves and sets default values used for endpoint resolution.
550
     */
662
     */
551
    private function setClientBuiltIns($args)
663
    private function setClientBuiltIns($args, $resolvedConfig)
552
    {
664
    {
553
        $builtIns = [];
665
        $builtIns = [];
554
        $config = $this->getConfig();
666
        $config = $resolvedConfig['config'];
Línea -... Línea 667...
-
 
667
        $service = $args['service'];
-
 
668
 
555
        $service = $args['service'];
669
        $builtIns['SDK::Endpoint'] = null;
-
 
670
        if (!empty($args['endpoint'])) {
-
 
671
            $builtIns['SDK::Endpoint'] = $args['endpoint'];
-
 
672
        } elseif (isset($config['configured_endpoint_url'])) {
556
 
673
            $builtIns['SDK::Endpoint'] = (string) $this->getEndpoint();
557
        $builtIns['SDK::Endpoint'] = isset($args['endpoint']) ? $args['endpoint'] : null;
674
        }
558
        $builtIns['AWS::Region'] = $this->getRegion();
675
        $builtIns['AWS::Region'] = $this->getRegion();
559
        $builtIns['AWS::UseFIPS'] = $config['use_fips_endpoint']->isUseFipsEndpoint();
676
        $builtIns['AWS::UseFIPS'] = $config['use_fips_endpoint']->isUseFipsEndpoint();
560
        $builtIns['AWS::UseDualStack'] = $config['use_dual_stack_endpoint']->isUseDualstackEndpoint();
677
        $builtIns['AWS::UseDualStack'] = $config['use_dual_stack_endpoint']->isUseDualstackEndpoint();
Línea 565... Línea 682...
565
            $builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
682
            $builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
566
            $builtIns['AWS::S3::Accelerate'] = $config['use_accelerate_endpoint'];
683
            $builtIns['AWS::S3::Accelerate'] = $config['use_accelerate_endpoint'];
567
            $builtIns['AWS::S3::ForcePathStyle'] = $config['use_path_style_endpoint'];
684
            $builtIns['AWS::S3::ForcePathStyle'] = $config['use_path_style_endpoint'];
568
            $builtIns['AWS::S3::DisableMultiRegionAccessPoints'] = $config['disable_multiregion_access_points'];
685
            $builtIns['AWS::S3::DisableMultiRegionAccessPoints'] = $config['disable_multiregion_access_points'];
569
        }
686
        }
-
 
687
        $builtIns['AWS::Auth::AccountIdEndpointMode'] = $resolvedConfig['account_id_endpoint_mode'];
-
 
688
 
570
        $this->clientBuiltIns += $builtIns;
689
        $this->clientBuiltIns += $builtIns;
571
    }
690
    }
Línea 572... Línea 691...
572
 
691
 
573
    /**
692
    /**
Línea 604... Línea 723...
604
    {
723
    {
605
        return $this->endpointProvider instanceof EndpointProviderV2;
724
        return $this->endpointProvider instanceof EndpointProviderV2;
606
    }
725
    }
Línea 607... Línea 726...
607
 
726
 
-
 
727
    public static function emitDeprecationWarning() {
-
 
728
        trigger_error(
-
 
729
            "This method is deprecated. It will be removed in an upcoming release."
-
 
730
            , E_USER_DEPRECATED
-
 
731
        );
608
    public static function emitDeprecationWarning() {
732
 
609
        $phpVersion = PHP_VERSION_ID;
733
        $phpVersion = PHP_VERSION_ID;
610
        if ($phpVersion <  70205) {
734
        if ($phpVersion <  70205) {
611
            $phpVersionString = phpversion();
735
            $phpVersionString = phpversion();
612
            @trigger_error(
736
            @trigger_error(
Línea 637... Línea 761...
637
     * @codeCoverageIgnore
761
     * @codeCoverageIgnore
638
     */
762
     */
639
    public static function applyDocFilters(array $api, array $docs)
763
    public static function applyDocFilters(array $api, array $docs)
640
    {
764
    {
641
        $aliases = \Aws\load_compiled_json(__DIR__ . '/data/aliases.json');
765
        $aliases = \Aws\load_compiled_json(__DIR__ . '/data/aliases.json');
642
        $serviceId = $api['metadata']['serviceId'];
766
        $serviceId = $api['metadata']['serviceId'] ?? '';
643
        $version = $api['metadata']['apiVersion'];
767
        $version = $api['metadata']['apiVersion'];
Línea 644... Línea 768...
644
 
768
 
645
        // Replace names for any operations with SDK aliases
769
        // Replace names for any operations with SDK aliases
646
        if (!empty($aliases['operations'][$serviceId][$version])) {
770
        if (!empty($aliases['operations'][$serviceId][$version])) {