Пример #1
0
async def get_handler(request: web.Request):
    try:
        if len(request.rel_url.query.keys()) == 0:
            services = await Service.get_all(DB.get(request, table))
            return web.json_response({
                'data':
                DB.format_documents(Bson.to_json(services)),
                'status_code':
                200
            })
        else:
            services = []
            if 'id' in request.rel_url.query:
                Validate.validate_object_id(request.rel_url.query.get('id'))
                service = await Service.get_by_id(
                    request.rel_url.query.get('id'), DB.get(request, table))
                if service is not None:
                    services.append(service)
            elif 'state' in request.rel_url.query:
                services = await Service.get_by_state(
                    request.rel_url.query.get('state'), DB.get(request, table))
            elif 'secure' in request.rel_url.query:
                services = await Service.get_by_secure(
                    bool(request.rel_url.query.get('secure')),
                    DB.get(request, table))
            return web.json_response({
                'data':
                DB.format_documents(Bson.to_json(services)),
                'status_code':
                200
            })
    except Exception as err:
        return Error.handle(err)
Пример #2
0
async def get_handler(request: web.Request):
    try:
        admins = None
        if len(request.rel_url.query.keys()) == 0:
            admins = await Admin.get_all(DB.get(request, table))
        else:
            admins = []
            if 'id' in request.rel_url.query:
                admin_id = request.rel_url.query.get('id')
                Validate.validate_object_id(admin_id)
                admin = await Admin.get_by_id(admin_id, DB.get(request, table))
                if admin is not None:
                    admins.append(admin)
            elif 'email' in request.rel_url.query:
                admin_email = request.rel_url.query.get('email')
                admins = await Admin.get_by_email(admin_email,
                                                  DB.get(request, table))
            elif 'username' in request.rel_url.query:
                admin_username = request.rel_url.query.get('username')
                admins = await Admin.get_by_username(admin_username,
                                                     DB.get(request, table))
        return web.json_response({
            'data':
            DB.format_documents(Bson.to_json(admins)),
            'status_code':
            200
        })
    except Exception as err:
        return Error.handle(err)
Пример #3
0
async def get_handler(request: web.Request):
    try:
        circuit_breakers = None
        if len(request.rel_url.query.keys()) == 0:
            circuit_breakers = await CircuitBreaker.get_all(DB.get(request, table))
        else:
            circuit_breakers = []
            if 'id' in request.rel_url.query:
                Validate.validate_object_id(request.rel_url.query.get('id'))
                circuit_breaker = await CircuitBreaker.get_by_id(request.rel_url.query.get('id'), DB.get(request, table))
                if circuit_breaker is not None:
                    circuit_breakers.append(circuit_breaker)
            elif 'service_id' in request.rel_url.query:
                Validate.validate_object_id(
                    request.rel_url.query.get('service_id'))
                circuit_breakers = await CircuitBreaker.get_by_service_id(request.rel_url.query.get('service_id'), DB.get(request, table))
            elif 'status_code' in request.rel_url.query:
                circuit_breakers = await CircuitBreaker.get_by_status_code(int(request.rel_url.query.get('status_code')), DB.get(request, table))
            elif 'method' in request.rel_url.query:
                circuit_breakers = await CircuitBreaker.get_by_method(request.rel_url.query.get('method'), DB.get(request, table))
            elif 'threshold' in request.rel_url.query:
                circuit_breakers = await CircuitBreaker.get_by_threshold(float(request.rel_url.query.get('threshold')), DB.get(request, table))
        return web.json_response({
            'data': DB.format_documents(Bson.to_json(circuit_breakers)),
            'status_code': 200
        })
    except Exception as err:
        return Error.handle(err)
Пример #4
0
async def get_handler(request: web.Request):
    try:
        if len(request.rel_url.query.keys()) == 0:
            insights = await Insights.get_all(DB.get(request, table))
        else:
            insights = []
            if 'id' in request.rel_url.query:
                insight = await Insights.get_by_id(
                    request.rel_url.query.get('id'), DB.get(request, table))
                if insight is not None:
                    insights.append(insight)
            elif 'remote_ip' in request.rel_url.query:
                insights = await Insights.get_by_remote_ip(
                    request.rel_url.query.get('remote_ip'),
                    DB.get(request, table))
            elif 'status_code' in request.rel_url.query:
                insights = await Insights.get_by_status_code(
                    request.rel_url.query.get('status_code'),
                    DB.get(request, table))
            elif 'path' in request.rel_url.query:
                insights = await Insights.get_by_path(
                    request.rel_url.query.get('path'), DB.get(request, table))
            elif 'method' in request.rel_url.query:
                insights = await Insights.get_by_method(
                    request.rel_url.query.get('method'),
                    DB.get(request, table))
            elif 'service_id' in request.rel_url.query:
                insights = await Insights.get_by_service_id(
                    request.rel_url.query.get('service_id'),
                    DB.get(request, table))
            elif 'scheme' in request.rel_url.query:
                insights = await Insights.get_by_scheme(
                    request.rel_url.query.get('scheme'),
                    DB.get(request, table))
        return web.json_response({
            'data':
            DB.format_documents(Bson.to_json(insights)),
            'status_code':
            200
        })
    except Exception as err:
        return Error.handle(err)