53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
|
import json
|
||
|
|
||
|
from django.core.handlers.wsgi import WSGIRequest
|
||
|
from django.http import HttpResponse
|
||
|
|
||
|
from config import (DEBUG, ENABLED_APPLICATIONS, tCOMMON_TOKEN,
|
||
|
tCOMMON_URL_INTERNAL, tCOMMON_URL_PUBLIC)
|
||
|
|
||
|
|
||
|
def initialize(request: WSGIRequest) -> HttpResponse:
|
||
|
if request.GET.get("token") != tCOMMON_TOKEN:
|
||
|
return HttpResponse(
|
||
|
json.dumps({
|
||
|
"success": False
|
||
|
}),
|
||
|
content_type="application/json",
|
||
|
status=401
|
||
|
)
|
||
|
|
||
|
resp = {
|
||
|
"debug": DEBUG,
|
||
|
"success": True,
|
||
|
"services": {
|
||
|
"common": {
|
||
|
"url": {
|
||
|
"pub": tCOMMON_URL_PUBLIC,
|
||
|
"int": tCOMMON_URL_INTERNAL
|
||
|
},
|
||
|
"token": tCOMMON_TOKEN
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for service in [
|
||
|
"auth", "message"
|
||
|
]:
|
||
|
if service in ENABLED_APPLICATIONS and isinstance(s := ENABLED_APPLICATIONS[service], tuple):
|
||
|
resp["services"][service] = {
|
||
|
"url": {
|
||
|
"pub": s[2],
|
||
|
"int": s[1],
|
||
|
},
|
||
|
"token": s[0]
|
||
|
}
|
||
|
else:
|
||
|
resp["services"][service] = None
|
||
|
|
||
|
return HttpResponse(
|
||
|
json.dumps(resp),
|
||
|
content_type="application/json",
|
||
|
status=200
|
||
|
)
|