Read a project's credentials from the env file its config names, and keep every value out of messages and logs
CI / tests (pull_request) Successful in 2m21s
CI / tests (pull_request) Successful in 2m21s
This commit is contained in:
@@ -11,7 +11,10 @@ PROJECTS = ".claude-projects"
|
||||
CONFIG = "config.toml"
|
||||
# Every path a project sets, by its role. Three readers, seated as the human who writes the config, picked the spelling from four candidates. They picked role names over file names, which a client's project doesn't share.
|
||||
SETTINGS = ("plan", "working-rules", "decisions", "score-anchors", "comprehension-history", "reading-cost", "changelog", "goals-and-audience", "principles")
|
||||
# The one setting a project may leave out: the file holding the credentials its tools read. It has no default either, so that a project without it asks for none, and never reads another project's.
|
||||
ENV_FILE = "env-file"
|
||||
# They also picked a prefix over bare relative paths: each line says its own place, and a relative path with no prefix fails instead of landing somewhere by default.
|
||||
OUTSIDE = "a path that starts with / or ~/ and lies outside the checkout and the config's folder, so that no git remote receives the credentials"
|
||||
SPELLING = '"checkout:<path>" for a path in the checkout, "folder:<path>" for one in the config\'s folder, or a path that starts with / or ~/'
|
||||
|
||||
# Where a project keeps a file, for a tool that reads it at a commit: a path from the checkout's top, as git names it; or, outside the checkout, the file itself, which the tool reads as it stands, since the checkout's commits hold no version of it.
|
||||
@@ -25,6 +28,8 @@ class ProjectConfig:
|
||||
folder: pathlib.Path
|
||||
top: pathlib.Path
|
||||
paths: dict[str, pathlib.Path]
|
||||
# The file of KEY=value credentials the project's tools read, or None where the config sets none. It lies outside the checkout and the config's folder, whose git repos can reach a remote.
|
||||
env_file: pathlib.Path | None = None
|
||||
|
||||
def tracked(self, setting: str) -> str | None:
|
||||
"""setting's path from top, as git names a file in a commit; None where the config puts it outside the checkout, whose commits hold no version of it."""
|
||||
@@ -54,14 +59,22 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
return Failure(f"{' and '.join(str(file) for file, _ in named)} each name the checkout {main}; only one config may")
|
||||
file, values = named[0]
|
||||
paths = {name: placed(values[name], top, file.parent, home) for name in SETTINGS if name in values}
|
||||
env_file = anywhere(values.get(ENV_FILE), home)
|
||||
misplaced = ENV_FILE in values and (env_file is None or inside(env_file, top, file.parent))
|
||||
faults = [
|
||||
*(f"`{name}` is missing" for name in SETTINGS if name not in values),
|
||||
*(f"`{name}` is not a setting" for name in values if name not in SETTINGS),
|
||||
*(f"`{name}` is not a setting" for name in values if name not in (*SETTINGS, ENV_FILE)),
|
||||
*(f"`{name}` is {values[name]!r}, not {SPELLING}" for name, path in paths.items() if path is None),
|
||||
*([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, not {OUTSIDE}"] if misplaced else []),
|
||||
]
|
||||
if faults:
|
||||
return Failure(f"{file}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}.")
|
||||
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path})
|
||||
return Failure(f"{file}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}, and optionally {ENV_FILE}.")
|
||||
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path}, env_file)
|
||||
|
||||
|
||||
def inside(path: pathlib.Path, top: pathlib.Path, folder: pathlib.Path) -> bool:
|
||||
"""Whether path lies in the checkout or in the config's folder."""
|
||||
return any(path.resolve().is_relative_to(place.resolve()) for place in (top, folder))
|
||||
|
||||
|
||||
def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure | None:
|
||||
|
||||
Reference in New Issue
Block a user