From 9035ee9f1c5eaa05391baefb1a3043090c65d8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 08:50:25 -1000 Subject: [PATCH 01/30] Remove deprecated function is_bool() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Bool. --- lib/puppet/functions/is_bool.rb | 29 ---------------------- lib/puppet/parser/functions/is_bool.rb | 29 ---------------------- spec/functions/is_bool_spec.rb | 33 -------------------------- 3 files changed, 91 deletions(-) delete mode 100644 lib/puppet/functions/is_bool.rb delete mode 100644 lib/puppet/parser/functions/is_bool.rb delete mode 100644 spec/functions/is_bool_spec.rb diff --git a/lib/puppet/functions/is_bool.rb b/lib/puppet/functions/is_bool.rb deleted file mode 100644 index fa8170933..000000000 --- a/lib/puppet/functions/is_bool.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_bool) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - 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/parser/functions/is_bool.rb b/lib/puppet/parser/functions/is_bool.rb deleted file mode 100644 index 96cb2172e..000000000 --- a/lib/puppet/parser/functions/is_bool.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# -# is_bool.rb -# -module Puppet::Parser::Functions - newfunction(:is_bool, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the variable passed to this function is a boolean. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) 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 - - type = arguments[0] - - result = type.is_a?(TrueClass) || type.is_a?(FalseClass) - - return result - end -end diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb deleted file mode 100644 index 7c5eddac2..000000000 --- a/spec/functions/is_bool_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_bool' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(true, false).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(true).and_return(true) } - it { is_expected.to run.with_params(false).and_return(true) } - it { is_expected.to run.with_params([1]).and_return(false) } - it { is_expected.to run.with_params([{}]).and_return(false) } - it { is_expected.to run.with_params([[]]).and_return(false) } - it { is_expected.to run.with_params([true]).and_return(false) } - it { is_expected.to run.with_params('true').and_return(false) } - it { is_expected.to run.with_params('false').and_return(false) } - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(true).and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params(false).and_return(true) - end - end -end From ea93ca869cb43df339c050abee66d2814164a067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 08:51:19 -1000 Subject: [PATCH 02/30] Remove deprecated function validate_bool() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Bool. --- lib/puppet/functions/validate_bool.rb | 30 -------------- lib/puppet/parser/functions/validate_bool.rb | 41 -------------------- spec/functions/validate_bool_spec.rb | 40 ------------------- 3 files changed, 111 deletions(-) delete mode 100644 lib/puppet/functions/validate_bool.rb delete mode 100644 lib/puppet/parser/functions/validate_bool.rb delete mode 100644 spec/functions/validate_bool_spec.rb diff --git a/lib/puppet/functions/validate_bool.rb b/lib/puppet/functions/validate_bool.rb deleted file mode 100644 index a080a4112..000000000 --- a/lib/puppet/functions/validate_bool.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents a boolean. -Puppet::Functions.create_function(:validate_bool) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/parser/functions/validate_bool.rb b/lib/puppet/parser/functions/validate_bool.rb deleted file mode 100644 index 125d26278..000000000 --- a/lib/puppet/parser/functions/validate_bool.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -# -# validate_bool.rb -# -module Puppet::Parser::Functions - newfunction(:validate_bool, doc: <<-DOC - @summary - Validate that all passed values are either true or false. Abort catalog - compilation if any value fails this check. - - @return - validate boolean - - @example **Usage** - - The following values will pass: - - $iamtrue = true - validate_bool(true) - validate_bool(true, true, false, $iamtrue) - - The following values will fail, causing compilation to abort: - - $some_array = [ true ] - validate_bool("false") - validate_bool("true") - validate_bool($some_array) - DOC - ) do |args| - if args.empty? - raise Puppet::ParseError, "validate_bool(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - unless function_is_bool([arg]) - raise Puppet::ParseError, "#{arg.inspect} is not a boolean. It looks to be a #{arg.class}" - end - end - end -end diff --git a/spec/functions/validate_bool_spec.rb b/spec/functions/validate_bool_spec.rb deleted file mode 100644 index ffcf1ba02..000000000 --- a/spec/functions/validate_bool_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_bool' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(true) - end - - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - end - - describe 'acceptable values' do - it { is_expected.to run.with_params(true) } - it { is_expected.to run.with_params(false) } - it { is_expected.to run.with_params(true, false, false, true) } - end - - describe 'validation failures' do - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params(true, 'one').and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params('one', false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params('true').and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params('false').and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params(true, 'false').and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params('true', false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - it { is_expected.to run.with_params('true', false, false, false, false, false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) } - end -end From 140774390c8528c3259ad99f953b8726e06d8b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 08:54:52 -1000 Subject: [PATCH 03/30] Remove deprecated function is_string() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::String. --- lib/puppet/functions/is_string.rb | 29 -------------- lib/puppet/parser/functions/is_string.rb | 36 ----------------- spec/functions/is_string_spec.rb | 49 ------------------------ 3 files changed, 114 deletions(-) delete mode 100644 lib/puppet/functions/is_string.rb delete mode 100644 lib/puppet/parser/functions/is_string.rb delete mode 100644 spec/functions/is_string_spec.rb diff --git a/lib/puppet/functions/is_string.rb b/lib/puppet/functions/is_string.rb deleted file mode 100644 index b36796164..000000000 --- a/lib/puppet/functions/is_string.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_string) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolean] - # A boolean value returned from the called 3.x function. - 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/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb deleted file mode 100644 index 5b4627a45..000000000 --- a/lib/puppet/parser/functions/is_string.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -# -# is_string.rb -# -module Puppet::Parser::Functions - newfunction(:is_string, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the variable passed to this function is a string. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) 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.empty? - - type = arguments[0] - - # when called through the v4 API shim, undef gets translated to nil - result = type.is_a?(String) || type.nil? - - if result && (type == type.to_f.to_s || type == type.to_i.to_s) - return false - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb deleted file mode 100644 index 9a221501c..000000000 --- a/spec/functions/is_string_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_string' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { - pending('Current implementation ignores parameters after the first.') - is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) - } - - it { is_expected.to run.with_params(3).and_return(false) } - it { is_expected.to run.with_params('3').and_return(false) } - it { is_expected.to run.with_params(-3).and_return(false) } - it { is_expected.to run.with_params('-3').and_return(false) } - - it { is_expected.to run.with_params(3.7).and_return(false) } - it { is_expected.to run.with_params('3.7').and_return(false) } - it { is_expected.to run.with_params(-3.7).and_return(false) } - it { is_expected.to run.with_params('-3.7').and_return(false) } - - it { is_expected.to run.with_params(:undef).and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } - it { is_expected.to run.with_params([1]).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params(true).and_return(false) } - it { is_expected.to run.with_params(false).and_return(false) } - it { is_expected.to run.with_params('one').and_return(true) } - it { is_expected.to run.with_params('0001234').and_return(true) } - it { is_expected.to run.with_params('aaa' => 'www.com').and_return(false) } - - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('sponge').and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params('bob').and_return(true) - end - end -end From 7b541a58c98fb726efbf55c9de62017351aaca98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 08:55:17 -1000 Subject: [PATCH 04/30] Remove deprecated function validate_string() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::String. --- lib/puppet/functions/validate_string.rb | 30 ------------ .../parser/functions/validate_string.rb | 49 ------------------- spec/functions/validate_string_spec.rb | 36 -------------- 3 files changed, 115 deletions(-) delete mode 100644 lib/puppet/functions/validate_string.rb delete mode 100644 lib/puppet/parser/functions/validate_string.rb delete mode 100644 spec/functions/validate_string_spec.rb diff --git a/lib/puppet/functions/validate_string.rb b/lib/puppet/functions/validate_string.rb deleted file mode 100644 index a946da94a..000000000 --- a/lib/puppet/functions/validate_string.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate that all passed values are string data structures. -Puppet::Functions.create_function(:validate_string) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb deleted file mode 100644 index 6dd9634b9..000000000 --- a/lib/puppet/parser/functions/validate_string.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -# -# validate_String.rb -# -module Puppet::Parser::Functions - newfunction(:validate_string, doc: <<-DOC - @summary - Validate that all passed values are string data structures - - @return - Validate that all passed values are string data structures. Failed - compilation if any value fails this check. - - @example **Usage** - The following values will pass: - - $my_string = "one two" - validate_string($my_string, 'three') - - The following values will fail, causing compilation to abort: - - 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('...') - } - ``` - DOC - ) do |args| - 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.']) - - if args.empty? - raise Puppet::ParseError, "validate_string(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - # 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 - end -end diff --git a/spec/functions/validate_string_spec.rb b/spec/functions/validate_string_spec.rb deleted file mode 100644 index 515747f84..000000000 --- a/spec/functions/validate_string_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_string' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('', '') - end - - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - describe 'valid inputs' do - it { is_expected.to run.with_params('') } - it { is_expected.to run.with_params(nil) } - it { is_expected.to run.with_params('one') } - it { is_expected.to run.with_params('one', 'two') } - end - - describe 'invalid inputs' do - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('one', 2).and_raise_error(Puppet::ParseError, %r{is not a string}) } - end - end -end From 2f5d950d182fee54d10203e459c9401cad63ac7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:06:12 -1000 Subject: [PATCH 05/30] Remove deprecated function is_numeric() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Numeric. --- lib/puppet/functions/is_numeric.rb | 29 --------- lib/puppet/parser/functions/is_numeric.rb | 76 ----------------------- spec/functions/is_numeric_spec.rb | 49 --------------- 3 files changed, 154 deletions(-) delete mode 100644 lib/puppet/functions/is_numeric.rb delete mode 100644 lib/puppet/parser/functions/is_numeric.rb delete mode 100644 spec/functions/is_numeric_spec.rb diff --git a/lib/puppet/functions/is_numeric.rb b/lib/puppet/functions/is_numeric.rb deleted file mode 100644 index 06fcacc91..000000000 --- a/lib/puppet/functions/is_numeric.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_numeric) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - 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/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb deleted file mode 100644 index a949557a9..000000000 --- a/lib/puppet/parser/functions/is_numeric.rb +++ /dev/null @@ -1,76 +0,0 @@ -# frozen_string_literal: true - -# -# is_numeric.rb -# -module Puppet::Parser::Functions - newfunction(:is_numeric, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the given value is numeric. - - Returns true if the given argument is a Numeric (Integer or Float), - or a String containing either a valid integer in decimal base 10 form, or - a valid floating point string representation. - - The function recognizes only decimal (base 10) integers and float but not - integers in hex (base 16) or octal (base 8) form. - - The string representation may start with a '-' (minus). If a decimal '.' is used, - it must be followed by at least one digit. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) 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 - raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments given #{arguments.size} for 1") - end - - value = arguments[0] - - # Regex is taken from the lexer of puppet - # puppet/pops/parser/lexer.rb but modified to match also - # negative values and disallow invalid octal numbers or - # numbers prefixed with multiple 0's (except in hex numbers) - # - # TODO these parameters should be constants but I'm not sure - # if there is no risk to declare them inside of the module - # Puppet::Parser::Functions - - # TODO: decide if this should be used - # HEX numbers like - # 0xaa230F - # 0X1234009C - # 0x0012 - # -12FcD - # numeric_hex = %r{^-?0[xX][0-9A-Fa-f]+$} - - # TODO: decide if this should be used - # OCTAL numbers like - # 01234567 - # -045372 - # numeric_oct = %r{^-?0[1-7][0-7]*$} - - # Integer/Float numbers like - # -0.1234568981273 - # 47291 - # 42.12345e-12 - numeric = %r{^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$} - - if value.is_a?(Numeric) || (value.is_a?(String) && - value.match(numeric) # or - # value.match(numeric_hex) or - # value.match(numeric_oct) - ) - return true - else - return false - end - end -end diff --git a/spec/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb deleted file mode 100644 index 9c9d9dbf9..000000000 --- a/spec/functions/is_numeric_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_numeric' do - it { is_expected.not_to eq(nil) } - - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - it { is_expected.to run.with_params(3).and_return(true) } - it { is_expected.to run.with_params('3').and_return(true) } - it { is_expected.to run.with_params(-3).and_return(true) } - it { is_expected.to run.with_params('-3').and_return(true) } - - it { is_expected.to run.with_params(3.7).and_return(true) } - it { is_expected.to run.with_params('3.7').and_return(true) } - it { is_expected.to run.with_params(-3.7).and_return(true) } - it { is_expected.to run.with_params('-3.7').and_return(true) } - - it { is_expected.to run.with_params('-342.2315e-12').and_return(true) } - - it { is_expected.to run.with_params('one').and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } - it { is_expected.to run.with_params([1]).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params(true).and_return(false) } - it { is_expected.to run.with_params(false).and_return(false) } - it { is_expected.to run.with_params('0001234').and_return(false) } - it { is_expected.to run.with_params(' - 1234').and_return(false) } - it { is_expected.to run.with_params(['aaa.com', 'bbb', 'ccc']).and_return(false) } - - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(7).and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params(7).and_return(true) - end - end -end From fcee6a70c9a542a65c7821abddea89b4df91bacb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:06:41 -1000 Subject: [PATCH 06/30] Remove deprecated function validate_numeric() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Numeric. --- lib/puppet/functions/validate_numeric.rb | 30 ------ .../parser/functions/validate_numeric.rb | 101 ----------------- spec/functions/validate_numeric_spec.rb | 102 ------------------ 3 files changed, 233 deletions(-) delete mode 100644 lib/puppet/functions/validate_numeric.rb delete mode 100644 lib/puppet/parser/functions/validate_numeric.rb delete mode 100644 spec/functions/validate_numeric_spec.rb diff --git a/lib/puppet/functions/validate_numeric.rb b/lib/puppet/functions/validate_numeric.rb deleted file mode 100644 index c9daa75bc..000000000 --- a/lib/puppet/functions/validate_numeric.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents a numeric value. -Puppet::Functions.create_function(:validate_numeric) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/parser/functions/validate_numeric.rb b/lib/puppet/parser/functions/validate_numeric.rb deleted file mode 100644 index c836e9ed8..000000000 --- a/lib/puppet/parser/functions/validate_numeric.rb +++ /dev/null @@ -1,101 +0,0 @@ -# frozen_string_literal: true - -# -# validate_numeric.rb -# -module Puppet::Parser::Functions - newfunction(:validate_numeric, doc: <<-DOC - @summary - 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. - If, and only if, a minimum is given, the second argument may be an empty string or undef, which will be handled to just check - if (all elements of) the first argument are greater or equal to the given minimum. - It will fail if the first argument is not a numeric (Integer or Float) or array of numerics, and if arg 2 and arg 3 are not convertable to a numeric. - - @return - Validate that the first argument is a numeric value (or an array of numeric values). Fail compilation if any of the checks fail. - - For passing and failing usage, see `validate_integer()`. It is all the same for validate_numeric, yet now floating point values are allowed, too. - - DOC - ) do |args| - 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.empty? && args.length < 4 - - input, max, min = *args - - # check maximum parameter - if args.length > 1 - max = max.to_s - # allow max to be empty (or undefined) if we have a minimum set - if args.length > 2 && max == '' - max = nil - else - begin - max = Float(max) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_numeric(): Expected second argument to be unset or a Numeric, got #{max}:#{max.class}" - end - end - else - max = nil - end - - # check minimum parameter - if args.length > 2 - begin - min = Float(min.to_s) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_numeric(): Expected third argument to be unset or a Numeric, got #{min}:#{min.class}" - end - else - min = nil - end - - # ensure that min < max - if min && max && min > max - raise Puppet::ParseError, "validate_numeric(): Expected second argument to be larger than third argument, got #{max} < #{min}" - end - - # create lamba validator function - validator = ->(num) do - # check input < max - if max && num > max - raise Puppet::ParseError, "validate_numeric(): Expected #{input.inspect} to be smaller or equal to #{max}, got #{input.inspect}." - end - # check input > min (this will only be checked if no exception has been raised before) - if min && num < min - raise Puppet::ParseError, "validate_numeric(): Expected #{input.inspect} to be greater or equal to #{min}, got #{input.inspect}." - end - end - - # if this is an array, handle it. - case input - when Array - # check every element of the array - input.each_with_index do |arg, pos| - raise TypeError if arg.is_a?(Hash) - arg = Float(arg.to_s) - validator.call(arg) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_numeric(): Expected element at array position #{pos} to be a Numeric, got #{arg.class}" - end - # for the sake of compatibility with ruby 1.8, we need extra handling of hashes - when Hash - raise Puppet::ParseError, "validate_integer(): Expected first argument to be a Numeric or Array, got #{input.class}" - # check the input. this will also fail any stuff other than pure, shiny integers - else - begin - input = Float(input.to_s) - validator.call(input) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_numeric(): Expected first argument to be a Numeric or Array, got #{input.class}" - end - end - end -end diff --git a/spec/functions/validate_numeric_spec.rb b/spec/functions/validate_numeric_spec.rb deleted file mode 100644 index 8b593c318..000000000 --- a/spec/functions/validate_numeric_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_numeric' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(3) - end - - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - [true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x'].each do |invalid| - it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) } - it { is_expected.to run.with_params(invalid, 10.0).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) } - it { is_expected.to run.with_params(invalid, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) } - end - - context 'when running on modern rubies', unless: RUBY_VERSION == '1.8.7' do - it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) } - end - - context 'when running on ruby, which munges hashes weirdly', if: RUBY_VERSION == '1.8.7' do - it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } - it { is_expected.to run.with_params([0, 1, 2, { 0 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } - end - - it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, %r{to be unset or a Numeric}) } - it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, %r{to be unset or a Numeric}) } - it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, %r{second argument to be larger than third argument}) } - end - - context 'with no range constraints' do - it { is_expected.to run.with_params(1) } - it { is_expected.to run.with_params(-1) } - it { is_expected.to run.with_params('1') } - it { is_expected.to run.with_params('-1') } - it { is_expected.to run.with_params([1, 2, 3, 4]) } - it { is_expected.to run.with_params([1, '2', '3', 4]) } - end - - context 'with a maximum limit of 10.0' do - describe 'rejects numbers greater than the limit' do - it { is_expected.to run.with_params(11, 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(100, 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(2**65, 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params([1, 2, 10.0, 100], 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - end - - describe 'accepts numbers less or equal to the limit' do - it { is_expected.to run.with_params(10.0, 10.0) } - it { is_expected.to run.with_params(1, 10.0) } - it { is_expected.to run.with_params(-1, 10.0) } - it { is_expected.to run.with_params('1', 10.0) } - it { is_expected.to run.with_params('-1', 10.0) } - it { is_expected.to run.with_params([1, 2, 3, 4], 10.0) } - it { is_expected.to run.with_params([1, '2', '3', 4], 10.0) } - end - end - - context 'with a minimum limit of -10.0' do - describe 'rejects numbers greater than the upper limit' do - it { is_expected.to run.with_params(11, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(100, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(2**65, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params([1, 2, 10.0, 100], 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - end - - describe 'rejects numbers smaller than the lower limit' do - it { is_expected.to run.with_params(-11, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - it { is_expected.to run.with_params(-100, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - it { is_expected.to run.with_params(-2**65, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - it { is_expected.to run.with_params([-10.0, 1, 2, 10.0, -100], 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - end - - describe 'accepts numbers between and including the limits' do - it { is_expected.to run.with_params(10.0, 10.0, -10.0) } - it { is_expected.to run.with_params(-10.0, 10.0, -10.0) } - it { is_expected.to run.with_params(1, 10.0, -10.0) } - it { is_expected.to run.with_params(-1, 10.0, -10.0) } - it { is_expected.to run.with_params('1', 10.0, -10.0) } - it { is_expected.to run.with_params('-1', 10.0, -10.0) } - it { is_expected.to run.with_params([1, 2, 3, 4], 10.0, -10.0) } - it { is_expected.to run.with_params([1, '2', '3', 4], 10.0, -10.0) } - end - end - - it { is_expected.to run.with_params(10.0, 10.0, 10.0) } - - describe 'empty upper limit is interpreted as infinity' do - it { is_expected.to run.with_params(11, '', 10.0) } - end -end From 06e3ec739adcf261cbba2e8263c4436a58a64df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:08:23 -1000 Subject: [PATCH 07/30] Remove deprecated function validate_array() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Array. --- lib/puppet/functions/validate_array.rb | 30 ------------- lib/puppet/parser/functions/validate_array.rb | 42 ------------------- spec/functions/validate_array_spec.rb | 38 ----------------- 3 files changed, 110 deletions(-) delete mode 100644 lib/puppet/functions/validate_array.rb delete mode 100644 lib/puppet/parser/functions/validate_array.rb delete mode 100644 spec/functions/validate_array_spec.rb diff --git a/lib/puppet/functions/validate_array.rb b/lib/puppet/functions/validate_array.rb deleted file mode 100644 index 4287aa8c5..000000000 --- a/lib/puppet/functions/validate_array.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents an array. -Puppet::Functions.create_function(:validate_array) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return - # A boolean value (`true` or `false`) returned from the called function. - 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/parser/functions/validate_array.rb b/lib/puppet/parser/functions/validate_array.rb deleted file mode 100644 index 15cbc4480..000000000 --- a/lib/puppet/parser/functions/validate_array.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -# -# validate_array.rb -# -module Puppet::Parser::Functions - newfunction(:validate_array, doc: <<-DOC) do |args| - @summary - Validate that all passed values are array data structures. Abort catalog - compilation if any value fails this check. - - @return - validate array - - @example **Usage** - The following values will pass: - - $my_array = [ 'one', 'two' ] - validate_array($my_array) - - The following values will fail, causing compilation to abort: - - validate_array(true) - validate_array('some_string') - $undefined = undef - validate_array($undefined) - DOC - - 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.']) - - if args.empty? - raise Puppet::ParseError, "validate_array(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - unless arg.is_a?(Array) - raise Puppet::ParseError, "#{arg.inspect} is not an Array. It looks to be a #{arg.class}" - end - end - end -end diff --git a/spec/functions/validate_array_spec.rb b/spec/functions/validate_array_spec.rb deleted file mode 100644 index da8b093cf..000000000 --- a/spec/functions/validate_array_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_array' do - describe 'signature validation' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - it { is_expected.not_to eq(nil) } - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params([]) - end - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - describe 'valid inputs' do - it { is_expected.to run.with_params([]) } - it { is_expected.to run.with_params(['one']) } - it { is_expected.to run.with_params([], ['two']) } - it { is_expected.to run.with_params(['one'], ['two']) } - end - - describe 'invalid inputs' do - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params([], {}).and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params([], 1).and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params([], true).and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params([], 'one').and_raise_error(Puppet::ParseError, %r{is not an Array}) } - it { is_expected.to run.with_params(nil).and_raise_error(Puppet::ParseError, %r{is not an Array}) } - end - end -end From 7a01dc9e755411d314883b388087719fdc23dc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:10:50 -1000 Subject: [PATCH 08/30] Remove deprecated function is_integer() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Integer. --- lib/puppet/parser/functions/is_integer.rb | 52 ----------------------- spec/functions/is_integer_spec.rb | 48 --------------------- 2 files changed, 100 deletions(-) delete mode 100644 lib/puppet/parser/functions/is_integer.rb delete mode 100644 spec/functions/is_integer_spec.rb diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb deleted file mode 100644 index cdb57719b..000000000 --- a/lib/puppet/parser/functions/is_integer.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -# -# is_integer.rb -# -module Puppet::Parser::Functions - newfunction(:is_integer, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the variable passed to this function is an Integer or - a decimal (base 10) integer in String form. - - The string may start with a '-' (minus). A value of '0' is allowed, but a leading '0' - digit may not be followed by other digits as this indicates that the value is octal (base 8). - - If given any other argument `false` is returned. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) 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 - raise(Puppet::ParseError, "is_integer(): Wrong number of arguments given #{arguments.size} for 1") - end - - value = arguments[0] - - # Regex is taken from the lexer of puppet - # puppet/pops/parser/lexer.rb but modified to match also - # negative values and disallow numbers prefixed with multiple - # 0's - # - # TODO these parameter should be a constant but I'm not sure - # if there is no risk to declare it inside of the module - # Puppet::Parser::Functions - - # Integer numbers like - # -1234568981273 - # 47291 - numeric = %r{^-?(?:(?:[1-9]\d*)|0)$} - - return true if value.is_a?(Integer) || (value.is_a?(String) && value.match(numeric)) - return false - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb deleted file mode 100644 index 1de12c9c5..000000000 --- a/spec/functions/is_integer_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_integer' do - it { is_expected.not_to eq(nil) } - - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - it { is_expected.to run.with_params(3).and_return(true) } - it { is_expected.to run.with_params('3').and_return(true) } - it { is_expected.to run.with_params(-3).and_return(true) } - it { is_expected.to run.with_params('-3').and_return(true) } - it { is_expected.to run.with_params("123\nfoo").and_return(true) } - it { is_expected.to run.with_params("foo\n123").and_return(true) } - - it { is_expected.to run.with_params(3.7).and_return(false) } - it { is_expected.to run.with_params('3.7').and_return(false) } - it { is_expected.to run.with_params(-3.7).and_return(false) } - it { is_expected.to run.with_params('-3.7').and_return(false) } - - it { is_expected.to run.with_params('one').and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } - it { is_expected.to run.with_params([1]).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params(true).and_return(false) } - it { is_expected.to run.with_params(false).and_return(false) } - it { is_expected.to run.with_params('0001234').and_return(false) } - it { is_expected.to run.with_params("foo\nbar").and_return(false) } - - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(50).and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params(50).and_return(true) - end - end -end From 10b68539f65ce7e89657c7e2948f97b71a317890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:10:16 -1000 Subject: [PATCH 09/30] Remove deprecated function validate_integer() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Integer. --- lib/puppet/functions/validate_integer.rb | 30 ---- .../parser/functions/validate_integer.rb | 141 ------------------ spec/functions/validate_integer_spec.rb | 103 ------------- 3 files changed, 274 deletions(-) delete mode 100644 lib/puppet/functions/validate_integer.rb delete mode 100644 lib/puppet/parser/functions/validate_integer.rb delete mode 100644 spec/functions/validate_integer_spec.rb diff --git a/lib/puppet/functions/validate_integer.rb b/lib/puppet/functions/validate_integer.rb deleted file mode 100644 index ae8e90f3f..000000000 --- a/lib/puppet/functions/validate_integer.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents an integer. -Puppet::Functions.create_function(:validate_integer) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/parser/functions/validate_integer.rb b/lib/puppet/parser/functions/validate_integer.rb deleted file mode 100644 index f1e8be4d6..000000000 --- a/lib/puppet/parser/functions/validate_integer.rb +++ /dev/null @@ -1,141 +0,0 @@ -# frozen_string_literal: true - -# -# validate_interger.rb -# -module Puppet::Parser::Functions - newfunction(:validate_integer, doc: <<-DOC - @summary - 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. - If, and only if, a minimum is given, the second argument may be an empty string or undef, which will be handled to just check - if (all elements of) the first argument are greater or equal to the given minimum. - It will fail if the first argument is not an integer or array of integers, and if arg 2 and arg 3 are not convertable to an integer. - - @return - Validate that the first argument is an integer (or an array of integers). Fail compilation if any of the checks fail. - - @example **Usage** - - The following values will pass: - - validate_integer(1) - validate_integer(1, 2) - validate_integer(1, 1) - validate_integer(1, 2, 0) - validate_integer(2, 2, 2) - validate_integer(2, '', 0) - validate_integer(2, undef, 0) - $foo = undef - validate_integer(2, $foo, 0) - validate_integer([1,2,3,4,5], 6) - validate_integer([1,2,3,4,5], 6, 0) - - Plus all of the above, but any combination of values passed as strings ('1' or "1"). - Plus all of the above, but with (correct) combinations of negative integer values. - - The following values will not: - - validate_integer(true) - validate_integer(false) - validate_integer(7.0) - validate_integer({ 1 => 2 }) - $foo = undef - validate_integer($foo) - validate_integer($foobaridontexist) - - validate_integer(1, 0) - validate_integer(1, true) - validate_integer(1, '') - validate_integer(1, undef) - validate_integer(1, , 0) - validate_integer(1, 2, 3) - validate_integer(1, 3, 2) - validate_integer(1, 3, true) - - Plus all of the above, but any combination of values passed as strings ('false' or "false"). - Plus all of the above, but with incorrect combinations of negative integer values. - Plus all of the above, but with non-integer items in arrays or maximum / minimum argument. - - DOC - ) do |args| - 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.empty? && args.length < 4 - - input, max, min = *args - - # check maximum parameter - if args.length > 1 - max = max.to_s - # allow max to be empty (or undefined) if we have a minimum set - if args.length > 2 && max == '' - max = nil - else - begin - max = Integer(max) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_integer(): Expected second argument to be unset or an Integer, got #{max}:#{max.class}" - end - end - else - max = nil - end - - # check minimum parameter - if args.length > 2 - begin - min = Integer(min.to_s) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_integer(): Expected third argument to be unset or an Integer, got #{min}:#{min.class}" - end - else - min = nil - end - - # ensure that min < max - if min && max && min > max - raise Puppet::ParseError, "validate_integer(): Expected second argument to be larger than third argument, got #{max} < #{min}" - end - - # create lamba validator function - validator = ->(num) do - # check input < max - if max && num > max - raise Puppet::ParseError, "validate_integer(): Expected #{input.inspect} to be smaller or equal to #{max}, got #{input.inspect}." - end - # check input > min (this will only be checked if no exception has been raised before) - if min && num < min - raise Puppet::ParseError, "validate_integer(): Expected #{input.inspect} to be greater or equal to #{min}, got #{input.inspect}." - end - end - - # if this is an array, handle it. - case input - when Array - # check every element of the array - input.each_with_index do |arg, pos| - raise TypeError if arg.is_a?(Hash) - arg = Integer(arg.to_s) - validator.call(arg) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_integer(): Expected element at array position #{pos} to be an Integer, got #{arg.class}" - end - # for the sake of compatibility with ruby 1.8, we need extra handling of hashes - when Hash - raise Puppet::ParseError, "validate_integer(): Expected first argument to be an Integer or Array, got #{input.class}" - # check the input. this will also fail any stuff other than pure, shiny integers - else - begin - input = Integer(input.to_s) - validator.call(input) - rescue TypeError, ArgumentError - raise Puppet::ParseError, "validate_integer(): Expected first argument to be an Integer or Array, got #{input.class}" - end - end - end -end diff --git a/spec/functions/validate_integer_spec.rb b/spec/functions/validate_integer_spec.rb deleted file mode 100644 index 6252a6dc7..000000000 --- a/spec/functions/validate_integer_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_integer' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(3) - end - - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - [true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', 7.0, -7.0, {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x'].each do |invalid| - it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{to be an Integer}) } - it { is_expected.to run.with_params(invalid, 10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) } - it { is_expected.to run.with_params(invalid, 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) } - it { is_expected.to run.with_params([0, 1, 2, invalid, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) } - end - - context 'when running on modern rubies', unless: RUBY_VERSION == '1.8.7' do - it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) } - end - - context 'when running on ruby, which munges hashes weirdly', if: RUBY_VERSION == '1.8.7' do - it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } - it { is_expected.to run.with_params([0, 1, 2, { 0 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } - end - - it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, %r{to be unset or an Integer}) } - it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, %r{to be unset or an Integer}) } - it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, %r{second argument to be larger than third argument}) } - end - - context 'with no range constraints' do - it { is_expected.to run.with_params(1) } - it { is_expected.to run.with_params(-1) } - it { is_expected.to run.with_params('1') } - it { is_expected.to run.with_params('-1') } - it { is_expected.to run.with_params([1, 2, 3, 4]) } - it { is_expected.to run.with_params([1, '2', '3', 4]) } - end - - context 'with a maximum limit of 10' do - describe 'rejects numbers greater than the limit' do - it { is_expected.to run.with_params(11, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(100, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(2**65, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params([1, 2, 10, 100], 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - end - - describe 'accepts numbers less or equal to the limit' do - it { is_expected.to run.with_params(10, 10) } - it { is_expected.to run.with_params(1, 10) } - it { is_expected.to run.with_params(-1, 10) } - it { is_expected.to run.with_params('1', 10) } - it { is_expected.to run.with_params('-1', 10) } - it { is_expected.to run.with_params([1, 2, 3, 4], 10) } - it { is_expected.to run.with_params([1, '2', '3', 4], 10) } - end - end - - context 'with a minimum limit of -10' do - describe 'rejects numbers greater than the upper limit' do - it { is_expected.to run.with_params(11, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(100, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params(2**65, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - it { is_expected.to run.with_params([1, 2, 10, 100], 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) } - end - - describe 'rejects numbers smaller than the lower limit' do - it { is_expected.to run.with_params(-11, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - it { is_expected.to run.with_params(-100, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - it { is_expected.to run.with_params(-2**65, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - it { is_expected.to run.with_params([-10, 1, 2, 10, -100], 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) } - end - - describe 'accepts numbers between and including the limits' do - it { is_expected.to run.with_params(10, 10, -10) } - it { is_expected.to run.with_params(-10, 10, -10) } - it { is_expected.to run.with_params(1, 10, -10) } - it { is_expected.to run.with_params(-1, 10, -10) } - it { is_expected.to run.with_params('1', 10, -10) } - it { is_expected.to run.with_params('-1', 10, -10) } - it { is_expected.to run.with_params([1, 2, 3, 4], 10, -10) } - it { is_expected.to run.with_params([1, '2', '3', 4], 10, -10) } - end - end - - it { is_expected.to run.with_params(10, 10, 10) } - - describe 'empty upper limit is interpreted as infinity' do - it { is_expected.to run.with_params(11, '', 10) } - end -end From 52365f15f84abb620d6b8624c13be91637612db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:11:31 -1000 Subject: [PATCH 10/30] Remove deprecated function is_hash() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Hash. --- lib/puppet/parser/functions/is_hash.rb | 28 -------------------------- spec/functions/is_hash_spec.rb | 14 ------------- 2 files changed, 42 deletions(-) delete mode 100644 lib/puppet/parser/functions/is_hash.rb delete mode 100644 spec/functions/is_hash_spec.rb diff --git a/lib/puppet/parser/functions/is_hash.rb b/lib/puppet/parser/functions/is_hash.rb deleted file mode 100644 index 812ff8844..000000000 --- a/lib/puppet/parser/functions/is_hash.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -# -# is_hash.rb -# -module Puppet::Parser::Functions - newfunction(:is_hash, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the variable passed to this function is a hash. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - raise(Puppet::ParseError, "is_hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 - - type = arguments[0] - - result = type.is_a?(Hash) - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_hash_spec.rb b/spec/functions/is_hash_spec.rb deleted file mode 100644 index 126535db6..000000000 --- a/spec/functions/is_hash_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_hash' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('').and_return(false) } - it { is_expected.to run.with_params({}).and_return(true) } - it { is_expected.to run.with_params([]).and_return(false) } - it { is_expected.to run.with_params(1).and_return(false) } - it { is_expected.to run.with_params([{ 'aaa' => 'bbb' }]).and_return(false) } -end From f8c69d2556edbcb3ceac230d7b9ccfde51cdfa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:07:21 -1000 Subject: [PATCH 11/30] Remove deprecated function is_float() > This method is deprecated, please use match expressions with > Stdlib::Compat::Float instead. --- lib/puppet/functions/is_float.rb | 29 ------------------- lib/puppet/parser/functions/is_float.rb | 35 ----------------------- spec/functions/is_float_spec.rb | 38 ------------------------- 3 files changed, 102 deletions(-) delete mode 100644 lib/puppet/functions/is_float.rb delete mode 100644 lib/puppet/parser/functions/is_float.rb delete mode 100644 spec/functions/is_float_spec.rb diff --git a/lib/puppet/functions/is_float.rb b/lib/puppet/functions/is_float.rb deleted file mode 100644 index 408970b25..000000000 --- a/lib/puppet/functions/is_float.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_float) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - 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/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb deleted file mode 100644 index c44746b5e..000000000 --- a/lib/puppet/parser/functions/is_float.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -# -# is_float.rb -# -module Puppet::Parser::Functions - newfunction(:is_float, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the variable passed to this function is a float. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) 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 - raise(Puppet::ParseError, "is_float(): Wrong number of arguments given #{arguments.size} for 1") - end - - value = arguments[0] - - # Only allow Numeric or String types - return false unless value.is_a?(Numeric) || value.is_a?(String) - - return false if value != value.to_f.to_s && !value.is_a?(Float) - return true - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb deleted file mode 100644 index e80dc4cea..000000000 --- a/spec/functions/is_float_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_float' do - it { is_expected.not_to eq(nil) } - - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(0.1, 0.2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('0.1').and_return(true) } - it { is_expected.to run.with_params('1.0').and_return(true) } - it { is_expected.to run.with_params('1').and_return(false) } - it { is_expected.to run.with_params('one').and_return(false) } - it { is_expected.to run.with_params('one 1.0').and_return(false) } - it { is_expected.to run.with_params('1.0 one').and_return(false) } - it { is_expected.to run.with_params(0.1).and_return(true) } - it { is_expected.to run.with_params(1.0).and_return(true) } - it { is_expected.to run.with_params(1).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } - - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(2.2).and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params(1.0).and_return(true) - end - end -end From 890ea129d06cb76262a2dca42a5e8dd5a8d9fc73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:11:50 -1000 Subject: [PATCH 12/30] Remove deprecated function validate_hash() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Hash. --- lib/puppet/functions/validate_hash.rb | 30 -------------- lib/puppet/parser/functions/validate_hash.rb | 43 -------------------- spec/functions/validate_hash_spec.rb | 41 ------------------- 3 files changed, 114 deletions(-) delete mode 100644 lib/puppet/functions/validate_hash.rb delete mode 100644 lib/puppet/parser/functions/validate_hash.rb delete mode 100644 spec/functions/validate_hash_spec.rb diff --git a/lib/puppet/functions/validate_hash.rb b/lib/puppet/functions/validate_hash.rb deleted file mode 100644 index 77370e20b..000000000 --- a/lib/puppet/functions/validate_hash.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents a hash. -Puppet::Functions.create_function(:validate_hash) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return - # A boolean value (`true` or `false`) returned from the called function. - 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/parser/functions/validate_hash.rb b/lib/puppet/parser/functions/validate_hash.rb deleted file mode 100644 index c34f1e4bc..000000000 --- a/lib/puppet/parser/functions/validate_hash.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -# -# validate_hash.rb -# -module Puppet::Parser::Functions - newfunction(:validate_hash, doc: <<-DOC - @summary - Validate that all passed values are hash data structures. Abort catalog - compilation if any value fails this check. - - @return - validate hash - - @example **Usage** - - The following values will pass: - - $my_hash = { 'one' => 'two' } - validate_hash($my_hash) - - The following values will fail, causing compilation to abort: - - validate_hash(true) - validate_hash('some_string') - $undefined = undef - validate_hash($undefined) - DOC - ) do |args| - 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.']) - - if args.empty? - raise Puppet::ParseError, "validate_hash(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - unless arg.is_a?(Hash) - raise Puppet::ParseError, "#{arg.inspect} is not a Hash. It looks to be a #{arg.class}" - end - end - end -end diff --git a/spec/functions/validate_hash_spec.rb b/spec/functions/validate_hash_spec.rb deleted file mode 100644 index 89fe882ea..000000000 --- a/spec/functions/validate_hash_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_hash' do - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - describe 'check for deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('key' => 'value') - end - end - - describe 'valid inputs' do - it { is_expected.to run.with_params({}) } - it { is_expected.to run.with_params('key' => 'value') } - it { is_expected.to run.with_params({}, 'key' => 'value') } - it { is_expected.to run.with_params({ 'key1' => 'value1' }, 'key2' => 'value2') } - end - - describe 'invalid inputs' do - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params({}, []).and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params({}, true).and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params({}, 'one').and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - it { is_expected.to run.with_params("{ 'number' => 'one' }").and_raise_error(Puppet::ParseError, %r{is not a Hash}) } - end - end -end From 9d38434bd0f47168a9ffb4ac1cacffce0e07f386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:18:56 -1000 Subject: [PATCH 13/30] Remove deprecated function absolute_path() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Absolute_path. --- .../functions/validate_absolute_path.rb | 30 --------- .../functions/validate_absolute_path.rb | 61 ------------------- spec/type_aliases/absolute_path_spec.rb | 39 ------------ 3 files changed, 130 deletions(-) delete mode 100644 lib/puppet/functions/validate_absolute_path.rb delete mode 100644 lib/puppet/parser/functions/validate_absolute_path.rb delete mode 100644 spec/type_aliases/absolute_path_spec.rb diff --git a/lib/puppet/functions/validate_absolute_path.rb b/lib/puppet/functions/validate_absolute_path.rb deleted file mode 100644 index 9121cbbb6..000000000 --- a/lib/puppet/functions/validate_absolute_path.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the string represents an absolute path in the filesystem. -Puppet::Functions.create_function(:validate_absolute_path) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] - # A boolean value returned from the called function. - 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/parser/functions/validate_absolute_path.rb b/lib/puppet/parser/functions/validate_absolute_path.rb deleted file mode 100644 index e0ea72b4c..000000000 --- a/lib/puppet/parser/functions/validate_absolute_path.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -# -# validate_absolute_path.rb -# -module Puppet::Parser::Functions - newfunction(:validate_absolute_path, doc: <<-DOC) do |args| - @summary - Validate the string represents an absolute path in the filesystem. This function works - for windows and unix style paths. - - @return - passes when the string is an absolute path or raise an error when it is not and fails compilation - - @example **Usage** - - The following values will pass: - - $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet' - validate_absolute_path($my_path) - $my_path2 = '/var/lib/puppet' - validate_absolute_path($my_path2) - $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet','C:/Program Files/Puppet Labs/Puppet'] - validate_absolute_path($my_path3) - $my_path4 = ['/var/lib/puppet','/usr/share/puppet'] - validate_absolute_path($my_path4) - - The following values will fail, causing compilation to abort: - - validate_absolute_path(true) - validate_absolute_path('../var/lib/puppet') - validate_absolute_path('var/lib/puppet') - validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) - validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) - $undefined = undef - validate_absolute_path($undefined) - DOC - - require 'puppet/util' - - if args.empty? - raise Puppet::ParseError, "validate_absolute_path(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - # put arg to candidate var to be able to replace it - candidates = arg - # if arg is just a string with a path to test, convert it to an array - # to avoid test code duplication - unless arg.is_a?(Array) - candidates = Array.new(1, arg) - end - # iterate over all paths within the candidates array - candidates.each do |path| - unless function_is_absolute_path([path]) - raise Puppet::ParseError, "#{path.inspect} is not an absolute path." - end - end - end - end -end diff --git a/spec/type_aliases/absolute_path_spec.rb b/spec/type_aliases/absolute_path_spec.rb deleted file mode 100644 index b4c9ca460..000000000 --- a/spec/type_aliases/absolute_path_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Absolute_path' do - describe 'valid paths handling' do - ['C:/', 'C:\\', 'C:\\WINDOWS\\System32', 'C:/windows/system32', 'X:/foo/bar', 'X:\\foo\\bar', '\\\\host\\windows', '//host/windows', '/', '/var/tmp', '/var/opt/../lib/puppet', - '/var/opt//lib/puppet', '/var/ůťƒ8', '/var/ネット'].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'invalid path handling' do - context 'with garbage inputs' do - [ - nil, - [nil], - [nil, nil], - { 'foo' => 'bar' }, - {}, - '', - ].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end - - context 'with relative paths' do - ['relative1', '.', '..', './foo', '../foo', 'etc/puppetlabs/puppet', 'opt/puppet/bin', 'relative\\windows', '\\var\\ůťƒ8', '\\var\\ネット'].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end - end -end From 38b479f6920070f3d3a46391aed830b48e348b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:19:35 -1000 Subject: [PATCH 14/30] Remove deprecated function validate_re() > This method is deprecated, please use the stdlib validate_legacy > function, with Stdlib::Compat::Re. --- lib/puppet/functions/validate_re.rb | 35 ------------- lib/puppet/parser/functions/validate_re.rb | 60 ---------------------- spec/functions/validate_re_spec.rb | 58 --------------------- 3 files changed, 153 deletions(-) delete mode 100644 lib/puppet/functions/validate_re.rb delete mode 100644 lib/puppet/parser/functions/validate_re.rb delete mode 100644 spec/functions/validate_re_spec.rb diff --git a/lib/puppet/functions/validate_re.rb b/lib/puppet/functions/validate_re.rb deleted file mode 100644 index eaea9b6d8..000000000 --- a/lib/puppet/functions/validate_re.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Perform validation of a string against one or more regular -# expressions. -# -Puppet::Functions.create_function(:validate_re) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # The first argument of this function should be a string to - # test, and the second argument should be a stringified regular expression - # (without the // delimiters) or an array of regular expressions - # - # @return [Boolean] - # `true` or `false` returned from the called function. - 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/parser/functions/validate_re.rb b/lib/puppet/parser/functions/validate_re.rb deleted file mode 100644 index f11628004..000000000 --- a/lib/puppet/parser/functions/validate_re.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -# -# validate.rb -# -module Puppet::Parser::Functions - newfunction(:validate_re, doc: <<-DOC - @summary - Perform simple validation of a string against one or more regular - expressions. - - The first argument of this function should be a string to - test, and the second argument should be a stringified regular expression - (without the // delimiters) or an array of regular expressions. If none - of the regular expressions match the string passed in, compilation will - abort with a parse error. - If a third argument is specified, this will be the error message raised and - seen by the user. - - @return - validation of a string against one or more regular expressions. - - @example **Usage** - The following strings will validate against the regular expressions: - - validate_re('one', '^one$') - validate_re('one', [ '^one', '^two' ]) - - The following strings will fail to validate, causing compilation to abort: - - validate_re('one', [ '^two', '^three' ]) - - A helpful error message can be returned like this: - - validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') - - > *Note:* - Compilation will also abort, if the first argument is not a String. Always use - quotes to force stringification: - validate_re("${::operatingsystemmajrelease}", '^[57]$') - DOC - ) do |args| - 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) || (args.length > 3) - raise Puppet::ParseError, "validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)" - end - - raise Puppet::ParseError, "validate_re(): input needs to be a String, not a #{args[0].class}" unless args[0].is_a? String - - msg = args[2] || "validate_re(): #{args[0].inspect} does not match #{args[1].inspect}" - - # We're using a flattened array here because we can't call String#any? in - # Ruby 1.9 like we can in Ruby 1.8 - raise Puppet::ParseError, msg unless [args[1]].flatten.any? do |re_str| - args[0] =~ Regexp.compile(re_str) - end - end -end diff --git a/spec/functions/validate_re_spec.rb b/spec/functions/validate_re_spec.rb deleted file mode 100644 index bfa824e6e..000000000 --- a/spec/functions/validate_re_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_re' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('', '') - end - - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - describe 'valid inputs' do - it { is_expected.to run.with_params('', '') } - it { is_expected.to run.with_params('', ['']) } - it { is_expected.to run.with_params('', [''], 'custom error') } - it { is_expected.to run.with_params('one', '^one') } - it { is_expected.to run.with_params('one', ['^one', '^two']) } - it { is_expected.to run.with_params('one', ['^one', '^two'], 'custom error') } - end - - describe 'invalid inputs' do - it { is_expected.to run.with_params('', []).and_raise_error(Puppet::ParseError, %r{does not match}) } - it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) } - it { is_expected.to run.with_params('', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) } - it { is_expected.to run.with_params('', ['two']).and_raise_error(Puppet::ParseError, %r{does not match}) } - it { is_expected.to run.with_params('', ['two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) } - it { is_expected.to run.with_params('notone', '^one').and_raise_error(Puppet::ParseError, %r{does not match}) } - it { is_expected.to run.with_params('notone', ['^one', '^two']).and_raise_error(Puppet::ParseError, %r{does not match}) } - it { is_expected.to run.with_params('notone', ['^one', '^two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) } - end - - describe 'non-string inputs' do - [ - 1, # Fixnum - 3.14, # Float - nil, # NilClass - true, # TrueClass - false, # FalseClass - ['10'], # Array - :key, # Symbol - { key: 'val' }, # Hash - ].each do |input| - it { is_expected.to run.with_params(input, '.*').and_raise_error(Puppet::ParseError, %r{needs to be a String}) } - end - end - end -end From e66c5856c1d7aefdfaed04dfb768112214c6b430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:20:23 -1000 Subject: [PATCH 15/30] Remove deprecated function validate_slength() > This method is deprecated, please use the stdlib validate_legacy > function, with String. --- lib/puppet/functions/validate_slength.rb | 29 ------- .../parser/functions/validate_slength.rb | 76 ----------------- spec/functions/validate_slength_spec.rb | 83 ------------------- 3 files changed, 188 deletions(-) delete mode 100644 lib/puppet/functions/validate_slength.rb delete mode 100644 lib/puppet/parser/functions/validate_slength.rb delete mode 100644 spec/functions/validate_slength_spec.rb diff --git a/lib/puppet/functions/validate_slength.rb b/lib/puppet/functions/validate_slength.rb deleted file mode 100644 index f34e705b9..000000000 --- a/lib/puppet/functions/validate_slength.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# Validate that a passed string has length less/equal with the passed value -Puppet::Functions.create_function(:validate_slength) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/parser/functions/validate_slength.rb b/lib/puppet/parser/functions/validate_slength.rb deleted file mode 100644 index f6a31a25a..000000000 --- a/lib/puppet/parser/functions/validate_slength.rb +++ /dev/null @@ -1,76 +0,0 @@ -# frozen_string_literal: true - -# -# validate_slength.rb -# -module Puppet::Parser::Functions - newfunction(:validate_slength, doc: <<-DOC - @summary - Validate that the first argument is a string (or an array of strings), and less/equal to than the length of the second argument. - - An optional third parameter can be given the minimum length. It fails if the first argument is not a string or array of strings, - and if arg 2 and arg 3 are not convertable to a number. - - @return - validate that the first argument is a string (or an array of strings), and less/equal to than the length of the second argument. Fail compilation if any of the checks fail. - - @example **Usage** - The following values will pass: - - validate_slength("discombobulate",17) - validate_slength(["discombobulate","moo"],17) - validate_slength(["discombobulate","moo"],17,3) - - The following valueis will not: - - validate_slength("discombobulate",1) - validate_slength(["discombobulate","thermometer"],5) - validate_slength(["discombobulate","moo"],17,10) - DOC - ) do |args| - 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 || args.length == 3 - - input, max_length, min_length = *args - - begin - max_length = Integer(max_length) - raise ArgumentError if max_length <= 0 - rescue ArgumentError, TypeError - raise Puppet::ParseError, "validate_slength(): Expected second argument to be a positive Numeric, got #{max_length}:#{max_length.class}" - end - - if min_length - begin - min_length = Integer(min_length) - raise ArgumentError if min_length < 0 - rescue ArgumentError, TypeError - raise Puppet::ParseError, "validate_slength(): Expected third argument to be unset or a positive Numeric, got #{min_length}:#{min_length.class}" - end - else - min_length = 0 - end - - raise Puppet::ParseError, 'validate_slength(): Expected second argument to be equal to or larger than third argument' unless max_length >= min_length - - validator = ->(str) do - unless str.length <= max_length && str.length >= min_length - raise Puppet::ParseError, "validate_slength(): Expected length of #{input.inspect} to be between #{min_length} and #{max_length}, was #{input.length}" - end - end - - case input - when String - validator.call(input) - when Array - input.each_with_index do |arg, pos| - raise Puppet::ParseError, "validate_slength(): Expected element at array position #{pos} to be a String, got #{arg.class}" unless arg.is_a? String - validator.call(arg) - end - else - raise Puppet::ParseError, "validate_slength(): Expected first argument to be a String or Array, got #{input.class}" - end - end -end diff --git a/spec/functions/validate_slength_spec.rb b/spec/functions/validate_slength_spec.rb deleted file mode 100644 index 6ff44c737..000000000 --- a/spec/functions/validate_slength_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_slength' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('1234567890', 10) - end - - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('', 2, 3, 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{second argument to be a positive Numeric}) } - it { is_expected.to run.with_params('', -1).and_raise_error(Puppet::ParseError, %r{second argument to be a positive Numeric}) } - it { is_expected.to run.with_params('', 1, '').and_raise_error(Puppet::ParseError, %r{third argument to be unset or a positive Numeric}) } - it { is_expected.to run.with_params('', 1, -1).and_raise_error(Puppet::ParseError, %r{third argument to be unset or a positive Numeric}) } - it { is_expected.to run.with_params('', 1, 2).and_raise_error(Puppet::ParseError, %r{argument to be equal to or larger than third argument}) } - end - - context 'with a maximum length of 10' do - describe 'rejects strings longer than the limit' do - it { is_expected.to run.with_params('1234567890a', 10).and_raise_error(Puppet::ParseError, %r{Expected length}) } - it { is_expected.to run.with_params('1234567890abcdef', 10).and_raise_error(Puppet::ParseError, %r{Expected length}) } - it { is_expected.to run.with_params(['one', '1234567890abcdef'], 10).and_raise_error(Puppet::ParseError, %r{Expected length}) } - end - - describe 'accepts strings shorter or equal to the limit' do - it { is_expected.to run.with_params('1234567890', 10) } - it { is_expected.to run.with_params('12345', 10) } - it { is_expected.to run.with_params(['one', 'two'], 10) } - end - end - - context 'with a minimum length of 5' do - describe 'rejects strings longer than the upper limit' do - it { is_expected.to run.with_params('1234567890a', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) } - it { is_expected.to run.with_params('1234567890abcdef', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) } - end - - describe 'rejects numbers shorter than the lower limit' do - it { is_expected.to run.with_params('one', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) } - it { is_expected.to run.with_params(['12345678', 'two'], 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) } - end - - describe 'accepts strings of length between and including the limits' do - it { is_expected.to run.with_params('12345', 10, 5) } - it { is_expected.to run.with_params('123456', 10, 5) } - it { is_expected.to run.with_params('1234567', 10, 5) } - it { is_expected.to run.with_params('12345678', 10, 5) } - it { is_expected.to run.with_params('123456789', 10, 5) } - it { is_expected.to run.with_params('1234567890', 10, 5) } - it { is_expected.to run.with_params(['1233456', '12345678'], 10, 5) } - end - end - - describe 'corner cases' do - it { - pending('this should work') - is_expected.to run.with_params('', 0, 0) - } - it { is_expected.to run.with_params('1234567890', 10, 10) } - end - - describe 'empty upper limit is interpreted as infinity' do - it { - pending('not implemented') - is_expected.to run.with_params('1234567890ab', '', 10) - } - it { - pending('not implemented') - is_expected.to run.with_params('12345678', '', 10).and_raise_error(Puppet::ParseError, %r{Expected length}) - } - end -end From a4df1095b0a3ff59f4726a01890cd04bb1e54c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:21:04 -1000 Subject: [PATCH 16/30] Remove deprecated function is_ipv6_address() > This method is deprecated, please use match expressions with > Stdlib::Compat::Ipv6 --- lib/puppet/functions/is_ipv6_address.rb | 29 --------------- .../parser/functions/is_ipv6_address.rb | 37 ------------------- spec/functions/is_ipv6_address_spec.rb | 32 ---------------- 3 files changed, 98 deletions(-) delete mode 100644 lib/puppet/functions/is_ipv6_address.rb delete mode 100644 lib/puppet/parser/functions/is_ipv6_address.rb delete mode 100644 spec/functions/is_ipv6_address_spec.rb diff --git a/lib/puppet/functions/is_ipv6_address.rb b/lib/puppet/functions/is_ipv6_address.rb deleted file mode 100644 index 7833960f6..000000000 --- a/lib/puppet/functions/is_ipv6_address.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_ipv6_address) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - 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/parser/functions/is_ipv6_address.rb b/lib/puppet/parser/functions/is_ipv6_address.rb deleted file mode 100644 index abb79df58..000000000 --- a/lib/puppet/parser/functions/is_ipv6_address.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# -# is_ipv6_address.rb -# -module Puppet::Parser::Functions - newfunction(:is_ipv6_address, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the string passed to this function is a valid IPv6 address. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) 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 - raise(Puppet::ParseError, "is_ipv6_address(): Wrong number of arguments given #{arguments.size} for 1") - end - - begin - ip = IPAddr.new(arguments[0]) - rescue ArgumentError - return false - end - - return ip.ipv6? - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_ipv6_address_spec.rb b/spec/functions/is_ipv6_address_spec.rb deleted file mode 100644 index 39171336d..000000000 --- a/spec/functions/is_ipv6_address_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_ipv6_address' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) } - it { is_expected.to run.with_params('85a3:0000:0000:8a2e:0370:7334:100.100.100.100').and_return(true) } - it { is_expected.to run.with_params('1.2.3').and_return(false) } - it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) } - it { is_expected.to run.with_params('').and_return(false) } - it { is_expected.to run.with_params('one').and_return(false) } - it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334:ggg').and_return(false) } - - context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) - end - end -end From 41feb34ac80f5dc6ec24d3d1e387ee1b3fd7e2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 09:21:27 -1000 Subject: [PATCH 17/30] Remove deprecated function validate_ipv6_address() > This method is deprecated, please use the stdlib validate_legacy function, > with Stdlib::Compat::Ipv6. --- lib/puppet/functions/validate_ipv6_address.rb | 30 --------- .../parser/functions/validate_ipv6_address.rb | 58 ------------------ spec/functions/validate_ipv6_address_spec.rb | 61 ------------------- 3 files changed, 149 deletions(-) delete mode 100644 lib/puppet/functions/validate_ipv6_address.rb delete mode 100644 lib/puppet/parser/functions/validate_ipv6_address.rb delete mode 100644 spec/functions/validate_ipv6_address_spec.rb diff --git a/lib/puppet/functions/validate_ipv6_address.rb b/lib/puppet/functions/validate_ipv6_address.rb deleted file mode 100644 index 540842b48..000000000 --- a/lib/puppet/functions/validate_ipv6_address.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents an ipv6_address. -Puppet::Functions.create_function(:validate_ipv6_address) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/parser/functions/validate_ipv6_address.rb b/lib/puppet/parser/functions/validate_ipv6_address.rb deleted file mode 100644 index 009efef9b..000000000 --- a/lib/puppet/parser/functions/validate_ipv6_address.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -# -# validate_ipv6_address.rb -# -module Puppet::Parser::Functions - newfunction(:validate_ipv6_address, doc: <<-DOC - @summary - Validate that all values passed are valid IPv6 addresses. - Fail compilation if any value fails this check. - - @return - passes when the given values are valid IPv6 addresses or raise an error when they are not and fails compilation - - @example **Usage** - The following values will pass: - - $my_ip = "3ffe:505:2" - validate_ipv6_address(1) - validate_ipv6_address($my_ip) - validate_bool("fe80::baf6:b1ff:fe19:7507", $my_ip) - - The following values will fail, causing compilation to abort: - - $some_array = [ true, false, "garbage string", "1.2.3.4" ] - validate_ipv6_address($some_array) - - DOC - ) 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] - - if defined?(IPAddr::InvalidAddressError) - rescuable_exceptions << IPAddr::InvalidAddressError - end - - if args.empty? - raise Puppet::ParseError, "validate_ipv6_address(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - unless arg.is_a?(String) - raise Puppet::ParseError, "#{arg.inspect} is not a string." - end - - begin - unless IPAddr.new(arg).ipv6? - raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address." - end - rescue *rescuable_exceptions - raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address." - end - end - end -end diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb deleted file mode 100644 index 3e1563ed1..000000000 --- a/spec/functions/validate_ipv6_address_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_ipv6_address' do - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - end - - context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('3ffe:0505:0002::') - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params('3ffe:0505:0002::') - end - end - - describe 'valid inputs' do - it { is_expected.to run.with_params('3ffe:0505:0002::') } - it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } - it { is_expected.to run.with_params('::1/64') } - it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } - it { is_expected.to run.with_params('fe80:0000:0000:0000:0204:61ff:fe9d:f156') } - it { is_expected.to run.with_params('fe80:0:0:0:204:61ff:fe9d:f156') } - it { is_expected.to run.with_params('fe80::204:61ff:fe9d:f156') } - it { is_expected.to run.with_params('fe80:0:0:0:0204:61ff:254.157.241.86') } - it { is_expected.to run.with_params('::1') } - it { is_expected.to run.with_params('fe80::') } - it { is_expected.to run.with_params('2001::') } - end - - describe 'invalid inputs' do - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('::ffff:2.3.4').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('::ffff:257.1.2.3').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('::ffff:12345678901234567890.1.26').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - context 'unless running on ruby 1.8.7', if: RUBY_VERSION != '1.8.7' do - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) } - end - end -end From 49b9c4297ae1c65fab736ddd18077ae2be436784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 11:43:03 -1000 Subject: [PATCH 18/30] Remove deprecated function is_ipv4_address() > This method is deprecated, please use match expressions with > Stdlib::Compat::Ipv4. --- lib/puppet/functions/is_ipv4_address.rb | 29 --------------- .../parser/functions/is_ipv4_address.rb | 37 ------------------- spec/functions/is_ipv4_address_spec.rb | 33 ----------------- 3 files changed, 99 deletions(-) delete mode 100644 lib/puppet/functions/is_ipv4_address.rb delete mode 100644 lib/puppet/parser/functions/is_ipv4_address.rb delete mode 100644 spec/functions/is_ipv4_address_spec.rb diff --git a/lib/puppet/functions/is_ipv4_address.rb b/lib/puppet/functions/is_ipv4_address.rb deleted file mode 100644 index 8a79a16dc..000000000 --- a/lib/puppet/functions/is_ipv4_address.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_ipv4_address) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - 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/parser/functions/is_ipv4_address.rb b/lib/puppet/parser/functions/is_ipv4_address.rb deleted file mode 100644 index 4610805f5..000000000 --- a/lib/puppet/parser/functions/is_ipv4_address.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# -# is_ipv4_address.rb -# -module Puppet::Parser::Functions - newfunction(:is_ipv4_address, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the string passed to this function is a valid IPv4 address. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - 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 - raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments given #{arguments.size} for 1") - end - - begin - ip = IPAddr.new(arguments[0]) - rescue ArgumentError - return false - end - - return ip.ipv4? - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_ipv4_address_spec.rb b/spec/functions/is_ipv4_address_spec.rb deleted file mode 100644 index 42986836f..000000000 --- a/spec/functions/is_ipv4_address_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_ipv4_address' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - - SharedData::IPV4_PATTERNS.each do |value| - it { is_expected.to run.with_params(value).and_return(true) } - end - - SharedData::IPV4_NEGATIVE_PATTERNS.each do |value| - it { is_expected.to run.with_params(value).and_return(false) } - end - - context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first).and_return(true) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first).and_return(true) - end - end -end From 207ef6884cc06c0895f4f493e57e252d65ebec1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 11:42:40 -1000 Subject: [PATCH 19/30] Remove deprecated function validate_ipv4_address() > This method is deprecated, please use the stdlib validate_legacy function, > with Stdlib::Compat::IPv4. --- lib/puppet/functions/validate_ipv4_address.rb | 30 ---------- .../parser/functions/validate_ipv4_address.rb | 56 ------------------- spec/functions/validate_ipv4_address_spec.rb | 47 ---------------- 3 files changed, 133 deletions(-) delete mode 100644 lib/puppet/functions/validate_ipv4_address.rb delete mode 100644 lib/puppet/parser/functions/validate_ipv4_address.rb delete mode 100644 spec/functions/validate_ipv4_address_spec.rb diff --git a/lib/puppet/functions/validate_ipv4_address.rb b/lib/puppet/functions/validate_ipv4_address.rb deleted file mode 100644 index 090292b10..000000000 --- a/lib/puppet/functions/validate_ipv4_address.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents an ipv4_address. -Puppet::Functions.create_function(:validate_ipv4_address) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb deleted file mode 100644 index 9e86690e3..000000000 --- a/lib/puppet/parser/functions/validate_ipv4_address.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -# -# validate_ipv4_address.rb -# -module Puppet::Parser::Functions - newfunction(:validate_ipv4_address, doc: <<-DOC - @summary - Validate that all values passed are valid IPv4 addresses. - Fail compilation if any value fails this check. - - @return - passes when the given values are valid IPv4 addresses or raise an error when they are not and fails compilation - - @example **Usage** - The following values will pass: - - $my_ip = "1.2.3.4" - validate_ipv4_address($my_ip) - validate_ipv4_address("8.8.8.8", "172.16.0.1", $my_ip) - - The following values will fail, causing compilation to abort: - - $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ] - validate_ipv4_address($some_array) - DOC - ) 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] - - if defined?(IPAddr::InvalidAddressError) - rescuable_exceptions << IPAddr::InvalidAddressError - end - - if args.empty? - raise Puppet::ParseError, "validate_ipv4_address(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - unless arg.is_a?(String) - raise Puppet::ParseError, "#{arg.inspect} is not a string." - end - - begin - unless IPAddr.new(arg).ipv4? - raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address." - end - rescue *rescuable_exceptions - raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address." - end - end - end -end diff --git a/spec/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb deleted file mode 100644 index bc8ed7648..000000000 --- a/spec/functions/validate_ipv4_address_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_ipv4_address' do - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - end - - context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first) - end - end - - SharedData::IPV4_PATTERNS.each do |value| - it { is_expected.to run.with_params(value) } - end - - SharedData::IPV4_NEGATIVE_PATTERNS.each do |value| - it { is_expected.to run.with_params(value).and_raise_error(Puppet::ParseError, %r{is not a valid IPv4}) } - end - - describe 'invalid inputs' do - [{}, [], 1, true].each do |invalid| - it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first, invalid).and_raise_error(Puppet::ParseError, %r{is not a string}) } - end - end - - describe 'multiple inputs' do - it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS[0], SharedData::IPV4_PATTERNS[1]) } - it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS[0], 'invalid ip').and_raise_error(Puppet::ParseError, %r{is not a valid IPv4}) } - end -end From 72446d01935be2039404cbc4fe581196677df0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 11:43:27 -1000 Subject: [PATCH 20/30] Remove deprecated function is_ip_address() > This method is deprecated, please use match expressions with > Stdlib::Compat::Ip_address. --- lib/puppet/functions/is_ip_address.rb | 29 --------------- lib/puppet/parser/functions/is_ip_address.rb | 38 -------------------- spec/functions/is_ip_address_spec.rb | 26 -------------- 3 files changed, 93 deletions(-) delete mode 100644 lib/puppet/functions/is_ip_address.rb delete mode 100644 lib/puppet/parser/functions/is_ip_address.rb delete mode 100644 spec/functions/is_ip_address_spec.rb diff --git a/lib/puppet/functions/is_ip_address.rb b/lib/puppet/functions/is_ip_address.rb deleted file mode 100644 index 3e1e015ca..000000000 --- a/lib/puppet/functions/is_ip_address.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_ip_address) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - 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/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb deleted file mode 100644 index 506244fc6..000000000 --- a/lib/puppet/parser/functions/is_ip_address.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -# -# is_ip_address.rb -# -module Puppet::Parser::Functions - newfunction(:is_ip_address, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the string passed to this function is a valid IP address. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - 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 - raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments given #{arguments.size} for 1") - end - - begin - ip = IPAddr.new(arguments[0]) - rescue ArgumentError - return false - end - - return true if ip.ipv4? || ip.ipv6? - return false - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb deleted file mode 100644 index 208d6459d..000000000 --- a/spec/functions/is_ip_address_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_ip_address' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('1.2.3.4').and_return(true) } - it { is_expected.to run.with_params('1.2.3.255').and_return(true) } - it { is_expected.to run.with_params('1.2.3.256').and_return(false) } - it { is_expected.to run.with_params('1.2.3').and_return(false) } - it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) } - it { is_expected.to run.with_params('fe00::1').and_return(true) } - it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74').and_return(true) } - it { is_expected.to run.with_params('FE80:0000:CD12:D123:E2F8:47FF:FE09:DD74').and_return(true) } - it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:zzzz').and_return(false) } - it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09').and_return(false) } - it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74:dd74').and_return(false) } - it { is_expected.to run.with_params('').and_return(false) } - it { is_expected.to run.with_params('one').and_return(false) } - it { is_expected.to run.with_params(1).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } - it { is_expected.to run.with_params('thisstring').and_return(false) } -end From 8804ccb2748ce00d809c0ad4af16112723acb5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 11:43:44 -1000 Subject: [PATCH 21/30] Remove deprecated function validate_ip_address() > This method is deprecated, please use the stdlib validate_legacy function, > with Stdlib::Compat::Ip_Address. --- lib/puppet/functions/validate_ip_address.rb | 30 --------- .../parser/functions/validate_ip_address.rb | 62 ----------------- spec/functions/validate_ip_address_spec.rb | 66 ------------------- 3 files changed, 158 deletions(-) delete mode 100644 lib/puppet/functions/validate_ip_address.rb delete mode 100644 lib/puppet/parser/functions/validate_ip_address.rb delete mode 100644 spec/functions/validate_ip_address_spec.rb diff --git a/lib/puppet/functions/validate_ip_address.rb b/lib/puppet/functions/validate_ip_address.rb deleted file mode 100644 index 706405262..000000000 --- a/lib/puppet/functions/validate_ip_address.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Validate the passed value represents an ip_address. -Puppet::Functions.create_function(:validate_ip_address) do - # @param scope - # The main value that will be passed to the method - # - # @param args - # Any additional values that are to be passed to the method - # - # @return [Boolean] `true` or `false` - # A boolean value returned from the called function. - 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/parser/functions/validate_ip_address.rb b/lib/puppet/parser/functions/validate_ip_address.rb deleted file mode 100644 index 32400e2b8..000000000 --- a/lib/puppet/parser/functions/validate_ip_address.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -# -# validate_ip_address.rb -# -module Puppet::Parser::Functions - newfunction(:validate_ip_address, doc: <<-DOC - @summary - Validate that all values passed are valid IP addresses, - regardless they are IPv4 or IPv6 - Fail compilation if any value fails this check. - - @return - passes when the given values are valid IP addresses or raise an error when they are not and fails compilation - - @example **Usage** - The following values will pass: - - $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) - DOC - ) do |args| - 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 - - if args.empty? - raise Puppet::ParseError, "validate_ip_address(): wrong number of arguments (#{args.length}; must be > 0)" - end - - args.each do |arg| - unless arg.is_a?(String) - raise Puppet::ParseError, "#{arg.inspect} is not a string." - end - - begin - unless IPAddr.new(arg).ipv4? || IPAddr.new(arg).ipv6? - raise Puppet::ParseError, "#{arg.inspect} is not a valid IP address." - end - rescue *rescuable_exceptions - raise Puppet::ParseError, "#{arg.inspect} is not a valid IP address." - end - end - end -end diff --git a/spec/functions/validate_ip_address_spec.rb b/spec/functions/validate_ip_address_spec.rb deleted file mode 100644 index ded6df976..000000000 --- a/spec/functions/validate_ip_address_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_ip_address' do - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - end - - describe 'valid inputs' do - it { is_expected.to run.with_params('0.0.0.0') } - it { is_expected.to run.with_params('8.8.8.8') } - it { is_expected.to run.with_params('127.0.0.1') } - it { is_expected.to run.with_params('10.10.10.10') } - it { is_expected.to run.with_params('194.232.104.150') } - it { is_expected.to run.with_params('244.24.24.24') } - it { is_expected.to run.with_params('255.255.255.255') } - it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') } - it { is_expected.to run.with_params('3ffe:0505:0002::') } - it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } - it { is_expected.to run.with_params('::1/64') } - it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } - - context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('1.2.3.4') - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - expect(scope).to receive(:warning).with(include('This method is deprecated')).never - is_expected.to run.with_params('1.2.3.4') - end - end - - context 'with netmasks' do - it { is_expected.to run.with_params('8.8.8.8/0') } - it { is_expected.to run.with_params('8.8.8.8/16') } - it { is_expected.to run.with_params('8.8.8.8/32') } - it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') } - end - end - - describe 'invalid inputs' do - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) } - it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) } - it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) } - it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) } - it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) } - it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, %r{is not a string}) } - it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) } - end -end From b7ea89acc0ba86b75b9b3745bd7f73a279423ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 11:52:29 -1000 Subject: [PATCH 22/30] Remove deprecated function size() > The length() function in Puppet is preferred over this. --- lib/puppet/parser/functions/size.rb | 52 ----------------------------- spec/functions/size_spec.rb | 40 ---------------------- 2 files changed, 92 deletions(-) delete mode 100644 lib/puppet/parser/functions/size.rb delete mode 100644 spec/functions/size_spec.rb diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb deleted file mode 100644 index 9942bb13b..000000000 --- a/lib/puppet/parser/functions/size.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -# -# size.rb -# -module Puppet::Parser::Functions - newfunction(:size, type: :rvalue, doc: <<-DOC - @summary - Returns the number of elements in a string, an array or a hash - - @return - the number of elements in a string, an array or a hash - - > *Note:* that since Puppet 5.4.0, the length() function in Puppet is preferred over this. For versions - of Puppet < 5.4.0 use the stdlib length() function. - DOC - ) do |arguments| - raise(Puppet::ParseError, "size(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? - - item = arguments[0] - - function_deprecation([:size, 'This method is going to be deprecated, please use the stdlib length function.']) - - if item.is_a?(String) - - begin - # - # Check whether your item is a numeric value or not ... - # This will take care about positive and/or negative numbers - # for both integer and floating-point values ... - # - # Please note that Puppet has no notion of hexadecimal - # nor octal numbers for its DSL at this point in time ... - # - Float(item) - - raise(Puppet::ParseError, 'size(): Requires either string, array or hash to work with') - rescue ArgumentError - result = item.size - end - - elsif item.is_a?(Array) || item.is_a?(Hash) - result = item.size - else - raise(Puppet::ParseError, 'size(): Unknown type given') - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/size_spec.rb b/spec/functions/size_spec.rb deleted file mode 100644 index 386f91249..000000000 --- a/spec/functions/size_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'size', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { - pending('Current implementation ignores parameters after the first.') - is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) - } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Unknown type given}) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Unknown type given}) } - it { is_expected.to run.with_params('1').and_raise_error(Puppet::ParseError, %r{Requires either string, array or hash to work}) } - it { is_expected.to run.with_params('1.0').and_raise_error(Puppet::ParseError, %r{Requires either string, array or hash to work}) } - it { is_expected.to run.with_params([]).and_return(0) } - it { is_expected.to run.with_params(['a']).and_return(1) } - it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) } - it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) } - - it { is_expected.to run.with_params({}).and_return(0) } - it { is_expected.to run.with_params('1' => '2').and_return(1) } - it { is_expected.to run.with_params('1' => '2', '4' => '4').and_return(2) } - it { is_expected.to run.with_params('€' => '@', '竹' => 'ǿňè').and_return(2) } - - it { is_expected.to run.with_params('').and_return(0) } - it { is_expected.to run.with_params('a').and_return(1) } - it { is_expected.to run.with_params('abc').and_return(3) } - it { is_expected.to run.with_params('abcd').and_return(4) } - it { is_expected.to run.with_params('万').and_return(1) } - it { is_expected.to run.with_params('āβćđ').and_return(4) } - - context 'when using a class extending String', unless: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') == 0 do - it 'calls its size method' do - value = AlsoString.new('asdfghjkl') - expect(value).to receive(:size).and_return('foo') - expect(subject).to run.with_params(value).and_return('foo') - end - end -end From bf65a1d1fd9fa92f7b3ab0281cfc239b805d242e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 11:53:20 -1000 Subject: [PATCH 23/30] Remove deprecated function sprintf_hash() > From Puppet 4.10.10/5.3.4 please use the built-in sprintf instead --- lib/puppet/functions/sprintf_hash.rb | 37 ---------------------------- spec/functions/sprintf_hash_spec.rb | 35 -------------------------- 2 files changed, 72 deletions(-) delete mode 100644 lib/puppet/functions/sprintf_hash.rb delete mode 100644 spec/functions/sprintf_hash_spec.rb diff --git a/lib/puppet/functions/sprintf_hash.rb b/lib/puppet/functions/sprintf_hash.rb deleted file mode 100644 index 42d27403a..000000000 --- a/lib/puppet/functions/sprintf_hash.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Uses sprintf with named references. -# -# The first parameter is format string describing how the rest of the parameters in the hash -# should be formatted. See the documentation for the `Kernel::sprintf` function in Ruby for -# all the details. -# -# In the given argument hash with parameters, all keys are converted to symbols so they work -# with the `sprintf` function. -# -# @example Format a string and number -# $output = sprintf_hash('String: %s / number converted to binary: %b', -# { 'foo' => 'a string', 'number' => 5 }) -# # $output = 'String: a string / number converted to binary: 101' -# -# Note that since Puppet 4.10.10, and 5.3.4 this functionality is supported by the -# `sprintf` function in puppet core. -# -Puppet::Functions.create_function(:sprintf_hash) do - # @param format The format to use. - # @param arguments Hash with parameters. - # @return The formatted string. - dispatch :sprintf_hash do - param 'String', :format - param 'Hash', :arguments - # Disabled for now. This gives issues on puppet 4.7.1. - # return_type 'String' - end - - def sprintf_hash(format, arguments) - call_function('deprecation', 'sprintf_hash', 'This method is deprecated. From Puppet 4.10.10/5.3.4 please use the built-in sprintf instead') - - Kernel.sprintf(format, Hash[arguments.map { |(k, v)| [k.to_sym, v] }]) - end -end diff --git a/spec/functions/sprintf_hash_spec.rb b/spec/functions/sprintf_hash_spec.rb deleted file mode 100644 index 4e72d3da8..000000000 --- a/spec/functions/sprintf_hash_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'sprintf_hash' do - it 'exists' do - is_expected.not_to eq(nil) - end - - context 'with param count' do - it 'fails with no arguments' do - is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects 2 arguments}i) - end - it 'fails with 1 argument' do - is_expected.to run.with_params('').and_raise_error(ArgumentError, %r{expects 2 arguments}i) - end - it 'fails with too many arguments' do - is_expected.to run.with_params('', '', '').and_raise_error(ArgumentError, %r{expects 2 arguments}i) - end - end - - context 'with param type' do - it 'fails with wrong format type' do - is_expected.to run.with_params(false, {}).and_raise_error(ArgumentError, %r{parameter 'format' expects a String value}i) - end - it 'fails with wrong arguments type' do - is_expected.to run.with_params('', false).and_raise_error(ArgumentError, %r{parameter 'arguments' expects a Hash value}i) - end - end - - it 'prints formats with name placeholders' do - is_expected.to run.with_params('string %s and integer %b', 'foo' => '_foo_', 'bar' => 5) # rubocop:disable Style/FormatStringToken : Template tokens needed for purposes of test - .and_return('string _foo_ and integer 101') - end -end From 03b5be2bdcde6cef25bb1c332cd46d1e9f2407e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 11:55:11 -1000 Subject: [PATCH 24/30] Remove deprecated 3.x function ensure_packages() > Deprecated 3x version of the `ensure_packages` function --- lib/puppet/parser/functions/ensure_packages.rb | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 lib/puppet/parser/functions/ensure_packages.rb diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb deleted file mode 100644 index e9a3288b9..000000000 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module Puppet::Parser::Functions - newfunction(:ensure_packages, type: :statement, doc: '@summary Deprecated 3x version of the `ensure_packages` function') do |arguments| - # Call the 4.x version of this function in case 3.x ruby code uses this function - Puppet.warn_once('deprecations', '3xfunction#ensure_packages', 'Calling function_ensure_packages via the Scope class is deprecated. Use Scope#call_function instead') - call_function('ensure_packages', arguments) - end -end From f5c271082fd862301209a9f384caf811b4dd25c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 14:24:17 -1000 Subject: [PATCH 25/30] Remove deprecated function is_email_address() > Will be removed in a future version of stdlib. --- .../parser/functions/is_email_address.rb | 28 ------------------- spec/functions/is_email_address_spec.rb | 16 ----------- 2 files changed, 44 deletions(-) delete mode 100644 lib/puppet/parser/functions/is_email_address.rb delete mode 100644 spec/functions/is_email_address_spec.rb diff --git a/lib/puppet/parser/functions/is_email_address.rb b/lib/puppet/parser/functions/is_email_address.rb deleted file mode 100644 index 5a9594c04..000000000 --- a/lib/puppet/parser/functions/is_email_address.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -# -# is_email_address.rb -# -module Puppet::Parser::Functions - newfunction(:is_email_address, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the string passed to this function is a valid email address. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - if arguments.size != 1 - raise(Puppet::ParseError, "is_email_address(): Wrong number of arguments given #{arguments.size} for 1") - end - - # Taken from http://emailregex.com/ (simpler regex) - valid_email_regex = %r{\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z} - return (arguments[0] =~ valid_email_regex) == 0 - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_email_address_spec.rb b/spec/functions/is_email_address_spec.rb deleted file mode 100644 index c2aeaf3d5..000000000 --- a/spec/functions/is_email_address_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_email_address' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('bob@gmail.com').and_return(true) } - it { is_expected.to run.with_params('alice+puppetlabs.com@gmail.com').and_return(true) } - it { is_expected.to run.with_params('peter.parker@gmail.com').and_return(true) } - it { is_expected.to run.with_params('1.2.3@domain').and_return(false) } - it { is_expected.to run.with_params('1.2.3.4.5@').and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } -end From 879a10fc3caded87ad05dc7afd56a82d973177a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 14:24:49 -1000 Subject: [PATCH 26/30] Remove deprecated function is_mac_address() > Will be removed in a future version of stdlib. --- lib/puppet/parser/functions/is_mac_address.rb | 30 ----------------- spec/functions/is_mac_address_spec.rb | 33 ------------------- 2 files changed, 63 deletions(-) delete mode 100644 lib/puppet/parser/functions/is_mac_address.rb delete mode 100644 spec/functions/is_mac_address_spec.rb diff --git a/lib/puppet/parser/functions/is_mac_address.rb b/lib/puppet/parser/functions/is_mac_address.rb deleted file mode 100644 index 67a269c4a..000000000 --- a/lib/puppet/parser/functions/is_mac_address.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# -# is_mac_address.rb -# -module Puppet::Parser::Functions - newfunction(:is_mac_address, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the string passed to this function is a valid mac address. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - if arguments.size != 1 - raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments given #{arguments.size} for 1") - end - - mac = arguments[0] - - return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$}i.match?(mac) - return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){19}$}i.match?(mac) - return false - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb deleted file mode 100644 index 3312bb398..000000000 --- a/spec/functions/is_mac_address_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_mac_address' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('00:a0:1f:12:7f:a0').and_return(true) } - it { is_expected.to run.with_params('00:A0:1F:12:7F:A0').and_return(true) } - it { is_expected.to run.with_params('80:00:02:09:fe:80:00:00:00:00:00:00:00:24:65:ff:ff:91:a3:12').and_return(true) } - it { is_expected.to run.with_params('00:00:00:00:00:0g').and_return(false) } - it { is_expected.to run.with_params('').and_return(false) } - it { is_expected.to run.with_params('one').and_return(false) } - - context 'with UTF8 and double byte characters' do - it { is_expected.to run.with_params('ƒốưř').and_return(false) } - it { is_expected.to run.with_params('三+').and_return(false) } - end - - it { - pending 'should properly typecheck its arguments' - is_expected.to run.with_params(1).and_return(false) - } - it { - pending 'should properly typecheck its arguments' - is_expected.to run.with_params({}).and_return(false) - } - it { - pending 'should properly typecheck its arguments' - is_expected.to run.with_params([]).and_return(false) - } -end From 1cc4c241daeb7afdd358cb3b284a882cb3113e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 14:25:48 -1000 Subject: [PATCH 27/30] Remove deprecated function is_domain_name() > Will be removed in a future version of stdlib. --- lib/puppet/parser/functions/is_domain_name.rb | 60 ------------------- spec/functions/is_domain_name_spec.rb | 51 ---------------- 2 files changed, 111 deletions(-) delete mode 100644 lib/puppet/parser/functions/is_domain_name.rb delete mode 100644 spec/functions/is_domain_name_spec.rb diff --git a/lib/puppet/parser/functions/is_domain_name.rb b/lib/puppet/parser/functions/is_domain_name.rb deleted file mode 100644 index 32b94816c..000000000 --- a/lib/puppet/parser/functions/is_domain_name.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -# -# is_domain_name.rb -# -module Puppet::Parser::Functions - newfunction(:is_domain_name, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the string passed to this function is - a syntactically correct domain name. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - if arguments.size != 1 - raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments given #{arguments.size} for 1") - end - - # Only allow string types - return false unless arguments[0].is_a?(String) - - domain = arguments[0].dup - - # Limits (rfc1035, 3.1) - domain_max_length = 255 - label_min_length = 1 - label_max_length = 63 - - # Allow ".", it is the top level domain - return true if domain == '.' - - # Remove the final dot, if present. - domain.chomp!('.') - - # Check the whole domain - return false if domain.empty? - return false if domain.length > domain_max_length - - # The top level domain must be alphabetic if there are multiple labels. - # See rfc1123, 2.1 - return false if domain.include?('.') && !%r{\.[A-Za-z]+$}.match(domain) - - # Check each label in the domain - labels = domain.split('.') - vlabels = labels.each do |label| - break if label.length < label_min_length - break if label.length > label_max_length - break if label[-1..-1] == '-' - break if label[0..0] == '-' - break unless %r{^[a-z\d-]+$}i.match?(label) - end - return vlabels == labels - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_domain_name_spec.rb b/spec/functions/is_domain_name_spec.rb deleted file mode 100644 index a0221408c..000000000 --- a/spec/functions/is_domain_name_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_domain_name' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(1).and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params('').and_return(false) } - it { is_expected.to run.with_params('.').and_return(true) } - it { is_expected.to run.with_params('com').and_return(true) } - it { is_expected.to run.with_params('com.').and_return(true) } - it { is_expected.to run.with_params('x.com').and_return(true) } - it { is_expected.to run.with_params('x.com.').and_return(true) } - it { is_expected.to run.with_params('foo.example.com').and_return(true) } - it { is_expected.to run.with_params('foo.example.com.').and_return(true) } - it { is_expected.to run.with_params('2foo.example.com').and_return(true) } - it { is_expected.to run.with_params('2foo.example.com.').and_return(true) } - it { is_expected.to run.with_params('www.2foo.example.com').and_return(true) } - it { is_expected.to run.with_params('www.2foo.example.com.').and_return(true) } - it { is_expected.to run.with_params(true).and_return(false) } - - describe 'inputs with spaces' do - it { is_expected.to run.with_params('invalid domain').and_return(false) } - end - - describe 'inputs with hyphens' do - it { is_expected.to run.with_params('foo-bar.example.com').and_return(true) } - it { is_expected.to run.with_params('foo-bar.example.com.').and_return(true) } - it { is_expected.to run.with_params('www.foo-bar.example.com').and_return(true) } - it { is_expected.to run.with_params('www.foo-bar.example.com.').and_return(true) } - it { is_expected.to run.with_params('-foo.example.com').and_return(false) } - it { is_expected.to run.with_params('-foo.example.com.').and_return(false) } - end - - # Values obtained from Facter values will be frozen strings - # in newer versions of Facter: - it { is_expected.to run.with_params('www.example.com').and_return(true) } - - describe 'top level domain must be alphabetic if there are multiple labels' do - it { is_expected.to run.with_params('2com').and_return(true) } - it { is_expected.to run.with_params('www.example.2com').and_return(false) } - end - - describe 'IP addresses are not domain names' do - it { is_expected.to run.with_params('192.168.1.1').and_return(false) } - end -end From 027861866122b32816bbb5566f8dc57d3b558ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 27 Apr 2023 14:27:53 -1000 Subject: [PATCH 28/30] Remove deprecated function is_function_available() > Will be removed in a future version of stdlib. --- .../parser/functions/is_function_available.rb | 32 ------------------- spec/functions/is_function_available_spec.rb | 14 -------- 2 files changed, 46 deletions(-) delete mode 100644 lib/puppet/parser/functions/is_function_available.rb delete mode 100644 spec/functions/is_function_available_spec.rb diff --git a/lib/puppet/parser/functions/is_function_available.rb b/lib/puppet/parser/functions/is_function_available.rb deleted file mode 100644 index d6f666fb4..000000000 --- a/lib/puppet/parser/functions/is_function_available.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -# -# is_function_available.rb -# -module Puppet::Parser::Functions - newfunction(:is_function_available, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Determines whether the Puppet runtime has access to a function by that name. - - This function accepts a string as an argument. - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - ) do |arguments| - if arguments.size != 1 - raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments given #{arguments.size} for 1") - end - - # Only allow String types - return false unless arguments[0].is_a?(String) - - function = Puppet::Parser::Functions.function(arguments[0].to_sym) - function.is_a?(String) && !function.empty? - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/is_function_available_spec.rb b/spec/functions/is_function_available_spec.rb deleted file mode 100644 index 3b3965427..000000000 --- a/spec/functions/is_function_available_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_function_available' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('include').and_return(true) } - it { is_expected.to run.with_params('no_such_function').and_return(false) } - it { is_expected.to run.with_params([]).and_return(false) } - it { is_expected.to run.with_params({}).and_return(false) } - it { is_expected.to run.with_params(1).and_return(false) } -end From 0d1228552de4c5f7f3476cae6a052d06ca8a7db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 4 May 2023 09:41:56 -1000 Subject: [PATCH 29/30] Remove deprecated function floor() > From Puppet 6.0.0, this function has been replaced with a built-in function. --- lib/puppet/parser/functions/floor.rb | 33 ---------------------------- spec/functions/floor_spec.rb | 15 ------------- 2 files changed, 48 deletions(-) delete mode 100644 lib/puppet/parser/functions/floor.rb delete mode 100644 spec/functions/floor_spec.rb diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb deleted file mode 100644 index 1d59963ad..000000000 --- a/lib/puppet/parser/functions/floor.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -# -# floor.rb -# -module Puppet::Parser::Functions - newfunction(:floor, type: :rvalue, doc: <<-DOC - @summary - Returns the largest integer less or equal to the argument. - - @return - the largest integer less or equal to the argument. - Takes a single numeric value as an argument. - - > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with - a built-in [`floor`](https://puppet.com/docs/puppet/latest/function.html#floor) function. - DOC - ) do |arguments| - raise(Puppet::ParseError, "floor(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 - - begin - arg = Float(arguments[0]) - rescue TypeError, ArgumentError => _e - raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arguments[0]} for Numeric)") - end - - raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false - - arg.floor - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/floor_spec.rb b/spec/functions/floor_spec.rb deleted file mode 100644 index fe45142f0..000000000 --- a/spec/functions/floor_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'floor', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } - it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError, %r{Wrong argument type}) } - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Wrong argument type}) } - - it { is_expected.to run.with_params(34).and_return(34) } - it { is_expected.to run.with_params(-34).and_return(-34) } - it { is_expected.to run.with_params(33.1).and_return(33) } - it { is_expected.to run.with_params(-33.1).and_return(-34) } -end From fcbd4267fd830982e86041599d4eb11c2072a94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 4 May 2023 10:22:23 -1000 Subject: [PATCH 30/30] Remove deprecated Stdlib::Compat::* data types These data types where introduced in Puppet 4 when deprecating the validate_* functions and provided backwards compatibility with older versions of Puppet where all parameters where String. With Puppet 4, we got the ability to manage proper data types and it is now time to remove these compatibility types. --- spec/type_aliases/array_spec.rb | 32 ------------------ spec/type_aliases/bool_spec.rb | 30 ----------------- spec/type_aliases/compat__ip_address.rb | 38 --------------------- spec/type_aliases/compat__ipv4_spec.rb | 20 ----------- spec/type_aliases/compat__ipv6_spec.rb | 44 ------------------------- spec/type_aliases/float_spec.rb | 26 --------------- spec/type_aliases/hash_spec.rb | 30 ----------------- spec/type_aliases/integer_spec.rb | 29 ---------------- spec/type_aliases/numeric_spec.rb | 30 ----------------- spec/type_aliases/string_spec.rb | 30 ----------------- types/compat/absolute_path.pp | 7 ---- types/compat/array.pp | 2 -- types/compat/bool.pp | 2 -- types/compat/float.pp | 19 ----------- types/compat/hash.pp | 2 -- types/compat/integer.pp | 23 ------------- types/compat/ip_address.pp | 2 -- types/compat/ipv4.pp | 2 -- types/compat/ipv6.pp | 2 -- types/compat/numeric.pp | 23 ------------- types/compat/re.pp | 3 -- types/compat/string.pp | 2 -- types/host.pp | 2 +- 23 files changed, 1 insertion(+), 399 deletions(-) delete mode 100644 spec/type_aliases/array_spec.rb delete mode 100644 spec/type_aliases/bool_spec.rb delete mode 100644 spec/type_aliases/compat__ip_address.rb delete mode 100644 spec/type_aliases/compat__ipv4_spec.rb delete mode 100644 spec/type_aliases/compat__ipv6_spec.rb delete mode 100644 spec/type_aliases/float_spec.rb delete mode 100644 spec/type_aliases/hash_spec.rb delete mode 100644 spec/type_aliases/integer_spec.rb delete mode 100644 spec/type_aliases/numeric_spec.rb delete mode 100644 spec/type_aliases/string_spec.rb delete mode 100644 types/compat/absolute_path.pp delete mode 100644 types/compat/array.pp delete mode 100644 types/compat/bool.pp delete mode 100644 types/compat/float.pp delete mode 100644 types/compat/hash.pp delete mode 100644 types/compat/integer.pp delete mode 100644 types/compat/ip_address.pp delete mode 100644 types/compat/ipv4.pp delete mode 100644 types/compat/ipv6.pp delete mode 100644 types/compat/numeric.pp delete mode 100644 types/compat/re.pp delete mode 100644 types/compat/string.pp diff --git a/spec/type_aliases/array_spec.rb b/spec/type_aliases/array_spec.rb deleted file mode 100644 index e47e5339d..000000000 --- a/spec/type_aliases/array_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Array' do - describe 'accepts arrays' do - [ - [], - ['one'], - [1], - [{}], - [[]], - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'rejects other values' do - [ - '', - 'one', - '1', - {}, - ].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/bool_spec.rb b/spec/type_aliases/bool_spec.rb deleted file mode 100644 index e295393d1..000000000 --- a/spec/type_aliases/bool_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Bool' do - describe 'accepts booleans' do - [ - true, - false, - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'rejects other values' do - [ - [1], - [{}], - [true], - 'true', - 'false', - ].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/compat__ip_address.rb b/spec/type_aliases/compat__ip_address.rb deleted file mode 100644 index b6d3b1c0c..000000000 --- a/spec/type_aliases/compat__ip_address.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Ip_address' do - describe 'accepts ipv4 and ipv6 addresses' do - [ - '224.0.0.0', - '255.255.255.255', - '0.0.0.0', - '192.88.99.0', - '2001:0db8:85a3:0000:0000:8a2e:0370:7334', - 'fa76:8765:34ac:0823:ab76:eee9:0987:1111', - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - describe 'rejects other values' do - [ - nil, - [nil], - [nil, nil], - { 'foo' => 'bar' }, - {}, - '', - 'nope', - '77', - '4.4.4', - '2001:0db8:85a3:000000:0000:8a2e:0370:7334', - ].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/compat__ipv4_spec.rb b/spec/type_aliases/compat__ipv4_spec.rb deleted file mode 100644 index 627fa354d..000000000 --- a/spec/type_aliases/compat__ipv4_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Ipv4' do - describe 'accepts ipv4 addresses' do - SharedData::IPV4_PATTERNS.each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - describe 'rejects other values' do - SharedData::IPV4_NEGATIVE_PATTERNS.each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/compat__ipv6_spec.rb b/spec/type_aliases/compat__ipv6_spec.rb deleted file mode 100644 index 906a5764b..000000000 --- a/spec/type_aliases/compat__ipv6_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Ipv6' do - describe 'accepts ipv6 addresses' do - [ - '2001:0db8:85a3:0000:0000:8a2e:0370:7334', - 'fa76:8765:34ac:0823:ab76:eee9:0987:1111', - 'fe80:0000:0000:0000:0204:61ff:fe9d:f156', - 'fe80:0:0:0:204:61ff:fe9d:f156', - 'fe80::204:61ff:fe9d:f156', - 'fe80:0:0:0:0204:61ff:254.157.241.86', - '::1', - 'fe80::', - '2001::', - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - describe 'rejects other values' do - [ - nil, - [nil], - [nil, nil], - { 'foo' => 'bar' }, - {}, - '', - 'nope', - '77', - '4.4.4', - '2000:7334', - '::ffff:2.3.4', - '::ffff:257.1.2.3', - '::ffff:12345678901234567890.1.26', - ].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/float_spec.rb b/spec/type_aliases/float_spec.rb deleted file mode 100644 index 4a1c52f46..000000000 --- a/spec/type_aliases/float_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Float' do - describe 'accepts floats' do - [ - 3.7, - '3.7', - -3.7, - '-342.2315e-12', - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'rejects other values' do - [true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x', 3, '3', -3, '-3'].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/hash_spec.rb b/spec/type_aliases/hash_spec.rb deleted file mode 100644 index 2e5bb91e0..000000000 --- a/spec/type_aliases/hash_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Hash' do - describe 'accepts hashes' do - [ - {}, - { 'one' => 'two' }, - { 'wan' => 3 }, - { '001' => 'helly' }, - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - describe 'rejects other values' do - [ - '', - 'one', - '1', - [], - ].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/integer_spec.rb b/spec/type_aliases/integer_spec.rb deleted file mode 100644 index 76ec2675a..000000000 --- a/spec/type_aliases/integer_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Integer' do - describe 'accepts integers' do - [ - 3, - '3', - -3, - '-3', - "123\nfoo", - "foo\n123", - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'rejects other values' do - ["foo\nbar", true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', - {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x', 3.7, '3.7', -3.7, '-342.2315e-12'].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/numeric_spec.rb b/spec/type_aliases/numeric_spec.rb deleted file mode 100644 index 31e57a899..000000000 --- a/spec/type_aliases/numeric_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::Numeric' do - describe 'accepts numerics' do - [ - 3, - '3', - -3, - '-3', - 3.7, - '3.7', - -3.7, - '-342.2315e-12', - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'rejects other values' do - [true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x'].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/spec/type_aliases/string_spec.rb b/spec/type_aliases/string_spec.rb deleted file mode 100644 index d977d32fe..000000000 --- a/spec/type_aliases/string_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Stdlib::Compat::String' do - describe 'accepts strings' do - [ - '', - 'one', - nil, - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'rejects other values' do - [ - [], - {}, - 1, - true, - ].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end -end diff --git a/types/compat/absolute_path.pp b/types/compat/absolute_path.pp deleted file mode 100644 index 28e03ab89..000000000 --- a/types/compat/absolute_path.pp +++ /dev/null @@ -1,7 +0,0 @@ -# @summary Emulate the is_absolute_path and validate_absolute_path functions -# -# The first pattern is originally from is_absolute_path, which had it from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path? -# slash = '[\\\\/]' -# name = '[^\\\\/]+' -# %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i, -type Stdlib::Compat::Absolute_path = Variant[Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/], Pattern[/^\//]] # lint:ignore:140chars diff --git a/types/compat/array.pp b/types/compat/array.pp deleted file mode 100644 index 12ddbab7e..000000000 --- a/types/compat/array.pp +++ /dev/null @@ -1,2 +0,0 @@ -# @summary Emulate the is_array and validate_array functions -type Stdlib::Compat::Array = Array[Any] diff --git a/types/compat/bool.pp b/types/compat/bool.pp deleted file mode 100644 index 1918bf8b0..000000000 --- a/types/compat/bool.pp +++ /dev/null @@ -1,2 +0,0 @@ -# @summary Emulate the is_bool and validate_bool functions -type Stdlib::Compat::Bool = Boolean diff --git a/types/compat/float.pp b/types/compat/float.pp deleted file mode 100644 index 84b261754..000000000 --- a/types/compat/float.pp +++ /dev/null @@ -1,19 +0,0 @@ -# @summary Emulate the is_float function -# The regex is what's currently used in is_float -# To keep your development moving forward, you can also add a deprecation warning using the Integer type: -# -# ```class example($value) { validate_float($value,) }``` -# -# would turn into -# -# ``` -# class example(Stdlib::Compat::Float $value) { -# validate_float($value, 10, 0) -# assert_type(Integer[0, 10], $value) |$expected, $actual| { -# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.") -# } -# } -# ``` -# -# This allows you to find all places where a consumers of your code call it with unexpected values. -type Stdlib::Compat::Float = Variant[Float, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)(?:[eE]-?\d+)?$/]] diff --git a/types/compat/hash.pp b/types/compat/hash.pp deleted file mode 100644 index 14dc6fd1d..000000000 --- a/types/compat/hash.pp +++ /dev/null @@ -1,2 +0,0 @@ -# @summary Emulate the is_hash and validate_hash functions -type Stdlib::Compat::Hash = Hash[Any, Any] diff --git a/types/compat/integer.pp b/types/compat/integer.pp deleted file mode 100644 index 811daacba..000000000 --- a/types/compat/integer.pp +++ /dev/null @@ -1,23 +0,0 @@ -# @summary Emulate the is_integer and validate_integer functions -# The regex is what's currently used in is_integer -# validate_numeric also allows range checking, which cannot be mapped to the string parsing inside the function. -# For full backwards compatibility, you will need to keep the validate_numeric call around to catch everything. -# To keep your development moving forward, you can also add a deprecation warning using the Integer type: -# -# ```class example($value) { validate_integer($value, 10, 0) }``` -# -# would turn into -# -# ``` -# class example(Stdlib::Compat::Integer $value) { -# validate_numeric($value, 10, 0) -# assert_type(Integer[0, 10], $value) |$expected, $actual| { -# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.") -# } -# } -# ``` -# -# > Note that you need to use Variant[Integer[0, 10], Float[0, 10]] if you want to match both integers and floating point numbers. -# -# This allows you to find all places where a consumers of your code call it with unexpected values. -type Stdlib::Compat::Integer = Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/], Array[Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/]]]] # lint:ignore:140chars diff --git a/types/compat/ip_address.pp b/types/compat/ip_address.pp deleted file mode 100644 index b877020cc..000000000 --- a/types/compat/ip_address.pp +++ /dev/null @@ -1,2 +0,0 @@ -# @summary Validate an IP address -type Stdlib::Compat::Ip_address = Variant[Stdlib::Compat::Ipv4, Stdlib::Compat::Ipv6] diff --git a/types/compat/ipv4.pp b/types/compat/ipv4.pp deleted file mode 100644 index bcd2c00bb..000000000 --- a/types/compat/ipv4.pp +++ /dev/null @@ -1,2 +0,0 @@ -# @summary Emulate the validate_ipv4_address and is_ipv4_address functions -type Stdlib::Compat::Ipv4 = Pattern[/^((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d)))(\/((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))|[0-9]+))?$/] # lint:ignore:140chars diff --git a/types/compat/ipv6.pp b/types/compat/ipv6.pp deleted file mode 100644 index 0c6f4228e..000000000 --- a/types/compat/ipv6.pp +++ /dev/null @@ -1,2 +0,0 @@ -# @summary Validate an IPv6 address -type Stdlib::Compat::Ipv6 = Pattern[/\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/] # lint:ignore:140chars diff --git a/types/compat/numeric.pp b/types/compat/numeric.pp deleted file mode 100644 index d509d7ab6..000000000 --- a/types/compat/numeric.pp +++ /dev/null @@ -1,23 +0,0 @@ -# @summary Emulate the is_numeric and validate_numeric functions -# The regex is what's currently used in is_numeric -# validate_numeric also allows range checking, which cannot be mapped to the string parsing inside the function. -# For full backwards compatibility, you will need to keep the validate_numeric call around to catch everything. -# To keep your development moving forward, you can also add a deprecation warning using the Integer type: -# -# ```class example($value) { validate_numeric($value, 10, 0) }``` -# -# would turn into -# -# ``` -# class example(Stdlib::Compat::Numeric $value) { -# validate_numeric($value, 10, 0) -# assert_type(Integer[0, 10], $value) |$expected, $actual| { -# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.") -# } -# } -# ``` -# -# > Note that you need to use Variant[Integer[0, 10], Float[0, 10]] if you want to match both integers and floating point numbers. -# -# This allows you to find all places where a consumers of your code call it with unexpected values. -type Stdlib::Compat::Numeric = Variant[Numeric, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$/], Array[Variant[Numeric, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$/]]]] # lint:ignore:140chars diff --git a/types/compat/re.pp b/types/compat/re.pp deleted file mode 100644 index 81db38cef..000000000 --- a/types/compat/re.pp +++ /dev/null @@ -1,3 +0,0 @@ -# @summary Emulate the validate_re function -# validate_re(value, re) translates to Pattern[re], which is not directly mappable as a type alias, but can be specified as Pattern[re]. -# Therefore this needs to be translated directly. diff --git a/types/compat/string.pp b/types/compat/string.pp deleted file mode 100644 index ce08bafb4..000000000 --- a/types/compat/string.pp +++ /dev/null @@ -1,2 +0,0 @@ -# @summary Emulate the is_string and validate_string functions -type Stdlib::Compat::String = Optional[String] diff --git a/types/host.pp b/types/host.pp index 21772f1fc..5b019b73e 100644 --- a/types/host.pp +++ b/types/host.pp @@ -1,2 +1,2 @@ # @summary Validate a host (FQDN or IP address) -type Stdlib::Host = Variant[Stdlib::Fqdn, Stdlib::Compat::Ip_address] +type Stdlib::Host = Variant[Stdlib::Fqdn, Stdlib::Ip::Address]