#NEWLINE# def validate_api_key( api_key_in_headers , api_key_query_params ) : #NEWLINE# #INDENT# '\n    Validate the provided API key.\n\n    :param api_key_in_headers: API key provided via headers.\n    :type api_key_in_headers: ``str``\n\n    :param api_key_query_params: API key provided via query params.\n    :type api_key_query_params: ``str``\n\n    :return: TokenDB object on success.\n    :rtype: :class:`.ApiKeyDB`\n    ' #NEWLINE# if ( ( not api_key_in_headers ) and ( not api_key_query_params ) ) : #NEWLINE# #INDENT# LOG . audit ( 'API key is not found in header or query parameters.' ) #NEWLINE# raise exceptions . ApiKeyNotProvidedError ( 'API key is not provided.' ) #NEWLINE# #UNINDENT# if api_key_in_headers : #NEWLINE# #INDENT# LOG . audit ( 'API key provided in headers' ) #NEWLINE# #UNINDENT# if api_key_query_params : #NEWLINE# #INDENT# LOG . audit ( 'API key provided in query parameters' ) #NEWLINE# #UNINDENT# api_key = ( api_key_in_headers or api_key_db ) #NEWLINE# api_key_db = ApiKey . get ( api_key ) #NEWLINE# if ( not api_key_db . enabled ) : #NEWLINE# #INDENT# raise exceptions . ApiKeyDisabledError ( 'API key is disabled.' ) #NEWLINE# #UNINDENT# LOG . audit ( ( 'API key with id "%s" is validated.' % api_key_db . id ) ) #NEWLINE# return api_key_db