Skip to content

Commit

Permalink
Persist credentials through restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
apotek committed Oct 31, 2024
1 parent dd26559 commit 7077872
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Robo/Plugin/Traits/DatabaseDownloadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function databaseDownload(ConsoleIO $io, string $siteName = 'default'): s
if (getenv('AWS_SECRET_ACCESS_KEY')) {
$io->error([
'Cannot authenticate to AWS S3. Please fix your AWS environment',
'variables, or remove them completely and try again.',
'variables in .env, or remove them completely and try again.',
]);
return Result::cancelled();
}
Expand Down Expand Up @@ -116,6 +116,7 @@ protected function configureAwsCredentials(ConsoleIO $io): Result|ResultData
{
$awsConfigDirPath = getenv('HOME') . '/.aws';
$awsConfigFilePath = "$awsConfigDirPath/credentials";
$persistentCredentialsPath = '.ddev/homeadditions/.aws';
$authenticated = false;

while ($authenticated === false) {
Expand All @@ -131,11 +132,14 @@ protected function configureAwsCredentials(ConsoleIO $io): Result|ResultData
}
$awsKeyId = $io->ask("AWS Access Key ID:");
$awsSecretKey = $io->askHidden("AWS Secret Access Key:");
$writeResult = $this->taskWriteToFile($awsConfigFilePath)
$collection = $this->collectionBuilder($io);
$collection->taskWriteToFile($awsConfigFilePath)
->line('[default]')
->line("aws_access_key_id = $awsKeyId")
->line("aws_secret_access_key = $awsSecretKey")
->run();
->line("aws_secret_access_key = $awsSecretKey");
$collection->taskCopyDir([$awsConfigDirPath => $persistentCredentialsPath])
->overwrite(true);
$writeResult = $collection->run();
try {
$sts = new StsClient();
$stsResponse = $sts->getCallerIdentity();
Expand Down

0 comments on commit 7077872

Please sign in to comment.