mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
log user agents on api call auth.
this'll be useful for trying to figure out which services are using what
This commit is contained in:
@@ -93,7 +93,11 @@ def requires_auth():
|
|||||||
g.service_id = api_key.service_id
|
g.service_id = api_key.service_id
|
||||||
_request_ctx_stack.top.authenticated_service = service
|
_request_ctx_stack.top.authenticated_service = service
|
||||||
_request_ctx_stack.top.api_user = api_key
|
_request_ctx_stack.top.api_user = api_key
|
||||||
current_app.logger.info('Succesful login for service {} with api key {}'.format(service.id, api_key.id))
|
current_app.logger.info('Succesful login for service {} with api key {}, using client'.format(
|
||||||
|
service.id,
|
||||||
|
api_key.id,
|
||||||
|
request.headers.get('User-Agent')
|
||||||
|
))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# service has API keys, but none matching the one the user provided
|
# service has API keys, but none matching the one the user provided
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
from flask import jsonify, current_app
|
|
||||||
|
from flask import jsonify, current_app, request
|
||||||
from jsonschema import ValidationError
|
from jsonschema import ValidationError
|
||||||
from sqlalchemy.exc import DataError
|
from sqlalchemy.exc import DataError
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
from app.authentication.auth import AuthError
|
from app.authentication.auth import AuthError
|
||||||
from app.errors import InvalidRequest
|
from app.errors import InvalidRequest
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ def register_errors(blueprint):
|
|||||||
|
|
||||||
@blueprint.errorhandler(AuthError)
|
@blueprint.errorhandler(AuthError)
|
||||||
def auth_error(error):
|
def auth_error(error):
|
||||||
current_app.logger.info('API AuthError: {}'.format(error))
|
current_app.logger.info('API AuthError, client: {} error: {}'.format(request.headers.get('User-Agent'), error))
|
||||||
return jsonify(error.to_dict_v2()), error.code
|
return jsonify(error.to_dict_v2()), error.code
|
||||||
|
|
||||||
@blueprint.errorhandler(Exception)
|
@blueprint.errorhandler(Exception)
|
||||||
|
|||||||
Reference in New Issue
Block a user