Skip to content

Commit dcba706

Browse files
authored
Merge pull request #1463 from alexjfisher/more_sensitive
Support `Sensitive` values in more functions
2 parents de41918 + 08e1fac commit dcba706

6 files changed

Lines changed: 22 additions & 4 deletions

File tree

lib/puppet/functions/stdlib/to_json.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
end
2020

2121
def to_json(data)
22-
data.to_json
22+
call_function('stdlib::rewrap_sensitive_data', data) do |unwrapped_data|
23+
unwrapped_data.to_json
24+
end
2325
end
2426
end

lib/puppet/functions/stdlib/to_toml.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
# }
1414
dispatch :to_toml do
1515
required_param 'Hash', :data
16-
return_type 'String'
16+
return_type 'Variant[String, Sensitive[String]]'
1717
end
1818

1919
def to_toml(data)
20-
PuppetX::Stdlib::TomlDumper.new(data).toml_str
20+
call_function('stdlib::rewrap_sensitive_data', data) do |unwrapped_data|
21+
PuppetX::Stdlib::TomlDumper.new(unwrapped_data).toml_str
22+
end
2123
end
2224
end

lib/puppet/functions/stdlib/to_yaml.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
end
2828

2929
def to_yaml(data, options = {})
30-
data.to_yaml(options.transform_keys(&:to_sym))
30+
call_function('stdlib::rewrap_sensitive_data', data) do |unwrapped_data|
31+
unwrapped_data.to_yaml(options.transform_keys(&:to_sym))
32+
end
3133
end
3234
end

spec/functions/to_json_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
it { is_expected.to run.with_params('竹').and_return('"竹"') }
2323
it { is_expected.to run.with_params('Ü').and_return('"Ü"') }
2424
it { is_expected.to run.with_params('∇').and_return('"∇"') }
25+
26+
context 'with data containing sensitive' do
27+
it { is_expected.to run.with_params('key' => sensitive('value')).and_return(sensitive('{"key":"value"}')) }
28+
end
2529
end

spec/functions/to_toml_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626
it { is_expected.to run.with_params(foo: ['bar', 'baz']).and_return("foo = [\"bar\", \"baz\"]\n") }
2727
it { is_expected.to run.with_params(foo: [{ bar: {}, baz: {} }]).and_return("[[foo]]\n[foo.bar]\n[foo.baz]\n") }
2828
end
29+
30+
context 'with data containing sensitive' do
31+
it { is_expected.to run.with_params('key' => sensitive('value')).and_return(sensitive("key = \"value\"\n")) }
32+
end
2933
end

spec/functions/to_yaml_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
it { is_expected.to run.with_params('∇').and_return("--- \"\"\n") }
2323

2424
it { is_expected.to run.with_params({ 'foo' => { 'bar' => true, 'baz' => false } }, 'indentation' => 4).and_return("---\nfoo:\n bar: true\n baz: false\n") }
25+
26+
context 'with data containing sensitive' do
27+
it { is_expected.to run.with_params('key' => sensitive('value')).and_return(sensitive("---\nkey: value\n")) }
28+
end
2529
end

0 commit comments

Comments
 (0)