|
1 | 1 | <?php |
2 | 2 | namespace Codeception\Module; |
3 | 3 |
|
| 4 | +use Codeception\Exception\ConfigurationException; |
4 | 5 | use Codeception\Exception\ModuleException; |
5 | 6 | use Codeception\Lib\Interfaces\ConflictsWithModule; |
6 | 7 | use Codeception\Module as CodeceptionModule; |
|
57 | 58 | class REST extends CodeceptionModule implements DependsOnModule, PartedModule, API, ConflictsWithModule |
58 | 59 | { |
59 | 60 | protected $config = [ |
60 | | - 'url' => '' |
| 61 | + 'url' => '', |
| 62 | + 'aws' => '' |
61 | 63 | ]; |
62 | 64 |
|
63 | 65 | protected $dependencyMessage = <<<EOF |
@@ -332,6 +334,51 @@ public function amNTLMAuthenticated($username, $password) |
332 | 334 | $this->client->setAuth($username, $password, 'ntlm'); |
333 | 335 | } |
334 | 336 |
|
| 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 | + |
335 | 382 | /** |
336 | 383 | * Sends a POST request to given uri. Parameters and files can be provided separately. |
337 | 384 | * |
|
0 commit comments