<commit_before>#     Copyright 2014 Netflix, Inc.
#
#     Licensed under the Apache License, Version 2.0 (the "License");
#     you may not use this file except in compliance with the License.
#     You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
"""
.. module: security_monkey.watchers.iam.iam_role
    :platform: Unix

.. version:: $$VERSION$$
.. moduleauthor:: <NAME> <<EMAIL>> @monkeysecurity

"""
from joblib import Parallel, delayed
from botor.aws.iam import get_role_inline_policies
from botor.aws.iam import get_role_instance_profiles
from botor.aws.iam import get_role_managed_policies
from botor.aws.iam import list_roles
from security_monkey.decorators import record_exception, iter_account_region
from security_monkey.watcher import ChangeItem
from security_monkey.watcher import Watcher


def _basic_config(role):
    return {
        'role': {
            'path': role.get('Path'),
            'role_name': role.get('RoleName'),
            'create_date': role.get('CreateDate').strftime('%Y-%m-%dT%H:%M:%SZ'),
            'arn': role.get('Arn'),
            'role_id': role.get('RoleId')
        },
        'assume_role_policy_document': role.get('AssumeRolePolicyDocument')
    }


@record_exception()
def process_role(role, **kwargs):
    print "processing role", kwargs['name']
    config = _basic_config(role)

    config.update(
        {
            # 'managed_policies': get_role_managed_policies(role, **kwargs),
            'rolepolicies': get_role_inline_policies(role, **kwargs),
            'instance_profiles': get_role_instance_profiles(role, **kwargs)
        }
    )

    return config<commit_msg>I'm bringing logging back.  Those other watchers don't know how to act.<commit_after>#     Copyright 2014 Netflix, Inc.
#
#     Licensed under the Apache License, Version 2.0 (the "License");
#     you may not use this file except in compliance with the License.
#     You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
"""
.. module: security_monkey.watchers.iam.iam_role
    :platform: Unix

.. version:: $$VERSION$$
.. moduleauthor:: <NAME> <<EMAIL>> @monkeysecurity

"""
from joblib import Parallel, delayed
from botor.aws.iam import get_role_inline_policies
from botor.aws.iam import get_role_instance_profiles
from botor.aws.iam import get_role_managed_policies
from botor.aws.iam import list_roles
from security_monkey.decorators import record_exception, iter_account_region
from security_monkey.watcher import ChangeItem
from security_monkey.watcher import Watcher
from flask import current_app


def _basic_config(role):
    return {
        'role': {
            'path': role.get('Path'),
            'role_name': role.get('RoleName'),
            'create_date': role.get('CreateDate').strftime('%Y-%m-%dT%H:%M:%SZ'),
            'arn': role.get('Arn'),
            'role_id': role.get('RoleId')
        },
        'assume_role_policy_document': role.get('AssumeRolePolicyDocument')
    }


@record_exception()
def process_role(role, **kwargs):
    current_app.logger.debug("Slurping {index} ({name}) from {account}".format(
        index=IAMRole.i_am_singular,
        name=kwargs['name'],
        account=kwargs['account_name'])
    )
    config = _basic_config(role)

    config.update(
        {
            # 'managed_policies': get_role_managed_policies(role, **kwargs),
            'rolepolicies': get_role_inline_policies(role, **kwargs),
            'instance_profiles': get_role_instance_profiles(role, **kwargs)
        }
    )

    return config
{'fraction_non_alphanumeric': 0.10839981229469732, 'fraction_numerical': 0.003754106053496011, 'mean_word_length': 3.4313929313929314, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3819392', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1243, 'n_words': 348}