-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added possibility of configuring multiple AWS SSM adapters
- Loading branch information
1 parent
a09be8b
commit b11a432
Showing
11 changed files
with
373 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,4 @@ | ||
parameters: | ||
pk.config.adapter.ssm_client.class: PK\Config\StorageAdapter\AwsSsm | ||
pk.config.adapter.ssm_by_path_client.class: PK\Config\StorageAdapter\AwsSsmByPath | ||
pk.config.aws.ssm_client.class: Aws\Ssm\SsmClient | ||
|
||
services: | ||
PK\Config\StorageAdapter\AwsSsm: '@pk.config.adapter.ssm_client' | ||
|
||
pk.config.adapter.ssm_client: | ||
class: '%pk.config.adapter.ssm_client.class%' | ||
arguments: | ||
$path: '%pk.config.adapter.ssm_client.path%' | ||
$ssmClient: '@pk.config.aws.ssm_client' | ||
|
||
pk.config.aws.ssm_client: | ||
class: '%pk.config.aws.ssm_client.class%' | ||
arguments: | ||
$args: '%pk.config.aws.ssm_client.args%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PK\Config\StorageAdapter; | ||
|
||
use Aws\Result; | ||
use Aws\Ssm\SsmClient; | ||
use PK\Config\Entry; | ||
use PK\Config\StorageAdapterInterface; | ||
|
||
class AwsSsmByPath implements StorageAdapterInterface | ||
{ | ||
private const ENV_PLACEHOLDER = '{env}'; | ||
|
||
/** | ||
* @var SsmClient | ||
*/ | ||
private $ssmClient; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $path; | ||
|
||
public function __construct(SsmClient $ssmClient, string $path) | ||
{ | ||
$this->ssmClient = $ssmClient; | ||
$this->path = $path; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetch(string $environment): array | ||
{ | ||
$path = str_replace(self::ENV_PLACEHOLDER, $environment, $this->path); | ||
|
||
$entries = []; | ||
$parameters = $nextToken = null; | ||
while (!$parameters || $nextToken) { | ||
$parameters = $this->doFetch($nextToken, $path); | ||
|
||
foreach ($parameters['Parameters'] as $parameter) { | ||
$entries[] = new Entry( | ||
str_replace($path, '', $parameter['Name']), | ||
$parameter['Value'] | ||
); | ||
} | ||
$nextToken = $parameters['NextToken'] ?? null; | ||
} | ||
|
||
return $entries; | ||
} | ||
|
||
private function doFetch(?string $nextToken, string $path): Result | ||
{ | ||
return $this->ssmClient->getParametersByPath( | ||
array_filter([ | ||
'Path' => $path, | ||
'WithDecryption' => true, | ||
'NextToken' => $nextToken, | ||
]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.