Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-48471 : Create Release 0.2.0 #159

Merged
merged 15 commits into from
Feb 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(client): Support client cookies
tcjennings committed Jan 30, 2025
commit 067896d36b14aa17afcc725b1be86e89c747de1c
6 changes: 6 additions & 0 deletions src/lsst/cmservice/client/client.py
Original file line number Diff line number Diff line change
@@ -41,6 +41,12 @@ def __init__(self: CMClient) -> None:
client_kwargs["headers"] = {"Authorization": f"Bearer {client_config.auth_token}"}
if "timeout" in client_config.model_fields_set: # pragma: no cover
client_kwargs["timeout"] = client_config.timeout
if "cookies" in client_config.model_fields_set: # pragma: no cover
cookies = httpx.Cookies()
if client_config.cookies:
for cookie in client_config.cookies:
cookies.set(name=cookie.name, value=cookie.value)
client_kwargs["cookies"] = cookies
self._client = httpx.Client(**client_kwargs)

self.production = CMProductionClient(self)
22 changes: 21 additions & 1 deletion src/lsst/cmservice/client/clientconfig.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from typing import Any

from pydantic import Field, field_validator
from pydantic import BaseModel, Field, field_validator
from pydantic_settings import BaseSettings, SettingsConfigDict

__all__ = ["ClientConfiguration", "client_config"]


class ClientCookie(BaseModel):
name: str
value: str


class ClientConfiguration(BaseSettings):
"""Configuration for cm-client."""

@@ -21,6 +26,14 @@ class ClientConfiguration(BaseSettings):
validation_alias="CM_TOKEN",
)

cookies: list[ClientCookie] | None = Field(
description=(
"Comma separated list of pipe-separated cookie names and values, e.g., `name|value,name|value`"
),
default=None,
validation_alias="CM_COOKIES",
)

timeout: float | None = Field(
default=None,
validation_alias="CM_TIMEOUT",
@@ -34,6 +47,13 @@ def validate_timeout(cls, v: Any) -> float | None:
return None
return v

@field_validator("cookies", mode="before", check_fields=True)
@classmethod
def validate_cookies(cls, v: Any) -> list[ClientCookie] | None:
if v is None: # pragma: no cover
return v
return [ClientCookie(name=n, value=v) for n, v in [a.split("|") for a in v.split(",")]]


client_config = ClientConfiguration()
"""Configuration for cm-client."""