mirror of
https://github.com/exo-explore/exo.git
synced 2026-06-24 05:48:57 -04:00
29 lines
623 B
Python
29 lines
623 B
Python
import logging
|
|
import os
|
|
from typing import TypeVar
|
|
|
|
from pydantic import BaseModel, ConfigDict, ValidationError
|
|
|
|
env_model_config = ConfigDict(
|
|
strict=True,
|
|
frozen=True,
|
|
extra="forbid",
|
|
)
|
|
|
|
|
|
class BaseEnv(BaseModel):
|
|
model_config = env_model_config
|
|
|
|
|
|
EnvSchema = TypeVar("EnvSchema", bound=BaseEnv)
|
|
|
|
|
|
def get_validated_env(
|
|
environment_schema: type[EnvSchema], logger: logging.Logger
|
|
) -> EnvSchema:
|
|
try:
|
|
return environment_schema.model_validate(os.environ, strict=True)
|
|
except ValidationError as e:
|
|
logger.error("Environment Variables Validation Failed: %s", e)
|
|
raise e
|