-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kim Pepper <[email protected]>
- Loading branch information
Showing
38 changed files
with
2,781 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace OpenSearch\Aws; | ||
|
||
use Aws\Credentials\CredentialsInterface; | ||
use Aws\Signature\SignatureInterface; | ||
use OpenSearch\RequestFactory; | ||
use OpenSearch\RequestFactoryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
/** | ||
* A decorator request factory that signs requests using the provided AWS credentials and signer. | ||
*/ | ||
class SigningRequestFactory implements RequestFactoryInterface | ||
{ | ||
public function __construct( | ||
protected RequestFactory $requestFactory, | ||
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 request factory.' | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createRequest( | ||
string $method, | ||
string $uri, | ||
array $params = [], | ||
array|string|null $body = null, | ||
array $headers = [], | ||
): RequestInterface { | ||
$request = $this->requestFactory->createRequest($method, $uri, $params, $body, $headers); | ||
$request = $request->withHeader('x-amz-content-sha256', hash('sha256', (string) $request->getBody())); | ||
return $this->signer->signRequest($request, $this->credentials); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.