diff --git a/powerdnsadmin/decorators.py b/powerdnsadmin/decorators.py index ed87d01..b57bc25 100644 --- a/powerdnsadmin/decorators.py +++ b/powerdnsadmin/decorators.py @@ -291,3 +291,13 @@ def dyndns_login_required(f): return f(*args, **kwargs) return decorated_function + +def apikey_or_basic_auth(f): + @wraps(f) + def decorated_function(*args, **kwargs): + api_auth_header = request.headers.get('X-API-KEY') + if api_auth_header: + return apikey_auth(f)(*args, **kwargs) + else: + return api_basic_auth(f)(*args, **kwargs) + return decorated_function diff --git a/powerdnsadmin/routes/api.py b/powerdnsadmin/routes/api.py index 51623b9..fe7a38f 100644 --- a/powerdnsadmin/routes/api.py +++ b/powerdnsadmin/routes/api.py @@ -24,6 +24,7 @@ from ..lib.errors import ( from ..decorators import ( api_basic_auth, api_can_create_domain, is_json, apikey_auth, apikey_is_admin, apikey_can_access_domain, api_role_can, + apikey_or_basic_auth, ) import random import string @@ -987,7 +988,7 @@ def api_server_config_forward(server_id): # The endpoint to snychronize Domains in background @api_bp.route('/sync_domains', methods=['GET']) -@apikey_auth +@apikey_or_basic_auth def sync_domains(): domain = Domain() domain.update()