Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
James T. Lee
Dotfiles
Commits
1042df79
Commit
1042df79
authored
Jul 30, 2021
by
James T. Lee
Browse files
Move puppet libraries into module for Puppet 7 compat
parent
d8c34007
Changes
278
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
785 additions
and
0 deletions
+785
-0
lib/puppet/stdlib/lib/puppet/functions/to_yaml.rb
lib/puppet/stdlib/lib/puppet/functions/to_yaml.rb
+31
-0
lib/puppet/stdlib/lib/puppet/functions/type_of.rb
lib/puppet/stdlib/lib/puppet/functions/type_of.rb
+26
-0
lib/puppet/stdlib/lib/puppet/functions/validate_absolute_path.rb
...pet/stdlib/lib/puppet/functions/validate_absolute_path.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_array.rb
lib/puppet/stdlib/lib/puppet/functions/validate_array.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_bool.rb
lib/puppet/stdlib/lib/puppet/functions/validate_bool.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_hash.rb
lib/puppet/stdlib/lib/puppet/functions/validate_hash.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_integer.rb
lib/puppet/stdlib/lib/puppet/functions/validate_integer.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_ip_address.rb
...puppet/stdlib/lib/puppet/functions/validate_ip_address.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_ipv4_address.rb
...ppet/stdlib/lib/puppet/functions/validate_ipv4_address.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_ipv6_address.rb
...ppet/stdlib/lib/puppet/functions/validate_ipv6_address.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_legacy.rb
lib/puppet/stdlib/lib/puppet/functions/validate_legacy.rb
+82
-0
lib/puppet/stdlib/lib/puppet/functions/validate_numeric.rb
lib/puppet/stdlib/lib/puppet/functions/validate_numeric.rb
+30
-0
lib/puppet/stdlib/lib/puppet/functions/validate_re.rb
lib/puppet/stdlib/lib/puppet/functions/validate_re.rb
+35
-0
lib/puppet/stdlib/lib/puppet/functions/validate_slength.rb
lib/puppet/stdlib/lib/puppet/functions/validate_slength.rb
+29
-0
lib/puppet/stdlib/lib/puppet/functions/validate_string.rb
lib/puppet/stdlib/lib/puppet/functions/validate_string.rb
+30
-0
lib/puppet/stdlib/lib/puppet/parser/functions/abs.rb
lib/puppet/stdlib/lib/puppet/parser/functions/abs.rb
+44
-0
lib/puppet/stdlib/lib/puppet/parser/functions/any2array.rb
lib/puppet/stdlib/lib/puppet/parser/functions/any2array.rb
+57
-0
lib/puppet/stdlib/lib/puppet/parser/functions/any2bool.rb
lib/puppet/stdlib/lib/puppet/parser/functions/any2bool.rb
+61
-0
lib/puppet/stdlib/lib/puppet/parser/functions/assert_private.rb
...ppet/stdlib/lib/puppet/parser/functions/assert_private.rb
+33
-0
lib/puppet/stdlib/lib/puppet/parser/functions/base64.rb
lib/puppet/stdlib/lib/puppet/parser/functions/base64.rb
+87
-0
No files found.
lib/puppet/stdlib/lib/puppet/functions/to_yaml.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
require
'yaml'
# @summary
# Convert a data structure and output it as YAML
#
# @example How to output YAML
# # output yaml to a file
# file { '/tmp/my.yaml':
# ensure => file,
# content => to_yaml($myhash),
# }
# @example Use options control the output format
# file { '/tmp/my.yaml':
# ensure => file,
# content => to_yaml($myhash, {indentation: 4})
# }
Puppet
::
Functions
.
create_function
(
:to_yaml
)
do
# @param data
# @param options
#
# @return [String]
dispatch
:to_yaml
do
param
'Any'
,
:data
optional_param
'Hash'
,
:options
end
def
to_yaml
(
data
,
options
=
{})
data
.
to_yaml
(
options
)
end
end
lib/puppet/stdlib/lib/puppet/functions/type_of.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
# @summary
# Returns the type of the passed value.
#
# @example how to compare values' types
# # compare the types of two values
# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }
# @example how to compare against an abstract type
# unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
# unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
#
# See the documentation for "The Puppet Type System" for more information about types.
# See the `assert_type()` function for flexible ways to assert the type of a value.
#
# The built-in type() function in puppet is generally preferred over this function
# this function is provided for backwards compatibility.
Puppet
::
Functions
.
create_function
(
:type_of
)
do
# @return [String]
# the type of the passed value
#
# @param value
def
type_of
(
value
)
Puppet
::
Pops
::
Types
::
TypeCalculator
.
infer_set
(
value
)
end
end
lib/puppet/stdlib/lib/puppet/functions/validate_absolute_path.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_array.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_bool.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_hash.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_integer.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_ip_address.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_ipv4_address.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_ipv6_address.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_legacy.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
# @summary
# Validate a value against both the target_type (new) and the previous_validation function (old).
Puppet
::
Functions
.
create_function
(
:validate_legacy
)
do
# The function checks a value against both the target_type (new) and the previous_validation function (old).
# @param scope
# The main value that will be passed to the method
# @param target_type
# @param function_name
# @param value
# @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
:validate_legacy
do
param
'Any'
,
:scope
param
'Type'
,
:target_type
param
'String'
,
:function_name
param
'Any'
,
:value
repeated_param
'Any'
,
:args
end
# @param scope
# The main value that will be passed to the method
# @param type_string
# @param function_name
# @param value
# @param args Any additional values that are to be passed to the method
# @return Legacy validation method
#
dispatch
:validate_legacy_s
do
param
'Any'
,
:scope
param
'String'
,
:type_string
param
'String'
,
:function_name
param
'Any'
,
:value
repeated_param
'Any'
,
:args
end
# Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-
# c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
def
call
(
scope
,
*
args
)
manipulated_args
=
[
scope
]
+
args
self
.
class
.
dispatcher
.
dispatch
(
self
,
scope
,
manipulated_args
)
end
def
validate_legacy_s
(
scope
,
type_string
,
*
args
)
t
=
Puppet
::
Pops
::
Types
::
TypeParser
.
new
.
parse
(
type_string
,
scope
)
validate_legacy
(
scope
,
t
,
*
args
)
end
def
validate_legacy
(
scope
,
target_type
,
function_name
,
value
,
*
prev_args
)
if
assert_type
(
target_type
,
value
)
if
previous_validation
(
scope
,
function_name
,
value
,
*
prev_args
)
# Silently passes
else
Puppet
.
notice
(
"Accepting previously invalid value for target type '
#{
target_type
}
'"
)
end
else
inferred_type
=
Puppet
::
Pops
::
Types
::
TypeCalculator
.
infer_set
(
value
)
error_msg
=
Puppet
::
Pops
::
Types
::
TypeMismatchDescriber
.
new
.
describe_mismatch
(
"validate_legacy(
#{
function_name
}
)"
,
target_type
,
inferred_type
)
if
previous_validation
(
scope
,
function_name
,
value
,
*
prev_args
)
call_function
(
'deprecation'
,
'validate_legacy'
,
error_msg
)
else
call_function
(
'fail'
,
error_msg
)
end
end
end
def
previous_validation
(
scope
,
function_name
,
value
,
*
prev_args
)
# Call the previous validation function and catch any errors. Return true if no errors are thrown.
scope
.
send
(
"function_
#{
function_name
}
"
.
to_s
,
[
value
,
*
prev_args
])
true
rescue
Puppet
::
ParseError
false
end
def
assert_type
(
type
,
value
)
Puppet
::
Pops
::
Types
::
TypeCalculator
.
instance?
(
type
,
value
)
end
end
lib/puppet/stdlib/lib/puppet/functions/validate_numeric.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_re.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_slength.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/functions/validate_string.rb
0 → 100644
View file @
1042df79
# 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
lib/puppet/stdlib/lib/puppet/parser/functions/abs.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
#
# abs.rb
#
module
Puppet::Parser::Functions
newfunction
(
:abs
,
type: :rvalue
,
doc:
<<-
DOC
@summary
**Deprecated:** Returns the absolute value of a number
For example -34.56 becomes 34.56.
Takes a single integer or float value as an argument.
> *Note:*
**Deprected** from Puppet 6.0.0, the built-in
['abs'](https://puppet.com/docs/puppet/6.4/function.html#abs)function will be used instead.
@return The absolute value of the given number if it was an Integer
DOC
)
do
|
arguments
|
raise
(
Puppet
::
ParseError
,
"abs(): Wrong number of arguments given (
#{
arguments
.
size
}
for 1)"
)
if
arguments
.
empty?
value
=
arguments
[
0
]
# Numbers in Puppet are often string-encoded which is troublesome ...
if
value
.
is_a?
(
String
)
if
%r{^-?(?:
\d
+)(?:
\.\d
+){1}$}
.
match?
(
value
)
value
=
value
.
to_f
elsif
%r{^-?
\d
+$}
.
match?
(
value
)
value
=
value
.
to_i
else
raise
(
Puppet
::
ParseError
,
'abs(): Requires float or integer to work with'
)
end
end
# We have numeric value to handle ...
result
=
value
.
abs
return
result
end
end
# vim: set ts=2 sw=2 et :
lib/puppet/stdlib/lib/puppet/parser/functions/any2array.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
#
# any2array.rb
#
module
Puppet::Parser::Functions
newfunction
(
:any2array
,
type: :rvalue
,
doc:
<<-
DOC
@summary
This converts any object to an array containing that object.
Empty argument lists are converted to an empty array. Arrays are left
untouched. Hashes are converted to arrays of alternating keys and values.
> *Note:*
since Puppet 5.0.0 it is possible to create new data types for almost any
datatype using the type system and the built-in
[`Array.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-array-and-tuple)
function is used to create a new Array..
```
$hsh = {'key' => 42, 'another-key' => 100}
notice(Array($hsh))
```
Would notice `[['key', 42], ['another-key', 100]]`
The Array data type also has a special mode to "create an array if not already an array"
```
notice(Array({'key' => 42, 'another-key' => 100}, true))
```
Would notice `[{'key' => 42, 'another-key' => 100}]`, as the `true` flag prevents the hash from being
transformed into an array.
@return [Array] The new array containing the given object
DOC
)
do
|
arguments
|
if
arguments
.
empty?
return
[]
end
return
arguments
unless
arguments
.
length
==
1
return
arguments
[
0
]
if
arguments
[
0
].
is_a?
(
Array
)
return
[]
if
arguments
==
[
''
]
if
arguments
[
0
].
is_a?
(
Hash
)
result
=
[]
arguments
[
0
].
each
do
|
key
,
value
|
result
<<
key
<<
value
end
return
result
end
return
arguments
end
end
# vim: set ts=2 sw=2 et :
lib/puppet/stdlib/lib/puppet/parser/functions/any2bool.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
#
# any2bool.rb
#
module
Puppet::Parser::Functions
newfunction
(
:any2bool
,
type: :rvalue
,
doc:
<<-
DOC
@summary
Converts 'anything' to a boolean.
In practise it does the following:
* Strings such as Y,y,1,T,t,TRUE,yes,'true' will return true
* Strings such as 0,F,f,N,n,FALSE,no,'false' will return false
* Booleans will just return their original value
* Number (or a string representation of a number) > 0 will return true, otherwise false
* undef will return false
* Anything else will return true
Also see the built-in [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean)
function.
@return [Boolean] The boolean value of the object that was given
DOC
)
do
|
arguments
|
raise
(
Puppet
::
ParseError
,
"any2bool(): Wrong number of arguments given (
#{
arguments
.
size
}
for 1)"
)
if
arguments
.
empty?
# If argument is already Boolean, return it
if
!!
arguments
[
0
]
==
arguments
[
0
]
# rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean
return
arguments
[
0
]
end
arg
=
arguments
[
0
]
if
arg
.
nil?
return
false
end
if
arg
==
:undef
return
false
end
valid_float
=
begin
!!
Float
(
arg
)
# rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean
rescue
false
end
if
arg
.
is_a?
(
Numeric
)
return
function_num2bool
([
arguments
[
0
]])
end
if
arg
.
is_a?
(
String
)
return
function_num2bool
([
arguments
[
0
]])
if
valid_float
return
function_str2bool
([
arguments
[
0
]])
end
return
true
end
end
# vim: set ts=2 sw=2 et :
lib/puppet/stdlib/lib/puppet/parser/functions/assert_private.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
#
# assert_private.rb
#
module
Puppet::Parser::Functions
newfunction
(
:assert_private
,
doc:
<<-
DOC
@summary
Sets the current class or definition as private.
@return
set the current class or definition as private.
Calling the class or definition from outside the current module will fail.
DOC
)
do
|
args
|
raise
(
Puppet
::
ParseError
,
"assert_private(): Wrong number of arguments given (
#{
args
.
size
}
}) for 0 or 1)"
)
if
args
.
size
>
1
scope
=
self
if
scope
.
lookupvar
(
'module_name'
)
!=
scope
.
lookupvar
(
'caller_module_name'
)
message
=
nil
if
args
[
0
]
&
.
is_a?
(
String
)
message
=
args
[
0
]
else
manifest_name
=
scope
.
source
.
name
manifest_type
=
scope
.
source
.
type
message
=
(
manifest_type
.
to_s
==
'hostclass'
)
?
'Class'
:
'Definition'
message
+=
"
#{
manifest_name
}
is private"
end
raise
(
Puppet
::
ParseError
,
message
)
end
end
end
lib/puppet/stdlib/lib/puppet/parser/functions/base64.rb
0 → 100644
View file @
1042df79
# frozen_string_literal: true
# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
module
Puppet::Parser::Functions
newfunction
(
:base64
,
type: :rvalue
,
doc:
<<-
DOC
)
do
|
args
|
@summary
Base64 encode or decode a string based on the command and the string submitted
@example Example usage
Encode and decode a string
$encodestring = base64('encode', 'thestring')
$decodestring = base64('decode', 'dGhlc3RyaW5n')
Explicitly define encode/decode method: default, strict, urlsafe
$method = 'default'
$encodestring = base64('encode', 'thestring', $method)
$decodestring = base64('decode', 'dGhlc3RyaW5n', $method)
Encode a string as if it was binary
$encodestring = String(Binary('thestring', '%s'))
Decode a Binary assuming it is an UTF-8 String
$decodestring = String(Binary("dGhlc3RyaW5n"), "%s")
> **Note:*
Since Puppet 4.8.0, the Binary data type can be used to produce base 64 encoded strings.
See the `new()` function for the Binary and String types for documentation. Also see `binary_file()`
function for reading a file with binary (non UTF-8) content.
@return [String] The encoded/decoded value
DOC
require
'base64'
raise
Puppet
::
ParseError
,
"base64(): Wrong number of arguments (
#{
args
.
length
}
; must be >= 2)"
unless
args
.
length
>=
2
actions
=
[
'encode'
,
'decode'
]
unless
actions
.
include?
(
args
[
0
])
raise
Puppet
::
ParseError
,
"base64(): the first argument must be one of 'encode' or 'decode'"
end
unless
args
[
1
].
is_a?
(
String
)
raise
Puppet
::
ParseError
,
'base64(): the second argument must be a string to base64'
end
method
=
[
'default'
,
'strict'
,
'urlsafe'
]
chosen_method
=
if
args
.
length
<=
2
'default'
else
args
[
2
]
end
unless
method
.
include?
(
chosen_method
)
raise
Puppet
::
ParseError
,
"base64(): the third argument must be one of 'default', 'strict', or 'urlsafe'"
end
case
args
[
0
]
when
'encode'
case
chosen_method
when
'default'
result
=
Base64
.
encode64
(
args
[
1
])
when
'strict'
result
=
Base64
.
strict_encode64
(
args
[
1
])
when
'urlsafe'
result
=
Base64
.
urlsafe_encode64
(
args
[
1
])
end
when
'decode'
case
chosen_method
when
'default'
result
=
Base64
.
decode64
(
args
[
1
])
when
'strict'
result
=
Base64
.
strict_decode64
(
args
[
1
])
when
'urlsafe'
result
=
Base64
.
urlsafe_decode64
(
args
[
1
])
end
end
return
result
end
end
Prev
1
2
3
4
5
6
7
8
…
14
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment