Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/puppet/functions/stdlib/to_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
end

def to_json(data)
data.to_json
call_function('stdlib::rewrap_sensitive_data', data) do |unwrapped_data|
unwrapped_data.to_json
end
end
end
6 changes: 4 additions & 2 deletions lib/puppet/functions/stdlib/to_toml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# }
dispatch :to_toml do
required_param 'Hash', :data
return_type 'String'
return_type 'Variant[String, Sensitive[String]]'
end

def to_toml(data)
PuppetX::Stdlib::TomlDumper.new(data).toml_str
call_function('stdlib::rewrap_sensitive_data', data) do |unwrapped_data|
PuppetX::Stdlib::TomlDumper.new(unwrapped_data).toml_str
end
end
end
4 changes: 3 additions & 1 deletion lib/puppet/functions/stdlib/to_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
end

def to_yaml(data, options = {})
data.to_yaml(options.transform_keys(&:to_sym))
call_function('stdlib::rewrap_sensitive_data', data) do |unwrapped_data|
unwrapped_data.to_yaml(options.transform_keys(&:to_sym))
end
end
end
4 changes: 4 additions & 0 deletions spec/functions/to_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
it { is_expected.to run.with_params('竹').and_return('"竹"') }
it { is_expected.to run.with_params('Ü').and_return('"Ü"') }
it { is_expected.to run.with_params('∇').and_return('"∇"') }

context 'with data containing sensitive' do
it { is_expected.to run.with_params('key' => sensitive('value')).and_return(sensitive('{"key":"value"}')) }
end
end
4 changes: 4 additions & 0 deletions spec/functions/to_toml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
it { is_expected.to run.with_params(foo: ['bar', 'baz']).and_return("foo = [\"bar\", \"baz\"]\n") }
it { is_expected.to run.with_params(foo: [{ bar: {}, baz: {} }]).and_return("[[foo]]\n[foo.bar]\n[foo.baz]\n") }
end

context 'with data containing sensitive' do
it { is_expected.to run.with_params('key' => sensitive('value')).and_return(sensitive("key = \"value\"\n")) }
end
end
4 changes: 4 additions & 0 deletions spec/functions/to_yaml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
it { is_expected.to run.with_params('∇').and_return("--- \"∇\"\n") }

it { is_expected.to run.with_params({ 'foo' => { 'bar' => true, 'baz' => false } }, 'indentation' => 4).and_return("---\nfoo:\n bar: true\n baz: false\n") }

context 'with data containing sensitive' do
it { is_expected.to run.with_params('key' => sensitive('value')).and_return(sensitive("---\nkey: value\n")) }
end
end
Loading