Skip to content
Snippets Groups Projects
Commit 3cfcce19 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Utility for checking if API request

Utility function for determining whether a request is directed at the
API.  Can specify that the check is for a certain API "type", like
shibboleth, X509, or basic.
parent 94dddcb6
No related branches found
No related tags found
No related merge requests found
......@@ -83,4 +83,23 @@ def api_reverse(viewname, args=None, kwargs=None, request=None, format=None,
if request is None:
url = build_absolute_uri(url)
return url
return url
def is_api_request(request_path, namespace='x509'):
"""
Returns True/False based on whether the request is directed to the API
The namespace variable determines whether we should be testing for the
'normal' API (x509 auth), basic auth API, or web API.
These namespaces are specified in the root urlconf (config/urls.py).
"""
# This is hard-coded because things break if we try to import it from .urls
api_app_name = 'api'
resolver_match = resolve(request_path)
if (resolver_match.app_name == api_app_name and
resolver_match.namespace == namespace):
return True
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment