Skip to content

Add a subdirectories templating function - #105

Merged
4 commits merged into
Infisical:mainfrom
Latent-ML:subdirectories-templating-function
Aug 6, 2026
Merged

Add a subdirectories templating function#105
4 commits merged into
Infisical:mainfrom
Latent-ML:subdirectories-templating-function

Conversation

@jwilm

@jwilm jwilm commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Adds a subdirectories templating function which enables ConfigMap templating to be highly dynamic based on the structure of the project it's pulling from.

This is useeful when a directory has a set of homogeneous subdirectories. (e.g. subdirectories a and b both have the same set of secrets, and the subdirectory names a and b may not be known).

@infisical-cla-app

infisical-cla-app Bot commented Jul 16, 2026

Copy link
Copy Markdown

CLA satisfied. All contributors have signed the current CLA. The cla/signed check is passing.

@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a subdirectories template function that lets ConfigMap templates enumerate immediate child directories at any path in the Infisical secret tree, enabling dynamic configuration generation when subdirectory names are not known in advance.

  • Adds V1Subdirectory{Name, Path} to the model and registers a subdirectories(dir string) function in the template engine that traverses the pre-built SecretTreeNode tree, filters out leaf nodes, sorts results by name, and returns them for ranging in templates.
  • The SecretTreeNode structure already allows a node to have both a Secret value and Children (e.g. a secret key at / whose name matches a folder path segment), but the new filter uses child.Secret != nil instead of len(child.Children) == 0, so any such hybrid node is incorrectly excluded from subdirectory results.
  • Test coverage is solid for the happy path and empty-result cases but does not exercise the mixed secret+directory node edge case that the tree explicitly supports.

Confidence Score: 3/5

Safe to merge for common usage, but the leaf-exclusion logic is wrong for an edge case the tree already supports, and there is no test catching it.

The subdirectories function silently drops directory nodes that also carry a secret value. This is a valid tree state confirmed by an existing BuildSecretTree test, so missing directories would cause silent, hard-to-debug gaps in rendered ConfigMaps without any error surfaced to the user.

internal/template/v1/template.go — the filter condition in the subdirectories closure; internal/template/v1/template_test.go — needs a test with a node that has both Secret and Children set

Important Files Changed

Filename Overview
internal/model/model.go Adds V1Subdirectory struct with Name and Path fields; minimal, clean addition
internal/template/v1/template.go Adds subdirectories template function; contains a logic bug in the leaf-exclusion filter that incorrectly skips nodes that are both a secret and a directory
internal/template/v1/template_test.go Adds five well-structured tests for subdirectories; missing coverage for the mixed secret+directory node edge case that the tree structure explicitly supports

Reviews (1): Last reviewed commit: "Add a subdirectories templating function" | Re-trigger Greptile

Comment thread internal/template/v1/template.go Outdated
jwilm added 4 commits August 3, 2026 14:12
Adds a subdirectories templating function which enables ConfigMap
templating to be highly dynamic based on the structure of the project
it's pulling from.

This is useeful when a directory has a set of homogeneous
subdirectories. (e.g. subdirectories a and b both have the same set of
secrets, and the subdirectory names a and b may not be known).
Fixes the feedback from @greptile-apps:

Incorrect leaf-exclusion filter silently drops valid subdirectories. The
tree allows a node to carry both a `Secret` (when a secret key name
matches a directory segment name) and `Children` (when that segment also
has nested secrets). The current guard

    if child.Secret != nil { continue }

skips any such node, so `subdirectories("/")` would never return a
folder whose name collides with a root-level secret key, even though
`BuildSecretTree` explicitly supports this state (see the "allows a
secret key and folder segment with the same name" test). The correct
predicate is to skip nodes that have no children (pure leaves), not
nodes that happen to also carry a secret value.
This naming is more consistent with other templating function names and
less ambiguous than subdirectories.
@jwilm
jwilm force-pushed the subdirectories-templating-function branch from dc1ee2b to 9227420 Compare August 3, 2026 21:13
@varonix0 varonix0 closed this pull request by merging all changes into Infisical:main in fc5931f Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants