Пример #1
0
    def match_and_execute(self, input_api, requester_user, show_secrets=False):
        """
        Try to find a matching alias and if one is found, schedule a new
        execution by parsing parameters from the provided command against
        the matched alias.

        Handles requests:
            POST /aliasexecution/match_and_execute
        """
        command = input_api.command

        try:
            format_ = get_matching_alias(command=command)
        except ActionAliasAmbiguityException as e:
            LOG.exception('Command "%s" matched (%s) patterns.', e.command,
                          len(e.matches))
            return abort(http_client.BAD_REQUEST, six.text_type(e))

        action_alias_db = format_["alias"]
        representation = format_["representation"]

        params = {
            "name": action_alias_db.name,
            "format": representation,
            "command": command,
            "user": input_api.user,
            "source_channel": input_api.source_channel,
        }

        # Add in any additional parameters provided by the user
        if input_api.notification_channel:
            params["notification_channel"] = input_api.notification_channel

        if input_api.notification_route:
            params["notification_route"] = input_api.notification_route

        alias_execution_api = AliasMatchAndExecuteInputAPI(**params)
        results = self._post(
            payload=alias_execution_api,
            requester_user=requester_user,
            show_secrets=show_secrets,
            match_multiple=format_["match_multiple"],
        )
        return Response(json={"results": results}, status=http_client.CREATED)
Пример #2
0
    def match_and_execute(self, input_api, requester_user, show_secrets=False):
        """
            Try to find a matching alias and if one is found, schedule a new
            execution by parsing parameters from the provided command against
            the matched alias.

            Handles requests:
                POST /aliasexecution/match_and_execute
        """
        command = input_api.command

        try:
            format_ = get_matching_alias(command=command)
        except ActionAliasAmbiguityException as e:
            LOG.exception('Command "%s" matched (%s) patterns.', e.command, len(e.matches))
            return abort(http_client.BAD_REQUEST, six.text_type(e))

        action_alias_db = format_['alias']
        representation = format_['representation']

        params = {
            'name': action_alias_db.name,
            'format': representation,
            'command': command,
            'user': input_api.user,
            'source_channel': input_api.source_channel
        }

        # Add in any additional parameters provided by the user
        if input_api.notification_channel:
            params['notification_channel'] = input_api.notification_channel

        if input_api.notification_route:
            params['notification_route'] = input_api.notification_route

        alias_execution_api = AliasMatchAndExecuteInputAPI(**params)
        results = self._post(
            payload=alias_execution_api,
            requester_user=requester_user,
            show_secrets=show_secrets,
            match_multiple=format_['match_multiple'])
        return Response(json={'results': results}, status=http_client.CREATED)
Пример #3
0
    def match(self, action_alias_match_api):
        """
            Find a matching action alias.

            Handles requests:
                POST /actionalias/match
        """
        command = action_alias_match_api.command

        try:
            match = get_matching_alias(command=command)
        except ActionAliasAmbiguityException as e:
            LOG.exception('Command "%s" matched (%s) patterns.', e.command, len(e.matches))
            return abort(http_client.BAD_REQUEST, str(e))

        # Convert ActionAliasDB to API
        action_alias_api = ActionAliasAPI.from_model(match[0])
        match = [action_alias_api, match[1], match[2]]
        result = self._match_tuple_to_dict(match=match)
        return result
Пример #4
0
    def match(self, action_alias_match_api):
        """
            Find a matching action alias.

            Handles requests:
                POST /actionalias/match
        """
        command = action_alias_match_api.command

        try:
            format_ = get_matching_alias(command=command)
        except ActionAliasAmbiguityException as e:
            LOG.exception('Command "%s" matched (%s) patterns.', e.command, len(e.matches))
            return abort(http_client.BAD_REQUEST, six.text_type(e))

        # Convert ActionAliasDB to API
        action_alias_api = ActionAliasAPI.from_model(format_['alias'])
        return {
            'actionalias': action_alias_api,
            'display': format_['display'],
            'representation': format_['representation'],
        }
Пример #5
0
    def match_and_execute(self, input_api, requester_user, show_secrets=False):
        """
            Try to find a matching alias and if one is found, schedule a new
            execution by parsing parameters from the provided command against
            the matched alias.

            Handles requests:
                POST /aliasexecution/match_and_execute
        """
        command = input_api.command

        try:
            match = get_matching_alias(command=command)
        except ActionAliasAmbiguityException as e:
            LOG.exception('Command "%s" matched (%s) patterns.', e.command, len(e.matches))
            return abort(http_client.BAD_REQUEST, str(e))

        action_alias_db = match[0]
        representation = match[2]

        params = {
            'name': action_alias_db.name,
            'format': representation,
            'command': command,
            'user': input_api.user,
            'source_channel': input_api.source_channel
        }

        # Add in any additional parameters provided by the user
        if input_api.notification_channel:
            params['notification_channel'] = input_api.notification_channel

        if input_api.notification_route:
            params['notification_route'] = input_api.notification_route

        alias_execution_api = AliasMatchAndExecuteInputAPI(**params)
        result = self.post(payload=alias_execution_api, requester_user=requester_user,
                           show_secrets=show_secrets)
        return result
Пример #6
0
    def match(self, action_alias_match_api):
        """
            Find a matching action alias.

            Handles requests:
                POST /actionalias/match
        """
        command = action_alias_match_api.command

        try:
            format_ = get_matching_alias(command=command)
        except ActionAliasAmbiguityException as e:
            LOG.exception('Command "%s" matched (%s) patterns.', e.command, len(e.matches))
            return abort(http_client.BAD_REQUEST, six.text_type(e))

        # Convert ActionAliasDB to API
        action_alias_api = ActionAliasAPI.from_model(format_['alias'])
        return {
            'actionalias': action_alias_api,
            'display': format_['display'],
            'representation': format_['representation'],
        }