diff --git a/parliament/cli.py b/parliament/cli.py index 4905e82..b01eade 100755 --- a/parliament/cli.py +++ b/parliament/cli.py @@ -138,6 +138,11 @@ def main(): type=str, ) parser.add_argument("--file", help="Provide a policy in a file", type=str) + parser.add_argument('--stdinfile', + help="Provide a policy via stdin instead of --file", + nargs='?', + type=argparse.FileType('r'), + default=sys.stdin) parser.add_argument( "--directory", help="Provide a path to directory with policy files", type=str ) @@ -212,6 +217,10 @@ def main(): if args.minimal and args.json: raise Exception("You cannot choose both minimal and json output") + # If I have some stdin to read it should be my policy so don't allow file input + if not sys.stdin.isatty() and args.file: + parser.error("You cannot pass a file with --file and use stdin together") + # Change the exit status if there are errors exit_status = 0 findings = [] @@ -321,6 +330,17 @@ def main(): config=config, ) findings.extend(policy.findings) + elif not sys.stdin.isatty(): + contents = args.stdinfile.read() + args.stdinfile.close() + policy = analyze_policy_string( + contents, + args.file, + private_auditors_custom_path=args.private_auditors, + include_community_auditors=args.include_community_auditors, + config=config, + ) + findings.extend(policy.findings) elif args.directory: file_paths = find_files( directory=args.directory,