コード例 #1
0
ファイル: _logs.py プロジェクト: pointw-dev/eve-utils
def _put_logging_config(request):
    """PUTs the verbosity for handlers."""
    response = make_error_response('Could not change log settings', 400)

    try:
        if request.content_type != 'application/json':
            raise TypeError('The request body must be application/json')

        payload = json.loads(request.data)

        logger = logging.getLogger()
        # first loop through to ensure everything is valid
        for key in payload:
            handler = [x for x in logger.handlers if x.name == key]
            if not handler:
                raise ValueError(f'{key} is not a valid log handler')
            try:
                getattr(logging, payload[key])
            except AttributeError:
                raise ValueError(f'{payload[key]} is not a valid log verbosity level')

        # now it's safe to iterate and change levels
        for key in payload:
            handler = [x for x in logger.handlers if x.name == key][0]
            handler.setLevel(getattr(logging, payload[key]))

        payload = {}
        for handler in logger.handlers:
            payload[handler.name] = logging.getLevelName(handler.level)

        response = make_response(jsonify(payload), 200)

    except (TypeError, ValueError) as ex:
        response = make_error_response('Invalid log setting specification', 422, exception=ex)

    except Exception as ex:
        response = make_error_response('Could not change log settings', 400, exception=ex)

    _log_request('_logging', request, response)
    return response
コード例 #2
0
ファイル: _settings.py プロジェクト: pointw-dev/eve-utils
def _fetch_settings(response):
    if current_app.auth and not current_app.auth.authorized(
            None, '_settings', 'GET'):
        abort(make_error_response('Please provide proper credentials', 401))

    del response['_items']
    del response['_meta']

    response['versions'] = {}
    response['settings'] = {}

    response['versions']['{$project_name}'] = VERSION
    response['versions']['eve'] = eve_version
    response['versions']['cerberus'] = cerberus_version
    response['versions']['python'] = platform.sys.version

    for env in sorted(SETTINGS):
        key = env.upper()
        if ('PASSWORD' not in key) and ('SECRET' not in key):
            response['settings'][env] = SETTINGS[env]
コード例 #3
0
 def catchall_exception_handler(ex):
     return make_error_response('Unexpected server error',
                                500,
                                exception=ex)
コード例 #4
0
 def mongo_missing_exception_handler(ex):
     message = 'Could not connect to mongodb.  ' \
               'Ask server admin to check connection settings and ensure database is running.'
     return make_error_response(message, 500, exception=ex)
コード例 #5
0
ファイル: _logs.py プロジェクト: pointw-dev/eve-utils
    def put_logging_config():
        """PUT logging level to handlers."""
        if app.auth and not app.auth.authorized(None, '_logging', 'PUT'):
            return make_error_response('Please provide proper credentials', 401)

        return _put_logging_config(flask_request)
コード例 #6
0
ファイル: _logs.py プロジェクト: pointw-dev/eve-utils
    def get_logging_config():
        """Returns the current verbosity levels for logging handlers."""
        if app.auth and not app.auth.authorized(None, '_logging', 'GET'):
            return make_error_response('Please provide proper credentials', 401)

        return _get_logging_config()