Skip to content

Commit 9a386a3

Browse files
committed
fix(routes): Update global variable naming for consistency and clarity
1 parent 68f1a2f commit 9a386a3

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

datalab/webapi/routes.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,34 @@
5454
router = APIRouter(prefix="/api/v1", tags=["workspace"])
5555

5656
# Global references (set by controller at startup)
57-
_adapter: WorkspaceAdapter | None = None
58-
_auth_token: str | None = None
59-
_server_url: str | None = None
60-
_localhost_no_token: bool = False
57+
_ADAPTER: WorkspaceAdapter | None = None
58+
_AUTH_TOKEN: str | None = None
59+
_SERVER_URL: str | None = None
60+
_LOCALHOST_NO_TOKEN: bool = False
6161

6262

6363
def set_adapter(adapter: WorkspaceAdapter) -> None:
6464
"""Set the workspace adapter for route handlers."""
65-
global _adapter # noqa: PLW0603 # pylint: disable=global-statement
66-
_adapter = adapter
65+
global _ADAPTER # noqa: PLW0603 # pylint: disable=global-statement
66+
_ADAPTER = adapter
6767

6868

6969
def set_auth_token(token: str) -> None:
7070
"""Set the authentication token."""
71-
global _auth_token # noqa: PLW0603 # pylint: disable=global-statement
72-
_auth_token = token
71+
global _AUTH_TOKEN # noqa: PLW0603 # pylint: disable=global-statement
72+
_AUTH_TOKEN = token
7373

7474

7575
def set_server_url(url: str) -> None:
7676
"""Set the server URL."""
77-
global _server_url # noqa: PLW0603 # pylint: disable=global-statement
78-
_server_url = url
77+
global _SERVER_URL # noqa: PLW0603 # pylint: disable=global-statement
78+
_SERVER_URL = url
7979

8080

8181
def set_localhost_no_token(enabled: bool) -> None:
8282
"""Set whether localhost connections can bypass authentication."""
83-
global _localhost_no_token # noqa: PLW0603 # pylint: disable=global-statement
84-
_localhost_no_token = enabled
83+
global _LOCALHOST_NO_TOKEN # noqa: PLW0603 # pylint: disable=global-statement
84+
_LOCALHOST_NO_TOKEN = enabled
8585

8686

8787
def generate_auth_token() -> str:
@@ -91,12 +91,12 @@ def generate_auth_token() -> str:
9191

9292
def get_adapter() -> WorkspaceAdapter:
9393
"""Dependency: Get the workspace adapter."""
94-
if _adapter is None:
94+
if _ADAPTER is None:
9595
raise HTTPException(
9696
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
9797
detail="Workspace adapter not initialized",
9898
)
99-
return _adapter
99+
return _ADAPTER
100100

101101

102102
def verify_token(
@@ -115,13 +115,13 @@ def verify_token(
115115
HTTPException: If token is missing or invalid.
116116
"""
117117
# Check for localhost bypass
118-
if _localhost_no_token:
118+
if _LOCALHOST_NO_TOKEN:
119119
client_ip = request.client.host if request.client else None
120120
if client_ip in ("127.0.0.1", "::1", "localhost"):
121121
# Localhost bypass enabled and request is from localhost
122122
return None
123123

124-
if _auth_token is None:
124+
if _AUTH_TOKEN is None:
125125
raise HTTPException(
126126
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
127127
detail="Authentication not configured",
@@ -143,7 +143,7 @@ def verify_token(
143143
headers={"WWW-Authenticate": "Bearer"},
144144
)
145145

146-
if not secrets.compare_digest(parts[1], _auth_token):
146+
if not secrets.compare_digest(parts[1], _AUTH_TOKEN):
147147
raise HTTPException(
148148
status_code=status.HTTP_401_UNAUTHORIZED,
149149
detail="Invalid token",
@@ -169,9 +169,9 @@ async def get_status() -> ApiStatus:
169169
running=True,
170170
version=__version__,
171171
api_version="v1",
172-
url=_server_url,
172+
url=_SERVER_URL,
173173
workspace_mode="live",
174-
localhost_no_token=_localhost_no_token,
174+
localhost_no_token=_LOCALHOST_NO_TOKEN,
175175
)
176176

177177

0 commit comments

Comments
 (0)