Skip to content

Commit a664d8e

Browse files
Take www into account for prod, reuse uuid pattern
1 parent 4a16989 commit a664d8e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/entitysdk/common.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
from entitysdk.exception import EntitySDKError
1010
from entitysdk.typedef import DeploymentEnvironment
1111

12+
UUID_RE = "[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}"
13+
14+
1215
VLAB_URL_PATTERN = re.compile(
13-
r"^https:\/\/(?:(?P<staging>staging)\.)?openbraininstitute\.org"
14-
r"\/app\/virtual-lab\/lab\/(?P<vlab>[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})"
15-
r"\/project\/(?P<proj>[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})(?:\/.*)?$"
16+
r"^https:\/\/(?P<env>staging|www)?\.openbraininstitute\.org"
17+
rf"\/app\/virtual-lab\/lab\/(?P<vlab>{UUID_RE})"
18+
rf"\/project\/(?P<proj>{UUID_RE})(?:\/.*)?$"
1619
)
1720

1821

@@ -31,11 +34,11 @@ def from_vlab_url(cls, url: str) -> Self:
3134
if not result:
3235
raise EntitySDKError(f"Badly formed vlab url: {url}")
3336

34-
env = (
35-
DeploymentEnvironment.staging
36-
if result.group("staging")
37-
else DeploymentEnvironment.production
38-
)
37+
env = {
38+
"www": DeploymentEnvironment.production,
39+
"staging": DeploymentEnvironment.staging,
40+
}[result.group("env")]
41+
3942
vlab_id = UUID(result.group("vlab"))
4043
proj_id = UUID(result.group("proj"))
4144

tests/unit/test_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
),
2929
),
3030
(
31-
f"https://openbraininstitute.org/app/virtual-lab/lab/{VLAB_ID}/project/{PROJ_ID}/home",
31+
f"https://www.openbraininstitute.org/app/virtual-lab/lab/{VLAB_ID}/project/{PROJ_ID}/home",
3232
test_module.ProjectContext(
3333
virtual_lab_id=VLAB_ID,
3434
project_id=PROJ_ID,
3535
environment=DeploymentEnvironment.production,
3636
),
3737
),
3838
(
39-
f"https://openbraininstitute.org/app/virtual-lab/lab/{VLAB_ID}/project/{PROJ_ID}",
39+
f"https://www.openbraininstitute.org/app/virtual-lab/lab/{VLAB_ID}/project/{PROJ_ID}",
4040
test_module.ProjectContext(
4141
virtual_lab_id=VLAB_ID,
4242
project_id=PROJ_ID,

0 commit comments

Comments
 (0)