From f318dcde3be1a5e37163ed469e7b6162d29a9ce4 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 5 Dec 2019 08:49:53 +0100 Subject: [PATCH] Force tmpfile.d drop file to end in .conf From tmpfiles.d(5) ``` SYNOPSIS /etc/tmpfiles.d/*.conf /run/tmpfiles.d/*.conf /usr/lib/tmpfiles.d/*.conf ``` Just like unit drop in files drop files for the tmpfiles.d must end in .conf to noticied. --- manifests/tmpfile.pp | 19 ++++++++++--------- spec/defines/tmpfile_spec.rb | 25 ++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/manifests/tmpfile.pp b/manifests/tmpfile.pp index c18eaae7..205d3493 100644 --- a/manifests/tmpfile.pp +++ b/manifests/tmpfile.pp @@ -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 @@ -26,15 +26,16 @@ # * 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 ? { @@ -42,7 +43,7 @@ default => $ensure, } - file { "${path}/${name}": + file { "${path}/${filename}": ensure => $_tmp_file_ensure, content => $content, source => $source, diff --git a/spec/defines/tmpfile_spec.rb b/spec/defines/tmpfile_spec.rb index 56323d28..912e9519 100644 --- a/spec/defines/tmpfile_spec.rb +++ b/spec/defines/tmpfile_spec.rb @@ -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' @@ -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