summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown2
-rw-r--r--lib/puppet/functions/validate_absolute_path.rb13
-rw-r--r--lib/puppet/functions/validate_array.rb13
-rw-r--r--lib/puppet/functions/validate_bool.rb13
-rw-r--r--lib/puppet/functions/validate_hash.rb13
-rw-r--r--lib/puppet/functions/validate_integer.rb13
-rw-r--r--lib/puppet/functions/validate_ip_address.rb13
-rw-r--r--lib/puppet/functions/validate_ipv4_address.rb13
-rw-r--r--lib/puppet/functions/validate_ipv6_address.rb13
-rw-r--r--lib/puppet/functions/validate_numeric.rb13
-rw-r--r--lib/puppet/functions/validate_re.rb13
-rw-r--r--lib/puppet/functions/validate_slength.rb10
-rw-r--r--lib/puppet/functions/validate_string.rb13
-rw-r--r--lib/puppet/parser/functions/validate_slength.rb2
-rw-r--r--lib/puppet/provider/file_line/ruby.rb6
-rw-r--r--lib/puppet/type/file_line.rb3
-rw-r--r--lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb19
-rwxr-xr-xspec/unit/puppet/provider/file_line/ruby_spec.rb7
18 files changed, 136 insertions, 56 deletions
diff --git a/README.markdown b/README.markdown
index 210e9f3..d445cc5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -128,7 +128,7 @@ All parameters are optional, unless otherwise noted.
* `ensure`: Ensures whether the resource is present. Valid options: 'present', 'absent'. Default: 'present'.
* `line`: **Required.** Sets the line to be added to the file located by the `path` parameter. Valid options: String. Default: Undefined.
* `match`: Specifies a regular expression to run against existing lines in the file; if a match is found, it is replaced rather than adding a new line. A regex comparison is performed against the line value, and if it does not match, an exception is raised. Valid options: String containing a regex. Default: Undefined.
-* `match_for_absence`: An optional value to determine if match should be applied when `ensure => absent`. If set to true and match is set, the line that matches match will be deleted. If set to false (the default), match is ignored when `ensure => absent` and the value of `line` is used instead. Default: false.
+* `match_for_absence`: An optional value to determine if match should be applied when `ensure => absent`. If set to true and match is set, the line that matches match will be deleted. If set to false (the default), match is ignored when `ensure => absent` and the value of `line` is used instead. Ignored when `ensure => present`. Default: false.
* `multiple`: Determines if `match` and/or `after` can change multiple lines. If set to false, an exception will be raised if more than one line matches. Valid options: 'true', 'false'. Default: Undefined.
* `name`: Sets the name to use as the identity of the resource. This is necessary if you want the resource namevar to differ from the supplied `title` of the resource. Valid options: String. Default: Undefined.
* `path`: **Required.** Defines the file in which Puppet will ensure the line specified by `line`. Must be an absolute path to the file.
diff --git a/lib/puppet/functions/validate_absolute_path.rb b/lib/puppet/functions/validate_absolute_path.rb
index 5ae9d29..94f52e1 100644
--- a/lib/puppet/functions/validate_absolute_path.rb
+++ b/lib/puppet/functions/validate_absolute_path.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_absolute_path", "Stdlib::Compat::Absolute_Path")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_absolute_path, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Absolute_Path. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_absolute_path", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_array.rb b/lib/puppet/functions/validate_array.rb
index 9155784..eb8f5e5 100644
--- a/lib/puppet/functions/validate_array.rb
+++ b/lib/puppet/functions/validate_array.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_array", "Stdlib::Compat::Array")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_array, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_array", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_bool.rb b/lib/puppet/functions/validate_bool.rb
index 10f6edf..168775d 100644
--- a/lib/puppet/functions/validate_bool.rb
+++ b/lib/puppet/functions/validate_bool.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_bool", "Stdlib::Compat::Bool")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_bool, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_bool", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_hash.rb b/lib/puppet/functions/validate_hash.rb
index 5349664..c356ceb 100644
--- a/lib/puppet/functions/validate_hash.rb
+++ b/lib/puppet/functions/validate_hash.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_hash", "Stdlib::Compat::Hash")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_hash, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_hash", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_integer.rb b/lib/puppet/functions/validate_integer.rb
index 2c4645d..db95f1c 100644
--- a/lib/puppet/functions/validate_integer.rb
+++ b/lib/puppet/functions/validate_integer.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_integer", "Stdlib::Compat::Integer")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_integer, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_integer", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_ip_address.rb b/lib/puppet/functions/validate_ip_address.rb
index 15a710e..eaf56bb 100644
--- a/lib/puppet/functions/validate_ip_address.rb
+++ b/lib/puppet/functions/validate_ip_address.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ip_address", "Stdlib::Compat::Ip_Address")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_ip_address, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_Address. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_ip_address", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_ipv4_address.rb b/lib/puppet/functions/validate_ipv4_address.rb
index 8e1bc59..6a870eb 100644
--- a/lib/puppet/functions/validate_ipv4_address.rb
+++ b/lib/puppet/functions/validate_ipv4_address.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv4_address", "Stdlib::Compat::Ipv4_Address")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_ipv4_address, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4_Address. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_ipv4_address", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_ipv6_address.rb b/lib/puppet/functions/validate_ipv6_address.rb
index 865648a..922a9ac 100644
--- a/lib/puppet/functions/validate_ipv6_address.rb
+++ b/lib/puppet/functions/validate_ipv6_address.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv6_address", "Stdlib::Compat::Ipv6_address")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_ipv6_address, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6_address. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_ipv6_address", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_numeric.rb b/lib/puppet/functions/validate_numeric.rb
index 0c2e1f2..e48bec4 100644
--- a/lib/puppet/functions/validate_numeric.rb
+++ b/lib/puppet/functions/validate_numeric.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_numeric", "Stdlib::Compat::Numeric")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_numeric, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_numeric", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_re.rb b/lib/puppet/functions/validate_re.rb
index d63ed42..8a95077 100644
--- a/lib/puppet/functions/validate_re.rb
+++ b/lib/puppet/functions/validate_re.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_re", "Stdlib::Compat::Re")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_re, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Pattern[]. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_re", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_slength.rb b/lib/puppet/functions/validate_slength.rb
new file mode 100644
index 0000000..2d71a14
--- /dev/null
+++ b/lib/puppet/functions/validate_slength.rb
@@ -0,0 +1,10 @@
+Puppet::Functions.create_function(:validate_slength, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with String[]. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_slength", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_string.rb b/lib/puppet/functions/validate_string.rb
index a196f43..fe4c623 100644
--- a/lib/puppet/functions/validate_string.rb
+++ b/lib/puppet/functions/validate_string.rb
@@ -1,3 +1,10 @@
-require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
-PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_string", "Stdlib::Compat::String")
-# Puppet::Functions.create_function
+Puppet::Functions.create_function(:validate_string, Puppet::Functions::InternalFunction) do
+ dispatch :deprecation_gen do
+ scope_param
+ optional_repeated_param 'Any', :args
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_string", args)
+ end
+end
diff --git a/lib/puppet/parser/functions/validate_slength.rb b/lib/puppet/parser/functions/validate_slength.rb
index 1641e5a..1828f49 100644
--- a/lib/puppet/parser/functions/validate_slength.rb
+++ b/lib/puppet/parser/functions/validate_slength.rb
@@ -21,7 +21,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String[x]. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with String[]. There is further documentation for validate_legacy function in the README.'])
raise Puppet::ParseError, "validate_slength(): Wrong number of arguments (#{args.length}; must be 2 or 3)" unless args.length == 2 or args.length == 3
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index aab6fe2..beeb430 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -4,7 +4,11 @@ Puppet::Type.type(:file_line).provide(:ruby) do
true
else
lines.find do |line|
- line.chomp == resource[:line].chomp
+ if resource[:ensure].to_s == 'absent' and resource[:match_for_absence].to_s == 'true'
+ line.chomp =~ Regexp.new(resource[:match])
+ else
+ line.chomp == resource[:line].chomp
+ end
end
end
end
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 6f5c188..7b7d44e 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -71,7 +71,8 @@ Puppet::Type.newtype(:file_line) do
newparam(:match_for_absence) do
desc 'An optional value to determine if match should be applied when ensure => absent.' +
' If set to true and match is set, the line that matches match will be deleted.' +
- ' If set to false (the default), match is ignored when ensure => absent.'
+ ' If set to false (the default), match is ignored when ensure => absent.' +
+ ' When `ensure => present`, match_for_absence is ignored.'
newvalues(true, false)
defaultto false
end
diff --git a/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb b/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb
deleted file mode 100644
index 0d8908d..0000000
--- a/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# Creates a Puppet 4 function for the corresponding puppet 3 validate function, who's name will be passed as an argument, alongside the type for deprecation output purposes.
-module PuppetX
- module Puppetlabs
- module Stdlib
- def self.deprecation_gen(funct, type)
- Puppet::Functions.create_function(funct, Puppet::Functions::InternalFunction) do
- dispatch :deprecation_gen do
- scope_param
- optional_repeated_param 'Any', :args
- end
- define_method 'deprecation_gen' do |scope, *args|
- call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with #{type}. There is further documentation for validate_legacy function in the README.")
- scope.send("function_#{funct}", args)
- end
- end
- end
- end
- end
-end
diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb
index fdeaf1a..1f41f62 100755
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -363,6 +363,13 @@ describe provider_class do
@provider = provider_class.new(@resource)
end
+ it 'should find a line to match' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2")
+ end
+ expect(@provider.exists?).to be_truthy
+ end
+
it 'should remove one line if it matches' do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo\nfoo2")