Skip to content

Commit e3e2cbf

Browse files
authored
Make sure we select region properly (#754)
* make sure we select region properly * Adding changelog
1 parent 259af62 commit e3e2cbf

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## NOT RELEASED
44

5+
## 1.4.1
6+
7+
### Fixed
8+
9+
- Make sure passing `@region` to an API operation has effect.
10+
- Check that both AWS access id and secret exists before using them.
11+
512
## 1.4.0
613

714
### Added

src/AbstractApi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected function getEndpointMetadata(?string $region): array
192192
protected function getEndpoint(string $uri, array $query, ?string $region): string
193193
{
194194
/** @var string $region */
195-
$region = $region ?? $this->configuration->isDefault('region') ? null : $this->configuration->get('region');
195+
$region = $region ?? ($this->configuration->isDefault('region') ? null : $this->configuration->get('region'));
196196
if (!$this->configuration->isDefault('endpoint')) {
197197
/** @var string $endpoint */
198198
$endpoint = $this->configuration->get('endpoint');

tests/Unit/AbstractApiTest.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AsyncAws\Core\Tests\Unit;
6+
7+
use AsyncAws\Core\AbstractApi;
8+
use AsyncAws\Core\Configuration;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class AbstractApiTest extends TestCase
12+
{
13+
public function testGetEndpointRegion()
14+
{
15+
$api = new DummyApi();
16+
17+
// Use default region
18+
$endpoint = $api->getEndpoint('/some/path', [], null);
19+
self::assertEquals('https://foobar.us-east-1.amazonaws.com/some/path', $endpoint);
20+
21+
$endpoint = $api->getEndpoint('/some/path', [], 'eu-central-1');
22+
self::assertEquals('https://foobar.eu-central-1.amazonaws.com/some/path', $endpoint);
23+
24+
// Use region from config
25+
$api = new DummyApi(['region' => 'eu-north-1']);
26+
$endpoint = $api->getEndpoint('/some/path', [], null);
27+
self::assertEquals('https://foobar.eu-north-1.amazonaws.com/some/path', $endpoint);
28+
29+
$endpoint = $api->getEndpoint('/some/path', [], 'eu-central-1');
30+
self::assertEquals('https://foobar.eu-central-1.amazonaws.com/some/path', $endpoint);
31+
}
32+
}
33+
34+
class DummyApi extends AbstractApi
35+
{
36+
public function getEndpoint(string $uri, array $query, ?string $region): string
37+
{
38+
return parent::getEndpoint($uri, $query, $region);
39+
}
40+
41+
protected function getEndpointMetadata(?string $region): array
42+
{
43+
if (null === $region) {
44+
$region = Configuration::DEFAULT_REGION;
45+
}
46+
47+
return [
48+
'endpoint' => "https://foobar.$region.amazonaws.com",
49+
'signRegion' => $region,
50+
'signService' => 'foobar',
51+
'signVersions' => ['v4'],
52+
];
53+
}
54+
}

0 commit comments

Comments
 (0)