feat: Add interpolation functions to Hiera#449
Open
isaiahfrantz wants to merge 1 commit into
Open
Conversation
Adds substring, match, grep_captures, and version comparison functions for string manipulation and pattern matching in Hiera interpolations. - substring(string, start, count) extracts portions of strings - match(string, pattern) tests string matching with regex or literal - grep_captures(string, regex, separator, groups) extracts regex captures - version_gt/gte/lt/lte(a, b) compares semantic versions using Gem::Version Updates interpolation parser to handle complex
14bae4a to
be65420
Compare
|
just fyi, I 'solved' the equal pai point you described with an custom hiera backend, that allow to run any puppet function. |
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.
Add String Manipulation and Pattern Matching Interpolation Functions
Summary
This PR adds a suite of new interpolation functions to Hiera, enabling powerful string manipulation, pattern matching, and version comparison directly within data values and hierarchy paths.
This change will solve a major pain point with hera by providing a way to construct data file names that can be more easily matched against without needing unnecessary new facts or global variables.
New Features
1.
substring(string, start[, count])Extract a portion of a string using 0-based indexing.
2.
match(string, pattern)Test if a string matches a regex or contains a substring. Returns
'true'or'false'.Supports regex flags:
i(case-insensitive),m(multiline),x(extended)3.
grep_captures(string, '/regex/'[, separator][, [groups]])Extract capture groups from a regex match and join them.
Key features:
''(empty string)4. Version Comparison Functions
Compare semantic versions using
Gem::Version:1.10.0 > 1.9.0)1.0.0.alpha < 1.0.0)Technical Changes
Changed
RX_METHOD_AND_ARGregex updated to support function arguments containing parentheses[1,2,3]for capture group indicesFixed
/a\/b/) now parsed correctly''or"") handled correctly as function argumentsSingle-Quoted Regex Patterns
All regex patterns should use single quotes (
'/pattern/') for:'/\d{3,5}/''/\d+/'instead of/\\d+/Files Changed
lib/hiera/interpolate.rb- Core implementationspec/unit/interpolate_spec.rb- Testsspec/unit/fixtures/interpolate/data/weird_keys.yaml- Test fixturesREADME.md- DocumentationCHANGELOG.md- Changelogdocs/tutorials/interpolation_functions.md- TutorialTesting
Use Cases
All functions can be used in both data values and hierarchy paths.
Dynamic hierarchy paths using all functions:
Data value examples: