diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b0e39c35..2cdfc30f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,6 @@ jobs: Acceptance: needs: Spec uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" - secrets: "inherit" with: - runs_on: "ubuntu-20.04" + flags: "--nightly" + secrets: "inherit" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index aaa4967f9..5a39a47c7 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -13,6 +13,6 @@ jobs: Acceptance: needs: Spec uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" - secrets: "inherit" with: - runs_on: "ubuntu-20.04" + flags: "--nightly" + secrets: "inherit" diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece05..9e15c6e01 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,9 @@ +--fail-on-warnings --relative +--no-80chars-check +--no-140chars-check +--no-class_inherits_from_params_class-check +--no-autoloader_layout-check +--no-documentation-check +--no-single_quote_string_with_variables-check +--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp diff --git a/.rubocop.yml b/.rubocop.yml index 439ea84ee..47b1aadbe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: AllCops: NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.6' + TargetRubyVersion: 3.1 Include: - "**/*.rb" Exclude: diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b2e8ac1..6f650b7a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). +## [v9.7.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.7.0) - 2024-12-17 + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v9.6.0...v9.7.0) + +### Added + +- (CAT-2119) Add Ubuntu 24.04 support [#1440](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1440) ([shubhamshinde360](https://github.com/shubhamshinde360)) +- (CAT-2101) Add support for Debian-12 [#1439](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1439) ([skyamgarp](https://github.com/skyamgarp)) +- Support for Amazon linux 2 and 2023 [#1427](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1427) ([h0tw1r3](https://github.com/h0tw1r3)) + +### Fixed + +- (CAT-2180) Upgrade rexml to address CVE-2024-49761 [#1443](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1443) ([amitkarsale](https://github.com/amitkarsale)) + ## [v9.6.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.6.0) - 2024-04-03 [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v9.5.0...v9.6.0) @@ -89,6 +103,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v8.6.0...v9.0.0) ### Changed + - Deprecate the `validate_legacy()` function [#1353](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1353) ([smortex](https://github.com/smortex)) - Remove deprecated functions [#1352](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1352) ([smortex](https://github.com/smortex)) - Rewrite validate_email_address() as a Puppet 4.x function [#1350](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1350) ([smortex](https://github.com/smortex)) @@ -247,6 +262,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v7.1.0...v8.0.0) ### Changed + - Flip installed and present in Function ensure_packages [#1196](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1196) ([cocker-cc](https://github.com/cocker-cc)) ### Added @@ -280,6 +296,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v6.6.0...v7.0.0) ### Changed + - pdksync - Remove Puppet 5 from testing and bump minimal version to 6.0.0 [#1164](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1164) ([carabasdaniel](https://github.com/carabasdaniel)) ### Added @@ -388,6 +405,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/5.2.0...v6.0.0) ### Changed + - pdksync - (MODULES-8444) - Raise lower Puppet bound [#1011](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1011) ([david22swan](https://github.com/david22swan)) ### Added diff --git a/Gemfile b/Gemfile index 8e9f845e1..6dd3b77cc 100644 --- a/Gemfile +++ b/Gemfile @@ -14,50 +14,55 @@ def location_for(place_or_version, fake_version = nil) end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "deep_merge", '~> 1.2.2', require: false gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false - gem "facterdb", '~> 2.1', require: false + gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "metadata-json-lint", '~> 4.0', require: false - gem "rspec-puppet-facts", '~> 4.0', require: false + gem "json-schema", '< 5.1.1', require: false + gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "dependency_checker", '~> 1.0.0', require: false gem "parallel_tests", '= 3.12.1', require: false gem "pry", '~> 0.10', require: false gem "simplecov-console", '~> 0.9', require: false - gem "puppet-debugger", '~> 1.0', require: false + gem "puppet-debugger", '~> 1.6', require: false gem "rubocop", '~> 1.50.0', require: false gem "rubocop-performance", '= 1.16.0', require: false gem "rubocop-rspec", '= 2.19.0', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "rexml", '>= 3.0.0', '< 3.2.7', require: false + gem "bigdecimal", '< 3.2.2', require: false, platforms: [:mswin, :mingw, :x64_mingw] end group :development, :release_prep do gem "puppet-strings", '~> 4.0', require: false - gem "puppetlabs_spec_helper", '~> 7.0', require: false + gem "puppetlabs_spec_helper", '~> 8.0', require: false + gem "puppet-blacksmith", '~> 7.0', require: false end group :system_tests do - gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] + gem "puppet_litmus", '~> 2.0', require: false, platforms: [:ruby, :x64_mingw] if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? + gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] if ENV['PUPPET_FORGE_TOKEN'].to_s.empty? gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "serverspec", '~> 2.41', require: false end -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - gems = {} +puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil) +facter_version = ENV.fetch('FACTER_GEM_VERSION', nil) +hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil) -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables +# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet +# Otherwise, do as before and use location_for to fetch gems from the default source +if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? + gems['puppet'] = ['~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] + gems['facter'] = ['~> 4.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] +else + gems['puppet'] = location_for(puppet_version) + gems['facter'] = location_for(facter_version) if facter_version +end -gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version gems.each do |gem_name, gem_params| diff --git a/REFERENCE.md b/REFERENCE.md index 63169ab67..a472419bc 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -63,9 +63,8 @@ environment. * [`grep`](#grep): This function searches through an array and returns any elements that match the provided regular expression. * [`has_interface_with`](#has_interface_with): DEPRECATED. Use the namespaced function [`stdlib::has_interface_with`](#stdlibhas_interface_with) instead. -* [`has_interface_with`](#has_interface_with): Returns boolean based on kind and value. -* [`has_ip_address`](#has_ip_address): Returns true if the client has the requested IP address on some interface. -* [`has_ip_network`](#has_ip_network): Returns true if the client has an IP address within the requested network. +* [`has_ip_address`](#has_ip_address): DEPRECATED. Use the namespaced function [`stdlib::has_ip_address`](#stdlibhas_ip_address) instead. +* [`has_ip_network`](#has_ip_network): DEPRECATED. Use the namespaced function [`stdlib::has_ip_network`](#stdlibhas_ip_network) instead. * [`intersection`](#intersection): This function returns an array of the intersection of two. * [`is_a`](#is_a): Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks. @@ -126,6 +125,8 @@ optional seed for repeatable randomness. * [`stdlib::fqdn_rotate`](#stdlib--fqdn_rotate): Rotates an array or string a random number of times, combining the `fqdn` fact and an optional seed for repeatable randomness. * [`stdlib::has_function`](#stdlib--has_function): Returns whether the Puppet runtime has access to a given function. * [`stdlib::has_interface_with`](#stdlib--has_interface_with): Returns boolean based on network interfaces present and their attribute values. +* [`stdlib::has_ip_address`](#stdlib--has_ip_address): Returns true if the client has the requested IPv4 address on some interface. +* [`stdlib::has_ip_network`](#stdlib--has_ip_network): Returns true if the client has the requested IPv4 network on some interface. * [`stdlib::ip_in_range`](#stdlib--ip_in_range): Returns true if the ipaddress is within the given CIDRs * [`stdlib::merge`](#stdlib--merge): Merges two or more hashes together or hashes resulting from iteration, and returns the resulting hash. @@ -2052,75 +2053,41 @@ Data type: `Any` -### `has_interface_with` - -Type: Ruby 3.x API - -Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`. - -#### Examples - -##### **Usage** - -```puppet -has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false` -has_interface_with("ipaddress", "127.0.0.1") # Returns `true` -``` - -##### If no "kind" is given, then the presence of the interface is checked: - -```puppet -has_interface_with("lo") # Returns `true` -``` +### `has_ip_address` -#### `has_interface_with()` +Type: Ruby 4.x API -Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`. +DEPRECATED. Use the namespaced function [`stdlib::has_ip_address`](#stdlibhas_ip_address) instead. -Returns: `Any` boolean values `true` or `false` +#### `has_ip_address(Any *$args)` -##### Examples +The has_ip_address function. -###### **Usage** - -```puppet -has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false` -has_interface_with("ipaddress", "127.0.0.1") # Returns `true` -``` +Returns: `Any` -###### If no "kind" is given, then the presence of the interface is checked: +##### `*args` -```puppet -has_interface_with("lo") # Returns `true` -``` +Data type: `Any` -### `has_ip_address` -Type: Ruby 3.x API -This function iterates through the 'interfaces' fact and checks the -'ipaddress_IFACE' facts, performing a simple string comparison. +### `has_ip_network` -#### `has_ip_address()` +Type: Ruby 4.x API -This function iterates through the 'interfaces' fact and checks the -'ipaddress_IFACE' facts, performing a simple string comparison. +DEPRECATED. Use the namespaced function [`stdlib::has_ip_network`](#stdlibhas_ip_network) instead. -Returns: `Boolean` `true` or `false` +#### `has_ip_network(Any *$args)` -### `has_ip_network` +The has_ip_network function. -Type: Ruby 3.x API +Returns: `Any` -This function iterates through the 'interfaces' fact and checks the -'network_IFACE' facts, performing a simple string comparision. +##### `*args` -#### `has_ip_network()` +Data type: `Any` -This function iterates through the 'interfaces' fact and checks the -'network_IFACE' facts, performing a simple string comparision. -Returns: `Any` Boolean value, `true` if the client has an IP address within the requested network. ### `intersection` @@ -3575,6 +3542,42 @@ Data type: `String[1]` The value of the attribute +### `stdlib::has_ip_address` + +Type: Puppet Language + +Returns true if the client has the requested IPv4 address on some interface. + +#### `stdlib::has_ip_address(Stdlib::IP::Address::V4::Nosubnet $ip_address)` + +The stdlib::has_ip_address function. + +Returns: `Boolean` Returns `true` if the requested IP address exists on any interface. + +##### `ip_address` + +Data type: `Stdlib::IP::Address::V4::Nosubnet` + +The IPv4 address you want to check the existence of + +### `stdlib::has_ip_network` + +Type: Puppet Language + +Returns true if the client has the requested IPv4 network on some interface. + +#### `stdlib::has_ip_network(Stdlib::IP::Address::V4::Nosubnet $ip_network)` + +The stdlib::has_ip_network function. + +Returns: `Boolean` Returns `true` if the requested IP network exists on any interface. + +##### `ip_network` + +Data type: `Stdlib::IP::Address::V4::Nosubnet` + +The IPv4 network you want to check the existence of + ### `stdlib::ip_in_range` Type: Ruby 4.x API diff --git a/Rakefile b/Rakefile index 77590fe6f..31b593053 100644 --- a/Rakefile +++ b/Rakefile @@ -7,3 +7,12 @@ require 'puppet-syntax/tasks/puppet-syntax' require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] + diff --git a/functions/has_ip_address.pp b/functions/has_ip_address.pp new file mode 100644 index 000000000..d8d7e6a79 --- /dev/null +++ b/functions/has_ip_address.pp @@ -0,0 +1,10 @@ +# @summary Returns true if the client has the requested IPv4 address on some interface. +# +# @param ip_address +# The IPv4 address you want to check the existence of +# @return [Boolean] Returns `true` if the requested IP address exists on any interface. +function stdlib::has_ip_address( + Stdlib::IP::Address::V4::Nosubnet $ip_address, +) >> Boolean { + stdlib::has_interface_with('ipaddress', $ip_address) +} diff --git a/functions/has_ip_network.pp b/functions/has_ip_network.pp new file mode 100644 index 000000000..b6b9cb0f8 --- /dev/null +++ b/functions/has_ip_network.pp @@ -0,0 +1,10 @@ +# @summary Returns true if the client has the requested IPv4 network on some interface. +# +# @param ip_network +# The IPv4 network you want to check the existence of +# @return [Boolean] Returns `true` if the requested IP network exists on any interface. +function stdlib::has_ip_network( + Stdlib::IP::Address::V4::Nosubnet $ip_network, +) >> Boolean { + stdlib::has_interface_with('network', $ip_network) +} diff --git a/lib/puppet/functions/has_ip_address.rb b/lib/puppet/functions/has_ip_address.rb new file mode 100644 index 000000000..392d5c550 --- /dev/null +++ b/lib/puppet/functions/has_ip_address.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` + +# @summary DEPRECATED. Use the namespaced function [`stdlib::has_ip_address`](#stdlibhas_ip_address) instead. +Puppet::Functions.create_function(:has_ip_address) do + dispatch :deprecation_gen do + repeated_param 'Any', :args + end + def deprecation_gen(*args) + call_function('deprecation', 'has_ip_address', 'This function is deprecated, please use stdlib::has_ip_address instead.', false) + call_function('stdlib::has_ip_address', *args) + end +end diff --git a/lib/puppet/functions/has_ip_network.rb b/lib/puppet/functions/has_ip_network.rb new file mode 100644 index 000000000..b0219b671 --- /dev/null +++ b/lib/puppet/functions/has_ip_network.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` + +# @summary DEPRECATED. Use the namespaced function [`stdlib::has_ip_network`](#stdlibhas_ip_network) instead. +Puppet::Functions.create_function(:has_ip_network) do + dispatch :deprecation_gen do + repeated_param 'Any', :args + end + def deprecation_gen(*args) + call_function('deprecation', 'has_ip_network', 'This function is deprecated, please use stdlib::has_ip_network instead.', false) + call_function('stdlib::has_ip_network', *args) + end +end diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb deleted file mode 100644 index b78029d08..000000000 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true - -# -# has_interface_with -# -module Puppet::Parser::Functions - newfunction(:has_interface_with, type: :rvalue, doc: <<-DOC - @summary - Returns boolean based on kind and value. - - @return - boolean values `true` or `false` - - Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`. - - @example **Usage** - has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false` - has_interface_with("ipaddress", "127.0.0.1") # Returns `true` - - @example If no "kind" is given, then the presence of the interface is checked: - has_interface_with("lo") # Returns `true` - DOC - ) do |args| - raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments given (#{args.size} for 1 or 2)") if args.empty? || args.size > 2 - - interfaces = lookupvar('interfaces') - - # If we do not have any interfaces, then there are no requested attributes - return false if interfaces == :undefined || interfaces.nil? - - interfaces = interfaces.split(',') - - return interfaces.member?(args[0]) if args.size == 1 - - kind, value = args - - # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable - # https://tickets.puppetlabs.com/browse/PUP-3597 - factval = nil - begin - catch :undefined_variable do - factval = lookupvar(kind) - end - rescue Puppet::ParseError - end - return true if factval == value - - result = false - interfaces.each do |iface| - iface.downcase! - factval = nil - begin - # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable - # https://tickets.puppetlabs.com/browse/PUP-3597 - catch :undefined_variable do - factval = lookupvar("#{kind}_#{iface}") - end - rescue Puppet::ParseError - end - if value == factval - result = true - break - end - end - - result - end -end diff --git a/lib/puppet/parser/functions/has_ip_address.rb b/lib/puppet/parser/functions/has_ip_address.rb deleted file mode 100644 index 763813c22..000000000 --- a/lib/puppet/parser/functions/has_ip_address.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -# -# has_ip_address -# -module Puppet::Parser::Functions - newfunction(:has_ip_address, type: :rvalue, doc: <<-DOC - @summary - Returns true if the client has the requested IP address on some interface. - - @return [Boolean] - `true` or `false` - - This function iterates through the 'interfaces' fact and checks the - 'ipaddress_IFACE' facts, performing a simple string comparison. - DOC - ) do |args| - raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 - - Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ - unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) - - function_has_interface_with(['ipaddress', args[0]]) - end -end - -# vim:sts=2 sw=2 diff --git a/lib/puppet/parser/functions/has_ip_network.rb b/lib/puppet/parser/functions/has_ip_network.rb deleted file mode 100644 index b556d97c0..000000000 --- a/lib/puppet/parser/functions/has_ip_network.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -# -# has_ip_network -# -module Puppet::Parser::Functions - newfunction(:has_ip_network, type: :rvalue, doc: <<-DOC - @summary - Returns true if the client has an IP address within the requested network. - - @return - Boolean value, `true` if the client has an IP address within the requested network. - - This function iterates through the 'interfaces' fact and checks the - 'network_IFACE' facts, performing a simple string comparision. - DOC - ) do |args| - raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 - - Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ - unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) - - function_has_interface_with(['network', args[0]]) - end -end - -# vim:sts=2 sw=2 diff --git a/lib/puppet/parser/functions/parseyaml.rb b/lib/puppet/parser/functions/parseyaml.rb index e1036386a..014c12d26 100644 --- a/lib/puppet/parser/functions/parseyaml.rb +++ b/lib/puppet/parser/functions/parseyaml.rb @@ -22,7 +22,7 @@ module Puppet::Parser::Functions require 'yaml' begin - YAML.load(arguments[0]) || arguments[1] # rubocop:disable Security/YAMLLoad : using YAML.safe_load causes the code to break + YAML.load(arguments[0]) || arguments[1] # : using YAML.safe_load causes the code to break # in ruby 1.9.3 Psych::SyntaxError is a RuntimeException # this still needs to catch that and work also on rubies that # do not have Psych available. diff --git a/lib/puppet/parser/functions/validate_augeas.rb b/lib/puppet/parser/functions/validate_augeas.rb index 8d89b1e7d..31df4cd66 100644 --- a/lib/puppet/parser/functions/validate_augeas.rb +++ b/lib/puppet/parser/functions/validate_augeas.rb @@ -67,7 +67,7 @@ module Puppet::Parser::Functions # Check for syntax lens = args[1] aug.transform( - lens: lens, + lens:, name: 'Validate_augeas', incl: tmpfile.path, ) diff --git a/metadata.json b/metadata.json index d458abfa7..c997c0457 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "9.6.0", + "version": "9.7.0", "author": "puppetlabs", "summary": "Standard library of resources for Puppet modules.", "license": "Apache-2.0", @@ -109,11 +109,11 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 7.0.0 < 9.0.0" + "version_requirement": ">= 8.0.0 < 9.0.0" } ], "description": "Standard Library for Puppet Modules", - "pdk-version": "3.2.0", + "pdk-version": "3.5.0", "template-url": "https://github.com/puppetlabs/pdk-templates#main", - "template-ref": "tags/3.2.0.4-0-g5d17ec1" + "template-ref": "heads/main-0-g11c0f3d" } diff --git a/spec/functions/has_ip_address_spec.rb b/spec/functions/has_ip_address_spec.rb index 5b787d693..7256e7518 100644 --- a/spec/functions/has_ip_address_spec.rb +++ b/spec/functions/has_ip_address_spec.rb @@ -4,22 +4,29 @@ describe 'has_ip_address' do it { is_expected.not_to be_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.and_raise_error(ArgumentError, %r{'stdlib::has_ip_address' expects 1 argument, got none}) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError, %r{'stdlib::has_ip_address' expects 1 argument, got 2}) } context 'when on Linux Systems' do let(:facts) do { - interfaces: 'eth0,lo', - ipaddress: '10.0.0.1', - ipaddress_lo: '127.0.0.1', - ipaddress_eth0: '10.0.0.1' + networking: { + 'interfaces' => { + 'eth0' => { + 'ip' => '10.0.0.1', + }, + 'lo' => { + 'ip' => '127.0.0.1', + }, + }, + 'ip' => '10.0.0.1', + }, } end it { is_expected.to run.with_params('127.0.0.1').and_return(true) } it { is_expected.to run.with_params('10.0.0.1').and_return(true) } it { is_expected.to run.with_params('8.8.8.8').and_return(false) } - it { is_expected.to run.with_params('invalid').and_return(false) } + it { is_expected.to run.with_params('invalid').and_raise_error(ArgumentError, %r{parameter 'ip_address' expects a match}) } end end diff --git a/spec/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb index 22564bb71..c8352272e 100644 --- a/spec/functions/has_ip_network_spec.rb +++ b/spec/functions/has_ip_network_spec.rb @@ -4,21 +4,28 @@ describe 'has_ip_network' do it { is_expected.not_to be_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.and_raise_error(ArgumentError, %r{'stdlib::has_ip_network' expects 1 argument, got none}) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError, %r{'stdlib::has_ip_network' expects 1 argument, got 2}) } context 'when on Linux Systems' do let(:facts) do { - interfaces: 'eth0,lo', - network_lo: '127.0.0.0', - network_eth0: '10.0.0.0' + networking: { + 'interfaces' => { + 'eth0' => { + 'network' => '10.0.0.0', + }, + 'lo' => { + 'network' => '127.0.0.0', + }, + }, + }, } end it { is_expected.to run.with_params('127.0.0.0').and_return(true) } it { is_expected.to run.with_params('10.0.0.0').and_return(true) } it { is_expected.to run.with_params('8.8.8.0').and_return(false) } - it { is_expected.to run.with_params('invalid').and_return(false) } + it { is_expected.to run.with_params('invalid').and_raise_error(ArgumentError, %r{parameter 'ip_network' expects a match}) } end end diff --git a/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb b/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb index 8b10a413c..310ac5c97 100644 --- a/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb @@ -172,8 +172,8 @@ name: 'foo', path: tmpfile, line: 'inserted = line', - after: after, - match: match, + after:, + match:, ) end end