<commit_before>"""Create IAM Instance Profiles, Roles, Users, and Groups."""
import logging

import boto3
from boto3.exceptions import botocore

from .consts import ROLE_POLICY

LOG = logging.getLogger(__name__)


def create_iam_resources(env='dev', group='forrest', app='unicorn'):
    """Create the IAM Resources for the application.

    Args:
        env (str): Deployment environment, i.e. dev, stage, prod.
        group (str): Application Group name.
        app (str): Application name.
    """
    session = boto3.session.Session(profile_name=env)
    client = session.client('iam')

    user_name = '{group}_{app}'.format(group=group, app=app)
    role_name = '{user}_role'.format(user=user_name)
    profile_name = '{user}_profile'.format(user=user_name)

    resource_action(client,
                    action='create_role',
                    log_format='Role: %(RoleName)s',
                    RoleName=role_name,
                    AssumeRolePolicyDocument=ROLE_POLICY)
    resource_action(client,
                    action='create_instance_profile',
                    log_format='Instance Profile: %(InstanceProfileName)s',
                    InstanceProfileName=profile_name)
    attach_profile_to_role(client,
                           role_name=role_name,
                           profile_name=profile_name)

    resource_action(client,
                    action='create_user',
                    log_format='User: %(UserName)s',
                    UserName=user_name)
    resource_action(client,
                    action='create_group',
                    log_format='Group: %(GroupName)s',
                    GroupName=group)
    resource_action(client,
                    action='add_user_to_group',
                    log_format='User to Group: %(UserName)s -> %(GroupName)s',
                    log_failure=True,
                    GroupName=group,
                    UserName=user_name)


def attach_profile_to_role(client,
                           role_name='forrest_unicorn_role',
                           profile_name='forrest_unicorn_profile'):
    """Attach an IAM Instance Profile _profile_name_ to Role _role_name_.

    Args:
        role_name (str): Name of Role.
        profile_name (str): Name of Instance Profile.

    Returns:
        True upon successful completion.
    """
    current_instance_profiles = client.list_instance_profiles_for_role(
        RoleName=role_name)['InstanceProfiles']
<commit_msg>fix: Return True for good run<commit_after>"""Create IAM Instance Profiles, Roles, Users, and Groups."""
import logging

import boto3
from boto3.exceptions import botocore

from .consts import ROLE_POLICY

LOG = logging.getLogger(__name__)


def create_iam_resources(env='dev', group='forrest', app='unicorn'):
    """Create the IAM Resources for the application.

    Args:
        env (str): Deployment environment, i.e. dev, stage, prod.
        group (str): Application Group name.
        app (str): Application name.

    Returns:
        True upon successful completion.
    """
    session = boto3.session.Session(profile_name=env)
    client = session.client('iam')

    user_name = '{group}_{app}'.format(group=group, app=app)
    role_name = '{user}_role'.format(user=user_name)
    profile_name = '{user}_profile'.format(user=user_name)

    resource_action(client,
                    action='create_role',
                    log_format='Role: %(RoleName)s',
                    RoleName=role_name,
                    AssumeRolePolicyDocument=ROLE_POLICY)
    resource_action(client,
                    action='create_instance_profile',
                    log_format='Instance Profile: %(InstanceProfileName)s',
                    InstanceProfileName=profile_name)
    attach_profile_to_role(client,
                           role_name=role_name,
                           profile_name=profile_name)

    resource_action(client,
                    action='create_user',
                    log_format='User: %(UserName)s',
                    UserName=user_name)
    resource_action(client,
                    action='create_group',
                    log_format='Group: %(GroupName)s',
                    GroupName=group)
    resource_action(client,
                    action='add_user_to_group',
                    log_format='User to Group: %(UserName)s -> %(GroupName)s',
                    log_failure=True,
                    GroupName=group,
                    UserName=user_name)

    return True


def attach_profile_to_role(client,
                           role_name='forrest_unicorn_role',
                           profile_name='forrest_unicorn_profile'):
    """Attach an IAM Instance Profile _profile_name_ to Role _role_name_.

    Args:
        role_name (str): Name of Role.
        profile_name (str): Name of Instance Profile.

    Returns:
        True upon successful completion.
    """
    current_instance_profiles = client.list_instance_profiles_for_role(
        RoleName=role_name)['InstanceProfiles']

{'fraction_non_alphanumeric': 0.09435836313071116, 'fraction_numerical': 0.0011918951132300357, 'mean_word_length': 2.1826801517067005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7451523', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1343, 'n_words': 272}