From 750d5cc465cadbe178ea81de511e3d7b455a5724 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 29 Oct 2019 10:47:50 +0100 Subject: [PATCH] Add basic structure to access django-orchestra API --- .env.example | 1 + musician/api.py | 24 ++++++++++++++++++++++++ requirements.txt | 1 + userpanel/settings.py | 4 ++++ 4 files changed, 30 insertions(+) create mode 100644 musician/api.py diff --git a/.env.example b/.env.example index 41acf39..e753e2b 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ SECRET_KEY='$omeR@nd0mSecr3tKeyWith4V3ryL0ng$tring!?' DEBUG=True ALLOWED_HOSTS=.localhost,127.0.0.1 +API_BASE_URL = 'https://api.examplea.org/' diff --git a/musician/api.py b/musician/api.py new file mode 100644 index 0000000..800cc1d --- /dev/null +++ b/musician/api.py @@ -0,0 +1,24 @@ +import urllib.parse + +from django.conf import settings +from django.urls.exceptions import NoReverseMatch + +DOMAINS_PATH = 'domains/' +TOKEN_PATH = '/api-token-auth/' + +API_PATHS = { + # auth + 'token-auth': '/api-token-auth/', + + # services + 'domain-list': 'domains/', + # ... TODO (@slamora) complete list of backend URLs +} + + +def build_absolute_uri(path_name): + path = API_PATHS.get(path_name, None) + if path is None: + raise NoReverseMatch("Not found API path name '{}'".format(path_name)) + + return urllib.parse.urljoin(settings.API_BASE_URL, path) diff --git a/requirements.txt b/requirements.txt index def8cfc..0691a4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ django==2.2 python-decouple==3.1 django-extensions dj_database_url==0.5.0 +requests==2.22.0 diff --git a/userpanel/settings.py b/userpanel/settings.py index 4a0121c..dd40d8a 100644 --- a/userpanel/settings.py +++ b/userpanel/settings.py @@ -135,3 +135,7 @@ USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = config('STATIC_ROOT') + +# Backend API configuration + +API_BASE_URL = config('API_BASE_URL')