Example #1
0
 async def test_003_exception(self):
     reporting.exception(Exception('nope'))
     # Troubles patching datetime.utcnow
     eq_(self.publisher.publish.call_count, 1)
     calls = self.publisher.publish
     call_arg = calls.call_args[0][0]
     assert_true('nope' in call_arg['data']['traceback'])
Example #2
0
 async def test_003_exception(self):
     reporting.exception(Exception('nope'))
     # Troubles patching datetime.utcnow
     eq_(self.publisher.publish.call_count, 1)
     calls = self.publisher.publish
     call_arg = calls.call_args[0][0]
     assert_true('nope' in call_arg['data']['traceback'])
Example #3
0
 async def _ensure_status():
     while True:
         try:
             return await self.backend.update(uid, status)
         except Exception as exc:
             reporting.exception(exc)
         log.error('Backend not available, retrying update in 5')
         await asyncio.sleep(5)
Example #4
0
 async def _ensure_backend():
     while True:
         try:
             return await self.backend.retrieve(since=since,
                                                status=status)
         except Exception as exc:
             reporting.exception(exc)
         log.error('Backend not available, retrying retrieve in 5')
         await asyncio.sleep(5)
Example #5
0
 async def _empty_last_events(self):
     if await self.backend.ping():
         if self._last_events.list:
             log.info('Dumping all event into backend')
         try:
             for event in self._last_events.empty():
                 await self.backend.store(event)
         except Exception as exc:
             reporting.exception(exc)
     else:
         log.warning('No connection to backend to empty in-memory events')
Example #6
0
    async def middleware(request):
        # Ensure a content-type check is necessary
        # aiohttp includes DELETE in post methods, we don't want that
        if request.method in POST_METHODS and getattr(capa_handler,
                                                      'CONTENT_TYPE', None):
            ctype = capa_handler.CONTENT_TYPE
            # Check content_type from @resource or @content_type decorators
            request_types = request.headers.get('Content-Type', '').split(';')
            required_types = ctype.split(';')
            for required in required_types:
                if required not in request_types:
                    log.debug("content-type '%s' required. Received '%s'",
                              required, request_types)
                    return Response({'error': 'Wrong or Missing content-type'},
                                    status=400)

            # Check application/json is really a JSON body
            if 'application/json' in required_types:
                try:
                    await request.json()
                except json.decoder.JSONDecodeError:
                    log.debug('request body for application/json must be JSON')
                    return Response(
                        {'error': 'application/json requires a JSON body'},
                        status=400)

            # Check multipart/form-data is really a post form
            if 'multipart/form-data' in required_types:
                try:
                    await request.post()
                except ValueError as exc:
                    log.debug(exc)
                    return Response(
                        status=400,
                        body={'error': 'multipart/form-data must be a form'})

        try:
            capa_resp = await capa_handler(request, **request.match_info)
        except (web.HTTPNotFound, web.HTTPMethodNotAllowed):
            # Avoid sending a report on a simple 404/405
            raise
        except HTTPBreak as exc:
            return Response(exc.body, status=exc.status)
        except Exception as exc:
            reporting.exception(exc)
            raise

        if capa_resp and isinstance(capa_resp, Response):
            return capa_resp
        return Response()
Example #7
0
    async def middleware(request):
        # Ensure a content-type check is necessary
        # aiohttp includes DELETE in post methods, we don't want that
        if request.method in POST_METHODS and getattr(capa_handler, 'CONTENT_TYPE', None):
            ctype = capa_handler.CONTENT_TYPE
            # Check content_type from @resource or @content_type decorators
            request_types = request.headers.get('Content-Type', '').split(';')
            required_types = ctype.split(';')
            for required in required_types:
                if required not in request_types:
                    log.debug(
                        "content-type '%s' required. Received '%s'",
                        required, request_types
                    )
                    return Response({'error': 'Wrong or Missing content-type'}, status=400)

            # Check application/json is really a JSON body
            if 'application/json' in required_types:
                try:
                    await request.json()
                except json.decoder.JSONDecodeError:
                    log.debug('request body for application/json must be JSON')
                    return Response(
                        {'error': 'application/json requires a JSON body'},
                        status=400
                    )

            # Check multipart/form-data is really a post form
            if 'multipart/form-data' in required_types:
                try:
                    await request.post()
                except ValueError as exc:
                    log.debug(exc)
                    return Response(status=400, body={
                        'error': 'multipart/form-data must be a form'
                    })

        try:
            capa_resp = await capa_handler(request, **request.match_info)
        except (web.HTTPNotFound, web.HTTPMethodNotAllowed):
            # Avoid sending a report on a simple 404/405
            raise
        except Exception as exc:
            reporting.exception(exc)
            raise

        if capa_resp and isinstance(capa_resp, Response):
            return capa_resp

        return Response()
Example #8
0
    async def reload_from_storage(self):
        """
        Check mongo, retrieve and load all templates
        """
        self.storage = MongoStorage(**self.mongo_config)

        templates = await self.storage.templates.get_all(
            latest=True,
            with_metadata=False
        )

        for template in templates:
            try:
                await self.engine.load(WorkflowTemplate.from_dict(template))
            except Exception as exc:
                # Means a bad workflow is in database, report it
                reporting.exception(exc)
Example #9
0
File: xmpp.py Project: thavel/nyuki
 def exception(self, exc):
     """
     xmlstream.py catches exceptions itself, calls this method afterwards
     """
     reporting.exception(exc)
Example #10
0
 def exception(self, exc):
     """
     xmlstream.py catches exceptions itself, calls this method afterwards
     """
     reporting.exception(exc)