summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/puppet_settings.rb35
-rw-r--r--lib/facter/puppet_vardir.rb26
-rw-r--r--lib/puppet/functions/deprecation.rb4
-rw-r--r--lib/puppet/functions/is_absolute_path.rb15
-rw-r--r--lib/puppet/functions/is_array.rb15
-rw-r--r--lib/puppet/functions/is_bool.rb15
-rw-r--r--lib/puppet/functions/is_float.rb15
-rw-r--r--lib/puppet/functions/is_ip_address.rb15
-rw-r--r--lib/puppet/functions/is_ipv4_address.rb15
-rw-r--r--lib/puppet/functions/is_ipv6_address.rb15
-rw-r--r--lib/puppet/functions/is_numeric.rb15
-rw-r--r--lib/puppet/functions/is_string.rb15
-rw-r--r--lib/puppet/functions/validate_absolute_path.rb15
-rw-r--r--lib/puppet/functions/validate_array.rb15
-rw-r--r--lib/puppet/functions/validate_bool.rb15
-rw-r--r--lib/puppet/functions/validate_hash.rb15
-rw-r--r--lib/puppet/functions/validate_integer.rb15
-rw-r--r--lib/puppet/functions/validate_ip_address.rb15
-rw-r--r--lib/puppet/functions/validate_ipv4_address.rb15
-rw-r--r--lib/puppet/functions/validate_ipv6_address.rb15
-rw-r--r--lib/puppet/functions/validate_legacy.rb62
-rw-r--r--lib/puppet/functions/validate_numeric.rb15
-rw-r--r--lib/puppet/functions/validate_re.rb15
-rw-r--r--lib/puppet/functions/validate_slength.rb15
-rw-r--r--lib/puppet/functions/validate_string.rb15
-rw-r--r--lib/puppet/parser/functions/deprecation.rb17
-rw-r--r--lib/puppet/parser/functions/dig44.rb37
-rw-r--r--lib/puppet/parser/functions/ensure_resources.rb2
-rw-r--r--lib/puppet/parser/functions/getparam.rb2
-rw-r--r--lib/puppet/parser/functions/getvar.rb6
-rw-r--r--lib/puppet/parser/functions/is_absolute_path.rb4
-rw-r--r--lib/puppet/parser/functions/is_array.rb4
-rw-r--r--lib/puppet/parser/functions/is_bool.rb4
-rw-r--r--lib/puppet/parser/functions/is_float.rb2
-rw-r--r--lib/puppet/parser/functions/is_integer.rb2
-rw-r--r--lib/puppet/parser/functions/is_ip_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_ipv4_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_ipv6_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_numeric.rb4
-rw-r--r--lib/puppet/parser/functions/is_string.rb5
-rw-r--r--lib/puppet/parser/functions/validate_absolute_path.rb3
-rw-r--r--lib/puppet/parser/functions/validate_array.rb2
-rw-r--r--lib/puppet/parser/functions/validate_bool.rb3
-rw-r--r--lib/puppet/parser/functions/validate_hash.rb2
-rw-r--r--lib/puppet/parser/functions/validate_integer.rb4
-rw-r--r--lib/puppet/parser/functions/validate_ip_address.rb6
-rw-r--r--lib/puppet/parser/functions/validate_ipv4_address.rb2
-rw-r--r--lib/puppet/parser/functions/validate_ipv6_address.rb2
-rw-r--r--lib/puppet/parser/functions/validate_numeric.rb4
-rw-r--r--lib/puppet/parser/functions/validate_re.rb3
-rw-r--r--lib/puppet/parser/functions/validate_slength.rb2
-rw-r--r--lib/puppet/parser/functions/validate_string.rb11
-rw-r--r--lib/puppet/provider/file_line/ruby.rb6
-rw-r--r--lib/puppet/type/file_line.rb3
54 files changed, 531 insertions, 59 deletions
diff --git a/lib/facter/puppet_settings.rb b/lib/facter/puppet_settings.rb
new file mode 100644
index 0000000..e6a066a
--- /dev/null
+++ b/lib/facter/puppet_settings.rb
@@ -0,0 +1,35 @@
+# These facter facts return the value of the Puppet vardir and environment path
+# settings for the node running puppet or puppet agent. The intent is to
+# enable Puppet modules to automatically have insight into a place where they
+# can place variable data, or for modules running on the puppet master to know
+# where environments are stored.
+#
+# The values should be directly usable in a File resource path attribute.
+#
+begin
+ require 'facter/util/puppet_settings'
+rescue LoadError => e
+ # puppet apply does not add module lib directories to the $LOAD_PATH (See
+ # #4248). It should (in the future) but for the time being we need to be
+ # defensive which is what this rescue block is doing.
+ rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
+ load rb_file if File.exists?(rb_file) or raise e
+end
+
+
+# These will be nil if Puppet is not available.
+Facter.add(:puppet_vardir) do
+ setcode do
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:vardir]
+ end
+ end
+end
+
+Facter.add(:puppet_environmentpath) do
+ setcode do
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:environmentpath]
+ end
+ end
+end
diff --git a/lib/facter/puppet_vardir.rb b/lib/facter/puppet_vardir.rb
deleted file mode 100644
index 0e6af40..0000000
--- a/lib/facter/puppet_vardir.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# This facter fact returns the value of the Puppet vardir setting for the node
-# running puppet or puppet agent. The intent is to enable Puppet modules to
-# automatically have insight into a place where they can place variable data,
-# regardless of the node's platform.
-#
-# The value should be directly usable in a File resource path attribute.
-
-
-begin
- require 'facter/util/puppet_settings'
-rescue LoadError => e
- # puppet apply does not add module lib directories to the $LOAD_PATH (See
- # #4248). It should (in the future) but for the time being we need to be
- # defensive which is what this rescue block is doing.
- rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
- load rb_file if File.exists?(rb_file) or raise e
-end
-
-Facter.add(:puppet_vardir) do
- setcode do
- # This will be nil if Puppet is not available.
- Facter::Util::PuppetSettings.with_puppet do
- Puppet[:vardir]
- end
- end
-end
diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb
index 3b84ae5..a860aa2 100644
--- a/lib/puppet/functions/deprecation.rb
+++ b/lib/puppet/functions/deprecation.rb
@@ -15,7 +15,9 @@ Puppet::Functions.create_function(:deprecation) do
when :error
fail("deprecation. #{key}. #{message}")
else
- Puppet.warn_once('deprecation', key, message)
+ unless ENV['STDLIB_LOG_DEPRECATIONS'] == 'false'
+ Puppet.deprecation_warning(message, key)
+ end
end
end
end
diff --git a/lib/puppet/functions/is_absolute_path.rb b/lib/puppet/functions/is_absolute_path.rb
new file mode 100644
index 0000000..b61064a
--- /dev/null
+++ b/lib/puppet/functions/is_absolute_path.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_absolute_path) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_absolute_path', "This method is deprecated, please use match expressions with Stdlib::Compat::Absolute_Path instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_absolute_path", args)
+ end
+end
diff --git a/lib/puppet/functions/is_array.rb b/lib/puppet/functions/is_array.rb
new file mode 100644
index 0000000..a29fe8a
--- /dev/null
+++ b/lib/puppet/functions/is_array.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_array) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_array', "This method is deprecated, please use match expressions with Stdlib::Compat::Array instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_array", args)
+ end
+end
diff --git a/lib/puppet/functions/is_bool.rb b/lib/puppet/functions/is_bool.rb
new file mode 100644
index 0000000..6e2c22b
--- /dev/null
+++ b/lib/puppet/functions/is_bool.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_bool) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_bool', "This method is deprecated, please use match expressions with Stdlib::Compat::Bool instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_bool", args)
+ end
+end
diff --git a/lib/puppet/functions/is_float.rb b/lib/puppet/functions/is_float.rb
new file mode 100644
index 0000000..c91aa5d
--- /dev/null
+++ b/lib/puppet/functions/is_float.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_float) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_float', "This method is deprecated, please use match expressions with Stdlib::Compat::Float instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_float", args)
+ end
+end
diff --git a/lib/puppet/functions/is_ip_address.rb b/lib/puppet/functions/is_ip_address.rb
new file mode 100644
index 0000000..4c72037
--- /dev/null
+++ b/lib/puppet/functions/is_ip_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_ip_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_ip_address', "This method is deprecated, please use match expressions with Stdlib::Compat::Ip_address instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_ip_address", args)
+ end
+end
diff --git a/lib/puppet/functions/is_ipv4_address.rb b/lib/puppet/functions/is_ipv4_address.rb
new file mode 100644
index 0000000..97b01ae
--- /dev/null
+++ b/lib/puppet/functions/is_ipv4_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_ipv4_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_ipv4_address', "This method is deprecated, please use match expressions with Stdlib::Compat::Ipv4 instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_ipv4_address", args)
+ end
+end
diff --git a/lib/puppet/functions/is_ipv6_address.rb b/lib/puppet/functions/is_ipv6_address.rb
new file mode 100644
index 0000000..be0c98a
--- /dev/null
+++ b/lib/puppet/functions/is_ipv6_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_ipv6_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_ipv4_address', "This method is deprecated, please use match expressions with Stdlib::Compat::Ipv6 instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_ipv6_address", args)
+ end
+end
diff --git a/lib/puppet/functions/is_numeric.rb b/lib/puppet/functions/is_numeric.rb
new file mode 100644
index 0000000..f5e9d41
--- /dev/null
+++ b/lib/puppet/functions/is_numeric.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_numeric) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_numeric', "This method is deprecated, please use match expressions with Stdlib::Compat::Numeric instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_numeric", args)
+ end
+end
diff --git a/lib/puppet/functions/is_string.rb b/lib/puppet/functions/is_string.rb
new file mode 100644
index 0000000..a05a796
--- /dev/null
+++ b/lib/puppet/functions/is_string.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_string) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_string', "This method is deprecated, please use match expressions with Stdlib::Compat::String instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_string", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_absolute_path.rb b/lib/puppet/functions/validate_absolute_path.rb
new file mode 100644
index 0000000..a3c696d
--- /dev/null
+++ b/lib/puppet/functions/validate_absolute_path.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_absolute_path) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_absolute_path', "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
new file mode 100644
index 0000000..f59c6b4
--- /dev/null
+++ b/lib/puppet/functions/validate_array.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_array) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_array', "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
new file mode 100644
index 0000000..5cfb2ac
--- /dev/null
+++ b/lib/puppet/functions/validate_bool.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_bool) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_bool', "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
new file mode 100644
index 0000000..89ad9ab
--- /dev/null
+++ b/lib/puppet/functions/validate_hash.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_hash) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_hash', "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
new file mode 100644
index 0000000..475ea0f
--- /dev/null
+++ b/lib/puppet/functions/validate_integer.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_integer) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_integer', "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
new file mode 100644
index 0000000..1521c08
--- /dev/null
+++ b/lib/puppet/functions/validate_ip_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_ip_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_ip_address', "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
new file mode 100644
index 0000000..fe66ab3
--- /dev/null
+++ b/lib/puppet/functions/validate_ipv4_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_ipv4_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_ipv4_address', "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
new file mode 100644
index 0000000..7cc3cbd
--- /dev/null
+++ b/lib/puppet/functions/validate_ipv6_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_ipv6_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_ipv6_address', "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_legacy.rb b/lib/puppet/functions/validate_legacy.rb
new file mode 100644
index 0000000..c9d1f56
--- /dev/null
+++ b/lib/puppet/functions/validate_legacy.rb
@@ -0,0 +1,62 @@
+Puppet::Functions.create_function(:validate_legacy) do
+ # The function checks a value against both the target_type (new) and the previous_validation function (old).
+
+ dispatch :validate_legacy do
+ param 'Any', :scope
+ param 'Type', :target_type
+ param 'String', :function_name
+ param 'Any', :value
+ repeated_param 'Any', :args
+ end
+
+ dispatch :validate_legacy_s do
+ param 'Any', :scope
+ param 'String', :type_string
+ param 'String', :function_name
+ param 'Any', :value
+ repeated_param 'Any', :args
+ end
+
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+
+ def validate_legacy_s(scope, type_string, *args)
+ t = Puppet::Pops::Types::TypeParser.new.parse(type_string, scope)
+ validate_legacy(scope, t, *args)
+ end
+
+ def validate_legacy(scope, target_type, function_name, value, *prev_args)
+ if assert_type(target_type, value)
+ if previous_validation(scope, function_name, value, *prev_args)
+ # Silently passes
+ else
+ Puppet.notice("Accepting previously invalid value for target type '#{target_type}'")
+ end
+ else
+ inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
+ error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("validate_legacy(#{function_name})", target_type, inferred_type)
+ if previous_validation(scope, function_name, value, *prev_args)
+ call_function('deprecation', 'validate_legacy', error_msg)
+ else
+ call_function('fail', error_msg)
+ end
+ end
+ end
+
+ def previous_validation(scope, function_name, value, *prev_args)
+ # Call the previous validation function and catch any errors. Return true if no errors are thrown.
+ begin
+ scope.send("function_#{function_name}".to_s, [value, *prev_args])
+ true
+ rescue Puppet::ParseError
+ false
+ end
+ end
+
+ def assert_type(type, value)
+ Puppet::Pops::Types::TypeCalculator.instance?(type, value)
+ end
+end
diff --git a/lib/puppet/functions/validate_numeric.rb b/lib/puppet/functions/validate_numeric.rb
new file mode 100644
index 0000000..3052d35
--- /dev/null
+++ b/lib/puppet/functions/validate_numeric.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_numeric) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_numeric', "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
new file mode 100644
index 0000000..19443a8
--- /dev/null
+++ b/lib/puppet/functions/validate_re.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_re) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_re', "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..584232a
--- /dev/null
+++ b/lib/puppet/functions/validate_slength.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_slength) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_slength', "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
new file mode 100644
index 0000000..91ff004
--- /dev/null
+++ b/lib/puppet/functions/validate_string.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_string) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_string', "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/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb
new file mode 100644
index 0000000..e30f3a0
--- /dev/null
+++ b/lib/puppet/parser/functions/deprecation.rb
@@ -0,0 +1,17 @@
+module Puppet::Parser::Functions
+ newfunction(:deprecation, :type => :rvalue, :doc => <<-EOS
+ Function to print deprecation warnings (this is the 3.X version of it), The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method.).
+EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "deprecation: Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") unless arguments.size == 2
+
+ key = arguments[0]
+ message = arguments[1]
+
+ if ENV['STDLIB_LOG_DEPRECATIONS'] == "true"
+ warning("deprecation. #{key}. #{message}")
+ end
+ end
+end
diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb
index a7de363..1e7c318 100644
--- a/lib/puppet/parser/functions/dig44.rb
+++ b/lib/puppet/parser/functions/dig44.rb
@@ -3,21 +3,28 @@
#
module Puppet::Parser::Functions
- newfunction(:dig44, :type => :rvalue, :doc => <<-EOS
+ newfunction(
+ :dig44,
+ :type => :rvalue,
+ :arity => -2,
+ :doc => <<-eos
DEPRECATED: This function has been replaced in puppet 4.5.0.
-Looks up into a complex structure of arrays and hashes and returns nil
+Looks up into a complex structure of arrays and hashes and returns a value
or the default value if nothing was found.
-Path is an array of keys to be looked up in data argument. The function
-will go down the structure and try to extract the required value.
+Key can contain slashes to describe path components. The function will go down
+the structure and try to extract the required value.
$data = {
'a' => {
'b' => [
'b1',
'b2',
- 'b3' ]}}
+ 'b3',
+ ]
+ }
+}
$value = dig44($data, ['a', 'b', '2'], 'not_found')
=> $value = 'b3'
@@ -29,18 +36,18 @@ b -> second hash key
not_found -> (optional) will be returned if there is no value or the path
did not match. Defaults to nil.
-In addition to the required "path" argument, "dig44" accepts default
+In addition to the required "key" argument, the function accepts a default
argument. It will be returned if no value was found or a path component is
missing. And the fourth argument can set a variable path separator.
- EOS
- ) do |arguments|
+ eos
+ ) do |arguments|
# Two arguments are required
raise(Puppet::ParseError, "dig44(): Wrong number of arguments " +
"given (#{arguments.size} for at least 2)") if arguments.size < 2
data, path, default = *arguments
- if !(data.is_a?(Hash) || data.is_a?(Array))
+ unless data.is_a?(Hash) or data.is_a?(Array)
raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, " <<
"given #{data.class.name}")
end
@@ -50,7 +57,17 @@ missing. And the fourth argument can set a variable path separator.
"given #{path.class.name}")
end
- value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break }
+ value = path.reduce(data) do |structure, key|
+ if structure.is_a? Hash or structure.is_a? Array
+ if structure.is_a? Array
+ key = Integer key rescue break
+ end
+ break if structure[key].nil? or structure[key] == :undef
+ structure[key]
+ else
+ break
+ end
+ end
value.nil? ? default : value
end
end
diff --git a/lib/puppet/parser/functions/ensure_resources.rb b/lib/puppet/parser/functions/ensure_resources.rb
index 30d57a8..b3c51e6 100644
--- a/lib/puppet/parser/functions/ensure_resources.rb
+++ b/lib/puppet/parser/functions/ensure_resources.rb
@@ -36,7 +36,7 @@ ENDOFDOC
params ||= {}
if title.is_a?(Hash)
- resource_hash = Hash(title)
+ resource_hash = title.dup
resources = resource_hash.keys
Puppet::Parser::Functions.function(:ensure_resource)
diff --git a/lib/puppet/parser/functions/getparam.rb b/lib/puppet/parser/functions/getparam.rb
index 6d51006..0a5cbe0 100644
--- a/lib/puppet/parser/functions/getparam.rb
+++ b/lib/puppet/parser/functions/getparam.rb
@@ -28,7 +28,7 @@ ENDOFDOC
return '' if param.empty?
if resource = findresource(reference.to_s)
- return resource[param] if resource[param]
+ return resource[param] unless resource[param].nil?
end
return ''
diff --git a/lib/puppet/parser/functions/getvar.rb b/lib/puppet/parser/functions/getvar.rb
index ae9c869..3af8d48 100644
--- a/lib/puppet/parser/functions/getvar.rb
+++ b/lib/puppet/parser/functions/getvar.rb
@@ -20,9 +20,13 @@ module Puppet::Parser::Functions
end
begin
+ result = nil
catch(:undefined_variable) do
- self.lookupvar("#{args[0]}")
+ result = self.lookupvar("#{args[0]}")
end
+
+ # avoid relying on incosistent behaviour around ruby return values from catch
+ result
rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
end
diff --git a/lib/puppet/parser/functions/is_absolute_path.rb b/lib/puppet/parser/functions/is_absolute_path.rb
index 53a5445..e64777f 100644
--- a/lib/puppet/parser/functions/is_absolute_path.rb
+++ b/lib/puppet/parser/functions/is_absolute_path.rb
@@ -23,7 +23,7 @@ module Puppet::Parser::Functions
is_absolute_path($undefined)
ENDHEREDOC
-
+ function_deprecation([:is_absolute_path, '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.'])
require 'puppet/util'
path = args[0]
@@ -47,4 +47,4 @@ module Puppet::Parser::Functions
end
value
end
-end \ No newline at end of file
+end
diff --git a/lib/puppet/parser/functions/is_array.rb b/lib/puppet/parser/functions/is_array.rb
index b39e184..1d2c0fa 100644
--- a/lib/puppet/parser/functions/is_array.rb
+++ b/lib/puppet/parser/functions/is_array.rb
@@ -8,6 +8,8 @@ Returns true if the variable passed to this function is an array.
EOS
) do |arguments|
+ function_deprecation([:is_array, '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.'])
+
raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
@@ -18,5 +20,3 @@ Returns true if the variable passed to this function is an array.
return result
end
end
-
-# vim: set ts=2 sw=2 et :
diff --git a/lib/puppet/parser/functions/is_bool.rb b/lib/puppet/parser/functions/is_bool.rb
index 8bbdbc8..83d2ebe 100644
--- a/lib/puppet/parser/functions/is_bool.rb
+++ b/lib/puppet/parser/functions/is_bool.rb
@@ -8,6 +8,8 @@ Returns true if the variable passed to this function is a boolean.
EOS
) do |arguments|
+ function_deprecation([:is_bool, '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.'])
+
raise(Puppet::ParseError, "is_bool(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1
@@ -18,5 +20,3 @@ Returns true if the variable passed to this function is a boolean.
return result
end
end
-
-# vim: set ts=2 sw=2 et :
diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb
index a2da943..1186458 100644
--- a/lib/puppet/parser/functions/is_float.rb
+++ b/lib/puppet/parser/functions/is_float.rb
@@ -8,6 +8,8 @@ Returns true if the variable passed to this function is a float.
EOS
) do |arguments|
+ function_deprecation([:is_float, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb
index c03d28d..e04fd1f 100644
--- a/lib/puppet/parser/functions/is_integer.rb
+++ b/lib/puppet/parser/functions/is_integer.rb
@@ -13,6 +13,8 @@ If given any other argument `false` is returned.
EOS
) do |arguments|
+ function_deprecation([:is_integer, '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.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb
index a90adab..5f1d765 100644
--- a/lib/puppet/parser/functions/is_ip_address.rb
+++ b/lib/puppet/parser/functions/is_ip_address.rb
@@ -10,6 +10,8 @@ Returns true if the string passed to this function is a valid IP address.
require 'ipaddr'
+ function_deprecation([:is_ip_address, '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.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ipv4_address.rb b/lib/puppet/parser/functions/is_ipv4_address.rb
index b4861d5..1764e61 100644
--- a/lib/puppet/parser/functions/is_ipv4_address.rb
+++ b/lib/puppet/parser/functions/is_ipv4_address.rb
@@ -10,6 +10,8 @@ Returns true if the string passed to this function is a valid IPv4 address.
require 'ipaddr'
+ function_deprecation([:is_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ipv6_address.rb b/lib/puppet/parser/functions/is_ipv6_address.rb
index 475ad50..7ca4997 100644
--- a/lib/puppet/parser/functions/is_ipv6_address.rb
+++ b/lib/puppet/parser/functions/is_ipv6_address.rb
@@ -8,6 +8,8 @@ Returns true if the string passed to this function is a valid IPv6 address.
EOS
) do |arguments|
+ function_deprecation([:is_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
+
require 'ipaddr'
if (arguments.size != 1) then
diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb
index e7e1d2a..4a55225 100644
--- a/lib/puppet/parser/functions/is_numeric.rb
+++ b/lib/puppet/parser/functions/is_numeric.rb
@@ -24,6 +24,8 @@ Valid examples:
EOS
) do |arguments|
+ function_deprecation([:is_numeric, '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.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
"given #{arguments.size} for 1")
@@ -71,5 +73,3 @@ Valid examples:
end
end
end
-
-# vim: set ts=2 sw=2 et :
diff --git a/lib/puppet/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb
index f5bef04..31ee91e 100644
--- a/lib/puppet/parser/functions/is_string.rb
+++ b/lib/puppet/parser/functions/is_string.rb
@@ -8,12 +8,15 @@ Returns true if the variable passed to this function is a string.
EOS
) do |arguments|
+ function_deprecation([:is_string, '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.'])
+
raise(Puppet::ParseError, "is_string(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
type = arguments[0]
- result = type.is_a?(String)
+ # when called through the v4 API shim, undef gets translated to nil
+ result = type.is_a?(String) || type.nil?
if result and (type == type.to_f.to_s or type == type.to_i.to_s) then
return false
diff --git a/lib/puppet/parser/functions/validate_absolute_path.rb b/lib/puppet/parser/functions/validate_absolute_path.rb
index 5f85f72..c73f3df 100644
--- a/lib/puppet/parser/functions/validate_absolute_path.rb
+++ b/lib/puppet/parser/functions/validate_absolute_path.rb
@@ -26,6 +26,9 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ # The deprecation function was being called twice, as validate_absolute_path calls is_absolute_path. I have removed it from here so it only calls deprecation once within is_absolute_path.
+ # function_deprecation([:validate_absolute_path, '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.'])
+
require 'puppet/util'
unless args.length > 0 then
diff --git a/lib/puppet/parser/functions/validate_array.rb b/lib/puppet/parser/functions/validate_array.rb
index 34b5118..3bf3983 100644
--- a/lib/puppet/parser/functions/validate_array.rb
+++ b/lib/puppet/parser/functions/validate_array.rb
@@ -18,6 +18,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_array, '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.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)")
end
diff --git a/lib/puppet/parser/functions/validate_bool.rb b/lib/puppet/parser/functions/validate_bool.rb
index 59a0805..49075b8 100644
--- a/lib/puppet/parser/functions/validate_bool.rb
+++ b/lib/puppet/parser/functions/validate_bool.rb
@@ -19,6 +19,9 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ # The deprecation function was being called twice, as validate_bool calls is_bool. I have removed it from here so it only calls deprecation once within is_bool.
+ # function_deprecation([:validate_bool, '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.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)")
end
diff --git a/lib/puppet/parser/functions/validate_hash.rb b/lib/puppet/parser/functions/validate_hash.rb
index 9bdd543..fcdc7e1 100644
--- a/lib/puppet/parser/functions/validate_hash.rb
+++ b/lib/puppet/parser/functions/validate_hash.rb
@@ -18,6 +18,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_hash, '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.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)")
end
diff --git a/lib/puppet/parser/functions/validate_integer.rb b/lib/puppet/parser/functions/validate_integer.rb
index a950916..2ae0293 100644
--- a/lib/puppet/parser/functions/validate_integer.rb
+++ b/lib/puppet/parser/functions/validate_integer.rb
@@ -2,7 +2,7 @@ module Puppet::Parser::Functions
newfunction(:validate_integer, :doc => <<-'ENDHEREDOC') do |args|
Validate that the first argument is an integer (or an array of integers). Abort catalog compilation if any of the checks fail.
-
+
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
@@ -53,6 +53,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_integer, '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.'])
+
# tell the user we need at least one, and optionally up to two other parameters
raise Puppet::ParseError, "validate_integer(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless args.length > 0 and args.length < 4
diff --git a/lib/puppet/parser/functions/validate_ip_address.rb b/lib/puppet/parser/functions/validate_ip_address.rb
index 64fbd75..5d80cfb 100644
--- a/lib/puppet/parser/functions/validate_ip_address.rb
+++ b/lib/puppet/parser/functions/validate_ip_address.rb
@@ -8,12 +8,12 @@ module Puppet::Parser::Functions
$my_ip = "1.2.3.4"
validate_ip_address($my_ip)
validate_ip_address("8.8.8.8", "172.16.0.1", $my_ip)
-
+
$my_ip = "3ffe:505:2"
validate_ip_address(1)
validate_ip_address($my_ip)
validate_ip_address("fe80::baf6:b1ff:fe19:7507", $my_ip)
-
+
The following values will fail, causing compilation to abort:
$some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ]
validate_ip_address($some_array)
@@ -23,6 +23,8 @@ module Puppet::Parser::Functions
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
+ function_deprecation([:validate_ip_address, '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.'])
+
if defined?(IPAddr::InvalidAddressError)
rescuable_exceptions << IPAddr::InvalidAddressError
end
diff --git a/lib/puppet/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb
index 97faa57..0660abd 100644
--- a/lib/puppet/parser/functions/validate_ipv4_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv4_address.rb
@@ -18,6 +18,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
) do |args|
+ function_deprecation([:validate_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
+
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
diff --git a/lib/puppet/parser/functions/validate_ipv6_address.rb b/lib/puppet/parser/functions/validate_ipv6_address.rb
index b0f2558..f5dd9e5 100644
--- a/lib/puppet/parser/functions/validate_ipv6_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv6_address.rb
@@ -19,6 +19,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
) do |args|
+ function_deprecation([:validate_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
+
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
diff --git a/lib/puppet/parser/functions/validate_numeric.rb b/lib/puppet/parser/functions/validate_numeric.rb
index 3a14443..4205b30 100644
--- a/lib/puppet/parser/functions/validate_numeric.rb
+++ b/lib/puppet/parser/functions/validate_numeric.rb
@@ -2,7 +2,7 @@ module Puppet::Parser::Functions
newfunction(:validate_numeric, :doc => <<-'ENDHEREDOC') do |args|
Validate that the first argument is a numeric value (or an array of numeric values). Abort catalog compilation if any of the checks fail.
-
+
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
@@ -15,6 +15,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_numeric, '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.'])
+
# tell the user we need at least one, and optionally up to two other parameters
raise Puppet::ParseError, "validate_numeric(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless args.length > 0 and args.length < 4
diff --git a/lib/puppet/parser/functions/validate_re.rb b/lib/puppet/parser/functions/validate_re.rb
index efee7f8..0ac83dd 100644
--- a/lib/puppet/parser/functions/validate_re.rb
+++ b/lib/puppet/parser/functions/validate_re.rb
@@ -29,6 +29,9 @@ module Puppet::Parser::Functions
validate_re("${::operatingsystemmajrelease}", '^[57]$')
ENDHEREDOC
+
+ function_deprecation([:validate_re, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Re. There is further documentation for validate_legacy function in the README.'])
+
if (args.length < 2) or (args.length > 3) then
raise Puppet::ParseError, "validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)"
end
diff --git a/lib/puppet/parser/functions/validate_slength.rb b/lib/puppet/parser/functions/validate_slength.rb
index 47c7d4a..383855c 100644
--- a/lib/puppet/parser/functions/validate_slength.rb
+++ b/lib/puppet/parser/functions/validate_slength.rb
@@ -21,6 +21,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_slength, '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
input, max_length, min_length = *args
diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb
index c841f6a..6675d86 100644
--- a/lib/puppet/parser/functions/validate_string.rb
+++ b/lib/puppet/parser/functions/validate_string.rb
@@ -13,22 +13,25 @@ module Puppet::Parser::Functions
validate_string(true)
validate_string([ 'some', 'array' ])
-
+
Note: validate_string(undef) will not fail in this version of the
functions API (incl. current and future parser). Instead, use:
-
+
if $var == undef {
fail('...')
}
-
+
ENDHEREDOC
+ function_deprecation([:validate_string, '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.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
end
args.each do |arg|
- unless arg.is_a?(String)
+ # when called through the v4 API shim, undef gets translated to nil
+ unless arg.is_a?(String) || arg.nil?
raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
end
end
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