6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from datetime import UTC, datetime
|
|
|
|
from pydantic import BaseModel, field_validator
|
|
|
|
|
|
class LinearAuthCredentialsBase(BaseModel):
|
|
access_token: str
|
|
refresh_token: str | None = None
|
|
token_type: str = "Bearer"
|
|
expires_in: int | None = None
|
|
expires_at: datetime | None = None
|
|
scope: str | None = None
|
|
|
|
@property
|
|
def is_expired(self) -> bool:
|
|
"""Check if the credentials have expired."""
|
|
if self.expires_at is None:
|
|
return False
|
|
return self.expires_at <= datetime.now(UTC)
|
|
|
|
@property
|
|
def is_refreshable(self) -> bool:
|
|
"""Check if the credentials can be refreshed."""
|
|
return self.refresh_token is not None
|
|
|
|
def to_dict(self) -> dict:
|
|
"""Convert credentials to dictionary for storage."""
|
|
return {
|
|
"access_token": self.access_token,
|
|
"refresh_token": self.refresh_token,
|
|
"token_type": self.token_type,
|
|
"expires_in": self.expires_in,
|
|
"expires_at": self.expires_at.isoformat() if self.expires_at else None,
|
|
"scope": self.scope,
|
|
}
|
|
|
|
@classmethod
|
|
def from_dict(cls, data: dict) -> "LinearAuthCredentialsBase":
|
|
"""Create credentials from dictionary."""
|
|
expires_at = None
|
|
if data.get("expires_at"):
|
|
expires_at = datetime.fromisoformat(data["expires_at"])
|
|
|
|
return cls(
|
|
access_token=data["access_token"],
|
|
refresh_token=data.get("refresh_token"),
|
|
token_type=data.get("token_type", "Bearer"),
|
|
expires_in=data.get("expires_in"),
|
|
expires_at=expires_at,
|
|
scope=data.get("scope"),
|
|
)
|
|
|
|
@field_validator("expires_at", mode="before")
|
|
@classmethod
|
|
def ensure_aware_utc(cls, v):
|
|
# Strings like "2025-08-26T14:46:57.367184"
|
|
if isinstance(v, str):
|
|
# add +00:00 if missing tz info
|
|
if v.endswith("Z"):
|
|
return datetime.fromisoformat(v.replace("Z", "+00:00"))
|
|
dt = datetime.fromisoformat(v)
|
|
return dt if dt.tzinfo else dt.replace(tzinfo=UTC)
|
|
# datetime objects
|
|
if isinstance(v, datetime):
|
|
return v if v.tzinfo else v.replace(tzinfo=UTC)
|
|
return v
|