-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hiera lookup single sigil #152
Add hiera lookup single sigil #152
Conversation
This fixes the backend test if previous tests loaded a backend
performing a hiera lookup: [Redmine Ticket](https://projects.puppetlabs.com/issues/21367) This commit adds support for interpolating hiera data in a similar fashion to how scope interpolation functions in hiera. This commit adds the syntax, `%{hiera('foo')}`, for hiera lookups and the syntax, `%{scope('foo')}`, for scope lookups, in order to clearly differentiate the two types. It also retains backward compatibility with the previous syntax for scope lookups, `%{foo}`. Example: ips.yaml potto01_ip: 10.10.1.52 potto01.yaml firewall_rules: - "0.0.0.0:22:%{hiera('potto01_ip')}" When evaluating the string, `"0.0.0.0:22:%{hiera('potto01_ip')}"` hiera would lookup the value for potto01_ip in hiera and interpolate that into the string, the result being, `"0.0.0.0:22:10.10.1.52"`. This avoids having to repeatedly perform this type of lookup logic in puppet and allows you to use your hiera data from within hiera itself.
CLA signed by all contributors. |
# Allow for safe recursive lookup of values during variable interpolation. | ||
# | ||
# @api private | ||
class Hiera::RecursiveGuard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the impetus for changing this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale was two fold:
- The previous class was called RecursiveLookup, even though it was not doing recursive lookups, RecursiveGuard is more descriptive as to the intent of the class, i.e. guarding against recursive lookups, rather than performing them.
- The previous class performed the scope lookup in the guard, which was confusing and made it difficult to add hiera lookup support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍, thanks for the explanation. :)
use Matchdata objects rather than Perl style variables.
… a generic exception
@adrienthebo I believe I have addressed most of your concerns it the last commits, but I would appreciate any additional feedback you might have. |
"test_%{scope('rspec')}_test" => "test_false_test" | ||
} | ||
|
||
@intreprets_false_in_scope_tests.each do |input, expected| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: @intreprets
-> @interprets
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Thanks for looking at those changes! I've looked this over and I like the general change, but since I missed the error with supporting the old style interpolation syntax last time I would like to get another pair of eyes on this. Thanks again for this contribution! |
@adrienthebo anyone else had a chance to review this pull request? |
@adrienthebo I just looked it over. I think the test coverage looks good to make sure we aren't regressing on any functionality. |
Add hiera lookup single sigil
summary: merged into master in f347bbe; this should be released in 1.3.0. Thanks again for the contribution! |
PR puppetlabs#152 broke a common use case: interpolate %{this} and %{this} again Since each interpolation scans the entire input string and shares the same recursion guard, this causes an InterpolationLoop error to be raised.
PR puppetlabs#152 broke a common use case: interpolate %{this} and %{this} again Since each interpolation scans the entire input string and shares the same recursion guard, this causes an InterpolationLoop error to be raised.
PR puppetlabs#152 broke a common use case: interpolate %{this} and %{this} again Since each interpolation scans the entire input string and shares the same recursion guard, this causes an InterpolationLoop error to be raised.
PR puppetlabs#152 broke a common use case: interpolate %{this} and %{this} again Since each interpolation scans the entire input string and shares the same recursion guard, this causes an InterpolationLoop error to be raised.
performing a hiera lookup:
Redmine Ticket
This commit adds support for interpolating hiera data in a similar fashion to
how scope interpolation functions in hiera. This commit adds the syntax,
%{hiera('foo')}
, for hiera lookups and the syntax,%{scope('foo')}
, forscope lookups, in order to clearly differentiate the two types. It also retains
backward compatibility with the previous syntax for scope lookups,
%{foo}
.Example:
ips.yaml
potto01.yaml
When evaluating the string,
"0.0.0.0:22:%{hiera('potto01_ip')}"
hiera wouldlookup the value for potto01_ip in hiera and interpolate that into the string,
the result being,
"0.0.0.0:22:10.10.1.52"
. This avoids having to repeatedlyperform this type of lookup logic in puppet and allows you to use your hiera
data from within hiera itself.