Skip to content

Commit 9a1fdd1

Browse files
committed
MQE-1919: MFTF AWS Secrets Manager - CI Use
1 parent 12c3bdf commit 9a1fdd1

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

etc/config/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ BROWSER=chrome
3737
#*** To use AWS Secrets Manager to manage _CREDS secrets, uncomment and set region, profile is optional, when omitted, AWS default credential provider chain will be used ***#
3838
#CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE=default
3939
#CREDENTIAL_AWS_SECRETS_MANAGER_REGION=us-east-1
40+
#*** If using non-default AWS account ***#
41+
#CREDENTIAL_AWS_ACCOUNT_ID=
4042

4143
#*** Uncomment these properties to set up a dev environment with symlinked projects ***#
4244
#TESTS_BP=

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/CredentialStore.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ private function __construct()
7979
// Initialize AWS Secrets Manager storage
8080
$awsRegion = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_REGION');
8181
$awsProfile = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE');
82+
$awsId = getenv('CREDENTIAL_AWS_ACCOUNT_ID');
8283
if ($awsRegion !== false) {
8384
if ($awsProfile === false) {
8485
$awsProfile = null;
8586
}
87+
if ($awsId === false) {
88+
$awsId = null;
89+
}
8690
try {
8791
$this->credStorage[self::ARRAY_KEY_FOR_AWS_SECRETS_MANAGER] = new AwsSecretsManagerStorage(
8892
$awsRegion,
89-
$awsProfile
93+
$awsProfile,
94+
$awsId
9095
);
9196
} catch (TestFrameworkException $e) {
9297
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/SecretStorage/AwsSecretsManagerStorage.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class AwsSecretsManagerStorage extends BaseStorage
2222
*/
2323
const MFTF_PATH = 'mftf';
2424

25+
/**
26+
* AWS Secrets Manager partial ARN
27+
*/
28+
const AWS_SM_PARTIAL_ARN = 'arn:aws:secretsmanager:';
29+
2530
/**
2631
* AWS Secrets Manager version
2732
*
@@ -36,18 +41,35 @@ class AwsSecretsManagerStorage extends BaseStorage
3641
*/
3742
private $client = null;
3843

44+
/**
45+
* AWS account id
46+
*
47+
* @var string
48+
*/
49+
private $awsAccountId;
50+
51+
/**
52+
* AWS account region
53+
*
54+
* @var string
55+
*/
56+
private $region;
57+
3958
/**
4059
* AwsSecretsManagerStorage constructor
4160
*
4261
* @param string $region
4362
* @param string $profile
63+
* @param string $accountId
4464
* @throws TestFrameworkException
4565
* @throws InvalidArgumentException
4666
*/
47-
public function __construct($region, $profile = null)
67+
public function __construct($region, $profile = null, $accountId = null)
4868
{
4969
parent::__construct();
5070
$this->createAwsSecretsManagerClient($region, $profile);
71+
$this->region = $region;
72+
$this->awsAccountId = $accountId;
5173
}
5274

5375
/**
@@ -74,7 +96,12 @@ public function getEncryptedValue($key)
7496
try {
7597
// Split vendor/key to construct secret id
7698
list($vendor, $key) = explode('/', trim($key, '/'), 2);
77-
$secretId = self::MFTF_PATH
99+
// If AWS account id is specified, create and use full ARN, otherwise use partial ARN as secret id
100+
$secretId = '';
101+
if (!empty($this->awsAccountId)) {
102+
$secretId = self::AWS_SM_PARTIAL_ARN . $this->region . ':' . $this->awsAccountId . ':secret:';
103+
}
104+
$secretId .= self::MFTF_PATH
78105
. '/'
79106
. $vendor
80107
. '/'

0 commit comments

Comments
 (0)