<commit_before>#!/usr/bin/env python3

import ec2
import elb
import elbv2
import autoscaling
import cloudwatch
import os
import sys
import iam
from collections import defaultdict

policy_template = """
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1486065689000",
            "Effect": "Allow",
            "Action": [
%s                "iam:PassRole"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
"""


def _format(s):
    formatted = set()
    for x in s:
        formatted.add(x.title().replace("-", ""))
    return formatted


# TODO(andrewbackes): Figure out a way to pull the API calls from boto3.
_action_map = {
    "ec2": _format(ec2.actions),
    "elasticloadbalancing": _format(elb.actions),
    "elasticloadbalancingv2": _format(elbv2.actions),
    "autoscaling": _format(autoscaling.actions),
    "iam": _format(iam.actions),
    "cloudwatch": _format(cloudwatch.actions)
}


def _format_permission(collection, action):
    if collection == "elasticloadbalancingv2":
        return "elasticloadbalancing:%s" % action
    return "%s:%s" % (collection, action)


def _parse_actions(filename):
    """Run through the file looking for imported AWS libraries. Then look
    for calls from that library.
    """
    requested_action = set()
    imports = defaultdict(set)

    def imported(k, v):
        if imports.get(k) and "*" in imports[k]:<commit_msg>fix(iam): correctly find iam perms from idententymanagement library<commit_after>#!/usr/bin/env python3

import ec2
import elb
import elbv2
import autoscaling
import cloudwatch
import os
import sys
import iam
from collections import defaultdict

policy_template = """
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1486065689000",
            "Effect": "Allow",
            "Action": [
%s                "iam:PassRole"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
"""


def _format(s):
    formatted = set()
    for x in s:
        formatted.add(x.title().replace("-", ""))
    return formatted


# TODO(andrewbackes): Figure out a way to pull the API calls from boto3.
_action_map = {
    "ec2": _format(ec2.actions),
    "elasticloadbalancing": _format(elb.actions),
    "elasticloadbalancingv2": _format(elbv2.actions),
    "autoscaling": _format(autoscaling.actions),
    "identitymanagement": _format(iam.actions),
    "cloudwatch": _format(cloudwatch.actions)
}


def _format_permission(collection, action):
    if collection == "elasticloadbalancingv2":
        return "elasticloadbalancing:%s" % action
    if collection == "identitymanagement":
        return "iam:%s" % action
    return "%s:%s" % (collection, action)


def _parse_actions(filename):
    """Run through the file looking for imported AWS libraries. Then look
    for calls from that library.
    """
    requested_action = set()
    imports = defaultdict(set)

    def imported(k, v):
        if imports.get(k) and "*" in imports[k]:
{'fraction_non_alphanumeric': 0.12651988169569503, 'fraction_numerical': 0.019717384160368057, 'mean_word_length': 2.748768472906404, 'pattern_counts': {'":': 27, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7412626', 'n_tokens_mistral': 992, 'n_tokens_neox': 937, 'n_words': 238}