Repository navigation
Let a caller ask which targets a configuration declares - #144
Merged
Merged
Conversation
A caller that generates one configuration into several places -- relcoord, into a manifests directory per cluster -- has somewhere to put each target and needs to know which targets exist. Without a way to ask, it opens config.toml and composes find_config_file, load_toml_file, config_version and parse_targets into a small loader of its own, which is this package's business in another repository: it has to track what a target is, and can reach a different conclusion about a configuration than generate() does. The names alone answer it, with None distinguishing a directory that declares blocks directly -- which also tells a caller to pass variables rather than a target, the reason it was reading the file in the first place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A caller that generates one configuration into several places has somewhere to put each target, and so needs to know which targets there are. relcoord is that caller: it holds a manifests directory per cluster and generates a target into each.
With no way to ask, it opens
config.tomlitself and composesfind_config_file,load_toml_file,config_versionandparse_targetsinto a small loader of its own — this package's business, in another repository. Two costs: it has to keep its own idea of what a target is, and it can reach a different conclusion about a configuration thangenerate()does. It also has to importparse_targets, which reads more like an internal of the loader than a contract.declared_targets(config_dir)is the question those four calls were spelling out:Behaviour
Nonefor a directory that declares config blocks directly, and for one holding no config file at all — whichgenerate()reports on better than a version check would.parse_targetsthat decides.That
Nonealso answers the question the caller was really asking.generate()takestargetorvarsand rejects the wrong one for the layout, so a caller has to know which layout the file is before it can call at all — which is why relcoord was reading the file in the first place. One call now covers both.What it lets the caller stop doing
portswigger-cloud/relcoord#98 needs this. That PR is about a related problem — relcoord asks each configured output for the target of its own name, so a config repository declaring only the clusters it deploys to fails with
Unknown targeton the rest — and on top of this it shrinks to one call in place of a four-call composition and a version branch.Verification
276 passed;ruff check,ruff format --checkandty checkclean. Six new tests: the names in declared order,Nonefor both block-style layouts and for a missing file, amanifest-builder.toml, and a target withoutsectionsfailing the way generating it would.README gains a short Asking which targets a configuration declares subsection under Targets and sections.