Skip to content

Commit dca4bc1

Browse files
authored
enhancement: Endpointv2 Middleware (#2790)
1 parent 6485aad commit dca4bc1

18 files changed

+584
-294
lines changed

src/Api/Serializer/JsonRpcSerializer.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use Aws\Api\Service;
55
use Aws\CommandInterface;
6-
use Aws\EndpointV2\EndpointProviderV2;
76
use Aws\EndpointV2\EndpointV2SerializerTrait;
7+
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
88
use GuzzleHttp\Psr7\Request;
99
use Psr\Http\Message\RequestInterface;
1010

@@ -56,8 +56,7 @@ public function __construct(
5656
*/
5757
public function __invoke(
5858
CommandInterface $command,
59-
$endpointProvider = null,
60-
$clientArgs = null
59+
$endpoint = null
6160
)
6261
{
6362
$operationName = $command->getName();
@@ -68,15 +67,8 @@ public function __invoke(
6867
'Content-Type' => $this->contentType
6968
];
7069

71-
if ($endpointProvider instanceof EndpointProviderV2) {
72-
$this->setRequestOptions(
73-
$endpointProvider,
74-
$command,
75-
$operation,
76-
$commandArgs,
77-
$clientArgs,
78-
$headers
79-
);
70+
if ($endpoint instanceof RulesetEndpoint) {
71+
$this->setEndpointV2RequestOptions($endpoint, $headers);
8072
}
8173

8274
return new Request(

src/Api/Serializer/QuerySerializer.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Aws\CommandInterface;
66
use Aws\EndpointV2\EndpointProviderV2;
77
use Aws\EndpointV2\EndpointV2SerializerTrait;
8+
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
89
use GuzzleHttp\Psr7\Request;
910
use Psr\Http\Message\RequestInterface;
1011

@@ -42,8 +43,7 @@ public function __construct(
4243
*/
4344
public function __invoke(
4445
CommandInterface $command,
45-
$endpointProvider = null,
46-
$clientArgs = null
46+
$endpoint = null
4747
)
4848
{
4949
$operation = $this->api->getOperation($command->getName());
@@ -67,15 +67,8 @@ public function __invoke(
6767
'Content-Type' => 'application/x-www-form-urlencoded'
6868
];
6969

70-
if ($endpointProvider instanceof EndpointProviderV2) {
71-
$this->setRequestOptions(
72-
$endpointProvider,
73-
$command,
74-
$operation,
75-
$commandArgs,
76-
$clientArgs,
77-
$headers
78-
);
70+
if ($endpoint instanceof RulesetEndpoint) {
71+
$this->setEndpointV2RequestOptions($endpoint, $headers);
7972
}
8073

8174
return new Request(

src/Api/Serializer/RestSerializer.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Aws\CommandInterface;
1111
use Aws\EndpointV2\EndpointProviderV2;
1212
use Aws\EndpointV2\EndpointV2SerializerTrait;
13+
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
1314
use GuzzleHttp\Psr7;
1415
use GuzzleHttp\Psr7\Request;
1516
use GuzzleHttp\Psr7\Uri;
@@ -49,33 +50,25 @@ public function __construct(Service $api, $endpoint)
4950
*/
5051
public function __invoke(
5152
CommandInterface $command,
52-
$endpointProvider = null,
53-
$clientArgs = null
53+
$endpoint = null
5454
)
5555
{
5656
$operation = $this->api->getOperation($command->getName());
5757
$commandArgs = $command->toArray();
5858
$opts = $this->serialize($operation, $commandArgs);
59-
$headers = isset($opts['headers']) ? $opts['headers'] : [];
60-
61-
if ($endpointProvider instanceof EndpointProviderV2) {
62-
$this->setRequestOptions(
63-
$endpointProvider,
64-
$command,
65-
$operation,
66-
$commandArgs,
67-
$clientArgs,
68-
$headers
69-
);
70-
$this->endpoint = new Uri($this->endpoint);
59+
$headers = $opts['headers'] ?? [];
60+
61+
if ($endpoint instanceof RulesetEndpoint) {
62+
$this->setEndpointV2RequestOptions($endpoint, $headers);
7163
}
64+
7265
$uri = $this->buildEndpoint($operation, $commandArgs, $opts);
7366

7467
return new Request(
7568
$operation['http']['method'],
7669
$uri,
7770
$headers,
78-
isset($opts['body']) ? $opts['body'] : null
71+
$opts['body'] ?? null
7972
);
8073
}
8174

src/AwsClient.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Aws\Api\Service;
77
use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
88
use Aws\EndpointV2\EndpointProviderV2;
9+
use Aws\EndpointV2\EndpointV2Middleware;
910
use Aws\Exception\AwsException;
1011
use Aws\Signature\SignatureProvider;
1112
use GuzzleHttp\Psr7\Uri;
@@ -240,7 +241,9 @@ public function __construct(array $args)
240241
$this->loadAliases();
241242
$this->addStreamRequestPayload();
242243
$this->addRecursionDetection();
243-
$this->addRequestBuilder();
244+
if ($this->isUseEndpointV2()) {
245+
$this->addEndpointV2Middleware();
246+
}
244247

245248
if (!is_null($this->api->getMetadata('awsQueryCompatible'))) {
246249
$this->addQueryCompatibleInputMiddleware($this->api);
@@ -512,24 +515,18 @@ private function addRecursionDetection()
512515
);
513516
}
514517

515-
/**
516-
* Adds the `builder` middleware such that a client's endpoint
517-
* provider and endpoint resolution arguments can be passed.
518-
*/
519-
private function addRequestBuilder()
518+
private function addEndpointV2Middleware()
520519
{
521-
$handlerList = $this->getHandlerList();
522-
$serializer = $this->serializer;
523-
$endpointProvider = $this->endpointProvider;
520+
$list = $this->getHandlerList();
524521
$endpointArgs = $this->getEndpointProviderArgs();
525522

526-
$handlerList->prependBuild(
527-
Middleware::requestBuilder(
528-
$serializer,
529-
$endpointProvider,
523+
$list->prependBuild(
524+
EndpointV2Middleware::wrap(
525+
$this->endpointProvider,
526+
$this->getApi(),
530527
$endpointArgs
531528
),
532-
'builderV2'
529+
'endpointV2_middleware'
533530
);
534531
}
535532

src/ClientResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class ClientResolver
153153
],
154154
'serializer' => [
155155
'default' => [__CLASS__, '_default_serializer'],
156+
'fn' => [__CLASS__, '_apply_serializer'],
156157
'internal' => true,
157158
'type' => 'value',
158159
'valid' => ['callable'],
@@ -834,6 +835,11 @@ public static function _default_use_dual_stack_endpoint(array &$args) {
834835
return UseDualStackConfigProvider::defaultProvider($args);
835836
}
836837

838+
public static function _apply_serializer($value, array &$args, HandlerList $list)
839+
{
840+
$list->prependBuild(Middleware::requestBuilder($value), 'builder');
841+
}
842+
837843
public static function _apply_debug($value, array &$args, HandlerList $list)
838844
{
839845
if ($value !== false) {

0 commit comments

Comments
 (0)