Skip to content

Commit 6a06605

Browse files
committed
MQE-1919: MFTF AWS Secrets Manager - CI Use
1 parent 1c6a332 commit 6a06605

File tree

3 files changed

+76
-43
lines changed

3 files changed

+76
-43
lines changed

etc/config/.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ 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=
4240

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

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

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,45 +57,10 @@ public static function getInstance()
5757
*/
5858
private function __construct()
5959
{
60-
// Initialize file storage
61-
try {
62-
$this->credStorage[self::ARRAY_KEY_FOR_FILE] = new FileStorage();
63-
} catch (TestFrameworkException $e) {
64-
}
65-
66-
// Initialize vault storage
67-
$cvAddress = getenv('CREDENTIAL_VAULT_ADDRESS');
68-
$cvSecretPath = getenv('CREDENTIAL_VAULT_SECRET_BASE_PATH');
69-
if ($cvAddress !== false && $cvSecretPath !== false) {
70-
try {
71-
$this->credStorage[self::ARRAY_KEY_FOR_VAULT] = new VaultStorage(
72-
UrlFormatter::format($cvAddress, false),
73-
'/' . trim($cvSecretPath, '/')
74-
);
75-
} catch (TestFrameworkException $e) {
76-
}
77-
}
78-
79-
// Initialize AWS Secrets Manager storage
80-
$awsRegion = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_REGION');
81-
$awsProfile = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE');
82-
$awsId = getenv('CREDENTIAL_AWS_ACCOUNT_ID');
83-
if (!empty($awsRegion)) {
84-
if (empty($awsProfile)) {
85-
$awsProfile = null;
86-
}
87-
if (empty($awsId)) {
88-
$awsId = null;
89-
}
90-
try {
91-
$this->credStorage[self::ARRAY_KEY_FOR_AWS_SECRETS_MANAGER] = new AwsSecretsManagerStorage(
92-
$awsRegion,
93-
$awsProfile,
94-
$awsId
95-
);
96-
} catch (TestFrameworkException $e) {
97-
}
98-
}
60+
// Initialize credential storage by defined order of precedence as the following
61+
$this->initializeFileStorage();
62+
$this->initializeVaultStorage();
63+
$this->initializeAwsSecretsManagerStorage();
9964

10065
if (empty($this->credStorage)) {
10166
throw new TestFrameworkException(
@@ -155,4 +120,68 @@ public function decryptAllSecretsInString($string)
155120
return $storage->getAllDecryptedValuesInString($string);
156121
}
157122
}
123+
124+
/**
125+
* Initialize file storage
126+
*
127+
* @return void
128+
*/
129+
private function initializeFileStorage()
130+
{
131+
// Initialize file storage
132+
try {
133+
$this->credStorage[self::ARRAY_KEY_FOR_FILE] = new FileStorage();
134+
} catch (TestFrameworkException $e) {
135+
}
136+
}
137+
138+
/**
139+
* Initialize Vault storage
140+
*
141+
* @return void
142+
*/
143+
private function initializeVaultStorage()
144+
{
145+
// Initialize vault storage
146+
$cvAddress = getenv('CREDENTIAL_VAULT_ADDRESS');
147+
$cvSecretPath = getenv('CREDENTIAL_VAULT_SECRET_BASE_PATH');
148+
if ($cvAddress !== false && $cvSecretPath !== false) {
149+
try {
150+
$this->credStorage[self::ARRAY_KEY_FOR_VAULT] = new VaultStorage(
151+
UrlFormatter::format($cvAddress, false),
152+
'/' . trim($cvSecretPath, '/')
153+
);
154+
} catch (TestFrameworkException $e) {
155+
}
156+
}
157+
}
158+
159+
/**
160+
* Initialize AWS Secrets Manager storage
161+
*
162+
* @return void
163+
*/
164+
private function initializeAwsSecretsManagerStorage()
165+
{
166+
// Initialize AWS Secrets Manager storage
167+
$awsRegion = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_REGION');
168+
$awsProfile = getenv('CREDENTIAL_AWS_SECRETS_MANAGER_PROFILE');
169+
$awsId = getenv('CREDENTIAL_AWS_ACCOUNT_ID');
170+
if (!empty($awsRegion)) {
171+
if (empty($awsProfile)) {
172+
$awsProfile = null;
173+
}
174+
if (empty($awsId)) {
175+
$awsId = null;
176+
}
177+
try {
178+
$this->credStorage[self::ARRAY_KEY_FOR_AWS_SECRETS_MANAGER] = new AwsSecretsManagerStorage(
179+
$awsRegion,
180+
$awsProfile,
181+
$awsId
182+
);
183+
} catch (TestFrameworkException $e) {
184+
}
185+
}
186+
}
158187
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,19 @@ private function parseAwsSecretResult($awsResult, $key)
148148
if (isset($awsResult['SecretString'])) {
149149
$rawSecret = $awsResult['SecretString'];
150150
} else {
151-
throw new TestFrameworkException("Error parsing result from AWS Secrets Manager");
151+
print_r('raw result:');
152+
var_dump($awsResult);
153+
throw new TestFrameworkException(
154+
"'SecretString' is not set in AWS Result. Error parsing result from AWS Secrets Manager"
155+
);
152156
}
153157
$secret = json_decode($rawSecret, true);
154158
if (isset($secret[$key])) {
155159
return $secret[$key];
156160
}
157-
throw new TestFrameworkException("Error parsing result from AWS Secrets Manager");
161+
print_r('result:');
162+
var_dump($secret);
163+
throw new TestFrameworkException("$key not found in AWS Result. Error parsing result from AWS Secrets Manager");
158164
}
159165

160166
/**

0 commit comments

Comments
 (0)