From 7402c7e40914d29fd94f9634ea82b0e0fcdf905a Mon Sep 17 00:00:00 2001 From: floptical Date: Fri, 5 Jul 2024 18:36:39 +0000 Subject: [PATCH] properly write mulesoft creds [skip ci] --- write-secrets-to-env.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/write-secrets-to-env.py b/write-secrets-to-env.py index d6cae90..c405480 100644 --- a/write-secrets-to-env.py +++ b/write-secrets-to-env.py @@ -60,21 +60,21 @@ access_key_id = aws_creds["Citygeo AWS Key Pair PROD"]['access_key'] secret_access_key = aws_creds["Citygeo AWS Key Pair PROD"]['secret_key'] -home = expanduser("~") +aws_creds = cgs.get_secrets('Mulesoft AWS Key Pair PROD') +ms_access_key_id = aws_creds["Mulesoft AWS Key Pair PROD"]['login'] +ms_secret_access_key = aws_creds["Mulesoft AWS Key Pair PROD"]['password'] -filename = os.path.join(home, '.aws/credentials') -with open(filename, 'r') as file: - lines = file.readlines() +home = expanduser("~") -new_lines = [] -for line in lines: - if line.startswith('aws_access_key_id'): - new_lines.append(f'aws_access_key_id = {access_key_id}\n') - elif line.startswith('aws_secret_access_key'): - new_lines.append(f'aws_secret_access_key = {secret_access_key}\n') - else: - new_lines.append(line) +aws_credentials_path = os.path.join(home, '.aws/credentials') -with open(filename, 'w') as file: - file.writelines(new_lines) +# Open the file in write mode ('w') to ensure it will be overwritten if it exists +with open(aws_credentials_path, 'w') as file: + file.write(f"[default]\n") + file.write(f"aws_access_key_id = {access_key_id}\n") + file.write(f"aws_secret_access_key = {secret_access_key}\n") + file.write(f"[mulesoft]\n") + file.write(f"aws_access_key_id = {ms_access_key_id}\n") + file.write(f"aws_secret_access_key = {ms_secret_access_key}\n") +print("AWS credentials file created and overwritten successfully.")