Commit 1614426f authored by James T. Lee's avatar James T. Lee
Browse files

Squashed 'lib/puppet/stdlib/' content from commit bcb169b1

git-subtree-dir: lib/puppet/stdlib
git-subtree-split: bcb169b1047cbcd18d2d8a04c7081df6a3a08ba8
parents
# Type to match base32 String
type Stdlib::Base32 = Pattern[/^[a-z2-7]+={,6}$/, /^[A-Z2-7]+={,6}$/]
# Type to match base64 String
type Stdlib::Base64 = Pattern[/^[a-zA-Z0-9\/\+]+={,2}$/]
# 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
# Emulate the is_array and validate_array functions
type Stdlib::Compat::Array = Array[Any]
# Emulate the is_bool and validate_bool functions
type Stdlib::Compat::Bool = Boolean
# 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+)?$/]]
# Emulate the is_hash and validate_hash functions
type Stdlib::Compat::Hash = Hash[Any, Any]
# 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
type Stdlib::Compat::Ip_address = Variant[Stdlib::Compat::Ipv4, Stdlib::Compat::Ipv6]
# 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
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
# 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
# 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.
# Emulate the is_string and validate_string functions
type Stdlib::Compat::String = Optional[String]
type Stdlib::Ensure::Service = Enum['stopped', 'running']
# See `man chmod.1` for the regular expression for symbolic mode
type Stdlib::Filemode = Pattern[/^(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))$/]
# Validate the source parameter on file types
type Stdlib::Filesource = Variant[
Stdlib::Absolutepath,
Stdlib::HTTPUrl,
Pattern[
/^file:\/\/\/([^\/\0]+(\/)?)+$/,
/^puppet:\/\/(([\w-]+\.?)+)?\/([^\/\0]+(\/)?)+$/,
],
]
type Stdlib::Fqdn = Pattern[/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/]
type Stdlib::Host = Variant[Stdlib::Fqdn, Stdlib::Compat::Ip_address]
type Stdlib::HTTPSUrl = Pattern[/(?i:^https:\/\/)/]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment