Skip to content

Commit 49700c5

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 1cdcf47 commit 49700c5

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/Codeception/Module/REST.php

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Codeception\Module;
33

4+
use Codeception\Exception\ConfigurationException;
45
use Codeception\Exception\ModuleException;
56
use Codeception\Lib\Interfaces\ConflictsWithModule;
67
use Codeception\Module as CodeceptionModule;
@@ -57,7 +58,8 @@
5758
class REST extends CodeceptionModule implements DependsOnModule, PartedModule, API, ConflictsWithModule
5859
{
5960
protected $config = [
60-
'url' => ''
61+
'url' => '',
62+
'aws' => ''
6163
];
6264

6365
protected $dependencyMessage = <<<EOF
@@ -332,6 +334,51 @@ public function amNTLMAuthenticated($username, $password)
332334
$this->client->setAuth($username, $password, 'ntlm');
333335
}
334336

337+
/**
338+
* Allows to send REST request using AWS Authorization
339+
* Only works with PhpBrowser
340+
* Example
341+
* Config -
342+
*
343+
* modules:
344+
* enabled:
345+
* - REST:
346+
* aws:
347+
* key: accessKey
348+
* secret: accessSecret
349+
* service: awsService
350+
* region: awsRegion
351+
*
352+
* ```php
353+
* <?php
354+
* $I->amAWSAuthenticated();
355+
* ?>
356+
* ```
357+
* @param array $additionalAWSConfig
358+
* @throws ModuleException
359+
*/
360+
public function amAWSAuthenticated($additionalAWSConfig = [])
361+
{
362+
if (method_exists($this->client, 'setAwsAuth')) {
363+
$config = array_merge($this->config['aws'], $additionalAWSConfig);
364+
365+
if (!isset($this->config['key'])) {
366+
throw new ConfigurationException('AWS Key is not set');
367+
}
368+
if (!isset($this->config['secret'])) {
369+
throw new ConfigurationException('AWS Secret is not set');
370+
}
371+
if (!isset($this->config['service'])) {
372+
throw new ConfigurationException('AWS Service is not set');
373+
}
374+
if (!isset($this->config['region'])) {
375+
throw new ConfigurationException('AWS Region is not set');
376+
}
377+
378+
$this->client->setAwsAuth($config);
379+
}
380+
}
381+
335382
/**
336383
* Sends a POST request to given uri. Parameters and files can be provided separately.
337384
*

0 commit comments

Comments
 (0)