From 6f0f112e534277ddb0416bcf5b4de8279c1da800 Mon Sep 17 00:00:00 2001 From: DanielConnelly Date: Tue, 2 Jun 2026 15:20:12 +0100 Subject: [PATCH] [ISS-1258][DC] resolving formatting and line length issues --- pre_commit_hooks/detect_aws_credentials.py | 26 ++++++++++++++-------- tests/detect_aws_credentials_test.py | 6 ++++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pre_commit_hooks/detect_aws_credentials.py b/pre_commit_hooks/detect_aws_credentials.py index 5276b62..b704bf8 100644 --- a/pre_commit_hooks/detect_aws_credentials.py +++ b/pre_commit_hooks/detect_aws_credentials.py @@ -49,7 +49,14 @@ def get_aws_secrets_from_json_file(json_credentials_file: str) -> set[str]: return set() keys = set() - for var in ('AccessKeyId', 'SecretAccessKey', 'SessionToken', 'aws_secret_access_key', 'aws_security_token', 'aws_session_token'): + for var in ( + 'AccessKeyId', + 'SecretAccessKey', + 'SessionToken', + 'aws_secret_access_key', + 'aws_security_token', + 'aws_session_token' + ): if var in data.get('Credentials', {}): keys.add(data['Credentials'][var]) return keys @@ -125,8 +132,8 @@ def main(argv: Sequence[str] | None = None) -> int: ), ) parser.add_argument( - '--json-credentials-file', - dest='json_credential_file_locations', + '--json-credentials-dir', + dest='json_credential_dir', action='append', default=['~/.aws/cli/cache/', '~/.aws/login/cache/'], help=( @@ -143,13 +150,14 @@ def main(argv: Sequence[str] | None = None) -> int: args = parser.parse_args(argv) credential_files = set(args.credentials_file) - json_credential_file_locations = set(args.json_credential_file_locations) + json_credential_dirs = set(args.json_credential_dir) json_credential_files = set() - for json_credential_file_location in json_credential_file_locations: - if os.path.isdir(os.path.expanduser(json_credential_file_location)): - for filename in os.listdir(os.path.expanduser(json_credential_file_location)): - if filename.endswith('.json'): - json_credential_files.add(os.path.join(json_credential_file_location, filename)) + for json_credential_dir in json_credential_dirs: + if os.path.isdir(os.path.expanduser(json_credential_dir)): + for file in os.listdir(os.path.expanduser(json_credential_dir)): + if file.endswith('.json'): + (json_credential_files + .add(os.path.join(json_credential_dir, file))) # Add the credentials files configured via environment variables to the set # of files to to gather AWS secrets from. diff --git a/tests/detect_aws_credentials_test.py b/tests/detect_aws_credentials_test.py index ae26cd8..fc0ade5 100644 --- a/tests/detect_aws_credentials_test.py +++ b/tests/detect_aws_credentials_test.py @@ -73,7 +73,11 @@ def test_get_aws_secrets_from_env(env_vars, values): ( ( 'aws_temp_secrets_file.json', - {"tempAccessKeyId", "tempSecretAccessKey", "tempSessionToken"}, + { + "tempAccessKeyId", + "tempSecretAccessKey", + "tempSessionToken" + }, ), ('nonsense.txt', set()), ('ok_json.json', set()),