feat: load the env file at start-up, trim schema lookups, remove legacy samples
Start-up - Export the env file's variables for other libraries (the Cloud provider's client) into the process environment; the app's own settings and secrets are never exported, and a value already in the environment wins. - Use GOOGLE_GENAI_USE_ENTERPRISE in place of the deprecated GOOGLE_GENAI_USE_VERTEXAI. Target architect - Look each distinct resource type up once instead of once per setting: in the run of 2026-10-07 it made 39 lookups for 8 types and exhausted its budget. terraform_schema's find takes several names; budget 30 to 45. - A cut-off schema outline says so. Removed, as leftovers of the original pipeline that nothing read - terraform/ (no longer passed terraform validate), scripts/validate.sh, tests/test_package.py and the CI steps that ran on them. - The sample outputs under docs/ and requirements.yaml. - CI now pins Terraform 1.14.3, as the container image does. Plans record the case 01 run: completed at 100% in 18 minutes with no Revision, against 60 minutes and warnings before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
"""Typed settings for GCP Solution Architecture Agent."""
|
||||
|
||||
import os
|
||||
from collections.abc import MutableMapping
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import dotenv_values
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
@@ -100,9 +103,38 @@ class Settings(BaseSettings):
|
||||
_settings: Settings | None = None
|
||||
|
||||
|
||||
def export_env_file(
|
||||
path: str | Path = ".env", environ: MutableMapping[str, str] | None = None
|
||||
) -> list[str]:
|
||||
"""Put the env file's other variables into the process environment.
|
||||
|
||||
Settings reads its own fields from the env file. Everything else in it is for a
|
||||
library that reads the environment itself, such as a Cloud provider's client
|
||||
looking for its project and credentials, and would otherwise be ignored. A
|
||||
variable already set in the environment is left alone, and Settings' own fields
|
||||
are never exported, so the secrets among them do not reach child processes.
|
||||
Returns the names it set.
|
||||
"""
|
||||
environ = os.environ if environ is None else environ
|
||||
path = Path(path)
|
||||
if not path.is_file():
|
||||
return []
|
||||
own = {name.upper() for name in Settings.model_fields}
|
||||
exported = []
|
||||
for name, value in dotenv_values(path).items():
|
||||
if value is None or name.upper() in own or name in environ:
|
||||
continue
|
||||
environ[name] = value
|
||||
exported.append(name)
|
||||
return exported
|
||||
|
||||
|
||||
def get_settings() -> Settings:
|
||||
"""Get singleton Settings instance."""
|
||||
"""Get singleton Settings instance, loading the env file at first use."""
|
||||
global _settings
|
||||
if _settings is None:
|
||||
# Tests switch this off so they never depend on a developer's env file.
|
||||
if os.environ.get("ENV_FILE_EXPORT", "true").lower() != "false":
|
||||
export_env_file()
|
||||
_settings = Settings()
|
||||
return _settings
|
||||
|
||||
Reference in New Issue
Block a user