From 6e7e69fe203e042b28aacb01301c338d55448c5f Mon Sep 17 00:00:00 2001 From: tphoney Date: Wed, 3 Aug 2016 17:06:25 +0100 Subject: (modules-3533) deprecation for 3.x number function --- types/compat/float.pp | 19 +++++++++++++++++++ types/compat/integer.pp | 23 +++++++++++++++++++++++ types/compat/numeric.pp | 23 +++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 types/compat/float.pp create mode 100644 types/compat/integer.pp create mode 100644 types/compat/numeric.pp (limited to 'types') diff --git a/types/compat/float.pp b/types/compat/float.pp new file mode 100644 index 0000000..7f98bd2 --- /dev/null +++ b/types/compat/float.pp @@ -0,0 +1,19 @@ +# 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/integer.pp b/types/compat/integer.pp new file mode 100644 index 0000000..e5cadb6 --- /dev/null +++ b/types/compat/integer.pp @@ -0,0 +1,23 @@ +# 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)$/]]]] diff --git a/types/compat/numeric.pp b/types/compat/numeric.pp new file mode 100644 index 0000000..5bfc3d3 --- /dev/null +++ b/types/compat/numeric.pp @@ -0,0 +1,23 @@ +# 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+)?$/]]]] -- cgit v1.2.3 From 22fbe723acd22ae3491c41beeacbc76853c6820e Mon Sep 17 00:00:00 2001 From: tphoney Date: Mon, 8 Aug 2016 17:35:13 +0100 Subject: (modules-3532) deprecate string type checks --- types/compat/absolute_path.pp | 7 +++++++ types/compat/array.pp | 2 ++ types/compat/bool.pp | 2 ++ types/compat/re.pp | 3 +++ types/compat/string.pp | 2 ++ 5 files changed, 16 insertions(+) create mode 100644 types/compat/absolute_path.pp create mode 100644 types/compat/array.pp create mode 100644 types/compat/bool.pp create mode 100644 types/compat/re.pp create mode 100644 types/compat/string.pp (limited to 'types') diff --git a/types/compat/absolute_path.pp b/types/compat/absolute_path.pp new file mode 100644 index 0000000..d11784e --- /dev/null +++ b/types/compat/absolute_path.pp @@ -0,0 +1,7 @@ +# 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[/^\//]] diff --git a/types/compat/array.pp b/types/compat/array.pp new file mode 100644 index 0000000..ba65dc4 --- /dev/null +++ b/types/compat/array.pp @@ -0,0 +1,2 @@ +# 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 new file mode 100644 index 0000000..dda5f4b --- /dev/null +++ b/types/compat/bool.pp @@ -0,0 +1,2 @@ + # Emulate the is_bool and validate_bool functions + type Stdlib::Compat::Bool = Boolean diff --git a/types/compat/re.pp b/types/compat/re.pp new file mode 100644 index 0000000..e4b5f30 --- /dev/null +++ b/types/compat/re.pp @@ -0,0 +1,3 @@ +# 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 new file mode 100644 index 0000000..4c36e5f --- /dev/null +++ b/types/compat/string.pp @@ -0,0 +1,2 @@ +# Emulate the is_string and validate_string functions +type Stdlib::Compat::String = String -- cgit v1.2.3 From 6d185bdaa19f698270a0df4b0a0c05618864b955 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Tue, 16 Aug 2016 11:55:05 +0100 Subject: Deprecation of ip functions --- types/compat/ip_address.pp | 1 + types/compat/ipv4.pp | 2 ++ types/compat/ipv6.pp | 1 + 3 files changed, 4 insertions(+) create mode 100644 types/compat/ip_address.pp create mode 100644 types/compat/ipv4.pp create mode 100644 types/compat/ipv6.pp (limited to 'types') diff --git a/types/compat/ip_address.pp b/types/compat/ip_address.pp new file mode 100644 index 0000000..bf4c4b4 --- /dev/null +++ b/types/compat/ip_address.pp @@ -0,0 +1 @@ +type Stdlib::Compat::Ip_address = Variant[Stdlib::Compat::Ipv4, Stdlib::Compat::Ipv6] diff --git a/types/compat/ipv4.pp b/types/compat/ipv4.pp new file mode 100644 index 0000000..1d72ebd --- /dev/null +++ b/types/compat/ipv4.pp @@ -0,0 +1,2 @@ +# Emulate the validate_ipv4_address and is_ipv4_address functions +type Stdlib::Compat::Ipv4 = Pattern[/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/] diff --git a/types/compat/ipv6.pp b/types/compat/ipv6.pp new file mode 100644 index 0000000..18b148d --- /dev/null +++ b/types/compat/ipv6.pp @@ -0,0 +1 @@ +type Stdlib::Compat::Ipv6 = Pattern[/^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|((?:[\da-f]{1,4}:){6})(\d+)\.(\d+)\.(\d+)\.(\d+))$/] -- cgit v1.2.3 From cce67b42bb6d09d4e9773b64e28c07d8a93ed088 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Tue, 4 Oct 2016 09:36:20 +0100 Subject: Permit undef passed as `nil` to validate_string When validate_string is called via the Puppet 4 deprecation wrappers from deprecation_gen (introduced in 970852d), `undef` is passed as `nil` where it was previously passed as `''` from the Puppet 3-style function API. This change explicitly permits a `nil` value in validate_string, and adds a test case to `is_string` which also accepts the same. Fixes test failures in apt, concat etc: Error while evaluating a Function Call, nil is not a string. It looks to be a NilClass at apt/manifests/source.pp:23:3 [..] # ./spec/fixtures/modules/stdlib/lib/puppet/parser/functions/validate_string.rb:34:in `block (2 levels) in ' # ./spec/fixtures/modules/stdlib/lib/puppet/parser/functions/validate_string.rb:32:in `each' # ./spec/fixtures/modules/stdlib/lib/puppet/parser/functions/validate_string.rb:32:in `block in ' # puppet-4.7.0/lib/puppet/parser/functions.rb:174:in `block (2 levels) in newfunction' # puppet-4.7.0/lib/puppet/util/profiler/around_profiler.rb:58:in `profile' # puppet-4.7.0/lib/puppet/util/profiler.rb:51:in `profile' # puppet-4.7.0/lib/puppet/parser/functions.rb:167:in `block in newfunction' # ./spec/fixtures/modules/stdlib/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb:13:in `block (2 levels) in deprecation_gen' --- types/compat/string.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'types') diff --git a/types/compat/string.pp b/types/compat/string.pp index 4c36e5f..b06255d 100644 --- a/types/compat/string.pp +++ b/types/compat/string.pp @@ -1,2 +1,2 @@ # Emulate the is_string and validate_string functions -type Stdlib::Compat::String = String +type Stdlib::Compat::String = Optional[String] -- cgit v1.2.3 From 83539371e5b1e6ff412eda48c3a725653c506ece Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Thu, 6 Oct 2016 14:22:13 +0100 Subject: Addition of several new types --- types/absolutepath.pp | 2 ++ types/httpsurl.pp | 1 + types/httpurl.pp | 1 + types/unixpath.pp | 2 ++ types/windowspath.pp | 1 + 5 files changed, 7 insertions(+) create mode 100644 types/absolutepath.pp create mode 100644 types/httpsurl.pp create mode 100644 types/httpurl.pp create mode 100644 types/unixpath.pp create mode 100644 types/windowspath.pp (limited to 'types') diff --git a/types/absolutepath.pp b/types/absolutepath.pp new file mode 100644 index 0000000..70ec916 --- /dev/null +++ b/types/absolutepath.pp @@ -0,0 +1,2 @@ +# A strict absolutepath type +type Stdlib::Absolutepath = Variant[Stdlib::Windowspath, Stdlib::Unixpath] diff --git a/types/httpsurl.pp b/types/httpsurl.pp new file mode 100644 index 0000000..36fd30f --- /dev/null +++ b/types/httpsurl.pp @@ -0,0 +1 @@ +type Stdlib::HTTPSUrl = Pattern[/^https:\/\//] diff --git a/types/httpurl.pp b/types/httpurl.pp new file mode 100644 index 0000000..0d93a95 --- /dev/null +++ b/types/httpurl.pp @@ -0,0 +1 @@ +type Stdlib::HTTPUrl = Pattern[/^https?:\/\//] diff --git a/types/unixpath.pp b/types/unixpath.pp new file mode 100644 index 0000000..76f2c17 --- /dev/null +++ b/types/unixpath.pp @@ -0,0 +1,2 @@ +# this regex rejects any path component that is a / or a NUL +type Stdlib::Unixpath = Pattern[/^\/([^\/\0]+(\/)?)+$/] diff --git a/types/windowspath.pp b/types/windowspath.pp new file mode 100644 index 0000000..bc1ee9c --- /dev/null +++ b/types/windowspath.pp @@ -0,0 +1 @@ +type Stdlib::Windowspath = Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/] -- cgit v1.2.3 From ea929418c6c539fe6aa6506e520c5fe8fe68559f Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 25 Oct 2016 15:28:40 +0100 Subject: (MODULES-3980) Fix ipv4 regex validator This also updates all ipv4 tests to use the same test data for better comparability. Closes #676, #679 Fix-Originally-By: Nate Potter --- types/compat/ipv4.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'types') diff --git a/types/compat/ipv4.pp b/types/compat/ipv4.pp index 1d72ebd..a0ba0d6 100644 --- a/types/compat/ipv4.pp +++ b/types/compat/ipv4.pp @@ -1,2 +1,2 @@ # Emulate the validate_ipv4_address and is_ipv4_address functions -type Stdlib::Compat::Ipv4 = Pattern[/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/] +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]+))?$/] -- cgit v1.2.3 From 5d1cbf33978c21f206b9757d1c8235130fdbce19 Mon Sep 17 00:00:00 2001 From: Chris Clonch Date: Mon, 24 Oct 2016 15:31:15 -0400 Subject: Remove leading spaces This corrects puppet-linting error. --- types/compat/bool.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'types') diff --git a/types/compat/bool.pp b/types/compat/bool.pp index dda5f4b..5d8e27e 100644 --- a/types/compat/bool.pp +++ b/types/compat/bool.pp @@ -1,2 +1,2 @@ - # Emulate the is_bool and validate_bool functions - type Stdlib::Compat::Bool = Boolean +# Emulate the is_bool and validate_bool functions +type Stdlib::Compat::Bool = Boolean -- cgit v1.2.3