Skip to content

Commit

Permalink
Merge pull request #129 from traylenator/tmpconf
Browse files Browse the repository at this point in the history
Force tmpfiles.d drop file to end in .conf
  • Loading branch information
bastelfreak authored Dec 9, 2019
2 parents b082921 + f318dcd commit cf15b55
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
19 changes: 10 additions & 9 deletions manifests/tmpfile.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
# @see systemd-tmpfiles(8)
#
# @attr name [String]
# @attr name [Pattern['^.+\.conf$']] (filename)
# The name of the tmpfile to create
#
# * May not contain ``/``
# * May not contain ``/`` and must end in .conf
#
# @param $ensure
# Whether to drop a file or remove it
Expand All @@ -26,23 +26,24 @@
# * Mutually exclusive with ``$limits``
#
define systemd::tmpfile(
Enum['present', 'absent', 'file'] $ensure = 'file',
Stdlib::Absolutepath $path = '/etc/tmpfiles.d',
Optional[String] $content = undef,
Optional[String] $source = undef,
Enum['present', 'absent', 'file'] $ensure = 'file',
Systemd::Dropin $filename = $name,
Stdlib::Absolutepath $path = '/etc/tmpfiles.d',
Optional[String] $content = undef,
Optional[String] $source = undef,
) {
include systemd::tmpfiles

if $name =~ Pattern['/'] {
fail('$name may not contain a forward slash "(/)"')
if $filename =~ Pattern['/'] {
fail('$filename may not contain a forward slash "(/)"')
}

$_tmp_file_ensure = $ensure ? {
'present' => 'file',
default => $ensure,
}

file { "${path}/${name}":
file { "${path}/${filename}":
ensure => $_tmp_file_ensure,
content => $content,
source => $source,
Expand Down
25 changes: 24 additions & 1 deletion spec/defines/tmpfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
context "on #{os}" do
let(:facts) { facts }

let(:title) { 'random_tmpfile' }
let(:title) { 'random_tmpfile.conf' }

let(:params) {{
:content => 'random stuff'
Expand All @@ -18,6 +18,29 @@
:content => /#{params[:content]}/,
:mode => '0444'
) }

context 'with a bad tmpfile name' do
let(:title) { 'test.badtype' }
it {
expect{
is_expected.to compile.with_all_deps
}.to raise_error(/expects a match for Systemd::Dropin/)
}
end

context 'with a tmpfile name specified with filename' do
let(:title) { 'test.badtype' }
let(:params) {{
:filename => 'goodname.conf',
:content => 'random stuff'
}}
it { is_expected.to create_file("/etc/tmpfiles.d/goodname.conf").with(
:ensure => 'file',
:content => /#{params[:content]}/,
:mode => '0444'
)}
end

end
end
end
Expand Down

0 comments on commit cf15b55

Please sign in to comment.