X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;ds=sidebyside;f=3rdparty%2Fmodules%2Fconcat%2Flib%2Fpuppet%2Ftype%2Fconcat_file.rb;h=359c96341e1da6fa1f26a8908cce393610a97bf3;hb=33d8a6c91f60158a8d6aeaa5f911c000f0bcc280;hp=6a6225e3b77adc28ce0d3e433b43b8c9645689ef;hpb=23d29143ac40015ce61cf83a4067466f8f7d66dc;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/concat/lib/puppet/type/concat_file.rb b/3rdparty/modules/concat/lib/puppet/type/concat_file.rb index 6a6225e3b..359c96341 100644 --- a/3rdparty/modules/concat/lib/puppet/type/concat_file.rb +++ b/3rdparty/modules/concat/lib/puppet/type/concat_file.rb @@ -20,6 +20,7 @@ Puppet::Type.newtype(:concat_file) do ensure_newline => false # Optional, Defaults to false } " + ensurable do defaultvalues @@ -30,18 +31,17 @@ Puppet::Type.newtype(:concat_file) do self[:ensure] == :present end - newparam(:name, :namevar => true) do - desc "Resource name" - end - newparam(:tag) do desc "Tag reference to collect all concat_fragment's with the same tag" end - newparam(:path) do + newparam(:path, :namevar => true) do desc "The output file" - defaultto do - resource.value(:name) + + validate do |value| + unless (Puppet::Util.absolute_path?(value, :posix) or Puppet::Util.absolute_path?(value, :windows)) + raise ArgumentError, "File paths must be fully qualified, not '#{value}'" + end end end @@ -58,8 +58,11 @@ Puppet::Type.newtype(:concat_file) do end newparam(:order) do - desc "Controls the ordering of fragments. Can be set to alphabetical or numeric." - defaultto 'numeric' + desc "Controls the ordering of fragments. Can be set to alpha or numeric." + + newvalues(:alpha, :numeric) + + defaultto :numeric end newparam(:backup) do @@ -67,26 +70,43 @@ Puppet::Type.newtype(:concat_file) do defaultto 'puppet' end - newparam(:replace) do + newparam(:replace, :boolean => true, :parent => Puppet::Parameter::Boolean) do desc "Whether to replace a file that already exists on the local system." - defaultto true + defaultto :true end newparam(:validate_cmd) do desc "Validates file." end - newparam(:ensure_newline) do + newparam(:ensure_newline, :boolean => true, :parent => Puppet::Parameter::Boolean) do desc "Whether to ensure there is a newline after each fragment." - defaultto false + defaultto :false end - autorequire(:concat_fragment) do - catalog.resources.collect do |r| - if r.is_a?(Puppet::Type.type(:concat_fragment)) && r[:tag] == self[:tag] - r.name - end - end.compact + # Inherit File parameters + newparam(:selinux_ignore_defaults) do + end + + newparam(:selrange) do + end + + newparam(:selrole) do + end + + newparam(:seltype) do + end + + newparam(:seluser) do + end + + newparam(:show_diff) do + end + # End file parameters + + # Autorequire the file we are generating below + autorequire(:file) do + [self[:path]] end def should_content @@ -102,21 +122,18 @@ Puppet::Type.newtype(:concat_file) do content_fragments << ["#{r[:order]}___#{r[:name]}", fragment_content(r)] end - if self[:order] == 'numeric' + if self[:order] == :numeric sorted = content_fragments.sort do |a, b| def decompound(d) - d.split('___').map { |v| v =~ /^\d+$/ ? v.to_i : v } + d.split('___', 2).map { |v| v =~ /^\d+$/ ? v.to_i : v } end decompound(a[0]) <=> decompound(b[0]) end else - sorted = content_fragments.sort do |a, b| - def decompound(d) - d.split('___').first - end - - decompound(a[0]) <=> decompound(b[0]) + sorted = content_fragments.sort_by do |a| + a_order, a_name = a[0].split('__', 2) + [a_order, a_name] end end @@ -137,7 +154,7 @@ Puppet::Type.newtype(:concat_file) do end end self.fail "Could not retrieve source(s) #{r[:source].join(", ")}" unless @source - tmp = Puppet::FileServing::Content.indirection.find(@source, :environment => catalog.environment) + tmp = Puppet::FileServing::Content.indirection.find(@source) fragment_content = tmp.content unless tmp.nil? end @@ -148,18 +165,48 @@ Puppet::Type.newtype(:concat_file) do fragment_content end - def eval_generate + def generate file_opts = { :ensure => self[:ensure] == :absent ? :absent : :file, - :content => self.should_content, } - [:path, :owner, :group, :mode, :replace, :backup].each do |param| + [:path, + :owner, + :group, + :mode, + :replace, + :backup, + :selinux_ignore_defaults, + :selrange, + :selrole, + :seltype, + :seluser, + :validate_cmd, + :show_diff].each do |param| unless self[param].nil? file_opts[param] = self[param] end end + metaparams = Puppet::Type.metaparams + excluded_metaparams = [ :before, :notify, :require, :subscribe, :tag ] + + metaparams.reject! { |param| excluded_metaparams.include? param } + + metaparams.each do |metaparam| + file_opts[metaparam] = self[metaparam] if self[metaparam] + end + [Puppet::Type.type(:file).new(file_opts)] end + + def eval_generate + content = should_content + + if !content.nil? and !content.empty? + catalog.resource("File[#{self[:path]}]")[:content] = content + end + + [ catalog.resource("File[#{self[:path]}]") ] + end end