def on_post(self, req, res):
        helpers.validate_authorization(req, self._default_authorized_roles)

        stream_definition = helpers.read_json_msg_body(req)

        self._validate_stream_definition(stream_definition)

        tenant_id = helpers.get_tenant_id(req)
        name = get_query_stream_definition_name(stream_definition)
        description = get_query_stream_definition_description(
            stream_definition)
        select = stream_definition['select']
        for s in select:
            if 'traits' in s:
                s['traits']['_tenant_id'] = tenant_id
            else:
                s['traits'] = {'_tenant_id': tenant_id}

        group_by = stream_definition['group_by']
        fire_criteria = stream_definition['fire_criteria']
        expiration = stream_definition['expiration']
        fire_actions = get_query_stream_definition_fire_actions(
            stream_definition)
        expire_actions = get_query_stream_definition_expire_actions(
            stream_definition)

        result = self._stream_definition_create(tenant_id, name, description,
                                                select, group_by,
                                                fire_criteria, expiration,
                                                fire_actions, expire_actions)

        helpers.add_links_to_resource(result, req.uri)
        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_201
예제 #2
0
    def on_get(self, req, res, event_id=None):
        helpers.validate_authorization(req, self._default_authorized_roles)
        tenant_id = helpers.get_tenant_id(req)

        if event_id:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            result = self._list_event(tenant_id, event_id)
            helpers.add_links_to_resource(result[0], re.sub("/" + event_id, "", req.uri))
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
        else:
            offset = helpers.normalize_offset(helpers.get_query_param(req, "offset"))
            limit = helpers.get_query_param(req, "limit")

            result = self._list_events(tenant_id, req.uri, offset, limit)
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
 def send_event(self, message_queue, event_msg):
     try:
         message_queue.send_message(
             helpers.dumpit_utf8(event_msg))
     except message_queue_exceptions.MessageQueueException as ex:
         LOG.exception(ex)
         raise falcon.HTTPInternalServerError(
             'Message queue service unavailable'.encode('utf8'),
             ex.message.encode('utf8'))
    def on_get(self, req, res, stream_id=None):
        if stream_id:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            result = self._stream_definition_show(tenant_id, stream_id)

            helpers.add_links_to_resource(
                result, re.sub('/' + stream_id, '', req.uri))
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
        else:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            name = helpers.get_query_name(req)
            offset = helpers.normalize_offset(
                helpers.get_query_param(req, 'offset'))
            limit = helpers.get_query_param(req, 'limit')
            result = self._stream_definition_list(tenant_id, name,
                                                  req.uri, offset, limit)

            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
    def on_patch(self, req, res, stream_id):
        helpers.validate_authorization(req, self._default_authorized_roles)

        stream_definition = helpers.read_json_msg_body(req)

        tenant_id = helpers.get_tenant_id(req)

        name = get_query_stream_definition_name(stream_definition, return_none=True)
        description = get_query_stream_definition_description(
            stream_definition, return_none=True)
        select = get_query_stream_definition_select(stream_definition, return_none=True)
        if select:
            for s in select:
                if 'traits' in s:
                    s['traits']['_tenant_id'] = tenant_id
                else:
                    s['traits'] = {'_tenant_id': tenant_id}

        group_by = get_query_stream_definition_group_by(stream_definition, return_none=True)
        fire_criteria = get_query_stream_definition_fire_criteria(stream_definition, return_none=True)
        expiration = get_query_stream_definition_expiration(stream_definition, return_none=True)
        fire_actions = get_query_stream_definition_fire_actions(
            stream_definition, return_none=True)
        expire_actions = get_query_stream_definition_expire_actions(
            stream_definition, return_none=True)

        result = self._stream_definition_patch(tenant_id,
                                               stream_id,
                                               name,
                                               description,
                                               select,
                                               group_by,
                                               fire_criteria,
                                               expiration,
                                               fire_actions,
                                               expire_actions)

        helpers.add_links_to_resource(result, req.uri)
        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_201