Пример #1
0
    def apply(self, transaction, state):
        try:
            payload = RBACPayload()
            payload.ParseFromString(transaction.payload)

            if self._processor.has_message_handler(
                    message_type=payload.message_type):
                return self._processor.handle_message(
                    header=transaction.header, payload=payload, context=state)
        except (ValueError, KeyError) as err:
            raise InvalidTransaction(err)
        except Exception as err:  # pylint: disable=broad-except
            LOGGER.exception("Unexpected processor %s exception", type(err))
            LOGGER.exception(err)
            raise InvalidTransaction(err)

        if payload.message_type in CREATE:
            apply_create(transaction.header, payload, state)

        elif payload.message_type in USER_PROPOSE:
            apply_user_propose(transaction.header, payload, state)

        elif payload.message_type in USER_CONFIRM:
            apply_user_confirm(transaction.header, payload, state)

        elif payload.message_type in USER_REJECT:
            apply_user_reject(transaction.header, payload, state)

        elif payload.message_type in ROLE_PROPOSE:
            apply_role_propose(transaction.header, payload, state)

        elif payload.message_type in ROLE_CONFIRM:
            apply_role_confirm(transaction.header, payload, state)

        elif payload.message_type in ROLE_REJECT:
            apply_role_reject(transaction.header, payload, state)

        elif payload.message_type in TASK_PROPOSE:
            apply_task_propose(transaction.header, payload, state)

        elif payload.message_type in TASK_CONFIRM:
            apply_task_confirm(transaction.header, payload, state)

        elif payload.message_type in TASK_REJECT:
            apply_task_reject(transaction.header, payload, state)

        else:
            raise InvalidTransaction("Message type unknown.")
    def apply(self, transaction, state):
        payload = RBACPayload()
        payload.ParseFromString(transaction.payload)

        if payload.message_type in CREATE:
            apply_create(transaction.header, payload, state)

        elif payload.message_type in USER_PROPOSE:
            apply_user_propose(transaction.header, payload, state)

        elif payload.message_type in USER_CONFIRM:
            apply_user_confirm(transaction.header, payload, state)

        elif payload.message_type in USER_REJECT:
            apply_user_reject(transaction.header, payload, state)

        elif payload.message_type in ROLE_PROPOSE:
            apply_role_propose(transaction.header, payload, state)

        elif payload.message_type in ROLE_CONFIRM:
            apply_role_confirm(transaction.header, payload, state)

        elif payload.message_type in ROLE_REJECT:
            apply_role_reject(transaction.header, payload, state)

        elif payload.message_type in TASK_PROPOSE:
            apply_task_propose(transaction.header, payload, state)

        elif payload.message_type in TASK_CONFIRM:
            apply_task_confirm(transaction.header, payload, state)

        elif payload.message_type in TASK_REJECT:
            apply_task_reject(transaction.header, payload, state)

        else:
            raise InvalidTransaction("Message type unknown.")