<commit_before># Copyright 2014 Isotoma Limited
#
# 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.

import json

from touchdown.core.resource import Resource
from touchdown.core.plan import Plan
from touchdown.core import argument, errors, serializers

from ..account import Account
from ..common import SimpleDescribe, SimpleApply, SimpleDestroy


class Role(Resource):

    resource_name = "role"

    name = argument.String(field="RoleName")
    path = argument.String(field='Path')
    assume_role_policy = argument.Dict(field="AssumeRolePolicyDocument", serializer=serializers.Json())

    policies = argument.Dict()
    account = argument.Resource(Account)

    def clean_assume_role_policy(self, policy):
        if frozenset(policy.keys()).difference(frozenset(("Version", "Statement"))):
            raise errors.InvalidParameter("Unexpected policy key")

        result = {}
        result['Version'] = policy.get('Version', '2012-10-17')
        result['Statement'] = []
        for statement in policy.get("Statement", []):
            s = {
                "Action": statement["Action"],
                "Effect": statement["Effect"],
                "Principal": statement["Principal"],
                "Sid": statement.get("Sid", ""),
            }
            result['Statement'].append(s)
        return result


class Describe(SimpleDescribe, Plan):

    resource = Role
    service_name = 'iam'
    describe_action = "list_roles"
    describe_envelope = "Roles"
    describe_filters = {}
    key = 'RoleName'

    def describe_object_matches(self, role):<commit_msg>Fix bug where condition is missing from IAM role<commit_after># Copyright 2014 Isotoma Limited
#
# 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.

import json

from touchdown.core.resource import Resource
from touchdown.core.plan import Plan
from touchdown.core import argument, errors, serializers

from ..account import Account
from ..common import SimpleDescribe, SimpleApply, SimpleDestroy


class Role(Resource):

    resource_name = "role"

    name = argument.String(field="RoleName")
    path = argument.String(field='Path')
    assume_role_policy = argument.Dict(field="AssumeRolePolicyDocument", serializer=serializers.Json())

    policies = argument.Dict()
    account = argument.Resource(Account)

    def clean_assume_role_policy(self, policy):
        if frozenset(policy.keys()).difference(frozenset(("Version", "Statement"))):
            raise errors.InvalidParameter("Unexpected policy key")

        result = {}
        result['Version'] = policy.get('Version', '2012-10-17')
        result['Statement'] = []
        for statement in policy.get("Statement", []):
            s = {
                "Action": statement["Action"],
                "Effect": statement["Effect"],
                "Principal": statement["Principal"],
                "Sid": statement.get("Sid", ""),
            }
            if "Condition" in statement:
                s['Condition'] = statement['Condition']
            result['Statement'].append(s)
        return result


class Describe(SimpleDescribe, Plan):

    resource = Role
    service_name = 'iam'
    describe_action = "list_roles"
    describe_envelope = "Roles"
    describe_filters = {}
    key = 'RoleName'

    def describe_object_matches(self, role):
{'fraction_non_alphanumeric': 0.10727611940298508, 'fraction_numerical': 0.007462686567164179, 'mean_word_length': 3.3235887096774195, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '5185454', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1089, 'n_words': 357}