Skip to content

Commit

Permalink
Switch to signing decorator
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper committed Nov 20, 2024
1 parent 225edda commit f9b7f1a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
34 changes: 34 additions & 0 deletions src/OpenSearch/Aws/SigningClientDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace OpenSearch\Aws;

use Aws\Credentials\CredentialsInterface;
use Aws\Signature\SignatureInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* A decorator client that signs requests using the provided AWS credentials and signer.
*/
class SigningClientDecorator implements ClientInterface
{
public function __construct(
protected ClientInterface $inner,
protected CredentialsInterface $credentials,
protected SignatureInterface $signer,
) {
if (!class_exists(SignatureInterface::class)) {
throw new \RuntimeException(
'The AWS SDK for PHP must be installed in order to use the AWS signing client.'
);
}
}

public function sendRequest(RequestInterface $request): ResponseInterface
{
$request = $request->withHeader('x-amz-content-sha256', hash('sha256', (string) $request->getBody()));
$request = $this->signer->signRequest($request, $this->credentials);
return $this->inner->sendRequest($request);
}
}
43 changes: 0 additions & 43 deletions src/OpenSearch/Aws/SigningRequestFactory.php

This file was deleted.

5 changes: 4 additions & 1 deletion util/template/namespace-property
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
protected :namespaceNamespace $:var_namespace;
/**
* @var :namespaceNamespace
*/
protected $:var_namespace;

0 comments on commit f9b7f1a

Please sign in to comment.