Skip to content
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

allow Sensitive type for content param #115

Merged
merged 1 commit into from
Jul 15, 2019
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
24 changes: 12 additions & 12 deletions manifests/dropin_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@
# May cause multiple daemon reloads.
#
define systemd::dropin_file(
Systemd::Unit $unit,
Systemd::Dropin $filename = $name,
Enum['present', 'absent', 'file'] $ensure = 'present',
Stdlib::Absolutepath $path = '/etc/systemd/system',
Optional[String] $content = undef,
Optional[String] $source = undef,
Optional[Stdlib::Absolutepath] $target = undef,
String $owner = 'root',
String $group = 'root',
String $mode = '0444',
Boolean $show_diff = true,
Enum['lazy', 'eager'] $daemon_reload = 'lazy',
Systemd::Unit $unit,
Systemd::Dropin $filename = $name,
Enum['present', 'absent', 'file'] $ensure = 'present',
Stdlib::Absolutepath $path = '/etc/systemd/system',
Optional[Variant[String,Sensitive[String]]] $content = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be clearer to make that a Variant[String,Sensitive[String],Undef]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raphink hm IMHO Optional is the more idomatic way. Also grepping over a couple of modules i have checked out here from various sources it seems Optional[Variant] is what is usually used:

$ find . -name "*.pp" |xargs grep -E "Variant.*Undef" | wc -l
40
$ find . -name "*.pp" |xargs grep -E "Optional\[Variant" | wc -l
492

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I go with @TheMeier here. The default should be undef and that requires the type to be Optional

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastelfreak technically it doesn't require to use Optional, as a variant allowing Undef works as well.

Optional[String] $source = undef,
Optional[Stdlib::Absolutepath] $target = undef,
String $owner = 'root',
String $group = 'root',
String $mode = '0444',
Boolean $show_diff = true,
Enum['lazy', 'eager'] $daemon_reload = 'lazy',
) {
include systemd

Expand Down
13 changes: 13 additions & 0 deletions spec/defines/dropin_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
:mode => '0444'
) }
end
context 'with sensitve content' do
let(:title) { 'sensitive.conf' }
let(:params) {{
:unit => 'sensitive.service',
:content => RSpec::Puppet::RawString.new("Sensitive('TEST_CONTENT')")
}}

it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").with(
:ensure => 'file',
:content => 'TEST_CONTENT'
) }

end
end
end
end
Expand Down