"""Lint IAM policy files offline with Parliament (open-source IAM linter). Lab policies only."""
import sys, parliament

def lint(path):
    policy = open(path).read()
    p = parliament.analyze_policy_string(policy, path)
    p.analyze()
    return sorted(p.findings, key=lambda f: f.issue)

for path in sys.argv[1:]:
    print(f"== {path}")
    findings = lint(path)
    if not findings:
        print("   no findings")
    for f in findings:
        print(f"   [{f.severity}] {f.issue}: {f.title}")
