def generate_example_report():
    output_directory = os.getcwd()
    account_name = "fake"
    account_metadata = {
        "account_name": account_name,
        "account_id": "000011112222",
        "customer_managed_policies": 20,  # Fake value
        "aws_managed_policies": 30,  # Fake value
    }

    rendered_html_report = scan_account_authorization_details(
        account_authorization_details_cfg,
        DEFAULT_EXCLUSIONS,
        account_name="example",
        output_directory=os.getcwd())
    # html_output_file = os.path.join(output_directory, f"index.html")
    html_output_file = os.path.join(output_directory,
                                    f"iam-report-{account_name}.html")

    with open(html_output_file, "w") as f:
        f.write(rendered_html_report)

    print(f"Wrote HTML results to: {html_output_file}")
    index_output_file = os.path.join(output_directory, "index.html")
    shutil.copyfile(os.path.join(output_directory, "iam-report-fake.html"),
                    index_output_file)
    url = "file://%s" % os.path.abspath(index_output_file)
    webbrowser.open(url, new=2)
Esempio n. 2
0
def scripting_example(file):
    with open(file) as f:
        contents = f.read()
        account_authorization_details_cfg = json.loads(contents)
    rendered_html_report = scan_account_authorization_details(
        account_authorization_details_cfg,
        DEFAULT_EXCLUSIONS,
        account_name="example")
    print(rendered_html_report)
Esempio n. 3
0
    def test_scan_authz_details_and_output_html_as_string(self):
        example_authz_details_file = os.path.abspath(
            os.path.join(
                os.path.dirname(__file__),
                os.path.pardir,
                "files",
                "example-authz-details.json",
            ))
        with open(example_authz_details_file, "r") as json_file:
            cfg = json.load(json_file)
            decision = check_authorization_details_schema(cfg)
        self.assertTrue(decision)

        rendered_html_report = scan_account_authorization_details(
            cfg,
            DEFAULT_EXCLUSIONS,
            account_name="Something",
            output_directory=os.getcwd(),
            write_data_files=False)