Commit 1042df79 authored by James T. Lee's avatar James T. Lee
Browse files

Move puppet libraries into module for Puppet 7 compat

parent d8c34007
# frozen_string_literal: true
# @summary
# Wrapper that calls the Puppet 3.x function of the same name.
Puppet::Functions.create_function(:is_array) 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_array', 'This method is deprecated, please use match expressions with Stdlib::Compat::Array instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.')
scope.send('function_is_array', args)
end
end
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# frozen_string_literal: true
# @summary
# **Deprecated:** A function to eventually replace the old size() function for stdlib
#
# The original size() function did not handle Puppets new type capabilities, so this function
# is a Puppet 4 compatible solution.
#
# > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a
# built-in [`length`](https://puppet.com/docs/puppet/latest/function.html#length) function.
#
Puppet::Functions.create_function(:length) do
# @param value
# The value whose length is to be found
#
# @return [Integer]
# The length of the given object
dispatch :length do
param 'Variant[String,Array,Hash]', :value
end
def length(value)
if value.is_a?(String)
result = value.length
elsif value.is_a?(Array) || value.is_a?(Hash)
result = value.size
end
result
end
end
This diff is collapsed.
# frozen_string_literal: true
# @summary
# Checks if the OS version is at least a certain version.
# > *Note:*
# Only the major version is taken into account.
#
# @example Example usage:#
# if os_version_gte('Debian', '9') { }
# if os_version_gte('Ubuntu', '18.04') { }
Puppet::Functions.create_function(:os_version_gte) do
# @param os operating system
# @param version
#
# @return [Boolean] `true` or `false
dispatch :os_version_gte do
param 'String[1]', :os
param 'String[1]', :version
return_type 'Boolean'
end
def os_version_gte(os, version)
facts = closure_scope['facts']
(facts['operatingsystem'] == os &&
Puppet::Util::Package.versioncmp(version, facts['operatingsystemmajrelease']) >= 0)
end
end
# frozen_string_literal: true
# @summary
# This function accepts HOCON as a string and converts it into the correct
# Puppet structure
#
# @return
# Data
#
# @example How to parse hocon
# $data = parsehocon("{any valid hocon: string}")
#
Puppet::Functions.create_function(:parsehocon) do
# @param hocon_string A valid HOCON string
# @param default An optional default to return if parsing hocon_string fails
dispatch :parsehocon do
param 'String', :hocon_string
optional_param 'Any', :default
end
def parsehocon(hocon_string, default = :no_default_provided)
require 'hocon/config_factory'
begin
data = Hocon::ConfigFactory.parse_string(hocon_string)
data.resolve.root.unwrapped
rescue Hocon::ConfigError::ConfigParseError => err
Puppet.debug("Parsing hocon failed with error: #{err.message}")
raise err if default == :no_default_provided
default
end
end
end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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