Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
Línea 2... Línea 2...
2
 
2
 
Línea 3... Línea 3...
3
namespace Aws\EndpointV2;
3
namespace Aws\EndpointV2;
-
 
4
 
4
 
5
use Aws\Api\Serializer\RestSerializer;
Línea 5... Línea 6...
5
use Aws\Api\Serializer\RestSerializer;
6
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
6
use GuzzleHttp\Psr7\Uri;
7
use GuzzleHttp\Psr7\Uri;
7
 
8
 
Línea 12... Línea 13...
12
 * @internal
13
 * @internal
13
 */
14
 */
14
trait EndpointV2SerializerTrait
15
trait EndpointV2SerializerTrait
15
{
16
{
16
    /**
17
    /**
17
     * Merges endpoint resolution arguments passed from the client
18
     * Applies a resolved endpoint, headers and any custom HTTP schemes provided
18
     * and command and attempts to resolve an endpoint. Headers and
-
 
19
     * auth schemes may be returned in a resolved endpoint object.
-
 
20
     * A resolved endpoint uri and headers will be applied to the request.
19
     * in client configuration to options which are applied to the serialized request.
21
     * Auth schemes are applied to the command and compared against the default
-
 
22
     * auth scheme at signing.
-
 
23
     *
20
     *
-
 
21
     * @param $endpoint
-
 
22
     * @param $headers
-
 
23
     *
24
     * @internal
24
     * @return void
25
     */
25
     */
26
    private function setRequestOptions(
26
    private function setEndpointV2RequestOptions(
27
        $endpointProvider,
27
        RulesetEndpoint $endpoint,
28
        $command,
-
 
29
        $operation,
-
 
30
        $commandArgs,
-
 
31
        $clientArgs,
-
 
32
        &$headers
28
        array &$headers
33
    )
29
    ): void
34
    {
30
    {
35
        $providerArgs = $this->resolveProviderArgs(
-
 
36
            $endpointProvider,
-
 
37
            $operation,
-
 
38
            $commandArgs,
-
 
39
            $clientArgs
-
 
40
        );
-
 
41
        $endpoint = $endpointProvider->resolveEndpoint($providerArgs);
31
        $this->applyHeaders($endpoint, $headers);
42
        $resolvedUrl = $endpoint->getUrl();
32
        $resolvedUrl = $endpoint->getUrl();
43
 
-
 
44
        $this->applyScheme($resolvedUrl);
33
        $this->applyScheme($resolvedUrl);
45
        $this->endpoint = $resolvedUrl;
34
        $this->endpoint = $this instanceof RestSerializer
46
        $this->applyAuthSchemeToCommand($endpoint, $command);
-
 
47
        $this->applyHeaders($endpoint, $headers);
-
 
48
    }
-
 
49
 
-
 
50
    private function resolveProviderArgs(
-
 
51
        $endpointProvider,
-
 
52
        $operation,
-
 
53
        $commandArgs,
-
 
54
        $clientArgs
-
 
55
    )
-
 
56
    {
-
 
57
        $rulesetParams = $endpointProvider->getRuleset()->getParameters();
-
 
58
        $endpointCommandArgs = $this->filterEndpointCommandArgs(
-
 
59
            $rulesetParams,
-
 
60
            $commandArgs
-
 
61
        );
-
 
62
        $staticContextParams = $this->bindStaticContextParams(
-
 
63
            $operation->getStaticContextParams()
-
 
64
        );
-
 
65
        $contextParams = $this->bindContextParams(
-
 
66
            $commandArgs, $operation->getContextParams()
-
 
67
        );
-
 
68
        $providerArgs = $this->normalizeEndpointProviderArgs(
-
 
69
            $endpointCommandArgs,
35
            ? new Uri($resolvedUrl)
70
            $clientArgs,
36
            : $resolvedUrl;
71
            $contextParams,
-
 
72
            $staticContextParams
-
 
73
        );
-
 
74
 
-
 
75
        return $providerArgs;
-
 
76
    }
37
    }
Línea 77... Línea 38...
77
 
38
 
78
    /**
39
    /**
79
     * Merges endpoint provider arguments from different sources.
40
     * Combines modeled headers and headers resolved from an endpoint object.
80
     * Client built-ins are superseded by client context params.
41
     *
81
     * Client context params are superseded by context params on
42
     * @param $endpoint
82
     * an input member's shape.  Context params are superseded by
-
 
83
     * static context params. The result of this combination is then
43
     * @param $headers
84
     * merged with any appropriate arguments from the command.
44
     * @return void
85
     */
-
 
86
    private function normalizeEndpointProviderArgs(
-
 
87
        $endpointCommandArgs,
-
 
88
        $clientArgs,
-
 
89
        $contextParams,
-
 
90
        $staticContextParams
-
 
91
    )
-
 
92
    {
-
 
93
        $commandContextParams = array_merge($contextParams, $staticContextParams);
-
 
94
        $combinedEndpointArgs = array_merge($clientArgs, $commandContextParams);
-
 
95
 
-
 
96
        return array_merge($combinedEndpointArgs, $endpointCommandArgs);
-
 
97
    }
-
 
98
 
-
 
99
    private function bindContextParams($commandArgs, $contextParams)
-
 
100
    {
-
 
101
        $scopedParams = [];
-
 
102
 
-
 
103
        foreach($contextParams as $name => $spec) {
-
 
104
            if (isset($commandArgs[$spec['shape']])) {
-
 
105
                $scopedParams[$name] = $commandArgs[$spec['shape']];
-
 
106
            }
-
 
107
        }
-
 
108
        return $scopedParams;
-
 
109
    }
-
 
110
 
-
 
111
    private function bindStaticContextParams($staticContextParams)
-
 
112
    {
-
 
113
        $scopedParams = [];
-
 
114
 
-
 
115
        forEach($staticContextParams as $paramName => $paramValue) {
-
 
116
            $scopedParams[$paramName] = $paramValue['value'];
-
 
117
        }
-
 
118
        return $scopedParams;
-
 
119
    }
-
 
120
 
-
 
121
    private function filterEndpointCommandArgs(
-
 
122
        $rulesetParams,
-
 
123
        $commandArgs
-
 
124
    )
-
 
125
    {
-
 
126
        $endpointMiddlewareOpts = [
-
 
127
            '@use_dual_stack_endpoint' => 'UseDualStack',
-
 
128
            '@use_accelerate_endpoint' => 'Accelerate',
-
 
129
            '@use_path_style_endpoint' => 'ForcePathStyle'
-
 
130
        ];
-
 
131
 
-
 
132
        $filteredArgs = [];
-
 
133
 
-
 
134
        foreach($rulesetParams as $name => $value) {
-
 
135
            if (isset($commandArgs[$name])) {
-
 
136
                if (!empty($value->getBuiltIn())) {
-
 
137
                    continue;
-
 
138
                }
-
 
139
                $filteredArgs[$name] = $commandArgs[$name];
-
 
140
            }
-
 
141
        }
-
 
142
 
-
 
143
        if ($this->api->getServiceName() === 's3') {
-
 
144
            foreach($endpointMiddlewareOpts as $optionName => $newValue) {
-
 
145
                if (isset($commandArgs[$optionName])) {
-
 
146
                    $filteredArgs[$newValue] = $commandArgs[$optionName];
-
 
147
                }
-
 
148
            }
-
 
149
        }
-
 
150
 
-
 
151
        return $filteredArgs;
-
 
152
    }
-
 
153
 
45
     */
154
    private function applyHeaders($endpoint, &$headers)
46
    private function applyHeaders(RulesetEndpoint $endpoint, array &$headers): void
155
    {
47
    {
156
        if (!is_null($endpoint->getHeaders())) {
48
        if (!is_null($endpoint->getHeaders())) {
157
           $headers = array_merge(
49
           $headers = array_merge(
158
               $headers,
50
               $headers,
159
               $endpoint->getHeaders()
51
               $endpoint->getHeaders()
160
           );
52
           );
161
        }
53
        }
Línea 162... Línea -...
162
    }
-
 
163
 
54
    }
164
    private function applyAuthSchemeToCommand($endpoint, $command)
55
 
165
    {
-
 
166
        if (isset($endpoint->getProperties()['authSchemes'])) {
-
 
167
            $authScheme = $this->selectAuthScheme(
-
 
168
                $endpoint->getProperties()['authSchemes']
-
 
169
            );
-
 
170
            $command->setAuthSchemes($authScheme);
-
 
171
        }
-
 
172
    }
-
 
173
 
56
    /**
174
    private function selectAuthScheme($authSchemes)
-
 
175
    {
-
 
176
        $validAuthSchemes = ['sigv4', 'sigv4a', 'none', 'bearer'];
-
 
177
        $invalidAuthSchemes = [];
-
 
178
 
-
 
179
        foreach($authSchemes as $authScheme) {
-
 
180
            if (in_array($authScheme['name'], $validAuthSchemes)) {
57
     * Applies custom HTTP schemes provided in client configuration.
181
                return $this->normalizeAuthScheme($authScheme);
-
 
182
            } else {
58
     *
183
                $invalidAuthSchemes[] = "`{$authScheme['name']}`";
-
 
184
            }
-
 
185
        }
-
 
186
 
-
 
187
        $invalidAuthSchemesString = implode(', ', $invalidAuthSchemes);
-
 
188
        $validAuthSchemesString = '`' . implode('`, `', $validAuthSchemes) . '`';
-
 
189
        throw new \InvalidArgumentException(
-
 
190
            "This operation requests {$invalidAuthSchemesString}"
-
 
191
            . " auth schemes, but the client only supports {$validAuthSchemesString}."
-
 
192
        );
-
 
193
    }
-
 
194
 
-
 
195
    private function normalizeAuthScheme($authScheme)
-
 
196
    {
-
 
197
       /*
-
 
198
            sigv4a will contain a regionSet property. which is guaranteed to be `*`
-
 
199
            for now.  The SigV4 class handles this automatically for now. It seems
59
     * @param $resolvedUrl
200
            complexity will be added here in the future.
-
 
201
       */
-
 
202
        $normalizedAuthScheme = [];
-
 
203
 
-
 
204
        if (isset($authScheme['disableDoubleEncoding'])
-
 
205
            && $authScheme['disableDoubleEncoding'] === true
-
 
206
            && $authScheme['name'] !== 'sigv4a'
-
 
207
        ) {
-
 
208
            $normalizedAuthScheme['version'] = 's3v4';
-
 
209
        } elseif ($authScheme['name'] === 'none') {
-
 
210
            $normalizedAuthScheme['version'] = 'anonymous';
-
 
211
        }
-
 
212
        else {
-
 
213
            $normalizedAuthScheme['version'] = str_replace(
-
 
214
                'sig', '', $authScheme['name']
-
 
215
            );
-
 
216
        }
-
 
217
 
-
 
218
        $normalizedAuthScheme['name'] = isset($authScheme['signingName']) ?
-
 
219
            $authScheme['signingName'] : null;
-
 
220
        $normalizedAuthScheme['region'] = isset($authScheme['signingRegion']) ?
-
 
221
            $authScheme['signingRegion'] : null;
-
 
222
        $normalizedAuthScheme['signingRegionSet'] = isset($authScheme['signingRegionSet']) ?
-
 
223
            $authScheme['signingRegionSet'] : null;
-
 
224
 
-
 
225
        return $normalizedAuthScheme;
-
 
226
    }
60
     * @return void
227
 
61
     */
228
    private function applyScheme(&$resolvedUrl)
62
    private function applyScheme(&$resolvedUrl): void
229
    {
63
    {
230
        $resolvedEndpointScheme = parse_url($resolvedUrl, PHP_URL_SCHEME);
64
        $resolvedEndpointScheme = parse_url($resolvedUrl, PHP_URL_SCHEME);
231
        $scheme = $this->endpoint instanceof Uri
65
        $scheme = $this->endpoint instanceof Uri