Skip to content

Commit f84aca7

Browse files
authored
Refactor endpoint generation (#605)
* Refactor endpoint generation * Regenerate code * Use default case for "global" endpoint * Add an UnsupportedRegion exception * Handle null region * Check region for global * Display only supported versions * Fix cs * Add blank line, and replace PHP_EOL bt \n
1 parent dff8ada commit f84aca7

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

src/DynamoDbClient.php

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AsyncAws\DynamoDb;
44

55
use AsyncAws\Core\AbstractApi;
6+
use AsyncAws\Core\Configuration;
7+
use AsyncAws\Core\Exception\UnsupportedRegion;
68
use AsyncAws\Core\RequestContext;
79
use AsyncAws\DynamoDb\Input\CreateTableInput;
810
use AsyncAws\DynamoDb\Input\DeleteItemInput;
@@ -374,6 +376,156 @@ public function updateTable($input): UpdateTableOutput
374376
return new UpdateTableOutput($response);
375377
}
376378

379+
protected function getEndpointMetadata(?string $region): array
380+
{
381+
if (null === $region) {
382+
$region = Configuration::DEFAULT_REGION;
383+
}
384+
385+
switch ($region) {
386+
case 'af-south-1':
387+
case 'ap-east-1':
388+
case 'ap-northeast-1':
389+
case 'ap-northeast-2':
390+
case 'ap-south-1':
391+
case 'ap-southeast-1':
392+
case 'ap-southeast-2':
393+
case 'ca-central-1':
394+
case 'eu-central-1':
395+
case 'eu-north-1':
396+
case 'eu-south-1':
397+
case 'eu-west-1':
398+
case 'eu-west-2':
399+
case 'eu-west-3':
400+
case 'me-south-1':
401+
case 'sa-east-1':
402+
case 'us-east-1':
403+
case 'us-east-2':
404+
case 'us-west-1':
405+
case 'us-west-2':
406+
return [
407+
'endpoint' => 'https://dynamodb.%region%.amazonaws.com',
408+
'signRegion' => $region,
409+
'signService' => 'dynamodb',
410+
'signVersions' => [
411+
0 => 'v4',
412+
],
413+
];
414+
case 'cn-north-1':
415+
case 'cn-northwest-1':
416+
return [
417+
'endpoint' => 'https://dynamodb.%region%.amazonaws.com.cn',
418+
'signRegion' => $region,
419+
'signService' => 'dynamodb',
420+
'signVersions' => [
421+
0 => 'v4',
422+
],
423+
];
424+
case 'us-gov-east-1':
425+
case 'us-gov-west-1':
426+
return [
427+
'endpoint' => 'https://dynamodb.%region%.amazonaws.com',
428+
'signRegion' => $region,
429+
'signService' => 'dynamodb',
430+
'signVersions' => [
431+
0 => 'v4',
432+
],
433+
];
434+
case 'us-isob-east-1':
435+
return [
436+
'endpoint' => 'https://dynamodb.%region%.sc2s.sgov.gov',
437+
'signRegion' => $region,
438+
'signService' => 'dynamodb',
439+
'signVersions' => [
440+
0 => 'v4',
441+
],
442+
];
443+
case 'ca-central-1-fips':
444+
return [
445+
'endpoint' => 'https://dynamodb-fips.ca-central-1.amazonaws.com',
446+
'signRegion' => 'ca-central-1',
447+
'signService' => 'dynamodb',
448+
'signVersions' => [
449+
0 => 'v4',
450+
],
451+
];
452+
case 'local':
453+
return [
454+
'endpoint' => 'http://localhost:8000',
455+
'signRegion' => 'us-east-1',
456+
'signService' => 'dynamodb',
457+
'signVersions' => [
458+
0 => 'v4',
459+
],
460+
];
461+
case 'us-east-1-fips':
462+
return [
463+
'endpoint' => 'https://dynamodb-fips.us-east-1.amazonaws.com',
464+
'signRegion' => 'us-east-1',
465+
'signService' => 'dynamodb',
466+
'signVersions' => [
467+
0 => 'v4',
468+
],
469+
];
470+
case 'us-east-2-fips':
471+
return [
472+
'endpoint' => 'https://dynamodb-fips.us-east-2.amazonaws.com',
473+
'signRegion' => 'us-east-2',
474+
'signService' => 'dynamodb',
475+
'signVersions' => [
476+
0 => 'v4',
477+
],
478+
];
479+
case 'us-gov-east-1-fips':
480+
return [
481+
'endpoint' => 'https://dynamodb.us-gov-east-1.amazonaws.com',
482+
'signRegion' => 'us-gov-east-1',
483+
'signService' => 'dynamodb',
484+
'signVersions' => [
485+
0 => 'v4',
486+
],
487+
];
488+
case 'us-gov-west-1-fips':
489+
return [
490+
'endpoint' => 'https://dynamodb.us-gov-west-1.amazonaws.com',
491+
'signRegion' => 'us-gov-west-1',
492+
'signService' => 'dynamodb',
493+
'signVersions' => [
494+
0 => 'v4',
495+
],
496+
];
497+
case 'us-iso-east-1':
498+
return [
499+
'endpoint' => 'https://dynamodb.us-iso-east-1.c2s.ic.gov',
500+
'signRegion' => 'us-iso-east-1',
501+
'signService' => 'dynamodb',
502+
'signVersions' => [
503+
0 => 'v4',
504+
],
505+
];
506+
case 'us-west-1-fips':
507+
return [
508+
'endpoint' => 'https://dynamodb-fips.us-west-1.amazonaws.com',
509+
'signRegion' => 'us-west-1',
510+
'signService' => 'dynamodb',
511+
'signVersions' => [
512+
0 => 'v4',
513+
],
514+
];
515+
case 'us-west-2-fips':
516+
return [
517+
'endpoint' => 'https://dynamodb-fips.us-west-2.amazonaws.com',
518+
'signRegion' => 'us-west-2',
519+
'signService' => 'dynamodb',
520+
'signVersions' => [
521+
0 => 'v4',
522+
],
523+
];
524+
}
525+
526+
throw new UnsupportedRegion(sprintf('The region "%s" is not supported by "DynamoDb".', $region));
527+
}
528+
377529
protected function getServiceCode(): string
378530
{
379531
return 'dynamodb';

0 commit comments

Comments
 (0)