-
-
Save KyMidd/54a3585eedc8e477b5f8ea94f61d4987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Find all secrets that match string | |
| def search_for_secrets(SecretSearchString, SecretSearchRegion): | |
| secret_search_string = SecretSearchString | |
| secret_search_region = SecretSearchRegion | |
| session = boto3.session.Session() | |
| client = session.client( | |
| service_name='secretsmanager', | |
| region_name=secret_search_region, | |
| ) | |
| try: | |
| list_secrets_response = client.list_secrets( | |
| MaxResults=100, #100 is max supported | |
| Filters=[ | |
| { | |
| 'Key': 'name', | |
| 'Values': [ | |
| secret_search_string, | |
| ] | |
| }, | |
| ] | |
| ) | |
| except ClientError as e: | |
| print("The requested secret search string returned no results: " + secret_search_string) | |
| print("The error is:", e) | |
| else: | |
| # Store all secrets in array: | |
| foundSecrets = [] | |
| for secret_name in list_secrets_response["SecretList"]: | |
| #print("Found secrets:", secret_name["Name"]) | |
| foundSecrets.append(secret_name["Name"]) | |
| #print("The list of secrets is: ", foundSecrets) | |
| return(foundSecrets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment