2024-12-20 21:18:31 -05:00
|
|
|
import json
|
|
|
|
|
|
|
|
from django.core.handlers.wsgi import WSGIRequest
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
2024-12-23 13:22:20 -05:00
|
|
|
from config import (ALLOW_NEW_USERS, DEBUG, ENABLED_APPLICATIONS,
|
|
|
|
tCOMMON_TOKEN, tCOMMON_URL_INTERNAL, tCOMMON_URL_PUBLIC)
|
2024-12-20 21:24:37 -05:00
|
|
|
from tcommon.settings import VERSION
|
2024-12-20 21:18:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
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,
|
2024-12-20 21:24:37 -05:00
|
|
|
"version": list(VERSION),
|
2024-12-20 23:44:40 -05:00
|
|
|
"version_str": ".".join([str(i) for i in VERSION]),
|
2024-12-23 13:22:20 -05:00
|
|
|
"new_users": ALLOW_NEW_USERS,
|
2024-12-20 21:18:31 -05:00
|
|
|
"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),
|
2024-12-22 00:07:48 -05:00
|
|
|
content_type="application/json"
|
2024-12-20 21:18:31 -05:00
|
|
|
)
|