Skip to content

Commit 252bf44

Browse files
committed
move status page logic to constants and settings
1 parent b2becc2 commit 252bf44

5 files changed

Lines changed: 71 additions & 47 deletions

File tree

src/aignostics/gui/_frame.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from loguru import logger
1515

1616
from aignostics.constants import WINDOW_TITLE
17-
from aignostics.platform import API_ROOT_PRODUCTION, API_ROOT_STAGING
1817
from aignostics.utils import __version__, open_user_data_directory
1918

2019
from ._theme import theme
@@ -30,23 +29,6 @@
3029
CLASSES_FULL_SIZE = f"{CLASSES_FULL_WIDTH} {CLASSES_FULL_HEIGHT}"
3130

3231

33-
def get_status_page_url(api_root: str) -> str | None:
34-
"""Get the status page URL based on the API root environment.
35-
36-
Args:
37-
api_root: The API root URL to determine the environment
38-
39-
Returns:
40-
The status page URL for production/staging, or None for dev/test
41-
"""
42-
if api_root == API_ROOT_PRODUCTION:
43-
return "https://status.platform.aignostics.com"
44-
if api_root == API_ROOT_STAGING:
45-
return "https://status.platform-staging.aignostics.com"
46-
# No status page for dev and test environments
47-
return None
48-
49-
5032
@contextmanager
5133
def frame( # noqa: C901, PLR0915
5234
navigation_title: str,
@@ -232,7 +214,7 @@ def _update_health() -> None:
232214
name="_health_load_and_render",
233215
)
234216
# Only refresh the status iframe if it exists (production/staging)
235-
if get_status_page_url(settings().api_root):
217+
if settings().status_page_url:
236218
ui.run_javascript("document.getElementById('betterstack').src = document.getElementById('betterstack').src;")
237219

238220
ui.timer(interval=HEALTH_UPDATE_INTERVAL, callback=_update_health, immediate=True)
@@ -362,7 +344,7 @@ def toggle_dark_mode() -> None:
362344
ui.link("Get Support", "https://platform.aignostics.com/support", new_tab=True).mark(
363345
"LINK_DOCUMENTATION"
364346
)
365-
status_url = get_status_page_url(settings().api_root)
347+
status_url = settings().status_page_url
366348
if status_url:
367349
with ui.item().props("clickable"):
368350
with ui.item_section().props("avatar"):
@@ -390,7 +372,7 @@ def toggle_dark_mode() -> None:
390372
ui.row(align_items="center").classes("justify-start w-full"),
391373
):
392374
health_link()
393-
status_url = get_status_page_url(settings().api_root)
375+
status_url = settings().status_page_url
394376
if status_url:
395377
with ui.row().style("padding: 0"):
396378
ui.html(

src/aignostics/platform/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
REDIRECT_URI_TEST,
7272
REDIRECT_URI_STAGING,
7373
REDIRECT_URI_PRODUCTION,
74+
STATUS_PAGE_URL_DEV,
75+
STATUS_PAGE_URL_TEST,
76+
STATUS_PAGE_URL_STAGING,
77+
STATUS_PAGE_URL_PRODUCTION,
7478
TOKEN_URL_DEV,
7579
TOKEN_URL_TEST,
7680
TOKEN_URL_STAGING,

src/aignostics/platform/_constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
REDIRECT_URI_DEV = "http://localhost:8989/"
99
DEVICE_URL_DEV = "https://dev-8ouohmmrbuh2h4vu.eu.auth0.com/oauth/device/code"
1010
JWS_JSON_URL_DEV = "https://dev-8ouohmmrbuh2h4vu.eu.auth0.com/.well-known/jwks.json"
11+
STATUS_PAGE_URL_DEV = None # No dedicated status page for dev environment
1112

1213
API_ROOT_TEST = "https://platform-test.aignostics.ai"
1314
CLIENT_ID_INTERACTIVE_TEST = "gqduveFvx7LX90drQPGzr4JGUYdh24gA" # not a secret, but a public client ID (same as dev)
@@ -17,6 +18,7 @@
1718
REDIRECT_URI_TEST = "http://localhost:8989/"
1819
DEVICE_URL_TEST = "https://dev-8ouohmmrbuh2h4vu.eu.auth0.com/oauth/device/code"
1920
JWS_JSON_URL_TEST = "https://dev-8ouohmmrbuh2h4vu.eu.auth0.com/.well-known/jwks.json"
21+
STATUS_PAGE_URL_TEST = None # No dedicated status page for test environment
2022

2123
API_ROOT_STAGING = "https://platform-staging.aignostics.com"
2224
CLIENT_ID_INTERACTIVE_STAGING = "fQkbvYzQPPVwLxc3uque5JsyFW00rJ7b" # not a secret, but a public client ID
@@ -26,6 +28,7 @@
2628
REDIRECT_URI_STAGING = "http://localhost:8989/"
2729
DEVICE_URL_STAGING = "https://aignostics-platform-staging.eu.auth0.com/oauth/device/code"
2830
JWS_JSON_URL_STAGING = "https://aignostics-platform-staging.eu.auth0.com/.well-known/jwks.json"
31+
STATUS_PAGE_URL_STAGING = "https://status.platform-staging.aignostics.com"
2932

3033
API_ROOT_PRODUCTION = "https://platform.aignostics.com"
3134
CLIENT_ID_INTERACTIVE_PRODUCTION = "YtJ7F9lAtxx16SZGQlYPe6wcjlXB78MM" # not a secret, but a public client ID
@@ -35,6 +38,7 @@
3538
REDIRECT_URI_PRODUCTION = "http://localhost:8989/"
3639
DEVICE_URL_PRODUCTION = "https://aignostics-platform.eu.auth0.com/oauth/device/code"
3740
JWS_JSON_URL_PRODUCTION = "https://aignostics-platform.eu.auth0.com/.well-known/jwks.json"
41+
STATUS_PAGE_URL_PRODUCTION = "https://status.platform.aignostics.com"
3842

3943
# Pipeline orchestration defaults
4044
DEFAULT_GPU_TYPE = "L4"

src/aignostics/platform/_settings.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
REDIRECT_URI_TEST,
5151
REDIRECT_URI_STAGING,
5252
REDIRECT_URI_PRODUCTION,
53+
STATUS_PAGE_URL_DEV,
54+
STATUS_PAGE_URL_TEST,
55+
STATUS_PAGE_URL_STAGING,
56+
STATUS_PAGE_URL_PRODUCTION,
5357
TOKEN_URL_DEV,
5458
TOKEN_URL_TEST,
5559
TOKEN_URL_STAGING,
@@ -205,6 +209,9 @@ def profile_edit_url(self) -> str:
205209
str, BeforeValidator(_validate_url), Field(description="JWS key set URL for token verification")
206210
]
207211
client_id_interactive: Annotated[str, Field(description="OAuth client ID for interactive flows")]
212+
status_page_url: Annotated[
213+
str | None, Field(description="Status page URL for monitoring platform health", default=None)
214+
] = None
208215

209216
@computed_field # type: ignore[prop-decorator]
210217
@property
@@ -510,6 +517,20 @@ def pre_init(cls, values: dict) -> dict: # type: ignore[type-arg] # noqa: N805
510517
# See https://github.com/pydantic/pydantic/issues/9789
511518
api_root = values.get("api_root", API_ROOT_PRODUCTION)
512519

520+
# Set status_page_url based on environment (independent of auth fields)
521+
if "status_page_url" not in values:
522+
match api_root:
523+
case x if x == API_ROOT_DEV:
524+
values["status_page_url"] = STATUS_PAGE_URL_DEV
525+
case x if x == API_ROOT_TEST:
526+
values["status_page_url"] = STATUS_PAGE_URL_TEST
527+
case x if x == API_ROOT_STAGING:
528+
values["status_page_url"] = STATUS_PAGE_URL_STAGING
529+
case x if x == API_ROOT_PRODUCTION:
530+
values["status_page_url"] = STATUS_PAGE_URL_PRODUCTION
531+
case _:
532+
values["status_page_url"] = None
533+
513534
# Check if all required auth fields are already provided
514535
auth_fields = [
515536
"audience",

tests/aignostics/gui/frame_test.py

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,83 @@
22

33
import pytest
44

5-
from aignostics.gui._frame import get_status_page_url
65
from aignostics.platform import (
76
API_ROOT_DEV,
87
API_ROOT_PRODUCTION,
98
API_ROOT_STAGING,
109
API_ROOT_TEST,
10+
STATUS_PAGE_URL_DEV,
11+
STATUS_PAGE_URL_PRODUCTION,
12+
STATUS_PAGE_URL_STAGING,
13+
STATUS_PAGE_URL_TEST,
14+
Settings,
1115
)
1216

1317

1418
@pytest.mark.unit
15-
def test_get_status_page_url_production(record_property) -> None:
16-
"""Test that production environment returns correct status page URL.
19+
def test_status_page_url_production(record_property) -> None:
20+
"""Test that production environment has correct status page URL in settings.
1721
1822
Args:
1923
record_property: pytest record_property fixture
2024
"""
21-
record_property("tested-item-id", "SPEC-GUI-FRAME")
22-
url = get_status_page_url(API_ROOT_PRODUCTION)
23-
assert url == "https://status.platform.aignostics.com"
25+
record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS")
26+
settings = Settings(api_root=API_ROOT_PRODUCTION)
27+
assert settings.status_page_url == STATUS_PAGE_URL_PRODUCTION
28+
assert settings.status_page_url == "https://status.platform.aignostics.com"
2429

2530

2631
@pytest.mark.unit
27-
def test_get_status_page_url_staging(record_property) -> None:
28-
"""Test that staging environment returns correct status page URL.
32+
def test_status_page_url_staging(record_property) -> None:
33+
"""Test that staging environment has correct status page URL in settings.
2934
3035
Args:
3136
record_property: pytest record_property fixture
3237
"""
33-
record_property("tested-item-id", "SPEC-GUI-FRAME")
34-
url = get_status_page_url(API_ROOT_STAGING)
35-
assert url == "https://status.platform-staging.aignostics.com"
38+
record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS")
39+
settings = Settings(api_root=API_ROOT_STAGING)
40+
assert settings.status_page_url == STATUS_PAGE_URL_STAGING
41+
assert settings.status_page_url == "https://status.platform-staging.aignostics.com"
3642

3743

3844
@pytest.mark.unit
39-
def test_get_status_page_url_dev(record_property) -> None:
40-
"""Test that dev environment returns None (no status page).
45+
def test_status_page_url_dev(record_property) -> None:
46+
"""Test that dev environment has no status page URL in settings.
4147
4248
Args:
4349
record_property: pytest record_property fixture
4450
"""
45-
record_property("tested-item-id", "SPEC-GUI-FRAME")
46-
url = get_status_page_url(API_ROOT_DEV)
47-
assert url is None
51+
record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS")
52+
settings = Settings(api_root=API_ROOT_DEV)
53+
assert settings.status_page_url == STATUS_PAGE_URL_DEV
54+
assert settings.status_page_url is None
4855

4956

5057
@pytest.mark.unit
51-
def test_get_status_page_url_test(record_property) -> None:
52-
"""Test that test environment returns None (no status page).
58+
def test_status_page_url_test(record_property) -> None:
59+
"""Test that test environment has no status page URL in settings.
5360
5461
Args:
5562
record_property: pytest record_property fixture
5663
"""
57-
record_property("tested-item-id", "SPEC-GUI-FRAME")
58-
url = get_status_page_url(API_ROOT_TEST)
59-
assert url is None
64+
record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS")
65+
settings = Settings(api_root=API_ROOT_TEST)
66+
assert settings.status_page_url == STATUS_PAGE_URL_TEST
67+
assert settings.status_page_url is None
6068

6169

6270
@pytest.mark.unit
63-
def test_get_status_page_url_unknown(record_property) -> None:
64-
"""Test that unknown environment returns None (no status page).
71+
def test_status_page_url_configurable(record_property, monkeypatch) -> None:
72+
"""Test that status page URL can be explicitly configured via settings.
6573
6674
Args:
6775
record_property: pytest record_property fixture
76+
monkeypatch: pytest monkeypatch fixture
6877
"""
69-
record_property("tested-item-id", "SPEC-GUI-FRAME")
70-
url = get_status_page_url("https://custom.example.com")
71-
assert url is None
78+
record_property("tested-item-id", "SPEC-PLATFORM-SETTINGS")
79+
# Test that we can override the status page URL
80+
custom_url = "https://custom-status.example.com"
81+
monkeypatch.setenv("AIGNOSTICS_STATUS_PAGE_URL", custom_url)
82+
settings = Settings(api_root=API_ROOT_PRODUCTION)
83+
assert settings.status_page_url == custom_url
84+

0 commit comments

Comments
 (0)