ctfy.sdk.admin_resources.settings

client.admin.settings — runtime-tunable platform settings (super-admin).

 1"""``client.admin.settings`` — runtime-tunable platform settings (super-admin)."""
 2
 3from __future__ import annotations
 4
 5import builtins
 6from typing import Any
 7
 8from ctfy.sdk._helpers import _raise_for_status
 9from ctfy.sdk.base import BaseHttpClient
10from ctfy.server.models import PlatformSettingInfo
11
12
13class AdminSettingsResource:
14    """The DB overlay over ``CtfyConfig`` (resolution: DB > env > default)."""
15
16    def __init__(self, http: BaseHttpClient) -> None:
17        self._http = http
18
19    def list(self) -> builtins.list[PlatformSettingInfo]:
20        """Every runtime-tunable setting with its currently resolved
21        value (DB > env > default) plus the env / default values that
22        would resolve if the DB override were removed.
23
24        Super-admin only on the server side; non-super callers get 403.
25        """
26        resp = self._http.request("GET", "/admin/platform-settings")
27        _raise_for_status(resp)
28        return [PlatformSettingInfo.model_validate(row) for row in resp.json()]
29
30    def set(self, key: str, value: Any) -> PlatformSettingInfo:
31        """Persist a DB override for *key*. The server's per-key
32        validator rejects shape / range violations with 400."""
33        resp = self._http.request(
34            "PATCH",
35            f"/admin/platform-settings/{key}",
36            json={"value": value},
37        )
38        _raise_for_status(resp)
39        return PlatformSettingInfo.model_validate(resp.json())
40
41    def unset(self, key: str) -> PlatformSettingInfo:
42        """Remove the DB override for *key* so the resolved value
43        falls back to env / built-in default."""
44        resp = self._http.request("DELETE", f"/admin/platform-settings/{key}")
45        _raise_for_status(resp)
46        return PlatformSettingInfo.model_validate(resp.json())
class AdminSettingsResource:
14class AdminSettingsResource:
15    """The DB overlay over ``CtfyConfig`` (resolution: DB > env > default)."""
16
17    def __init__(self, http: BaseHttpClient) -> None:
18        self._http = http
19
20    def list(self) -> builtins.list[PlatformSettingInfo]:
21        """Every runtime-tunable setting with its currently resolved
22        value (DB > env > default) plus the env / default values that
23        would resolve if the DB override were removed.
24
25        Super-admin only on the server side; non-super callers get 403.
26        """
27        resp = self._http.request("GET", "/admin/platform-settings")
28        _raise_for_status(resp)
29        return [PlatformSettingInfo.model_validate(row) for row in resp.json()]
30
31    def set(self, key: str, value: Any) -> PlatformSettingInfo:
32        """Persist a DB override for *key*. The server's per-key
33        validator rejects shape / range violations with 400."""
34        resp = self._http.request(
35            "PATCH",
36            f"/admin/platform-settings/{key}",
37            json={"value": value},
38        )
39        _raise_for_status(resp)
40        return PlatformSettingInfo.model_validate(resp.json())
41
42    def unset(self, key: str) -> PlatformSettingInfo:
43        """Remove the DB override for *key* so the resolved value
44        falls back to env / built-in default."""
45        resp = self._http.request("DELETE", f"/admin/platform-settings/{key}")
46        _raise_for_status(resp)
47        return PlatformSettingInfo.model_validate(resp.json())

The DB overlay over CtfyConfig (resolution: DB > env > default).

AdminSettingsResource(http: ctfy.sdk.base.BaseHttpClient)
17    def __init__(self, http: BaseHttpClient) -> None:
18        self._http = http
def list(self) -> list[ctfy.server.models.PlatformSettingInfo]:
20    def list(self) -> builtins.list[PlatformSettingInfo]:
21        """Every runtime-tunable setting with its currently resolved
22        value (DB > env > default) plus the env / default values that
23        would resolve if the DB override were removed.
24
25        Super-admin only on the server side; non-super callers get 403.
26        """
27        resp = self._http.request("GET", "/admin/platform-settings")
28        _raise_for_status(resp)
29        return [PlatformSettingInfo.model_validate(row) for row in resp.json()]

Every runtime-tunable setting with its currently resolved value (DB > env > default) plus the env / default values that would resolve if the DB override were removed.

Super-admin only on the server side; non-super callers get 403.

def set( self, key: str, value: Any) -> ctfy.server.models.PlatformSettingInfo:
31    def set(self, key: str, value: Any) -> PlatformSettingInfo:
32        """Persist a DB override for *key*. The server's per-key
33        validator rejects shape / range violations with 400."""
34        resp = self._http.request(
35            "PATCH",
36            f"/admin/platform-settings/{key}",
37            json={"value": value},
38        )
39        _raise_for_status(resp)
40        return PlatformSettingInfo.model_validate(resp.json())

Persist a DB override for key. The server's per-key validator rejects shape / range violations with 400.

def unset(self, key: str) -> ctfy.server.models.PlatformSettingInfo:
42    def unset(self, key: str) -> PlatformSettingInfo:
43        """Remove the DB override for *key* so the resolved value
44        falls back to env / built-in default."""
45        resp = self._http.request("DELETE", f"/admin/platform-settings/{key}")
46        _raise_for_status(resp)
47        return PlatformSettingInfo.model_validate(resp.json())

Remove the DB override for key so the resolved value falls back to env / built-in default.