fix: reject duplicate keys in execution catalogs
All checks were successful
ci / validate (push) Successful in 2m53s
All checks were successful
ci / validate (push) Successful in 2m53s
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a0726e-5232-73f2-aaca-2c05ceb62efb
This commit is contained in:
parent
f5eec5b23f
commit
863fab7a3b
5 changed files with 97 additions and 1 deletions
|
|
@ -62,9 +62,28 @@ def _default_data_dir(kind: str) -> Path:
|
|||
return _source_root() / ("profiles" if kind == "profiles" else "registry/reins")
|
||||
|
||||
|
||||
class _UniqueKeyLoader(yaml.SafeLoader):
|
||||
"""Reject overwrites, including collisions introduced by YAML merges."""
|
||||
|
||||
def construct_mapping(self, node, deep=False):
|
||||
mapping = super().construct_mapping(node, deep=deep)
|
||||
seen = set()
|
||||
for key_node, _ in node.value:
|
||||
key = self.construct_object(key_node, deep=deep)
|
||||
if key in seen:
|
||||
mark = key_node.start_mark
|
||||
# Key names and source snippets can themselves contain secrets.
|
||||
raise yaml.YAMLError(
|
||||
f"duplicate YAML key at line {mark.line + 1}, "
|
||||
f"column {mark.column + 1}"
|
||||
)
|
||||
seen.add(key)
|
||||
return mapping
|
||||
|
||||
|
||||
def _read_yaml(path: Path) -> dict[str, Any]:
|
||||
try:
|
||||
data = yaml.safe_load(path.read_text())
|
||||
data = yaml.load(path.read_text(), Loader=_UniqueKeyLoader)
|
||||
except (OSError, yaml.YAMLError) as exc:
|
||||
raise ProfileError(f"cannot read {path}: {exc}") from exc
|
||||
if not isinstance(data, dict):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue