Skip to content

Commit 551d7d0

Browse files
committed
Use referenceid not uuid to refer to services
1 parent 63d2fa7 commit 551d7d0

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

appstore/core/tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ def test_private_route_redirects_guid_to_controller_uuid(self, mock_get_helxinst
7171
"/private/pgadmin/wateim/3ccf4b07-ea15-488e-9208-48b0e3ffbb53/",
7272
)
7373

74+
@patch("core.views._get_helxinst_manager")
75+
def test_private_route_keeps_reference_id_path(self, mock_get_helxinst_manager):
76+
sid = "4ec0678656034b7198ae30fa598196af"
77+
mock_mgr = Mock()
78+
mock_mgr.get.return_value = {
79+
"spec": {"referenceID": sid},
80+
"status": {"uuid": "3ccf4b07-ea15-488e-9208-48b0e3ffbb53"},
81+
}
82+
mock_get_helxinst_manager.return_value = mock_mgr
83+
84+
response = self.client.get(f"/private/pgadmin/wateim/{sid}/")
85+
86+
self.assertEqual(response.status_code, 404)
87+
7488
@patch("core.views._get_helxinst_manager")
7589
def test_private_route_returns_404_when_no_matching_helxinst(self, mock_get_helxinst_manager):
7690
mock_mgr = Mock()

appstore/core/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ def _resolve_private_redirect_path(path):
132132
if helxinst is None:
133133
return None
134134

135+
spec = helxinst.get("spec", {}) or {}
136+
reference_id = spec.get("referenceID")
137+
if reference_id and reference_id == sid:
138+
return None
139+
135140
controller_uuid = (helxinst.get("status") or {}).get("uuid")
136141
if not controller_uuid or controller_uuid == sid:
137142
return None

appstore/registry/spec_builder.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,11 @@
1717
)
1818
from registry.models import ResolvedApp
1919

20-
# Standard ambassador prefix — routes /private/<app>/<user>/<uuid>/ to this
21-
# service. Uses Go template expressions resolved by the controller at
20+
# Standard ambassador prefix — routes /private/<app>/<user>/<referenceID>/ to
21+
# the service. Uses Go template expressions resolved by the controller at
2222
# deployment time.
2323
_AMBASSADOR_PREFIX = (
24-
"/private/{{ .system.AppClassName }}/{{ .system.UserName }}/{{ .system.UUID }}/"
25-
)
26-
27-
# AppStore still launches applications with a stable reference ID in NB_PREFIX.
28-
# The helxapp-controller labels Services with its own UUID. Match on the
29-
# controller UUID externally, then rewrite the upstream path back to the
30-
# AppStore reference ID so path-aware apps (pgAdmin, filebrowser, notebooks)
31-
# see the prefix they were configured with at launch time.
32-
_AMBASSADOR_REFERENCE_REWRITE = (
33-
'/private/{{ .system.AppClassName }}/{{ .system.UserName }}/'
34-
'{{ .system.ReferenceID }}/'
24+
"/private/{{ .system.AppClassName }}/{{ .system.UserName }}/{{ .system.ReferenceID }}/"
3525
)
3626

3727

@@ -85,7 +75,7 @@ def build_helxapp_spec(app: ResolvedApp, compose_spec: dict) -> HelxAppSpec:
8575
if has_service_port and not ambassador_assigned:
8676
proxy_rewrite = None
8777
if app.proxy_rewrite_enabled:
88-
proxy_rewrite = app.proxy_rewrite_target or _AMBASSADOR_REFERENCE_REWRITE
78+
proxy_rewrite = app.proxy_rewrite_target or _AMBASSADOR_PREFIX
8979
ambassador = AmbassadorSpec(
9080
prefix=_AMBASSADOR_PREFIX,
9181
ambassador_id=ambassador_id,

appstore/registry/tests/test_spec_builder.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_ambassador_added_for_service_with_port(self):
131131
assert svc.ambassador is not None
132132
assert "{{ .system.AppClassName }}" in svc.ambassador.prefix
133133
assert "{{ .system.UserName }}" in svc.ambassador.prefix
134-
assert "{{ .system.UUID }}" in svc.ambassador.prefix
134+
assert "{{ .system.ReferenceID }}" in svc.ambassador.prefix
135135

136136
def test_ambassador_in_to_dict(self):
137137
spec = build_helxapp_spec(_app(), _compose())
@@ -146,10 +146,7 @@ def test_ambassador_rewrite_defaults_to_prefix_when_enabled(self):
146146
)
147147
ambassador = spec.services[0].ambassador
148148
assert ambassador is not None
149-
assert ambassador.proxy_rewrite != ambassador.prefix
150-
assert "{{ .system.AppClassName }}" in ambassador.proxy_rewrite
151-
assert "{{ .system.UserName }}" in ambassador.proxy_rewrite
152-
assert "{{ .system.ReferenceID }}" in ambassador.proxy_rewrite
149+
assert ambassador.proxy_rewrite == ambassador.prefix
153150

154151
def test_ambassador_rewrite_uses_explicit_target(self):
155152
spec = build_helxapp_spec(

0 commit comments

Comments
 (0)