Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lib/facter/facter_dot_d.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(dir = '/etc/facts.d', cache_file = File.join(Puppet[:libdir], 'fa

def entries
Dir.entries(@dir).reject { |f| f =~ %r{^\.|\.ttl$} }.sort.map { |f| File.join(@dir, f) }
rescue
rescue # rubocop:disable Lint/RescueWithoutErrorClass
[]
end

Expand Down Expand Up @@ -113,14 +113,14 @@ def script_parser(file)
def cache_save!
cache = load_cache
File.open(@cache_file, 'w', 0o600) { |f| f.write(YAML.dump(cache)) }
rescue # rubocop:disable Lint/HandleExceptions - Is meant to be suppressed
rescue # rubocop:disable Lint/HandleExceptions, Lint/RescueWithoutErrorClass
end

def cache_store(file, data)
load_cache

@cache[file] = { :data => data, :stored => Time.now.to_i }
rescue # rubocop:disable Lint/HandleExceptions - Is meant to be suppressed
rescue # rubocop:disable Lint/HandleExceptions, Lint/RescueWithoutErrorClass
end

def cache_lookup(file)
Expand All @@ -136,29 +136,27 @@ def cache_lookup(file)
return cache[file][:data] if ttl == -1
return cache[file][:data] if (now - cache[file][:stored]) <= ttl
return nil
rescue
rescue # rubocop:disable Lint/RescueWithoutErrorClass
return nil
end

def cache_time(file)
meta = file + '.ttl'

return File.read(meta).chomp.to_i
rescue
rescue # rubocop:disable Lint/RescueWithoutErrorClass
return 0
end

def load_cache
unless @cache
@cache = if File.exist?(@cache_file)
@cache ||= if File.exist?(@cache_file)
YAML.load_file(@cache_file)
else
{}
end
end

return @cache
rescue
rescue # rubocop:disable Lint/RescueWithoutErrorClass
@cache = {}
return @cache
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/abs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# abs.rb
#
module Puppet::Parser::Functions
newfunction(:abs, :type => :rvalue, :doc => <<-EOS
newfunction(:abs, :type => :rvalue, :doc => <<-DOC
Returns the absolute value of a number, for example -34.56 becomes
34.56. Takes a single integer and float value as an argument.
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/any2array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# any2array.rb
#
module Puppet::Parser::Functions
newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
newfunction(:any2array, :type => :rvalue, :doc => <<-DOC
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.
EOS
DOC
) do |arguments|

if arguments.empty?
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/parser/functions/any2bool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# any2bool.rb
#
module Puppet::Parser::Functions
newfunction(:any2bool, :type => :rvalue, :doc => <<-EOS
newfunction(:any2bool, :type => :rvalue, :doc => <<-DOC
This 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
Expand All @@ -11,7 +11,7 @@ module Puppet::Parser::Functions
* Number (or a string representation of a number) > 0 will return true, otherwise false
* undef will return false
* Anything else will return true
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "any2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
Expand All @@ -33,7 +33,7 @@ module Puppet::Parser::Functions

valid_float = begin
!!Float(arg) # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean
rescue
rescue # rubocop:disable Lint/RescueWithoutErrorClass
false
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/assert_private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# assert_private.rb
#
module Puppet::Parser::Functions
newfunction(:assert_private, :doc => <<-'EOS'
newfunction(:assert_private, :doc => <<-DOC
Sets the current class or definition as private.
Calling the class or definition from outside the current module will fail.
EOS
DOC
) do |args|

raise(Puppet::ParseError, "assert_private(): Wrong number of arguments given (#{args.size}}) for 0 or 1)") if args.size > 1
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/base64.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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 => <<-'ENDHEREDOC') do |args|
newfunction(:base64, :type => :rvalue, :doc => <<-'DOC') do |args|
Base64 encode or decode a string based on the command and the string submitted

Usage:
Expand All @@ -13,7 +13,7 @@ module Puppet::Parser::Functions
$encodestring = base64('encode', 'thestring', $method)
$decodestring = base64('decode', 'dGhlc3RyaW5n', $method)

ENDHEREDOC
DOC

require 'base64'

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/basename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# basename.rb
#
module Puppet::Parser::Functions
newfunction(:basename, :type => :rvalue, :doc => <<-EOS
newfunction(:basename, :type => :rvalue, :doc => <<-DOC
Strips directory (and optional suffix) from a filename
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, 'basename(): No arguments given') if arguments.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/bool2num.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# bool2num.rb
#
module Puppet::Parser::Functions
newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
newfunction(:bool2num, :type => :rvalue, :doc => <<-DOC
Converts a boolean to a number. Converts the values:
false, f, 0, n, and no to 0
true, t, 1, y, and yes to 1
Requires a single boolean or string as an input.
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/bool2str.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# bool2str.rb
#
module Puppet::Parser::Functions
newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS
newfunction(:bool2str, :type => :rvalue, :doc => <<-DOC
Converts a boolean to a string using optionally supplied arguments. The
optional second and third arguments represent what true and false will be
converted to respectively. If only one argument is given, it will be
Expand All @@ -15,7 +15,7 @@ module Puppet::Parser::Functions
bool2str(false, 't', 'f') => 'f'

Requires a single boolean as an input.
EOS
DOC
) do |arguments|

unless arguments.size == 1 || arguments.size == 3
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/camelcase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# 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(:camelcase, :type => :rvalue, :doc => <<-EOS
newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC
Converts the case of a string or all strings in an array to camel case.
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/capitalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# 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(:capitalize, :type => :rvalue, :doc => <<-EOS
newfunction(:capitalize, :type => :rvalue, :doc => <<-DOC
Capitalizes the first letter of a string or array of strings.
Requires either a single string or an array as an input.
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "capitalize(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/ceiling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# ceiling.rb
#
module Puppet::Parser::Functions
newfunction(:ceiling, :type => :rvalue, :doc => <<-EOS
newfunction(:ceiling, :type => :rvalue, :doc => <<-DOC
Returns the smallest integer greater or equal to the argument.
Takes a single numeric value as an argument.
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "ceiling(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/chomp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# chomp.rb
#
module Puppet::Parser::Functions
newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
newfunction(:chomp, :type => :rvalue, :doc => <<-DOC
Removes the record separator from the end of a string or an array of
strings, for example `hello\n` becomes `hello`.
Requires a single string or array as an input.
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "chomp(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/chop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# chop.rb
#
module Puppet::Parser::Functions
newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
newfunction(:chop, :type => :rvalue, :doc => <<-DOC
Returns a new string with the last character removed. If the string ends
with `\r\n`, both characters are removed. Applying chop to an empty
string returns an empty string. If you wish to merely remove record
separators then you should use the `chomp` function.
Requires a string or array of strings as input.
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "chop(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/clamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# clamp.rb
#
module Puppet::Parser::Functions
newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-EOS
newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-DOC
Clamps value to a range.
EOS
DOC
) do |args|

args.flatten!
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/concat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# concat.rb
#
module Puppet::Parser::Functions
newfunction(:concat, :type => :rvalue, :doc => <<-EOS
newfunction(:concat, :type => :rvalue, :doc => <<-DOC
Appends the contents of multiple arrays into array 1.

*Example:*
Expand All @@ -12,7 +12,7 @@ module Puppet::Parser::Functions
Would result in:

['1','2','3','4','5','6','7','8','9']
EOS
DOC
) do |arguments|

# Check that more than 2 arguments have been given ...
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/convert_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# convert_base.rb
#
module Puppet::Parser::Functions
newfunction(:convert_base, :type => :rvalue, :arity => 2, :doc => <<-'ENDHEREDOC') do |args|
newfunction(:convert_base, :type => :rvalue, :arity => 2, :doc => <<-'DOC') do |args|
Converts a given integer or base 10 string representing an integer to a specified base, as a string.

Usage:

$binary_repr = convert_base(5, 2) # $binary_repr is now set to "101"
$hex_repr = convert_base("254", "16") # $hex_repr is now set to "fe"

ENDHEREDOC
DOC

raise Puppet::ParseError, 'convert_base(): First argument must be either a string or an integer' unless args[0].is_a?(Integer) || args[0].is_a?(String)
raise Puppet::ParseError, 'convert_base(): Second argument must be either a string or an integer' unless args[1].is_a?(Integer) || args[1].is_a?(String)
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# count.rb
#
module Puppet::Parser::Functions
newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS
newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-DOC
Takes an array as first argument and an optional second argument.
Count the number of elements in array that matches second argument.
If called with only an array it counts the number of elements that are not nil/undef.
EOS
DOC
) do |args|

if args.size > 2
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/deep_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# deep_merge.rb
#
module Puppet::Parser::Functions
newfunction(:deep_merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
newfunction(:deep_merge, :type => :rvalue, :doc => <<-'DOC') do |args|
Recursively merges two or more hashes together and returns the resulting hash.

For example:
Expand All @@ -16,7 +16,7 @@ module Puppet::Parser::Functions
When there is a duplicate key that is a hash, they are recursively merged.
When there is a duplicate key that is not a hash, the key in the rightmost hash will "win."

ENDHEREDOC
DOC

if args.length < 2
raise Puppet::ParseError, "deep_merge(): wrong number of arguments (#{args.length}; must be at least 2)"
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/defined_with_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Puppet::Parser::Functions.newfunction(:defined_with_params,
:type => :rvalue,
:doc => <<-'ENDOFDOC'
:doc => <<-'DOC'
Takes a resource reference and an optional hash of attributes.

Returns true if a resource with the specified attributes has already been added
Expand All @@ -16,7 +16,7 @@
if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
user { 'dan': ensure => present, }
}
ENDOFDOC
DOC
) do |vals|
reference, params = vals
raise(ArgumentError, 'Must specify a reference') unless reference
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# delete.rb
#
module Puppet::Parser::Functions
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
newfunction(:delete, :type => :rvalue, :doc => <<-DOC
Deletes all instances of a given element from an array, substring from a
string, or key from a hash.

Expand All @@ -19,7 +19,7 @@ module Puppet::Parser::Functions

delete('abracadabra', 'bra')
Would return: 'acada'
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "delete(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/delete_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# delete_at.rb
#
module Puppet::Parser::Functions
newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
newfunction(:delete_at, :type => :rvalue, :doc => <<-DOC
Deletes a determined indexed value from an array.

*Examples:*

delete_at(['a','b','c'], 1)

Would return: ['a','c']
EOS
DOC
) do |arguments|

raise(Puppet::ParseError, "delete_at(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2
Expand Down
Loading