Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update secrets_enum to list found secrets #448

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions pacu/modules/secrets__enum/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ def main(args, pacu_main: 'Main'):

if response:
for secret in response['SecretList']:
print(' Found secret: {}'.format(secret["Name"]))
secret_ids.append({"name": secret["Name"], "region": region})

all_secrets_ids_sm += secret_ids

for sec in all_secrets_ids_sm:
secret_values = []
print("Probing Secret: {}".format(sec['name']))
client = pacu_main.get_boto3_client('secretsmanager', sec["region"])

response = None
Expand All @@ -113,24 +115,24 @@ def main(args, pacu_main: 'Main'):
)
except ClientError as error:
code = error.response['Error']['Code']
print('FAILURE: ')
print(' FAILURE: ')
if code == 'UnauthorizedOperation':
print(' Access denied to GetSecretsValue.')
print(' Access denied to GetSecretsValue.')
else:
print(' ' + code)
print(' Could not get secrets value... Exiting')
print(' ' + code)
print(' Could not get secrets value... Exiting')
response = None
break
except EndpointConnectionError as error:
print(' Error connecting to SecretsManager Endpoint for getting secret for region: {}'.format(
print(' Error connecting to SecretsManager Endpoint for getting secret for region: {}'.format(
sec["region"]))
print(' Error: {}, {}'.format(error.__class__, str(error)))
print(' Error: {}, {}'.format(error.__class__, str(error)))
response = None
break
except Exception as error:
print(' Generic Error when getting Secret from Secrets Manager for region: {}'.format(
print(' Generic Error when getting Secret from Secrets Manager for region: {}'.format(
sec["region"]))
print(' Error: {}, {}'.format(error.__class__, str(error)))
print(' Error: {}, {}'.format(error.__class__, str(error)))
response = None
break

Expand All @@ -139,6 +141,7 @@ def main(args, pacu_main: 'Main'):
f.write("{}:{}\n".format(sec["name"], response["SecretString"]))

if args.parameter_store:
print("Probing parameter store")
client = pacu_main.get_boto3_client('ssm', region)

response = None
Expand All @@ -147,23 +150,23 @@ def main(args, pacu_main: 'Main'):
response = client.describe_parameters()
except ClientError as error:
code = error.response['Error']['Code']
print('FAILURE: ')
print(' FAILURE: ')
if code == 'UnauthorizedOperation':
print(' Access denied to DescribeParameters.')
print(' Access denied to DescribeParameters.')
else:
print(' ' + code)
print(' Could not list parameters... Exiting')
print(' ' + code)
print(' Could not list parameters... Exiting')
response = None
break
except EndpointConnectionError as error:
print(' Error connecting to SSM Endpoint for describing SSM Parameters for region: {}'.format(
print(' Error connecting to SSM Endpoint for describing SSM Parameters for region: {}'.format(
region))
print(' Error: {}, {}'.format(error.__class__, str(error)))
print(' Error: {}, {}'.format(error.__class__, str(error)))
response = None
break
except Exception as error:
print(' Generic Error when describing SSM Parameters for region: {}'.format(region))
print(' Error: {}, {}'.format(error.__class__, str(error)))
print(' Generic Error when describing SSM Parameters for region: {}'.format(region))
print(' Error: {}, {}'.format(error.__class__, str(error)))
response = None
break

Expand Down
Loading