Records the service ID if present, or if an ADMIN api call the string admin-api.

this is used later in logging of requests.
This commit is contained in:
Martyn Inglis
2016-11-30 10:59:55 +00:00
parent 2ae8967a5f
commit 23ca62a7ac
2 changed files with 3 additions and 4 deletions

View File

@@ -1,11 +1,10 @@
from flask import request, _request_ctx_stack, current_app from flask import request, _request_ctx_stack, current_app, g
from sqlalchemy.exc import DataError from sqlalchemy.exc import DataError
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
from notifications_python_client.authentication import decode_jwt_token, get_token_issuer from notifications_python_client.authentication import decode_jwt_token, get_token_issuer
from notifications_python_client.errors import TokenDecodeError, TokenExpiredError, TokenIssuerError from notifications_python_client.errors import TokenDecodeError, TokenExpiredError, TokenIssuerError
from app.dao.api_key_dao import get_model_api_keys
from app.dao.services_dao import dao_fetch_service_by_id from app.dao.services_dao import dao_fetch_service_by_id
@@ -50,6 +49,7 @@ def requires_auth():
raise AuthError("Invalid token: iss not provided", 403) raise AuthError("Invalid token: iss not provided", 403)
if client == current_app.config.get('ADMIN_CLIENT_USER_NAME'): if client == current_app.config.get('ADMIN_CLIENT_USER_NAME'):
g.service_id = current_app.config.get('ADMIN_CLIENT_USER_NAME')
return handle_admin_key(auth_token, current_app.config.get('ADMIN_CLIENT_SECRET')) return handle_admin_key(auth_token, current_app.config.get('ADMIN_CLIENT_SECRET'))
try: try:
@@ -74,6 +74,7 @@ def requires_auth():
if api_key.expiry_date: if api_key.expiry_date:
raise AuthError("Invalid token: API key revoked", 403) raise AuthError("Invalid token: API key revoked", 403)
g.service_id = api_key.service_id
_request_ctx_stack.top.api_user = api_key _request_ctx_stack.top.api_user = api_key
return return
else: else:

View File

@@ -36,8 +36,6 @@ from app.schemas import (
) )
from app.service.utils import service_allowed_to_send_to from app.service.utils import service_allowed_to_send_to
from app.utils import pagination_links from app.utils import pagination_links
from app import redis_store
from app.clients import redis
notifications = Blueprint('notifications', __name__) notifications = Blueprint('notifications', __name__)