22
33import argparse
44import configparser
5+ import json
56import os
67from collections .abc import Sequence
78from typing import NamedTuple
8- import json
9+
910
1011class BadFile (NamedTuple ):
1112 filename : str
1213 key : str
1314
15+
1416def get_aws_cred_files_from_env () -> set [str ]:
1517 """Extract credential file paths from environment variables."""
1618 return {
@@ -22,6 +24,7 @@ def get_aws_cred_files_from_env() -> set[str]:
2224 if env_var in os .environ
2325 }
2426
27+
2528def get_aws_secrets_from_env () -> set [str ]:
2629 """Extract AWS secrets from environment variables."""
2730 keys = set ()
@@ -32,6 +35,7 @@ def get_aws_secrets_from_env() -> set[str]:
3235 keys .add (os .environ [env_var ])
3336 return keys
3437
38+
3539def get_aws_secrets_from_json_file (json_credentials_file : str ) -> set [str ]:
3640 """Extract AWS secrets from JSON configuration files.
3741
@@ -42,7 +46,7 @@ def get_aws_secrets_from_json_file(json_credentials_file: str) -> set[str]:
4246 if not os .path .exists (aws_credentials_file_path ):
4347 return set ()
4448
45- with open (aws_credentials_file_path , 'r' ) as f :
49+ with open (aws_credentials_file_path ) as f :
4650 try :
4751 data = json .load (f )
4852 except json .JSONDecodeError :
@@ -55,7 +59,7 @@ def get_aws_secrets_from_json_file(json_credentials_file: str) -> set[str]:
5559 'SessionToken' ,
5660 'aws_secret_access_key' ,
5761 'aws_security_token' ,
58- 'aws_session_token'
62+ 'aws_session_token' ,
5963 ):
6064 if var in data .get ('Credentials' , {}):
6165 keys .add (data ['Credentials' ][var ])
@@ -156,8 +160,10 @@ def main(argv: Sequence[str] | None = None) -> int:
156160 if os .path .isdir (os .path .expanduser (json_credential_dir )):
157161 for file in os .listdir (os .path .expanduser (json_credential_dir )):
158162 if file .endswith ('.json' ):
159- (json_credential_files
160- .add (os .path .join (json_credential_dir , file )))
163+ (
164+ json_credential_files
165+ .add (os .path .join (json_credential_dir , file ))
166+ )
161167
162168 # Add the credentials files configured via environment variables to the set
163169 # of files to to gather AWS secrets from.
@@ -195,4 +201,4 @@ def main(argv: Sequence[str] | None = None) -> int:
195201
196202
197203if __name__ == '__main__' :
198- raise SystemExit (main ())
204+ raise SystemExit (main ())
0 commit comments