Skip to content

Commit

Permalink
Revert "enhancement: Endpointv2 Middleware (#2790)" (#2833)
Browse files Browse the repository at this point in the history
  • Loading branch information
stobrien89 authored Nov 21, 2023
1 parent dca4bc1 commit 3daedce
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 584 deletions.
16 changes: 12 additions & 4 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,7 +56,8 @@ public function __construct(
*/
public function __invoke(
CommandInterface $command,
$endpoint = null
$endpointProvider = null,
$clientArgs = null
)
{
$operationName = $command->getName();
Expand All @@ -67,8 +68,15 @@ public function __invoke(
'Content-Type' => $this->contentType
];

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

return new Request(
Expand Down
15 changes: 11 additions & 4 deletions src/Api/Serializer/QuerySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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 @@ -43,7 +42,8 @@ public function __construct(
*/
public function __invoke(
CommandInterface $command,
$endpoint = null
$endpointProvider = null,
$clientArgs = null
)
{
$operation = $this->api->getOperation($command->getName());
Expand All @@ -67,8 +67,15 @@ public function __invoke(
'Content-Type' => 'application/x-www-form-urlencoded'
];

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

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

if ($endpoint instanceof RulesetEndpoint) {
$this->setEndpointV2RequestOptions($endpoint, $headers);
$headers = isset($opts['headers']) ? $opts['headers'] : [];

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

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

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

Expand Down
25 changes: 14 additions & 11 deletions src/AwsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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 @@ -241,9 +240,7 @@ public function __construct(array $args)
$this->loadAliases();
$this->addStreamRequestPayload();
$this->addRecursionDetection();
if ($this->isUseEndpointV2()) {
$this->addEndpointV2Middleware();
}
$this->addRequestBuilder();

if (!is_null($this->api->getMetadata('awsQueryCompatible'))) {
$this->addQueryCompatibleInputMiddleware($this->api);
Expand Down Expand Up @@ -515,18 +512,24 @@ private function addRecursionDetection()
);
}

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

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

Expand Down
6 changes: 0 additions & 6 deletions src/ClientResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class ClientResolver
],
'serializer' => [
'default' => [__CLASS__, '_default_serializer'],
'fn' => [__CLASS__, '_apply_serializer'],
'internal' => true,
'type' => 'value',
'valid' => ['callable'],
Expand Down Expand Up @@ -835,11 +834,6 @@ 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

0 comments on commit 3daedce

Please sign in to comment.