File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 4646 entry : check-json
4747 language : python
4848 types : [json]
49+ - id : check-iam
50+ name : check IAM
51+ description : checks terraform files for parseable IAM syntax.
52+ entry : check-iam
53+ language : python
54+ types : [tf]
4955- id : check-shebang-scripts-are-executable
5056 name : check that scripts with shebangs are executable
5157 description : ensures that (non-binary) files with a shebang are executable.
Original file line number Diff line number Diff line change 1+ import argparse
2+ import hcl2
3+ # from typing import Any
4+ from typing import Sequence
5+
6+
7+ def main (argv : Sequence [str ] | None = None ) -> int :
8+ parser = argparse .ArgumentParser ()
9+ parser .add_argument ('filenames' , nargs = '*' , help = 'Filenames to check.' )
10+ args = parser .parse_args (argv )
11+
12+ retval = 0
13+ for filename in args .filenames :
14+ if filename == "iam.tf" :
15+ continue
16+ with open (filename , 'rb' ) as f :
17+ try :
18+ dict = hcl2 .load (f )
19+ except ValueError as exc :
20+ print (f'{ filename } : Failed to hcl decode ({ exc } )' )
21+ retval = 1
22+ resources = data .get ('resource' )
23+ if resources :
24+ for item in resources :
25+ for keys in item :
26+ if key .startswith ("aws_iam" ):
27+ print (f'{ filename } : Has { key } resource' )
28+ retval = 1
29+ resources = data .get ('data' )
30+ if resources :
31+ for item in resources :
32+ for keys in item :
33+ if key .startswith ("aws_iam" ):
34+ print (f'{ filename } : Has { key } data resource' )
35+ retval = 1
36+ return retval
37+
38+
39+ if __name__ == '__main__' :
40+ raise SystemExit (main ())
You can’t perform that action at this time.
0 commit comments