Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 4... Línea 4...
4
use Aws\Api\Service;
4
use Aws\Api\Service;
5
use Aws\Api\Validator;
5
use Aws\Api\Validator;
6
use Aws\Credentials\CredentialsInterface;
6
use Aws\Credentials\CredentialsInterface;
7
use Aws\EndpointV2\EndpointProviderV2;
7
use Aws\EndpointV2\EndpointProviderV2;
8
use Aws\Exception\AwsException;
8
use Aws\Exception\AwsException;
-
 
9
use Aws\Signature\S3ExpressSignature;
9
use Aws\Token\TokenAuthorization;
10
use Aws\Token\TokenAuthorization;
10
use Aws\Token\TokenInterface;
11
use Aws\Token\TokenInterface;
11
use GuzzleHttp\Promise;
12
use GuzzleHttp\Promise;
12
use GuzzleHttp\Psr7;
13
use GuzzleHttp\Psr7;
13
use GuzzleHttp\Psr7\LazyOpenStream;
14
use GuzzleHttp\Psr7\LazyOpenStream;
Línea 35... Línea 36...
35
            $bodyParameter,
36
            $bodyParameter,
36
            $sourceParameter
37
            $sourceParameter
37
        ) {
38
        ) {
38
            return function (
39
            return function (
39
                CommandInterface $command,
40
                CommandInterface $command,
40
                RequestInterface $request = null)
41
                ?RequestInterface $request = null)
41
            use (
42
            use (
42
                $handler,
43
                $handler,
43
                $api,
44
                $api,
44
                $bodyParameter,
45
                $bodyParameter,
45
                $sourceParameter
46
                $sourceParameter
Línea 48... Línea 49...
48
                $source = $command[$sourceParameter];
49
                $source = $command[$sourceParameter];
Línea 49... Línea 50...
49
 
50
 
50
                if ($source !== null
51
                if ($source !== null
51
                    && $operation->getInput()->hasMember($bodyParameter)
52
                    && $operation->getInput()->hasMember($bodyParameter)
52
                ) {
53
                ) {
-
 
54
                    $lazyOpenStream = new LazyOpenStream($source, 'r');
53
                    $command[$bodyParameter] = new LazyOpenStream($source, 'r');
55
                    $command[$bodyParameter] = $lazyOpenStream;
-
 
56
                    unset($command[$sourceParameter]);
-
 
57
 
-
 
58
                    $next = $handler($command, $request);
-
 
59
                    // To avoid failures in some tests cases
-
 
60
                    if ($next !== null && method_exists($next, 'then')) {
-
 
61
                        return $next->then(
-
 
62
                            function ($result) use ($lazyOpenStream) {
-
 
63
                                // To make sure the resource is closed.
-
 
64
                                $lazyOpenStream->close();
-
 
65
 
-
 
66
                                return $result;
-
 
67
                            }
-
 
68
                        )->otherwise(function (\Throwable $e) use ($lazyOpenStream) {
-
 
69
                            $lazyOpenStream->close();
-
 
70
 
-
 
71
                            throw $e;
-
 
72
                        });
-
 
73
                    }
-
 
74
 
54
                    unset($command[$sourceParameter]);
75
                    return $next;
Línea 55... Línea 76...
55
                }
76
                }
56
 
77
 
57
                return $handler($command, $request);
78
                return $handler($command, $request);
Línea 64... Línea 85...
64
     *
85
     *
65
     * @param Service $api API being accessed.
86
     * @param Service $api API being accessed.
66
     *
87
     *
67
     * @return callable
88
     * @return callable
68
     */
89
     */
69
    public static function validation(Service $api, Validator $validator = null)
90
    public static function validation(Service $api, ?Validator $validator = null)
70
    {
91
    {
71
        $validator = $validator ?: new Validator();
92
        $validator = $validator ?: new Validator();
72
        return function (callable $handler) use ($api, $validator) {
93
        return function (callable $handler) use ($api, $validator) {
73
            return function (
94
            return function (
74
                CommandInterface $command,
95
                CommandInterface $command,
75
                RequestInterface $request = null
96
                ?RequestInterface $request = null
76
            ) use ($api, $validator, $handler) {
97
            ) use ($api, $validator, $handler) {
77
                if ($api->isModifiedModel()) {
98
                if ($api->isModifiedModel()) {
78
                    $api = new Service(
99
                    $api = new Service(
79
                        $api->getDefinition(),
100
                        $api->getDefinition(),
80
                        $api->getProvider()
101
                        $api->getProvider()
Línea 98... Línea 119...
98
     *                             command.
119
     *                             command.
99
     * @param EndpointProviderV2 | null $endpointProvider
120
     * @param EndpointProviderV2 | null $endpointProvider
100
     * @param array $providerArgs
121
     * @param array $providerArgs
101
     * @return callable
122
     * @return callable
102
     */
123
     */
103
    public static function requestBuilder(
124
    public static function requestBuilder($serializer)
104
        $serializer,
-
 
105
        $endpointProvider = null,
-
 
106
        array $providerArgs = null
-
 
107
    )
-
 
108
    {
125
    {
109
        return function (callable $handler) use ($serializer, $endpointProvider, $providerArgs) {
126
        return function (callable $handler) use ($serializer) {
110
            return function (CommandInterface $command) use ($serializer, $handler, $endpointProvider, $providerArgs) {
127
            return function (CommandInterface $command, $endpoint = null) use ($serializer, $handler) {
111
                return $handler($command, $serializer($command, $endpointProvider, $providerArgs));
128
                return $handler($command, $serializer($command, $endpoint));
112
            };
129
            };
113
        };
130
        };
114
    }
131
    }
Línea 115... Línea 132...
115
 
132
 
Línea 123... Línea 140...
123
     *                                    object and returns a
140
     *                                    object and returns a
124
     *                                    SignatureInterface.
141
     *                                    SignatureInterface.
125
     *
142
     *
126
     * @return callable
143
     * @return callable
127
     */
144
     */
128
    public static function signer(callable $credProvider, callable $signatureFunction, $tokenProvider = null)
145
    public static function signer(callable $credProvider, callable $signatureFunction, $tokenProvider = null, $config = [])
129
    {
146
    {
130
        return function (callable $handler) use ($signatureFunction, $credProvider, $tokenProvider) {
147
        return function (callable $handler) use ($signatureFunction, $credProvider, $tokenProvider, $config) {
131
            return function (
148
            return function (
132
                CommandInterface $command,
149
                CommandInterface $command,
133
                RequestInterface $request
150
                RequestInterface $request
134
            ) use ($handler, $signatureFunction, $credProvider, $tokenProvider) {
151
            ) use ($handler, $signatureFunction, $credProvider, $tokenProvider, $config) {
135
                $signer = $signatureFunction($command);
152
                $signer = $signatureFunction($command);
136
                if ($signer instanceof TokenAuthorization) {
153
                if ($signer instanceof TokenAuthorization) {
137
                    return $tokenProvider()->then(
154
                    return $tokenProvider()->then(
138
                        function (TokenInterface $token)
155
                        function (TokenInterface $token)
139
                        use ($handler, $command, $signer, $request) {
156
                        use ($handler, $command, $signer, $request) {
Línea 141... Línea 158...
141
                                $command,
158
                                $command,
142
                                $signer->authorizeRequest($request, $token)
159
                                $signer->authorizeRequest($request, $token)
143
                            );
160
                            );
144
                        }
161
                        }
145
                    );
162
                    );
-
 
163
                }
-
 
164
 
-
 
165
                if ($signer instanceof S3ExpressSignature) {
-
 
166
                    $credentialPromise = $config['s3_express_identity_provider']($command);
146
                } else {
167
                } else {
147
                    return $credProvider()->then(
168
                    $credentialPromise = $credProvider();
148
                        function (CredentialsInterface $creds)
-
 
149
                        use ($handler, $command, $signer, $request) {
-
 
150
                            return $handler(
-
 
151
                                $command,
-
 
152
                                $signer->signRequest($request, $creds)
-
 
153
                            );
-
 
154
                        }
-
 
155
                    );
-
 
156
                }
169
                }
-
 
170
 
-
 
171
                return $credentialPromise->then(
-
 
172
                    function (CredentialsInterface $creds)
-
 
173
                    use ($handler, $command, $signer, $request) {
-
 
174
                        // Capture credentials metric
-
 
175
                        $command->getMetricsBuilder()->identifyMetricByValueAndAppend(
-
 
176
                            'credentials',
-
 
177
                            $creds
-
 
178
                        );
-
 
179
 
-
 
180
                        return $handler(
-
 
181
                            $command,
-
 
182
                            $signer->signRequest($request, $creds)
-
 
183
                        );
-
 
184
                    }
-
 
185
                );
157
            };
186
            };
158
        };
187
        };
159
    }
188
    }
Línea 160... Línea 189...
160
 
189
 
Línea 173... Línea 202...
173
    public static function tap(callable $fn)
202
    public static function tap(callable $fn)
174
    {
203
    {
175
        return function (callable $handler) use ($fn) {
204
        return function (callable $handler) use ($fn) {
176
            return function (
205
            return function (
177
                CommandInterface $command,
206
                CommandInterface $command,
178
                RequestInterface $request = null
207
                ?RequestInterface $request = null
179
            ) use ($handler, $fn) {
208
            ) use ($handler, $fn) {
180
                $fn($command, $request);
209
                $fn($command, $request);
181
                return $handler($command, $request);
210
                return $handler($command, $request);
182
            };
211
            };
183
        };
212
        };
Línea 199... Línea 228...
199
     *                          associated delay.
228
     *                          associated delay.
200
     *
229
     *
201
     * @return callable
230
     * @return callable
202
     */
231
     */
203
    public static function retry(
232
    public static function retry(
204
        callable $decider = null,
233
        ?callable $decider = null,
205
        callable $delay = null,
234
        ?callable $delay = null,
206
        $stats = false
235
        $stats = false
207
    ) {
236
    ) {
208
        $decider = $decider ?: RetryMiddleware::createDefaultDecider();
237
        $decider = $decider ?: RetryMiddleware::createDefaultDecider();
209
        $delay = $delay ?: [RetryMiddleware::class, 'exponentialDelay'];
238
        $delay = $delay ?: [RetryMiddleware::class, 'exponentialDelay'];
Línea 248... Línea 277...
248
    public static function contentType(array $operations)
277
    public static function contentType(array $operations)
249
    {
278
    {
250
        return function (callable $handler) use ($operations) {
279
        return function (callable $handler) use ($operations) {
251
            return function (
280
            return function (
252
                CommandInterface $command,
281
                CommandInterface $command,
253
                RequestInterface $request = null
282
                ?RequestInterface $request = null
254
            ) use ($handler, $operations) {
283
            ) use ($handler, $operations) {
255
                if (!$request->hasHeader('Content-Type')
284
                if (!$request->hasHeader('Content-Type')
256
                    && in_array($command->getName(), $operations, true)
285
                    && in_array($command->getName(), $operations, true)
257
                    && ($uri = $request->getBody()->getMetadata('uri'))
286
                    && ($uri = $request->getBody()->getMetadata('uri'))
258
                ) {
287
                ) {
Línea 317... Línea 346...
317
    public static function history(History $history)
346
    public static function history(History $history)
318
    {
347
    {
319
        return function (callable $handler) use ($history) {
348
        return function (callable $handler) use ($history) {
320
            return function (
349
            return function (
321
                CommandInterface $command,
350
                CommandInterface $command,
322
                RequestInterface $request = null
351
                ?RequestInterface $request = null
323
            ) use ($handler, $history) {
352
            ) use ($handler, $history) {
324
                $ticket = $history->start($command, $request);
353
                $ticket = $history->start($command, $request);
325
                return $handler($command, $request)
354
                return $handler($command, $request)
326
                    ->then(
355
                    ->then(
327
                        function ($result) use ($history, $ticket) {
356
                        function ($result) use ($history, $ticket) {
Línea 349... Línea 378...
349
    public static function mapRequest(callable $f)
378
    public static function mapRequest(callable $f)
350
    {
379
    {
351
        return function (callable $handler) use ($f) {
380
        return function (callable $handler) use ($f) {
352
            return function (
381
            return function (
353
                CommandInterface $command,
382
                CommandInterface $command,
354
                RequestInterface $request = null
383
                ?RequestInterface $request = null
355
            ) use ($handler, $f) {
384
            ) use ($handler, $f) {
356
                return $handler($command, $f($request));
385
                return $handler($command, $f($request));
357
            };
386
            };
358
        };
387
        };
359
    }
388
    }
Línea 370... Línea 399...
370
    public static function mapCommand(callable $f)
399
    public static function mapCommand(callable $f)
371
    {
400
    {
372
        return function (callable $handler) use ($f) {
401
        return function (callable $handler) use ($f) {
373
            return function (
402
            return function (
374
                CommandInterface $command,
403
                CommandInterface $command,
375
                RequestInterface $request = null
404
                ?RequestInterface $request = null
376
            ) use ($handler, $f) {
405
            ) use ($handler, $f) {
377
                return $handler($f($command), $request);
406
                return $handler($f($command), $request);
378
            };
407
            };
379
        };
408
        };
380
    }
409
    }
Línea 390... Línea 419...
390
    public static function mapResult(callable $f)
419
    public static function mapResult(callable $f)
391
    {
420
    {
392
        return function (callable $handler) use ($f) {
421
        return function (callable $handler) use ($f) {
393
            return function (
422
            return function (
394
                CommandInterface $command,
423
                CommandInterface $command,
395
                RequestInterface $request = null
424
                ?RequestInterface $request = null
396
            ) use ($handler, $f) {
425
            ) use ($handler, $f) {
397
                return $handler($command, $request)->then($f);
426
                return $handler($command, $request)->then($f);
398
            };
427
            };
399
        };
428
        };
400
    }
429
    }
Línea 402... Línea 431...
402
    public static function timer()
431
    public static function timer()
403
    {
432
    {
404
        return function (callable $handler) {
433
        return function (callable $handler) {
405
            return function (
434
            return function (
406
                CommandInterface $command,
435
                CommandInterface $command,
407
                RequestInterface $request = null
436
                ?RequestInterface $request = null
408
            ) use ($handler) {
437
            ) use ($handler) {
409
                $start = microtime(true);
438
                $start = microtime(true);
410
                return $handler($command, $request)
439
                return $handler($command, $request)
411
                    ->then(
440
                    ->then(
412
                        function (ResultInterface $res) use ($start) {
441
                        function (ResultInterface $res) use ($start) {