Exemplo n.º 1
0
def _check_isoformat(datetime):
    try:
        from_isoformat(datetime)
    except ValueError:
        log.warning('Unknown datetime format: %s', datetime)
        return False
    return True
Exemplo n.º 2
0
def _check_isoformat(datetime):
    try:
        from_isoformat(datetime)
    except ValueError:
        log.warning('Unknown datetime format: %s', datetime)
        return False
    return True
Exemplo n.º 3
0
Arquivo: bus.py Projeto: thavel/nyuki
    async def post(self, request):
        body = await request.json()

        try:
            self.nyuki._services.get('bus')
        except KeyError:
            return Response(status=404)

        # Format 'since' parameter from isoformat
        since = body.get('since')
        if since:
            try:
                since = from_isoformat(since)
            except ValueError:
                return Response(
                    {'error': 'Unknown datetime format: %s'.format(since)},
                    status=400)

        # Check and parse event status
        request_status = body.get('status')
        status = list()
        if request_status:
            try:
                if isinstance(request_status, list):
                    for es in request_status:
                        status.append(EventStatus[es])
                else:
                    status.append(EventStatus[request_status])
            except KeyError:
                return Response(
                    status=400,
                    body={'error': 'unknown event status type {}'.format(es)})

        await self.nyuki.bus.replay(since, status)
Exemplo n.º 4
0
    async def post(self, request):
        body = await request.json()

        try:
            self.nyuki._services.get('bus')
        except KeyError:
            return Response(status=404)

        # Format 'since' parameter from isoformat
        since = body.get('since')
        if since:
            try:
                since = from_isoformat(since)
            except ValueError:
                return Response({
                    'error': 'Unknown datetime format: %s'.format(since)
                }, status=400)

        # Check and parse event status
        request_status = body.get('status')
        status = list()
        if request_status:
            try:
                if isinstance(request_status, list):
                    for es in request_status:
                        status.append(EventStatus[es])
                else:
                    status.append(EventStatus[request_status])
            except KeyError:
                return Response(status=400, body={
                    'error': 'unknown event status type {}'.format(es)
                })

        await self.nyuki.bus.replay(since, status)
Exemplo n.º 5
0
    async def get(self, request):
        """
        Filters:
            * `root` return only the root workflows
            * `full` return the full graph and details of all workflows
                * :warning: can be a huge amount of data
            * `since` return the workflows since this date
            * `state` return the workflows on this FutureState
            * `offset` return the worflows from this offset
            * `limit` return this amount of workflows
            * `order` order results following the Ordering enum values
            * `search` search templates with specific title
        """
        # Filter on start date
        since = request.GET.get('since')
        if since:
            try:
                since = from_isoformat(since)
            except ValueError:
                return Response(
                    status=400,
                    body={'error': "Could not parse date '{}'".format(since)})
        # Filter on state value
        state = request.GET.get('state')
        if state:
            try:
                state = FutureState(state)
            except ValueError:
                return Response(
                    status=400,
                    body={'error': "Unknown state '{}'".format(state)})
        # Skip first items
        offset = request.GET.get('offset')
        if offset:
            try:
                offset = int(offset)
            except ValueError:
                return Response(status=400,
                                body={'error': 'Offset must be an int'})
        # Limit max result
        limit = request.GET.get('limit')
        if limit:
            try:
                limit = int(limit)
            except ValueError:
                return Response(status=400,
                                body={'error': 'Limit must be an int'})
        order = request.GET.get('ordering')
        if order:
            try:
                order = Ordering[order].value
            except KeyError:
                return Response(status=400,
                                body={
                                    'error':
                                    'Ordering must be in {}'.format(
                                        Ordering.keys())
                                })

        try:
            count, history = await self.nyuki.storage.instances.get(
                root=(request.GET.get('root') == '1'),
                full=(request.GET.get('full') == '1'),
                search=request.GET.get('search'),
                order=order,
                offset=offset,
                limit=limit,
                since=since,
                state=state,
            )
        except AutoReconnect:
            return Response(status=503)

        data = {'count': count, 'data': history}
        return Response(data)
Exemplo n.º 6
0
    async def get(self, request):
        """
        Filters:
            * `root` return only the root workflows
            * `full` return the full graph and details of all workflows
                * :warning: can be a huge amount of data
            * `since` return the workflows since this date
            * `state` return the workflows on this FutureState
            * `offset` return the worflows from this offset
            * `limit` return this amount of workflows
            * `order` order results following the Ordering enum values
            * `search` search templates with specific title
        """
        # Filter on start date
        since = request.GET.get('since')
        if since:
            try:
                since = from_isoformat(since)
            except ValueError:
                return Response(status=400, body={
                    'error': "Could not parse date '{}'".format(since)
                })
        # Filter on state value
        state = request.GET.get('state')
        if state:
            try:
                state = FutureState(state)
            except ValueError:
                return Response(status=400, body={
                    'error': "Unknown state '{}'".format(state)
                })
        # Skip first items
        offset = request.GET.get('offset')
        if offset:
            try:
                offset = int(offset)
            except ValueError:
                return Response(status=400, body={
                    'error': 'Offset must be an int'
                })
        # Limit max result
        limit = request.GET.get('limit')
        if limit:
            try:
                limit = int(limit)
            except ValueError:
                return Response(status=400, body={
                    'error': 'Limit must be an int'
                })
        order = request.GET.get('ordering')
        if order:
            try:
                order = Ordering[order].value
            except KeyError:
                return Response(status=400, body={
                    'error': 'Ordering must be in {}'.format(Ordering.keys())
                })

        try:
            count, history = await self.nyuki.storage.instances.get(
                root=(request.GET.get('root') == '1'),
                full=(request.GET.get('full') == '1'),
                search=request.GET.get('search'),
                order=order,
                offset=offset, limit=limit, since=since, state=state,
            )
        except AutoReconnect:
            return Response(status=503)

        data = {'count': count, 'data': history}
        return Response(
            json.dumps(data, default=serialize_wflow_exec),
            content_type='application/json'
        )