Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Endpointv2 Middleware #2790

Merged
merged 9 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/Api/Serializer/JsonRpcSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use Aws\Api\Service;
use Aws\CommandInterface;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2SerializerTrait;
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;

Expand Down Expand Up @@ -56,8 +56,7 @@ public function __construct(
*/
public function __invoke(
CommandInterface $command,
$endpointProvider = null,
$clientArgs = null
$endpoint = null
)
{
$operationName = $command->getName();
Expand All @@ -68,15 +67,8 @@ public function __invoke(
'Content-Type' => $this->contentType
];

if ($endpointProvider instanceof EndpointProviderV2) {
$this->setRequestOptions(
$endpointProvider,
$command,
$operation,
$commandArgs,
$clientArgs,
$headers
);
if ($endpoint instanceof RulesetEndpoint) {
$this->setEndpointV2RequestOptions($endpoint, $headers);
}

return new Request(
Expand Down
15 changes: 4 additions & 11 deletions src/Api/Serializer/QuerySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Aws\CommandInterface;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2SerializerTrait;
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;

Expand Down Expand Up @@ -42,8 +43,7 @@ public function __construct(
*/
public function __invoke(
CommandInterface $command,
$endpointProvider = null,
$clientArgs = null
$endpoint = null
)
{
$operation = $this->api->getOperation($command->getName());
Expand All @@ -67,15 +67,8 @@ public function __invoke(
'Content-Type' => 'application/x-www-form-urlencoded'
];

if ($endpointProvider instanceof EndpointProviderV2) {
$this->setRequestOptions(
$endpointProvider,
$command,
$operation,
$commandArgs,
$clientArgs,
$headers
);
if ($endpoint instanceof RulesetEndpoint) {
$this->setEndpointV2RequestOptions($endpoint, $headers);
}

return new Request(
Expand Down
23 changes: 8 additions & 15 deletions src/Api/Serializer/RestSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Aws\CommandInterface;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2SerializerTrait;
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
Expand Down Expand Up @@ -49,33 +50,25 @@ public function __construct(Service $api, $endpoint)
*/
public function __invoke(
CommandInterface $command,
$endpointProvider = null,
$clientArgs = null
$endpoint = null
)
{
$operation = $this->api->getOperation($command->getName());
$commandArgs = $command->toArray();
$opts = $this->serialize($operation, $commandArgs);
$headers = isset($opts['headers']) ? $opts['headers'] : [];

if ($endpointProvider instanceof EndpointProviderV2) {
$this->setRequestOptions(
$endpointProvider,
$command,
$operation,
$commandArgs,
$clientArgs,
$headers
);
$this->endpoint = new Uri($this->endpoint);
$headers = $opts['headers'] ?? [];

if ($endpoint instanceof RulesetEndpoint) {
stobrien89 marked this conversation as resolved.
Show resolved Hide resolved
$this->setEndpointV2RequestOptions($endpoint, $headers);
}

$uri = $this->buildEndpoint($operation, $commandArgs, $opts);

return new Request(
$operation['http']['method'],
$uri,
$headers,
isset($opts['body']) ? $opts['body'] : null
$opts['body'] ?? null
);
}

Expand Down
25 changes: 11 additions & 14 deletions src/AwsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Aws\Api\Service;
use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2Middleware;
use Aws\Exception\AwsException;
use Aws\Signature\SignatureProvider;
use GuzzleHttp\Psr7\Uri;
Expand Down Expand Up @@ -240,7 +241,9 @@ public function __construct(array $args)
$this->loadAliases();
$this->addStreamRequestPayload();
$this->addRecursionDetection();
$this->addRequestBuilder();
if ($this->isUseEndpointV2()) {
$this->addEndpointV2Middleware();
}

if (isset($args['with_resolved'])) {
$args['with_resolved']($config);
Expand Down Expand Up @@ -499,24 +502,18 @@ private function addRecursionDetection()
);
}

/**
* Adds the `builder` middleware such that a client's endpoint
* provider and endpoint resolution arguments can be passed.
*/
private function addRequestBuilder()
private function addEndpointV2Middleware()
{
$handlerList = $this->getHandlerList();
$serializer = $this->serializer;
$endpointProvider = $this->endpointProvider;
$list = $this->getHandlerList();
$endpointArgs = $this->getEndpointProviderArgs();

$handlerList->prependBuild(
Middleware::requestBuilder(
$serializer,
$endpointProvider,
$list->prependBuild(
EndpointV2Middleware::wrap(
$this->endpointProvider,
$this->getApi(),
$endpointArgs
),
'builderV2'
'endpointV2_middleware'
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/ClientResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class ClientResolver
],
'serializer' => [
'default' => [__CLASS__, '_default_serializer'],
'fn' => [__CLASS__, '_apply_serializer'],
'internal' => true,
'type' => 'value',
'valid' => ['callable'],
Expand Down Expand Up @@ -834,6 +835,11 @@ public static function _default_use_dual_stack_endpoint(array &$args) {
return UseDualStackConfigProvider::defaultProvider($args);
}

public static function _apply_serializer($value, array &$args, HandlerList $list)
{
$list->prependBuild(Middleware::requestBuilder($value), 'builder');
}

public static function _apply_debug($value, array &$args, HandlerList $list)
{
if ($value !== false) {
Expand Down
Loading