Skip to content

Commit dfffde5

Browse files
jderusseNyholm
andauthored
Fix endpoint without region (#880)
* Fix endpoint without region * Fixed tests * cs fix Co-authored-by: Nyholm <tobias.nyholm@gmail.com>
1 parent 9e67ca8 commit dfffde5

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

src/Sts/StsClient.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace AsyncAws\Core\Sts;
44

55
use AsyncAws\Core\AbstractApi;
6-
use AsyncAws\Core\Exception\UnsupportedRegion;
76
use AsyncAws\Core\RequestContext;
87
use AsyncAws\Core\Sts\Input\AssumeRoleRequest;
98
use AsyncAws\Core\Sts\Input\AssumeRoleWithWebIdentityRequest;
@@ -107,32 +106,6 @@ protected function getEndpointMetadata(?string $region): array
107106
}
108107

109108
switch ($region) {
110-
case 'af-south-1':
111-
case 'ap-east-1':
112-
case 'ap-northeast-1':
113-
case 'ap-northeast-2':
114-
case 'ap-south-1':
115-
case 'ap-southeast-1':
116-
case 'ap-southeast-2':
117-
case 'ca-central-1':
118-
case 'eu-central-1':
119-
case 'eu-north-1':
120-
case 'eu-south-1':
121-
case 'eu-west-1':
122-
case 'eu-west-2':
123-
case 'eu-west-3':
124-
case 'me-south-1':
125-
case 'sa-east-1':
126-
case 'us-east-1':
127-
case 'us-east-2':
128-
case 'us-west-1':
129-
case 'us-west-2':
130-
return [
131-
'endpoint' => "https://sts.$region.amazonaws.com",
132-
'signRegion' => $region,
133-
'signService' => 'sts',
134-
'signVersions' => ['v4'],
135-
];
136109
case 'cn-north-1':
137110
case 'cn-northwest-1':
138111
return [
@@ -207,7 +180,12 @@ protected function getEndpointMetadata(?string $region): array
207180
];
208181
}
209182

210-
throw new UnsupportedRegion(sprintf('The region "%s" is not supported by "Sts".', $region));
183+
return [
184+
'endpoint' => "https://sts.$region.amazonaws.com",
185+
'signRegion' => $region,
186+
'signService' => 'sts',
187+
'signVersions' => ['v4'],
188+
];
211189
}
212190

213191
protected function getServiceCode(): string

tests/Integration/StsClientTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace AsyncAws\Core\Tests\Integration;
44

55
use AsyncAws\Core\Credentials\NullProvider;
6-
use AsyncAws\Core\Exception\UnsupportedRegion;
76
use AsyncAws\Core\Sts\Input\AssumeRoleRequest;
87
use AsyncAws\Core\Sts\Input\AssumeRoleWithWebIdentityRequest;
98
use AsyncAws\Core\Sts\Input\GetCallerIdentityRequest;
@@ -96,14 +95,16 @@ public function testNonAwsRegionWithCustomEndpoint(): void
9695
self::assertNotEmpty($client->presign(new AssumeRoleRequest(['RoleArn' => 'demo', 'RoleSessionName' => 'demo'])));
9796
}
9897

98+
/**
99+
* A region that is not recognized should be treated as "default" region.
100+
*/
99101
public function testNonAwsRegion(): void
100102
{
101103
$client = new StsClient([
102104
'region' => 'test',
103105
], new NullProvider());
104106

105-
$this->expectException(UnsupportedRegion::class);
106-
$client->presign(new AssumeRoleRequest(['RoleArn' => 'demo', 'RoleSessionName' => 'demo']));
107+
self::assertNotEmpty($client->presign(new AssumeRoleRequest(['RoleArn' => 'demo', 'RoleSessionName' => 'demo'])));
107108
}
108109

109110
public function testCustomEndpointSignature(): void

0 commit comments

Comments
 (0)