Skip to content

Commit

Permalink
add script name
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Jul 22, 2024
1 parent dc19682 commit a87bf22
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 38 deletions.
19 changes: 2 additions & 17 deletions contrib/builders/arkitekt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def _create_base_url(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "DockerServiceDescriptor", inside_port="80/tcp"):
protocol = "https" if context.secure else "http"
inside_base_url = f"{protocol}://{descriptor.internal_host}:{inside_port.split('/')[0]}"
outside_base_url = f"{protocol}://{context.request.host}" + (f"/{descriptor.internal_host}" if descriptor.internal_host != 'lok' else '')
outside_base_url = f"{protocol}://{context.request.host}" + f"/{descriptor.internal_host}"

# Depending on how the service is accessed, we need to return the correct base_url
if context.request.host == self.internal_host:
Expand Down Expand Up @@ -45,21 +45,6 @@ def lok(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "D
return { "base_url": base_url + "/o", "userinfo_url": f"{base_url}/o/userinfo", "token_url": f"{base_url}/o/token", "authorization_url": f"{base_url}/o/authorize", "client_id": context.client.client_id, "client_secret": context.client.client_secret, "client_type": context.client.client_type, "grant_type": context.client.authorization_grant_type, "name": context.client.name, "scopes": context.manifest.scopes, "__service": "live.arkitekt.lok"} | generic(self, context, descriptor)


def lok_dep(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "DockerServiceDescriptor"):

base_url = _create_base_url(self, context, descriptor)



return lok(self, context, descriptor)









def generic(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "DockerServiceDescriptor"):

Expand All @@ -82,7 +67,7 @@ def rekuest(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor
return generic(self, context, descriptor) | { "agent": {"endpoint_url": ws_base_url + "/agi"}}


def datalayer(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "DockerServiceDescriptor"):
def s3(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "DockerServiceDescriptor"):

protocol = "https" if context.secure else "http"
inside_base_url = f"{protocol}://{descriptor.internal_host}:9000"
Expand Down
8 changes: 2 additions & 6 deletions contrib/builders/livekitio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@


def _create_base_url(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "DockerServiceDescriptor", inside_port="80/tcp"):
try:
outside_port = descriptor.port_map[inside_port]
except KeyError:
raise Exception(f"Service {descriptor.internal_host} does not expose port {inside_port} only exposes ports: " + str(descriptor.port_map.keys()))

protocol = "http" #TODO: Until livekit supports custom certificates
inside_base_url = f"{protocol}://{descriptor.internal_host}:{inside_port.split('/')[0]}"
outside_base_url = f"{protocol}://{context.request.host}:{outside_port}"
outside_base_url = f"{protocol}://{context.request.host}:7880"

# Depending on how the service is accessed, we need to return the correct base_url
if context.request.host == self.internal_host:
Expand All @@ -29,7 +25,7 @@ def _create_base_url(self: "SelfServiceDescriptor", context: "LinkingContext", d

def livekit(self: "SelfServiceDescriptor", context: "LinkingContext", descriptor: "DockerServiceDescriptor"):

base_url = _create_base_url(self, context, descriptor, inside_port="7880/tcp")
base_url = _create_base_url(self, context, descriptor)



Expand Down
6 changes: 6 additions & 0 deletions fakts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

app_name = "fakts"


def index(request):
# Render that in the index template
raise NotImplementedError("This view is not implemented yet.")

# Basic url patterns for fakts
# as described in the fakts api documentation
base_urlpatterns = [
re_path(r"^$", index, name="index"),
re_path(r"^configure/$", views.ConfigureView.as_view(), name="configure"),
re_path(r"^retrieve/$", views.RetrieveView.as_view(), name="retrieve"),
re_path(r"^redeem/$", views.RedeemView.as_view(), name="redeem"),
Expand Down
2 changes: 1 addition & 1 deletion fakts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get(self, request, format=None):



return JsonResponse(data={"name": settings.DEPLOYMENT_NAME, "version": "0.0.1", "description": "This is the best server", "claim": request.build_absolute_uri("/f/claim") , "base_url": request.build_absolute_uri("/f/"), "ca_crt" : ca})
return JsonResponse(data={"name": settings.DEPLOYMENT_NAME, "version": "0.0.1", "description": "This is the best servesssr", "claim": request.build_absolute_uri(reverse("fakts:claim")) , "base_url": request.build_absolute_uri(reverse("fakts:index")), "ca_crt" : ca})



Expand Down
8 changes: 4 additions & 4 deletions lok/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from django.core.asgi import get_asgi_application
from ekke.consumers import EkkeHTTPConsumer, EkkeWsConsumer
from ekke.cors import CorsMiddleware

from .basepath import basepath, re_basepath


# Initialize Django ASGI application early to ensure the AppRegistry
Expand All @@ -39,16 +39,16 @@


websocket_urlpatterns = [
re_path(r"graphql", gql_ws_consumer),
re_basepath(r"graphql", gql_ws_consumer),
]

application = ProtocolTypeRouter(
{
"http": URLRouter(
[
re_path("^graphql", gql_http_consumer, name="graphql"),
re_basepath("graphql", gql_http_consumer, name="graphql"),
re_path(
"^", django_asgi_app
"", django_asgi_app
), # This might be another endpoint in your app
]
),
Expand Down
14 changes: 14 additions & 0 deletions lok/basepath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.urls import path, include, re_path
from django.conf import settings

def basepath(rel_path, *args, **kwargs):
if settings.MY_SCRIPT_NAME:
return path(settings.MY_SCRIPT_NAME.lstrip("/") + "/" + rel_path, *args, **kwargs)
else:
return path(rel_path, *args, **kwargs)

def re_basepath(rel_path, *args, **kwargs):
if settings.MY_SCRIPT_NAME:
return re_path(fr"^{settings.MY_SCRIPT_NAME.lstrip('/')}/" + rel_path, *args, **kwargs)
else:
return re_path(rel_path, *args, **kwargs)
6 changes: 4 additions & 2 deletions lok/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
"arkitekt.lok",
"arkitekt.generic",
"arkitekt.rekuest",
"arkitekt.datalayer",
"arkitekt.lok_dep",
"arkitekt.s3",
"livekitio.livekit",
"ollama.ollama",
],
Expand Down Expand Up @@ -295,6 +294,8 @@

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

CSRF_TRUSTED_ORIGINS = conf.get("csrf_trusted_origins", ["http://localhost", "https://localhost"])
MY_SCRIPT_NAME = conf.get("force_script_name", "lok")

LOGGING = {
"version": 1,
Expand Down Expand Up @@ -339,6 +340,7 @@
LOGIN_URL = "account_login"
LOGOUT_URL = "account_logout"


ENSURED_APPS = OmegaConf.to_object(conf.apps)

ENSURED_USERS = OmegaConf.to_object(conf.users)
Expand Down
21 changes: 13 additions & 8 deletions lok/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@
from django.urls import include, path
from fakts.views import WellKnownFakts
from django.shortcuts import render
from django.conf import settings
from .basepath import basepath

from django.urls import path, include, re_path
# Bootstrap Backend
def index(request):
# Render that in the index template
return render(request, "index.html")

urlpatterns = [

path("", index, name="index"),
path("ht/", include("health_check.urls")),
path("admin/", admin.site.urls),
path("o/", include("oauth2_provider.urls", namespace="oauth2_provider")),
path("f/", include("fakts.urls", namespace="fakts")),
path(".well-known/fakts", WellKnownFakts.as_view()),
path('accounts/', include('allauth.urls')),
path('accounts/', include('karakter.urls')),
basepath("", index, name="index"),
basepath("ht/", include("health_check.urls")),
basepath("admin/", admin.site.urls),
basepath("o/", include("oauth2_provider.urls", namespace="oauth2_provider")),
basepath("f/", include("fakts.urls", namespace="fakts")),
basepath(".well-known/fakts", WellKnownFakts.as_view()),
basepath('accounts/', include('allauth.urls')),
basepath('accounts/', include('karakter.urls')),

]


0 comments on commit a87bf22

Please sign in to comment.