Skip to content

Commit

Permalink
fix parameters after signing #73 (#76)
Browse files Browse the repository at this point in the history
* fix parameters after signing #73
Signed-off-by: Boris Charriere <[email protected]>

Signed-off-by: Boris Charriere <[email protected]>

* add test case for client paramters

Signed-off-by: Boris Charriere <[email protected]>

Co-authored-by: bcharriere <[email protected]>
  • Loading branch information
BorisCharriere and bcharriere authored Aug 10, 2022
1 parent 3c9c2f4 commit 845edd6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/OpenSearch/Handlers/SigV4Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __invoke(array $request)
$signedRequest = $this->signer
->signRequest($psr7Request, $creds);

return call_user_func($this->wrappedHandler, $this->createRingRequest($signedRequest));
return call_user_func($this->wrappedHandler, $this->createRingRequest($signedRequest, $request));
}

public static function assertDependenciesInstalled(): void
Expand Down Expand Up @@ -92,7 +92,7 @@ private function createPsr7Request(array $ringPhpRequest): Request
);
}

private function createRingRequest(RequestInterface $request): array
private function createRingRequest(RequestInterface $request, array $originalRequest): array
{
$uri = $request->getUri();
$body = (string) $request->getBody();
Expand All @@ -109,6 +109,7 @@ private function createRingRequest(RequestInterface $request): array
'uri' => $uri->getPath(),
'body' => $body,
'headers' => $request->getHeaders(),
'client' => $originalRequest['client']
];
if ($uri->getQuery()) {
$ringRequest['query_string'] = $uri->getQuery();
Expand Down
20 changes: 20 additions & 0 deletions tests/Handlers/SigV4HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ public function testNonEmptyRequestBodiesShouldNotBeNull()
]);
}

public function testClientParametersShouldBePassedToHandler()
{
$toWrap = function (array $ringRequest) {
$this->assertArrayHasKey('client', $ringRequest);
$this->assertArrayHasKey('timeout', $ringRequest['client']);
$this->assertArrayHasKey('connect_timeout', $ringRequest['client']);

return $this->getGenericResponse();
};

$client = ClientBuilder::create()
->setHandler($toWrap)
->setSigV4Region('us-west-2')
->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz'))
->setConnectionParams(['client' => ['timeout' => 5, 'connect_timeout' => 5]])
->build();

$client->indices()->exists(['index' => 'index']);
}

private function getGenericResponse()
{
return new CompletedFutureArray([
Expand Down

0 comments on commit 845edd6

Please sign in to comment.