Skip to content

feat: basic template validation function - #771

Merged
buchdag merged 2 commits into
mainfrom
feat/validation-functions
Jul 27, 2026
Merged

feat: basic template validation function#771
buchdag merged 2 commits into
mainfrom
feat/validation-functions

Conversation

@buchdag

@buchdag buchdag commented Jul 24, 2026

Copy link
Copy Markdown
Member

This PR introduce three template functions intended to be used as validators.

All three take a string as last input and either return it unmodified or return an error, so that they can be used in a go template pipeline and prevent docker-gen from rendering the template if their respective validation fail.

  • mustBeOneOf $slice $value: Validates that $value is one of the allowed string values in $slice.
  • mustBeInt $value: Validates that $value is a base-10 integer string.
  • mustBeIntInRange $min $max $value: Validates that $value is a base-10 integer string in the inclusive range $min..$max.

Example use:

{{ $value := somePipeline }}
{{ $allowedValues := list "foo" "bar" "baz" }}
{{ $sanitizedValue := $value | trim | mustBeOneOf $allowedValues }}
{{ /* the template rendering will fail at the above line if ($value | trim) does not evaluate as "foo", "bar" or "baz" /* }}

@buchdag buchdag self-assigned this Jul 24, 2026
Comment thread internal/template/validation_test.go Outdated
@buchdag
buchdag force-pushed the feat/validation-functions branch from d5e00d1 to 294ddc8 Compare July 24, 2026 15:41
@buchdag
buchdag marked this pull request as ready for review July 24, 2026 17:22
@buchdag
buchdag force-pushed the feat/validation-functions branch from 294ddc8 to caed88e Compare July 24, 2026 19:09
@buchdag
buchdag merged commit 9bfcdb4 into main Jul 27, 2026
14 checks passed
@buchdag
buchdag deleted the feat/validation-functions branch July 27, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant