Skip to content

Commit ce90881

Browse files
authored
Merge pull request #6412 from hlindberg/PUP-7806_support-fully-qualified-variable-assignments-in-epp-app
(PUP-7806) Allow epp CLI to set fully qualified variables
2 parents b2e212e + e4c2bd0 commit ce90881

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/puppet/pops/evaluator/epp_evaluator.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ def self.evaluate(parser, func_name, scope, use_global_scope_only, parse_result,
7171
enforce_parameters = true
7272
end
7373

74+
# filter out all qualified names and set them in qualified_variables
75+
# only pass unqualified (filtered) variable names to the the template
76+
filtered_args = {}
77+
template_args.each_pair do |k, v|
78+
if k =~ /::/
79+
k = k[2..-1] if k.start_with?('::')
80+
scope[k] = v
81+
else
82+
filtered_args[k] = v
83+
end
84+
end
85+
template_args = filtered_args
86+
7487
# inline_epp() logic sees all local variables, epp() all global
7588
if use_global_scope_only
7689
scope.with_global_scope do |global_scope|

spec/unit/face/epp_face_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@
201201
expect(eppface.render(:e => 'hello <%= $x %>', :values => '{x => "mr X"}')).to eq("hello mr X")
202202
end
203203

204-
it "adds values given in a puppet hash given on command line with --values" do
205-
expect(eppface.render(:e => 'hello <%= $x %>', :values => '{x => "mr X"}')).to eq("hello mr X")
204+
it "adds fully qualified values given in a puppet hash given on command line with --values" do
205+
expect(eppface.render(:e => 'hello <%= $mr::x %>', :values => '{mr::x => "mr X"}')).to eq("hello mr X")
206+
end
207+
208+
it "adds fully qualified values with leading :: given in a puppet hash given on command line with --values" do
209+
expect(eppface.render(:e => 'hello <%= $::mr %>', :values => '{"::mr" => "mr X"}')).to eq("hello mr X")
206210
end
207211

208212
it "adds values given in a puppet hash produced by a .pp file given with --values_file" do

spec/unit/functions/epp_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
expect(eval_template("all your base <%= $what %> to us")).to eq("all your base are belong to us")
1414
end
1515

16+
it "looks up a fully qualified value from the scope" do
17+
scope["what::is"] = "are belong"
18+
expect(eval_template("all your base <%= $what::is %> to us")).to eq("all your base are belong to us")
19+
end
20+
1621
it "get nil accessing a variable that does not exist" do
1722
expect(eval_template("<%= $kryptonite == undef %>")).to eq("true")
1823
end

0 commit comments

Comments
 (0)