summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/parser/functions/defined_with_params.rb20
-rw-r--r--lib/puppet/parser/functions/ensure_packages.rb1
-rw-r--r--lib/puppet/provider/file_line/ruby.rb7
-rw-r--r--lib/puppet/type/file_line.rb10
4 files changed, 35 insertions, 3 deletions
diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb
index 99687ae..c45a9df 100644
--- a/lib/puppet/parser/functions/defined_with_params.rb
+++ b/lib/puppet/parser/functions/defined_with_params.rb
@@ -24,7 +24,25 @@ ENDOFDOC
params = {}
end
ret = false
- if resource = findresource(reference.to_s)
+
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
+ # Workaround for PE-20308
+ if reference.is_a?(String)
+ type_name, title = Puppet::Resource.type_and_title(reference, nil)
+ type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name.downcase)
+ elsif reference.is_a?(Puppet::Resource)
+ type = reference.resource_type
+ title = reference.title
+ else
+ raise(ArgumentError, "Reference is not understood: '#{reference.class}'")
+ end
+ #end workaround
+ else
+ type = reference.to_s
+ title = nil
+ end
+
+ if resource = findresource(type, title)
matches = params.collect do |key, value|
# eql? avoids bugs caused by monkeypatching in puppet
resource_is_undef = resource[key].eql?(:undef) || resource[key].nil?
diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb
index 17942b8..034f997 100644
--- a/lib/puppet/parser/functions/ensure_packages.rb
+++ b/lib/puppet/parser/functions/ensure_packages.rb
@@ -36,6 +36,7 @@ third argument to the ensure_resource() function.
Puppet::Parser::Functions.function(:ensure_resource)
packages.each { |package_name|
+ raise(Puppet::ParseError, 'ensure_packages(): Empty String provided for package name') if package_name.length == 0
if !findresource("Package[#{package_name}]")
function_ensure_resource(['package', package_name, defaults ])
end
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index fbf7d8e..42f287a 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -40,7 +40,12 @@ Puppet::Type.type(:file_line).provide(:ruby) do
# file; for now assuming that this type is only used on
# small-ish config files that can fit into memory without
# too much trouble.
- @lines ||= File.readlines(resource[:path], :encoding => resource[:encoding])
+ begin
+ @lines ||= File.readlines(resource[:path], :encoding => resource[:encoding])
+ rescue TypeError => e
+ # Ruby 1.8 doesn't support open_args
+ @lines ||= File.readlines(resource[:path])
+ end
end
def match_regex
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index e82b246..3d691bf 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -104,8 +104,16 @@ Puppet::Type.newtype(:file_line) do
' This is also takes a regex.'
end
- newparam(:line) do
+ # The line property never changes; the type only ever performs a create() or
+ # destroy(). line is a property in order to allow it to correctly handle
+ # Sensitive type values. Because it is a property which will never change,
+ # it should never be considered out of sync.
+ newproperty(:line) do
desc 'The line to be appended to the file or used to replace matches found by the match attribute.'
+
+ def retrieve
+ @resource[:line]
+ end
end
newparam(:path) do