Skip to content

Commit d4de71c

Browse files
bnpatel1990DavertMik
authored andcommitted
AWS Authorization for REST requests (#4623)
* AWS Authentication For Rest * Docs Update * Coding Space Update * Code Review Updates * Method exists Update * Code Review Updates
1 parent b9bd5a8 commit d4de71c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Codeception/Lib/Connector/Guzzle.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Codeception\Lib\Connector;
33

4+
use Aws\Credentials\Credentials;
5+
use Aws\Signature\SignatureV4;
46
use Codeception\Util\Uri;
57
use GuzzleHttp\Exception\RequestException;
68
use GuzzleHttp\Message\Response;
@@ -19,6 +21,8 @@ class Guzzle extends Client
1921
];
2022
protected $refreshMaxInterval = 0;
2123

24+
protected $awsCredentials = null;
25+
protected $awsSignature = null;
2226

2327
/** @var \GuzzleHttp\Client */
2428
protected $client;
@@ -198,7 +202,11 @@ protected function doRequest($request)
198202

199203
// Let BrowserKit handle redirects
200204
try {
201-
$response = $this->client->send($guzzleRequest);
205+
if (null !== $this->awsCredentials) {
206+
$response = $this->client->send($this->awsSignature->signRequest($guzzleRequest, $this->awsCredentials));
207+
} else {
208+
$response = $this->client->send($guzzleRequest);
209+
}
202210
} catch (RequestException $e) {
203211
if ($e->hasResponse()) {
204212
$response = $e->getResponse();
@@ -278,4 +286,10 @@ protected function extractCookies(BrowserKitRequest $request)
278286
{
279287
return $this->getCookieJar()->allRawValues($request->getUri());
280288
}
289+
290+
public function setAwsAuth($config)
291+
{
292+
$this->awsCredentials = new Credentials($config['key'], $config['secret']);
293+
$this->awsSignature = new SignatureV4($config['service'], $config['region']);
294+
}
281295
}

0 commit comments

Comments
 (0)