Skip to content

Commit e626cd5

Browse files
authored
Merge pull request #175 from miketheman/miketheman/allow-missing-aws
Add flag to detect-aws-credentials to allow missing keys
2 parents 20f0462 + 312e721 commit e626cd5

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

pre_commit_hooks/detect_aws_credentials.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def main(argv=None):
9595
'secret keys from'
9696
)
9797
)
98+
parser.add_argument(
99+
'--allow-missing-credentials',
100+
dest='allow_missing_credentials',
101+
action='store_true',
102+
help='Allow hook to pass when no credentials are detected.'
103+
)
98104
args = parser.parse_args(argv)
99105

100106
credential_files = set(args.credential_files)
@@ -111,6 +117,9 @@ def main(argv=None):
111117
# the set of keys.
112118
keys |= get_aws_secrets_from_env()
113119

120+
if not keys and args.allow_missing_credentials:
121+
return 0
122+
114123
if not keys:
115124
print(
116125
'No AWS keys were found in the configured credential files and '

tests/detect_aws_credentials_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,17 @@ def test_non_existent_credentials(mock_secrets_env, mock_secrets_file, capsys):
130130
'and environment variables.\nPlease ensure you have the '
131131
'correct setting for --credentials-file\n'
132132
)
133+
134+
135+
@patch('pre_commit_hooks.detect_aws_credentials.get_aws_secrets_from_file')
136+
@patch('pre_commit_hooks.detect_aws_credentials.get_aws_secrets_from_env')
137+
def test_non_existent_credentials_with_allow_flag(mock_secrets_env, mock_secrets_file):
138+
"""Test behavior with no configured AWS secrets and flag to allow when missing."""
139+
mock_secrets_env.return_value = set()
140+
mock_secrets_file.return_value = set()
141+
ret = main((
142+
get_resource_path('aws_config_without_secrets.ini'),
143+
"--credentials-file=testing/resources/credentailsfilethatdoesntexist",
144+
"--allow-missing-credentials"
145+
))
146+
assert ret == 0

0 commit comments

Comments
 (0)