Files
microsoft-365-service/app/config.py
T
2026-05-28 13:10:01 +02:00

36 lines
1.3 KiB
Python

import os
from dataclasses import dataclass, replace
@dataclass(frozen=True)
class Settings:
app_name: str = os.getenv("APP_NAME", "Microsoft 365 Service")
app_version: str = os.getenv("APP_VERSION", "1.0.1")
root_path: str = os.getenv("ROOT_PATH", "")
tenant_id: str = os.getenv("MS365_TENANT_ID", "")
client_id: str = os.getenv("MS365_CLIENT_ID", "")
client_secret: str = os.getenv("MS365_CLIENT_SECRET", "")
credential_encoding_secret: str = os.getenv("MS365_CREDENTIAL_ENCODING_SECRET", "")
graph_base_url: str = os.getenv("MS365_GRAPH_BASE_URL", "https://graph.microsoft.com/v1.0")
graph_scope: str = os.getenv("MS365_GRAPH_SCOPE", "https://graph.microsoft.com/.default")
request_timeout_seconds: float = float(os.getenv("MS365_REQUEST_TIMEOUT_SECONDS", "30"))
@property
def token_url(self) -> str:
return f"https://login.microsoftonline.com/{self.tenant_id}/oauth2/v2.0/token"
@property
def is_configured(self) -> bool:
return bool(self.tenant_id and self.client_id and self.client_secret)
def with_credentials(self, tenant_id: str, client_id: str, client_secret: str) -> "Settings":
return replace(
self,
tenant_id=tenant_id,
client_id=client_id,
client_secret=client_secret,
)
settings = Settings()