Add basic structure to access django-orchestra API

This commit is contained in:
Santiago Lamora 2019-10-29 10:47:50 +01:00
parent 676e9b94a5
commit 750d5cc465
4 changed files with 30 additions and 0 deletions

View file

@ -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/'

24
musician/api.py Normal file
View file

@ -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)

View file

@ -2,4 +2,5 @@ django==2.2
python-decouple==3.1
django-extensions
dj_database_url==0.5.0
requests==2.22.0

View file

@ -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')