diff --git a/.rubocop.yml b/.rubocop.yml index be8d072e377..13a40c7f504 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -28,6 +28,11 @@ Layout/BeginEndAlignment: Exclude: - 'lib/puppet/provider/package/*.rb' +Layout/ElseAlignment: + Enabled: true + Exclude: + - 'lib/puppet/provider/package/*.rb' + # puppet uses symbol booleans in types and providers to work around long standing # bugs when trying to manage falsey pararameters and properties Lint/BooleanSymbol: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 873128789ad..37e066e96d9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -22,99 +22,6 @@ I18n/GetText/DecorateStringFormattingUsingPercent: I18n/RailsI18n/DecorateString: Enabled: false -# This cop supports safe auto-correction (--auto-correct). -Layout/ClosingParenthesisIndentation: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowForAlignment. -Layout/CommentIndentation: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: leading, trailing -Layout/DotPosition: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/ElseAlignment: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/EmptyLineAfterGuardClause: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/EmptyLineAfterMagicComment: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/EmptyLines: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: around, only_before -Layout/EmptyLinesAroundAccessModifier: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/EmptyLinesAroundArguments: - Exclude: - - 'lib/puppet/defaults.rb' - - 'lib/puppet/parser/functions/sprintf.rb' - - 'lib/puppet/settings.rb' - - 'lib/puppet/type.rb' - - 'lib/puppet/type/schedule.rb' - - 'lib/puppet/util/diff.rb' - - 'lib/puppet/util/rdoc/generators/puppet_generator.rb' - - 'lib/puppet/util/rdoc/generators/template/puppet/puppet.rb' - - 'lib/puppet/util/windows/com.rb' - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowAliasSyntax, AllowedMethods. -# AllowedMethods: alias_method, public, protected, private -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/EmptyLinesAroundBeginBody: - Exclude: - - 'lib/puppet/util/diff.rb' - - 'lib/puppet/util/retry_action.rb' - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/EmptyLinesAroundExceptionHandlingKeywords: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/EmptyLinesAroundMethodBody: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines -Layout/EmptyLinesAroundModuleBody: - Enabled: false - # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyleAlignWith, Severity. # SupportedStylesAlignWith: keyword, variable, start_of_line diff --git a/ext/windows/service/daemon.rb b/ext/windows/service/daemon.rb index 9dab31542bd..5f6a6551eb1 100755 --- a/ext/windows/service/daemon.rb +++ b/ext/windows/service/daemon.rb @@ -96,7 +96,6 @@ def service_main(*argsv) end end @run_thread.join - rescue Exception => e log_exception(e) ensure diff --git a/lib/hiera/puppet_function.rb b/lib/hiera/puppet_function.rb index 29ee5d422cb..cef4c325c08 100644 --- a/lib/hiera/puppet_function.rb +++ b/lib/hiera/puppet_function.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'hiera_puppet' # Provides the base class for the puppet functions hiera, hiera_array, hiera_hash, and hiera_include. diff --git a/lib/hiera/scope.rb b/lib/hiera/scope.rb index 93cae37de2e..c86d9914e59 100644 --- a/lib/hiera/scope.rb +++ b/lib/hiera/scope.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'forwardable' class Hiera class Scope @@ -86,6 +87,5 @@ def find_hostclass(scope) # This is needed for type conversion to work def_delegators :@real, :call_function - end end diff --git a/lib/hiera_puppet.rb b/lib/hiera_puppet.rb index e40ee0ac4c2..bd16a3f7747 100644 --- a/lib/hiera_puppet.rb +++ b/lib/hiera_puppet.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Puppet.features.hiera? require 'hiera/scope' require_relative 'puppet' diff --git a/lib/puppet.rb b/lib/puppet.rb index f7f710e53e7..1e52ed8a0f4 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'puppet/version' require_relative 'puppet/concurrent/synchronized' diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb index 65c1eb3b9f6..14f8573af2d 100644 --- a/lib/puppet/agent.rb +++ b/lib/puppet/agent.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet/application' require_relative '../puppet/error' require_relative '../puppet/util/at_fork' diff --git a/lib/puppet/agent/disabler.rb b/lib/puppet/agent/disabler.rb index 8fa8ba9a036..7f8be7c6a67 100644 --- a/lib/puppet/agent/disabler.rb +++ b/lib/puppet/agent/disabler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/json_lockfile' # This module is responsible for encapsulating the logic for @@ -41,10 +42,10 @@ def disable_message if data.has_key?(DISABLED_MESSAGE_JSON_KEY) return data[DISABLED_MESSAGE_JSON_KEY] end + nil end - def disable_lockfile @disable_lockfile ||= Puppet::Util::JsonLockfile.new(Puppet[:agent_disabled_lockfile]) diff --git a/lib/puppet/agent/locker.rb b/lib/puppet/agent/locker.rb index cfbeae79c02..319db65f180 100644 --- a/lib/puppet/agent/locker.rb +++ b/lib/puppet/agent/locker.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/pidlock' require_relative '../../puppet/error' @@ -42,6 +43,4 @@ def lockfile @lockfile end private :lockfile - - end diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index 9b165dc4792..cf84e28ef98 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'optparse' require_relative '../puppet/util/command_line' require_relative '../puppet/util/constant_inflector' @@ -6,7 +7,6 @@ require_relative '../puppet/application_support' module Puppet - # Defines an abstract Puppet application. # # # Usage @@ -170,6 +170,7 @@ def clear? # Thus, long-running background processes can potentially finish their work before a restart. def controlled_run(&block) return unless clear? + result = block.call Process.kill(:HUP, $PID) if restart_requested? result @@ -304,6 +305,7 @@ def run_mode(mode_name = nil) # @api public def environment_mode(mode_name) raise Puppet::Error, _("Invalid environment mode '%{mode_name}'") % { mode_name: mode_name } unless [:local, :remote, :not_required].include?(mode_name) + @environment_mode = mode_name end @@ -364,7 +366,7 @@ def initialize(command_line = Puppet::Util::CommandLine.new) def app_defaults Puppet::Settings.app_defaults_for_run_mode(self.class.run_mode).merge( :name => name - ) + ) end # Initialize application defaults. It's usually not necessary to override this method. @@ -399,7 +401,6 @@ def deprecated? # @return [void] # @api public def run - # I don't really like the names of these lifecycle phases. It would be nice to change them to some more meaningful # names, and make deprecated aliases. --cprice 2012-03-16 diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb index 4372f8d5680..c391441e006 100644 --- a/lib/puppet/application/agent.rb +++ b/lib/puppet/application/agent.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application' require_relative '../../puppet/daemon' require_relative '../../puppet/util/pidlock' @@ -7,7 +8,6 @@ require_relative '../../puppet/ssl/oids' class Puppet::Application::Agent < Puppet::Application - run_mode :agent def app_defaults @@ -405,6 +405,7 @@ def log_config Puppet.settings.stringify_settings(:agent, :all).each_pair do |k,v| next if k.include?("password") || v.to_s.empty? + Puppet.debug("Using setting: #{k}=#{v}") end end diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 1a7db86d2b1..e992b6abc2f 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application' require_relative '../../puppet/configurer' require_relative '../../puppet/util/profiler/aggregate' @@ -310,7 +311,6 @@ def setup Puppet.settings.use :main, :agent, :ssl - if Puppet[:catalog_cache_terminus] Puppet::Resource::Catalog.indirection.cache_class = Puppet[:catalog_cache_terminus] end @@ -382,6 +382,7 @@ def get_facts() def get_node() node = Puppet::Node.indirection.find(Puppet[:node_name_value]) raise _("Could not find node %{node}") % { node: Puppet[:node_name_value] } unless node + node end @@ -395,6 +396,7 @@ def get_manifest() else manifest = command_line.args.shift raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest) + Puppet.warning(_("Only one file can be applied per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0 end manifest diff --git a/lib/puppet/application/catalog.rb b/lib/puppet/application/catalog.rb index 847fbee4276..470a0f09097 100644 --- a/lib/puppet/application/catalog.rb +++ b/lib/puppet/application/catalog.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/indirection_base' class Puppet::Application::Catalog < Puppet::Application::IndirectionBase diff --git a/lib/puppet/application/config.rb b/lib/puppet/application/config.rb index e54408cea7a..7ede4e8bcfd 100644 --- a/lib/puppet/application/config.rb +++ b/lib/puppet/application/config.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' class Puppet::Application::Config < Puppet::Application::FaceBase diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb index 2d4b0e56648..e7961423723 100644 --- a/lib/puppet/application/describe.rb +++ b/lib/puppet/application/describe.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true + require_relative '../../puppet/application' class Formatter - def initialize(width) @width = width end def wrap(txt, opts) return "" unless txt && !txt.empty? + work = (opts[:scrub] ? scrub(txt) : txt) indent = (opts[:indent] ? opts[:indent] : 0) textLen = @width - indent @@ -48,17 +49,16 @@ def scrub(text) return text end end - end class TypeDoc - def initialize @format = Formatter.new(76) @types = {} Puppet::Type.loadall Puppet::Type.eachtype { |type| next if type.name == :component + @types[type.name] = type } end @@ -160,7 +160,6 @@ def list_providers(type) list = type.providers.sort_by(&:to_s).join(", ") puts @format.wrap(list, :indent => 4) end - end class Puppet::Application::Describe < Puppet::Application @@ -250,5 +249,4 @@ def setup handle_help(nil) unless options[:list] || options[:types].size > 0 $stderr.puts "Warning: ignoring types when listing all types" if options[:list] && options[:types].size > 0 end - end diff --git a/lib/puppet/application/device.rb b/lib/puppet/application/device.rb index d8d9e5f4c4d..50c8e930151 100644 --- a/lib/puppet/application/device.rb +++ b/lib/puppet/application/device.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true + require_relative '../../puppet/application' require_relative '../../puppet/configurer' require_relative '../../puppet/util/network_device' require_relative '../../puppet/ssl/oids' class Puppet::Application::Device < Puppet::Application - run_mode :agent attr_accessor :args, :agent, :host @@ -227,7 +227,6 @@ def help HELP end - def main if options[:resource] and !options[:target] raise _("resource command requires target") @@ -235,6 +234,7 @@ def main if options[:facts] and !options[:target] raise _("facts command requires target") end + unless options[:apply].nil? raise _("missing argument: --target is required when using --apply") if options[:target].nil? raise _("%{file} does not exist, cannot apply") % { file: options[:apply] } unless File.file?(options[:apply]) diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index 2ceeb6f83c8..58879291467 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application' class Puppet::Application::Doc < Puppet::Application diff --git a/lib/puppet/application/epp.rb b/lib/puppet/application/epp.rb index 5c29d9f1eac..31fb67e129f 100644 --- a/lib/puppet/application/epp.rb +++ b/lib/puppet/application/epp.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' require_relative '../../puppet/face' diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index 07ae18e6366..d3514bcf397 100644 --- a/lib/puppet/application/face_base.rb +++ b/lib/puppet/application/face_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application' require_relative '../../puppet/face' require 'optparse' @@ -158,6 +159,7 @@ def find_global_settings_argument(item) Puppet.settings.each do |_name, object| object.optparse_args.each do |arg| next unless arg =~ /^-/ + # sadly, we have to emulate some of optparse here... pattern = /^#{arg.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/ pattern.match item and return object @@ -170,8 +172,10 @@ def find_application_argument(item) self.class.option_parser_commands.each do |options, _function| options.each do |option| next unless option =~ /^-/ + pattern = /^#{option.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/ next unless pattern.match(item) + return { :argument => option =~ /[ =]/, :optional => option =~ /[ =]\[/ @@ -205,7 +209,6 @@ def setup self.render_as ||= (@action.render_as || :console) end - def main status = false @@ -266,11 +269,9 @@ def main # --kelsey 2012-02-14 rescue SystemExit => detail status = detail.status - rescue => detail Puppet.log_exception(detail) Puppet.err _("Try 'puppet help %{face} %{action}' for usage") % { face: @face.name, action: @action.name } - ensure exit status end diff --git a/lib/puppet/application/facts.rb b/lib/puppet/application/facts.rb index 2d0413872cc..d34e26337e0 100644 --- a/lib/puppet/application/facts.rb +++ b/lib/puppet/application/facts.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/indirection_base' class Puppet::Application::Facts < Puppet::Application::IndirectionBase diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb index 9529568f105..b9ab0bea703 100644 --- a/lib/puppet/application/filebucket.rb +++ b/lib/puppet/application/filebucket.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application' class Puppet::Application::Filebucket < Puppet::Application @@ -209,11 +210,11 @@ def help HELP end - def run_command @args = command_line.args command = args.shift return send(command) if %w{get backup restore diff list}.include? command + help end @@ -255,6 +256,7 @@ def restore def diff raise Puppet::Error, _("Need exactly two arguments: filebucket diff ") unless args.count == 2 + left = args.shift right = args.shift if Puppet::FileSystem.exist?(left) diff --git a/lib/puppet/application/generate.rb b/lib/puppet/application/generate.rb index 0b444c75f09..ff8b497c9ba 100644 --- a/lib/puppet/application/generate.rb +++ b/lib/puppet/application/generate.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' # The Generate application. diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb index 64c8b51d913..6cd85e73cba 100644 --- a/lib/puppet/application/help.rb +++ b/lib/puppet/application/help.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' class Puppet::Application::Help < Puppet::Application::FaceBase diff --git a/lib/puppet/application/indirection_base.rb b/lib/puppet/application/indirection_base.rb index 98d1fc594a5..2b98abc18cb 100644 --- a/lib/puppet/application/indirection_base.rb +++ b/lib/puppet/application/indirection_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' class Puppet::Application::IndirectionBase < Puppet::Application::FaceBase diff --git a/lib/puppet/application/lookup.rb b/lib/puppet/application/lookup.rb index 5e358b774e6..5f7382616aa 100644 --- a/lib/puppet/application/lookup.rb +++ b/lib/puppet/application/lookup.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true + require_relative '../../puppet/application' require_relative '../../puppet/pops' require_relative '../../puppet/node' require_relative '../../puppet/parser/compiler' class Puppet::Application::Lookup < Puppet::Application - RUN_HELP = _("Run 'puppet lookup --help' for more details").freeze DEEP_MERGE_OPTIONS = '--knock-out-prefix, --sort-merged-arrays, and --merge-hash-arrays' TRUSTED_INFORMATION_FACTS = ["hostname", "domain", "fqdn", "clientcert"].freeze @@ -427,6 +427,7 @@ def retrieve_node_facts(node, given_facts) if facts.values.empty? raise _("No facts available for target node: %{node}") % { node: node} end + facts end end diff --git a/lib/puppet/application/module.rb b/lib/puppet/application/module.rb index a5f74faad50..b4a40cea19f 100644 --- a/lib/puppet/application/module.rb +++ b/lib/puppet/application/module.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' class Puppet::Application::Module < Puppet::Application::FaceBase diff --git a/lib/puppet/application/node.rb b/lib/puppet/application/node.rb index d8e2f5f5d08..084fbff7d67 100644 --- a/lib/puppet/application/node.rb +++ b/lib/puppet/application/node.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/indirection_base' class Puppet::Application::Node < Puppet::Application::IndirectionBase diff --git a/lib/puppet/application/parser.rb b/lib/puppet/application/parser.rb index 9d1d39046ad..321a7588711 100644 --- a/lib/puppet/application/parser.rb +++ b/lib/puppet/application/parser.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' require_relative '../../puppet/face' diff --git a/lib/puppet/application/plugin.rb b/lib/puppet/application/plugin.rb index e5455c0abe1..4cbcf7cf672 100644 --- a/lib/puppet/application/plugin.rb +++ b/lib/puppet/application/plugin.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/face_base' class Puppet::Application::Plugin < Puppet::Application::FaceBase environment_mode :not_required diff --git a/lib/puppet/application/report.rb b/lib/puppet/application/report.rb index 4f5d4a42115..23935f9a052 100644 --- a/lib/puppet/application/report.rb +++ b/lib/puppet/application/report.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application/indirection_base' class Puppet::Application::Report < Puppet::Application::IndirectionBase diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index 70af603bf9e..3f89df9c1b0 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/application' class Puppet::Application::Resource < Puppet::Application @@ -21,6 +22,7 @@ def preinit Puppet::Type.typeloader.loadall(env) Puppet::Type.eachtype do |t| next if t.name == :component + types << t.name.to_s end puts types.sort @@ -241,6 +243,7 @@ def find_or_save_resources(type, name, params) if type == "file" raise _("Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc") end + Puppet::Resource.indirection.search( key, {} ) end end diff --git a/lib/puppet/application/script.rb b/lib/puppet/application/script.rb index 02b8eb63d29..eb1378a4116 100644 --- a/lib/puppet/application/script.rb +++ b/lib/puppet/application/script.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true + require_relative '../../puppet/application' require_relative '../../puppet/configurer' require_relative '../../puppet/util/profiler/aggregate' require_relative '../../puppet/parser/script_compiler' class Puppet::Application::Script < Puppet::Application - option("--debug","-d") option("--execute EXECUTE","-e") do |arg| options[:code] = arg @@ -138,6 +138,7 @@ def main else manifest = command_line.args.shift raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest) + Puppet.warning(_("Only one file can be used per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0 end @@ -212,7 +213,6 @@ def main topscope.merge_settings(node.environment.name, false) compiler.compile() - rescue Puppet::Error # already logged and handled by the compiler, including Puppet::ParseErrorWithIssue exit(1) @@ -224,7 +224,6 @@ def main exit(1) end end - ensure if @profiler Puppet::Util::Profiler.remove_profiler(@profiler) @@ -248,7 +247,7 @@ def setup # installed where a settings catalog have already been applied... # This saves 1/5th of the startup time -# Puppet.settings.use :main, :agent, :ssl + # Puppet.settings.use :main, :agent, :ssl # When running a script, the catalog is not relevant, and neither is caching of it Puppet::Resource::Catalog.indirection.cache_class = nil diff --git a/lib/puppet/application/ssl.rb b/lib/puppet/application/ssl.rb index 65322e152e3..0f8179585ff 100644 --- a/lib/puppet/application/ssl.rb +++ b/lib/puppet/application/ssl.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true + require_relative '../../puppet/application' require_relative '../../puppet/ssl/oids' class Puppet::Application::Ssl < Puppet::Application - run_mode :agent def summary @@ -157,6 +157,7 @@ def main puppet ssl clean --target END end + clean(certname) when 'bootstrap' if !Puppet::Util::Log.sendlevel?(:info) diff --git a/lib/puppet/application_support.rb b/lib/puppet/application_support.rb index 2a254c67fa8..c9efff12552 100644 --- a/lib/puppet/application_support.rb +++ b/lib/puppet/application_support.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'yaml' require_relative '../puppet' @@ -8,7 +9,6 @@ module Puppet module ApplicationSupport - # Pushes a Puppet Context configured with a remote environment for an agent # (one that exists at the master end), and a regular environment for other # modes. The configuration is overridden with options from the command line diff --git a/lib/puppet/coercion.rb b/lib/puppet/coercion.rb index 0badb4d907a..2b7d9a4f23b 100644 --- a/lib/puppet/coercion.rb +++ b/lib/puppet/coercion.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Various methods used to coerce values into a canonical form. # # @api private diff --git a/lib/puppet/compilable_resource_type.rb b/lib/puppet/compilable_resource_type.rb index 8f40568d9ec..ab1349f08f0 100644 --- a/lib/puppet/compilable_resource_type.rb +++ b/lib/puppet/compilable_resource_type.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet' # The CompilableResourceType module should be either included in a class or used as a class extension # to mark that the instance used as the 'resource type' of a resource instance diff --git a/lib/puppet/concurrent.rb b/lib/puppet/concurrent.rb index 460e66c921e..ea3b38ce138 100644 --- a/lib/puppet/concurrent.rb +++ b/lib/puppet/concurrent.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + module Puppet::Concurrent end diff --git a/lib/puppet/concurrent/lock.rb b/lib/puppet/concurrent/lock.rb index 623cbe9ce1b..5a4729a26c6 100644 --- a/lib/puppet/concurrent/lock.rb +++ b/lib/puppet/concurrent/lock.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true + require_relative '../../puppet/concurrent/synchronized' module Puppet module Concurrent - # A simple lock that at the moment only does any locking on jruby class Lock include Puppet::Concurrent::Synchronized @@ -11,7 +11,6 @@ def synchronize yield end end - end end diff --git a/lib/puppet/concurrent/synchronized.rb b/lib/puppet/concurrent/synchronized.rb index f74d3785d2b..e9f93e9c300 100644 --- a/lib/puppet/concurrent/synchronized.rb +++ b/lib/puppet/concurrent/synchronized.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true + module Puppet module Concurrent - # Including Puppet::Concurrent::Synchronized into a class when running on JRuby # causes all of its instance methods to be synchronized on the instance itself. # When running on MRI it has no effect. @@ -11,6 +11,5 @@ module Concurrent else module Synchronized; end end - end end diff --git a/lib/puppet/concurrent/thread_local_singleton.rb b/lib/puppet/concurrent/thread_local_singleton.rb index b91b96be137..f792e547790 100644 --- a/lib/puppet/concurrent/thread_local_singleton.rb +++ b/lib/puppet/concurrent/thread_local_singleton.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Puppet module Concurrent module ThreadLocalSingleton diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index b76f0a51a1c..2ddc43e193d 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # The client for interacting with the puppetmaster config server. require 'timeout' require_relative '../puppet/util' @@ -445,6 +446,7 @@ def run_internal(options) if tries > 3 raise Puppet::Error, _("Catalog environment didn't stabilize after %{tries} fetches, aborting run") % { tries: tries } end + Puppet.notice _("Local environment: '%{local_env}' doesn't match server specified environment '%{catalog_env}', restarting agent run with environment '%{catalog_env}'") % { local_env: @environment, catalog_env: catalog.environment } @environment = catalog.environment report.environment = @environment @@ -457,6 +459,7 @@ def run_internal(options) # if we get here, ignore the cached catalog catalog = prepare_and_retrieve_catalog(nil, facts, options, query_options) return nil unless catalog + tries += 1 end @@ -579,6 +582,7 @@ def last_server_specified_environment if Puppet::FileSystem.exist?(Puppet[:lastrunfile]) summary = Puppet::Util::Yaml.safe_load_file(Puppet[:lastrunfile]) return [nil, nil] unless summary['application']['run_mode'] == 'agent' + initial_environment = summary['application']['initial_environment'] converged_environment = summary['application']['converged_environment'] @last_server_specified_environment = converged_environment if initial_environment != converged_environment diff --git a/lib/puppet/configurer/downloader.rb b/lib/puppet/configurer/downloader.rb index 41e17fccf2e..91678d58c15 100644 --- a/lib/puppet/configurer/downloader.rb +++ b/lib/puppet/configurer/downloader.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/configurer' require_relative '../../puppet/resource/catalog' @@ -40,7 +41,6 @@ def evaluate def initialize(name, path, source, ignore = nil, environment = nil, source_permissions = :ignore) @name, @path, @source, @ignore, @environment, @source_permissions = name, path, source, ignore, environment, source_permissions - end def file diff --git a/lib/puppet/configurer/fact_handler.rb b/lib/puppet/configurer/fact_handler.rb index a07a060301e..b3e28d814b4 100644 --- a/lib/puppet/configurer/fact_handler.rb +++ b/lib/puppet/configurer/fact_handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/indirector/facts/facter' require_relative '../../puppet/configurer' diff --git a/lib/puppet/configurer/plugin_handler.rb b/lib/puppet/configurer/plugin_handler.rb index 403e03400aa..fb9bf311111 100644 --- a/lib/puppet/configurer/plugin_handler.rb +++ b/lib/puppet/configurer/plugin_handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Break out the code related to plugins. This module is # just included into the agent, but having it here makes it # easier to test. diff --git a/lib/puppet/confine.rb b/lib/puppet/confine.rb index bffb2c573b3..1884e53665e 100644 --- a/lib/puppet/confine.rb +++ b/lib/puppet/confine.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # The class that handles testing whether our providers # actually work or not. require_relative '../puppet/util' @@ -42,6 +43,7 @@ def self.test(name) # Mark that this confine is used for testing binary existence. attr_accessor :for_binary + def for_binary? for_binary end diff --git a/lib/puppet/confine/any.rb b/lib/puppet/confine/any.rb index 591b652f4b4..44f93c6de5d 100644 --- a/lib/puppet/confine/any.rb +++ b/lib/puppet/confine/any.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Puppet::Confine::Any < Puppet::Confine def self.summarize(confines) confines.inject(0) { |count, confine| count + confine.summary } diff --git a/lib/puppet/confine/boolean.rb b/lib/puppet/confine/boolean.rb index bef4b6927d7..8749192ff80 100644 --- a/lib/puppet/confine/boolean.rb +++ b/lib/puppet/confine/boolean.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/confine' # Common module for the Boolean confines. It currently diff --git a/lib/puppet/confine/exists.rb b/lib/puppet/confine/exists.rb index 03329684e5f..45752de666b 100644 --- a/lib/puppet/confine/exists.rb +++ b/lib/puppet/confine/exists.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/confine' class Puppet::Confine::Exists < Puppet::Confine diff --git a/lib/puppet/confine/false.rb b/lib/puppet/confine/false.rb index b00d596da69..37496092d33 100644 --- a/lib/puppet/confine/false.rb +++ b/lib/puppet/confine/false.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/confine/boolean' class Puppet::Confine::False < Puppet::Confine diff --git a/lib/puppet/confine/feature.rb b/lib/puppet/confine/feature.rb index ec43c973fb0..c8aedba42a7 100644 --- a/lib/puppet/confine/feature.rb +++ b/lib/puppet/confine/feature.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/confine' class Puppet::Confine::Feature < Puppet::Confine diff --git a/lib/puppet/confine/true.rb b/lib/puppet/confine/true.rb index 848a3f26cd9..e33b2e04f77 100644 --- a/lib/puppet/confine/true.rb +++ b/lib/puppet/confine/true.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/confine/boolean' class Puppet::Confine::True < Puppet::Confine diff --git a/lib/puppet/confine/variable.rb b/lib/puppet/confine/variable.rb index bb6162ed4e2..d03750dbed4 100644 --- a/lib/puppet/confine/variable.rb +++ b/lib/puppet/confine/variable.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/confine' # Require a specific value for a variable, either a Puppet setting diff --git a/lib/puppet/confine_collection.rb b/lib/puppet/confine_collection.rb index f7b77f940fc..e1d0b2009da 100644 --- a/lib/puppet/confine_collection.rb +++ b/lib/puppet/confine_collection.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Manage a collection of confines, returning a boolean or # helpful information. require_relative '../puppet/confine' @@ -26,6 +27,7 @@ def confine(hash) end attr_reader :label + def initialize(label) @label = label @confines = [] @@ -40,8 +42,8 @@ def summary confines.each do |klass, list| value = klass.summarize(list) next if (value.respond_to?(:length) and value.length == 0) or (value == 0) - result[klass.name] = value + result[klass.name] = value end result end diff --git a/lib/puppet/confiner.rb b/lib/puppet/confiner.rb index 1395ea1e420..563808ee0b8 100644 --- a/lib/puppet/confiner.rb +++ b/lib/puppet/confiner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet/confine_collection' # The Confiner module contains methods for managing a Provider's confinement (suitability under given diff --git a/lib/puppet/context.rb b/lib/puppet/context.rb index d857f9aad2d..886bc003bd3 100644 --- a/lib/puppet/context.rb +++ b/lib/puppet/context.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet/thread_local' # Puppet::Context is a system for tracking services and contextual information diff --git a/lib/puppet/context/trusted_information.rb b/lib/puppet/context/trusted_information.rb index 679385180f2..5dc685296ac 100644 --- a/lib/puppet/context/trusted_information.rb +++ b/lib/puppet/context/trusted_information.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/trusted_external' # @api private diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index ecb036aff66..ff59e9ad2f2 100644 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet/application' require_relative '../puppet/scheduler' @@ -25,6 +26,7 @@ class Puppet::Daemon def initialize(agent, pidfile, scheduler = Puppet::Scheduler::Scheduler.new()) raise Puppet::DevError, _("Daemons must have an agent") unless agent + @scheduler = scheduler @pidfile = pidfile @agent = agent @@ -80,6 +82,7 @@ def close_streams() def reexec raise Puppet::DevError, _("Cannot reexec unless ARGV arguments are set") unless argv + command = $0 + " " + argv.join(" ") Puppet.notice "Restarting with '#{command}'" stop(:exit => false) diff --git a/lib/puppet/data_binding.rb b/lib/puppet/data_binding.rb index 6a4a53009c4..f40ae784be3 100644 --- a/lib/puppet/data_binding.rb +++ b/lib/puppet/data_binding.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet/indirector' # A class for managing data lookups diff --git a/lib/puppet/datatypes.rb b/lib/puppet/datatypes.rb index 2cc008dfdf1..829b5fe73fa 100644 --- a/lib/puppet/datatypes.rb +++ b/lib/puppet/datatypes.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Data types in the Puppet Language can have implementations written in Ruby # and distributed in puppet modules. A data type can be declared together with # its implementation by creating a file in 'lib/puppet/functions/'. @@ -133,7 +134,6 @@ def self.create_type(type_name, &block) rescue StandardError => e raise ArgumentError, _("Data Type Load Error for type '%{type_name}': %{message}") % {type_name: type_name, message: e.message} end - end def self.create_loaded_type(type_name, loader, &block) @@ -155,6 +155,7 @@ def initialize(type_name) def create_type(loader) raise ArgumentError, _('a data type must have an interface') unless @interface.is_a?(String) + created_type = Puppet::Pops::Types::PObjectType.new( @type_name, Puppet::Pops::Parser::EvaluatingParser.new.parse_string("{ #{@interface} }").body) @@ -194,16 +195,19 @@ def initialize(type_builder) def interface(type_string) raise ArgumentError, _('a data type can only have one interface') unless @type_builder.interface.nil? + @type_builder.interface = type_string end def implementation(&block) raise ArgumentError, _('a data type can only have one implementation') if @type_builder.has_implementation? + @type_builder.implementation = block end def implementation_class(ruby_class) raise ArgumentError, _('a data type can only have one implementation') if @type_builder.has_implementation? + @type_builder.implementation_class = ruby_class end diff --git a/lib/puppet/datatypes/error.rb b/lib/puppet/datatypes/error.rb index 4cc48f6efa3..625c7f7f151 100644 --- a/lib/puppet/datatypes/error.rb +++ b/lib/puppet/datatypes/error.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Puppet::DataTypes.create_type('Error') do interface <<-PUPPET type_parameters => { diff --git a/lib/puppet/datatypes/impl/error.rb b/lib/puppet/datatypes/impl/error.rb index 9067836a12d..aab3dc24793 100644 --- a/lib/puppet/datatypes/impl/error.rb +++ b/lib/puppet/datatypes/impl/error.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Puppet::DataTypes::Error attr_reader :msg, :kind, :issue_code, :details alias message msg diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index cd275d430db..00a6e906813 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true + require_relative '../puppet/util/platform' module Puppet - def self.default_diffargs '-u' end @@ -31,6 +31,7 @@ def self.valid_file_checksum_types def self.default_cadir return "" if Puppet::Util::Platform.windows? + old_ca_dir = "#{Puppet[:ssldir]}/ca" new_ca_dir = "/etc/puppetlabs/puppetserver/ca" @@ -117,7 +118,7 @@ def self.initialize_default_settings!(settings) :desc => "The name of the application, if we are running as one. The default is essentially $0 without the path or `.rb`.", } - ) + ) settings.define_settings(:main, :logdir => { @@ -371,6 +372,7 @@ def self.initialize_default_settings!(settings) paths = ENV['PATH'].split(File::PATH_SEPARATOR) Puppet::Util::Platform.default_paths.each do |path| next if paths.include?(path) + ENV['PATH'] = ENV['PATH'] + File::PATH_SEPARATOR + path end value @@ -813,7 +815,6 @@ def self.initialize_default_settings!(settings) settings.define_settings( :main, - # We have to downcase the fqdn, because the current ssl stuff (as opposed to in master) doesn't have good facilities for # manipulating naming. :certname => { @@ -1273,7 +1274,7 @@ def self.initialize_default_settings!(settings) } ) - # Define the config default. + # Define the config default. settings.define_settings(:application, :config_file_name => { @@ -1298,7 +1299,7 @@ def self.initialize_default_settings!(settings) :default => nil, :desc => "The address the agent should use to initiate requests.", }, - ) + ) settings.define_settings(:environment, :manifest => { @@ -2054,7 +2055,7 @@ def self.initialize_default_settings!(settings) } ) - # Central fact information. + # Central fact information. settings.define_settings( :main, @@ -2135,7 +2136,7 @@ def self.initialize_default_settings!(settings) For more info, see [the ENC documentation](https://puppet.com/docs/puppet/latest/nodes_external.html).", } - ) + ) settings.define_settings( :ldap, @@ -2205,7 +2206,7 @@ def self.initialize_default_settings!(settings) have one already set. Generally, it should be the 'ou=Hosts' branch under your main directory.", } - ) + ) settings.define_settings(:server, :storeconfigs => { diff --git a/lib/puppet/environments.rb b/lib/puppet/environments.rb index 597effec61a..52fbd8425af 100644 --- a/lib/puppet/environments.rb +++ b/lib/puppet/environments.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true + require_relative '../puppet/concurrent/synchronized' # @api private module Puppet::Environments - class EnvironmentNotFound < Puppet::Error def initialize(environment_name, original = nil) environmentpath = Puppet[:environmentpath] @@ -139,7 +139,6 @@ def get_conf(name) # # @api private class StaticPrivate < Static - # Unlisted # # @!macro loader_list @@ -160,6 +159,7 @@ def initialize(env_name, env_dir, environment) # @!macro loader_get_conf def get_conf(name) return nil unless name.intern == @env_name + Puppet::Settings::EnvironmentConf.load_from(@env_dir, []) end end @@ -268,6 +268,7 @@ def validated_directory(envdir) def valid_environment_names return [] unless Puppet::FileSystem.directory?(@environment_dir) + Puppet::FileSystem.children(@environment_dir).map do |child| Puppet::FileSystem.basename_string(child).intern if validated_directory(child) end.compact diff --git a/lib/puppet/error.rb b/lib/puppet/error.rb index 6e7ee775c05..d080c60a494 100644 --- a/lib/puppet/error.rb +++ b/lib/puppet/error.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true + module Puppet # The base class for all Puppet errors. It can wrap another exception class Error < RuntimeError attr_accessor :original + def initialize(message, original=nil) super(message.scrub) @original = original diff --git a/lib/puppet/etc.rb b/lib/puppet/etc.rb index 6fa4b74414f..23a75683cc5 100644 --- a/lib/puppet/etc.rb +++ b/lib/puppet/etc.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet/util/character_encoding' # Wrapper around Ruby Etc module allowing us to manage encoding in a single # place. @@ -40,7 +41,6 @@ # @api private module Puppet::Etc class << self - # Etc::getgrent returns an Etc::Group struct object # On first call opens /etc/group and returns parse of first entry. Each subsquent call # returns new struct the next entry or nil if EOF. Call ::endgrent to close file. @@ -162,6 +162,7 @@ def puppet_etc_group_class # :canonical_ struct member. def override_field_values_to_utf8(struct) return nil if struct.nil? + new_struct = struct.is_a?(Etc::Passwd) ? puppet_etc_passwd_class.new : puppet_etc_group_class.new struct.each_pair do |member, value| if value.is_a?(String) diff --git a/lib/puppet/external/dot.rb b/lib/puppet/external/dot.rb index 3e75baa90ec..33335de1b02 100644 --- a/lib/puppet/external/dot.rb +++ b/lib/puppet/external/dot.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # rdot.rb # # @@ -8,7 +9,6 @@ # It also supports undirected edges. module DOT - # These global vars are used to make nice graph source. $tab = ' ' @@ -116,7 +116,6 @@ def change_tab(t) # a root class for any element in dot notation class DOTSimpleElement - attr_accessor :name def initialize(params = {}) @@ -131,7 +130,6 @@ def to_s # an element that has options ( node, edge, or graph ) class DOTElement < DOTSimpleElement - # attr_reader :parent attr_accessor :name, :options @@ -158,15 +156,12 @@ def each_option_pair # @parent.delete( self ) if defined?( @parent ) and @parent # @parent = thing #end - end - # This is used when we build nodes that have shape=record # ports don't have options :) class DOTPort < DOTSimpleElement - attr_accessor :label def initialize(params = {}) @@ -204,7 +199,6 @@ def pop end def to_s(t = '') - # This code is totally incomprehensible; it needs to be replaced! label = @options['shape'] != 'record' && @ports.length == 0 ? @@ -232,7 +226,6 @@ def to_s(t = '') def stringify(s) %("#{s.gsub('"', '\\"')}") end - end # A subgraph element is the same to graph, but has another header in dot @@ -275,24 +268,20 @@ def to_s(t = '') }.join( "\n" ) + "\n" hdr + options + nodes + t + "}\n" end - end # This is a graph. class DOTDigraph < DOTSubgraph - def initialize(params = {}, option_list = GRAPH_OPTS) super(params, option_list) @dot_string = 'digraph' end - end # This is an edge. class DOTEdge < DOTElement - attr_accessor :from, :to def initialize(params = {}, option_list = EDGE_OPTS) @@ -313,14 +302,11 @@ def to_s(t = '') i[1] ? t + $tab + "#{i[0]} = \"#{i[1]}\"" : nil }.compact.join( "\n" ) + "\n#{t}]\n" end - end class DOTDirectedEdge < DOTEdge - def edge_link '->' end - end end diff --git a/lib/puppet/face.rb b/lib/puppet/face.rb index fa418b760ee..309def6d011 100644 --- a/lib/puppet/face.rb +++ b/lib/puppet/face.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # The public name of this feature is 'face', but we have hidden all the # plumbing over in the 'interfaces' namespace to make clear the distinction # between the two. diff --git a/lib/puppet/face/catalog.rb b/lib/puppet/face/catalog.rb index 0f0677db01f..3a7ea1a975b 100644 --- a/lib/puppet/face/catalog.rb +++ b/lib/puppet/face/catalog.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/indirector/face' Puppet::Indirector::Face.define(:catalog, '0.0.1') do diff --git a/lib/puppet/face/catalog/select.rb b/lib/puppet/face/catalog/select.rb index 2c14a8eb077..53bdfd83f59 100644 --- a/lib/puppet/face/catalog/select.rb +++ b/lib/puppet/face/catalog/select.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Select and show a list of resources of a given type. Puppet::Face.define(:catalog, '0.0.1') do action :select do diff --git a/lib/puppet/face/config.rb b/lib/puppet/face/config.rb index dc0176f8429..9ce2ff09306 100644 --- a/lib/puppet/face/config.rb +++ b/lib/puppet/face/config.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/face' require_relative '../../puppet/settings/ini_file' @@ -136,7 +137,6 @@ def report_section_and_environment(section_name, environment_name) EOT when_invoked do |name, value, options| - @default_section = false if options[:section] == DEFAULT_SECTION_MARKER options[:section] = DEFAULT_SECTION @@ -219,7 +219,6 @@ def report_section_and_environment(section_name, environment_name) EOT when_invoked do |name, options| - @default_section = false if options[:section] == DEFAULT_SECTION_MARKER options[:section] = DEFAULT_SECTION @@ -230,7 +229,6 @@ def report_section_and_environment(section_name, environment_name) if Puppet::FileSystem.exist?(path) Puppet::FileSystem.open(path, nil, 'r+:UTF-8') do |file| Puppet::Settings::IniFile.update(file) do |config| - # delete from both master section and server section if options[:section] == "master" || options[:section] == "server" master_setting_string = config.delete("master", name) diff --git a/lib/puppet/face/epp.rb b/lib/puppet/face/epp.rb index d0dd2136571..56130e6d5c3 100644 --- a/lib/puppet/face/epp.rb +++ b/lib/puppet/face/epp.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/face' require_relative '../../puppet/pops' require_relative '../../puppet/parser/files' @@ -102,7 +103,6 @@ end end - action(:dump) do summary _("Outputs a dump of the internal template parse tree for debugging") arguments "[--format ] [--pretty] { -e | [ ...] } " @@ -334,7 +334,6 @@ compiler = create_compiler(options) compiler.with_context_overrides('For rendering epp') do - # Print to a buffer since the face needs to return the resulting string # and the face API is "all or nothing" # @@ -361,6 +360,7 @@ end end raise Puppet::Error, _("error while rendering epp") unless status + buffer.string end end @@ -530,6 +530,7 @@ def create_compiler(options) unless given_facts.instance_of?(Hash) raise _("Incorrect formatted data in %{fact_file} given via the --facts flag") % { fact_file: fact_file } end + # It is difficult to add to or modify the set of facts once the node is created # as changes does not show up in parameters. Rather than manually patching up # a node and risking future regressions, a new node is created from scratch @@ -563,5 +564,4 @@ def effective_template(file, env) nil end end - end diff --git a/lib/puppet/face/facts.rb b/lib/puppet/face/facts.rb index e1e0ac7921e..d59cc970305 100644 --- a/lib/puppet/face/facts.rb +++ b/lib/puppet/face/facts.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/indirector/face' require_relative '../../puppet/node/facts' diff --git a/lib/puppet/face/generate.rb b/lib/puppet/face/generate.rb index 7bc5fe4b606..f1ac1457987 100644 --- a/lib/puppet/face/generate.rb +++ b/lib/puppet/face/generate.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/face' require_relative '../../puppet/generate/type' @@ -56,6 +57,7 @@ if Puppet::FileSystem.exist?(outputdir) && !Puppet::FileSystem.directory?(outputdir) raise ArgumentError, _("The output directory '%{outputdir}' exists and is not a directory") % { outputdir: outputdir } end + Puppet::FileSystem::mkpath(outputdir) generator.generate(inputs, outputdir, options[:force]) diff --git a/lib/puppet/face/help.rb b/lib/puppet/face/help.rb index 0d5d6ac6563..0d062ca7272 100644 --- a/lib/puppet/face/help.rb +++ b/lib/puppet/face/help.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/face' require_relative '../../puppet/application/face_base' require_relative '../../puppet/util/constant_inflector' @@ -62,6 +63,7 @@ if actionname raise ArgumentError, _("The legacy subcommand '%{sub_command}' does not support supplying an action") % { sub_command: facename } end + # legacy apps already emit ronn output return render_application_help(facename) else @@ -239,5 +241,4 @@ def is_face_app?(appname) # that you can't use the 'private' keyword inside of a Face definition. # See #14205. #private :is_face_app? - end diff --git a/lib/puppet/face/module.rb b/lib/puppet/face/module.rb index c30c13194aa..486d8be9999 100644 --- a/lib/puppet/face/module.rb +++ b/lib/puppet/face/module.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/face' require_relative '../../puppet/module_tool' require_relative '../../puppet/util/colors' diff --git a/lib/puppet/face/module/changes.rb b/lib/puppet/face/module/changes.rb index e5f087c43a0..bea0bba9c49 100644 --- a/lib/puppet/face/module/changes.rb +++ b/lib/puppet/face/module/changes.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Puppet::Face.define(:module, '1.0.0') do action(:changes) do summary _("Show modified files of an installed module.") @@ -27,6 +28,7 @@ unless root_path raise ArgumentError, _("Could not find a valid module at %{path}") % { path: path.inspect } end + Puppet::ModuleTool::Applications::Checksummer.run(root_path, options) end diff --git a/lib/puppet/face/module/install.rb b/lib/puppet/face/module/install.rb index 780a8cd9192..d1f499bb397 100644 --- a/lib/puppet/face/module/install.rb +++ b/lib/puppet/face/module/install.rb @@ -1,5 +1,6 @@ # encoding: UTF-8 # frozen_string_literal: true + require_relative '../../../puppet/forge' require_relative '../../../puppet/module_tool/install_directory' require 'pathname' diff --git a/lib/puppet/face/module/list.rb b/lib/puppet/face/module/list.rb index bf813d5c545..b3162b7acc3 100644 --- a/lib/puppet/face/module/list.rb +++ b/lib/puppet/face/module/list.rb @@ -106,7 +106,6 @@ end end - def unmet_dependencies(environment) error_types = [:non_semantic_version, :version_mismatch, :missing] @@ -147,7 +146,6 @@ def unmet_dependencies(environment) unmet_deps end - def warn_unmet_dependencies(environment) @unmet_deps = unmet_dependencies(environment) @@ -215,6 +213,7 @@ def warn_unmet_dependencies(environment) def list_build_tree(list, ancestors=[], parent=nil, params={}) list.map do |mod| next if @seen[(mod.forge_name or mod.name)] + node = list_build_node(mod, parent, params) @seen[(mod.forge_name or mod.name)] = true diff --git a/lib/puppet/face/module/uninstall.rb b/lib/puppet/face/module/uninstall.rb index db17083bd1c..7da7befbd16 100644 --- a/lib/puppet/face/module/uninstall.rb +++ b/lib/puppet/face/module/uninstall.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Puppet::Face.define(:module, '1.0.0') do action(:uninstall) do summary _("Uninstall a puppet module.") diff --git a/lib/puppet/face/node.rb b/lib/puppet/face/node.rb index 16b1adf44ee..49a18dabe33 100644 --- a/lib/puppet/face/node.rb +++ b/lib/puppet/face/node.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/indirector/face' Puppet::Indirector::Face.define(:node, '0.0.1') do copyright "Puppet Inc.", 2011 diff --git a/lib/puppet/face/node/clean.rb b/lib/puppet/face/node/clean.rb index eca65250dae..3f817136f3f 100644 --- a/lib/puppet/face/node/clean.rb +++ b/lib/puppet/face/node/clean.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true + Puppet::Face.define(:node, '0.0.1') do action(:clean) do - summary _("Clean up signed certs, cached facts, node objects, and reports for a node stored by the puppetmaster") arguments _(" [ ...]") description <<-'EOT' @@ -103,6 +103,7 @@ def type_is_ensurable(resource) type = environment.known_resource_types.find_definition(resource.restype) return true if type && type.arguments.keys.include?('ensure') end + return false end end diff --git a/lib/puppet/face/parser.rb b/lib/puppet/face/parser.rb index 746dce0064e..902b0188163 100644 --- a/lib/puppet/face/parser.rb +++ b/lib/puppet/face/parser.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/face' require_relative '../../puppet/parser' @@ -100,7 +101,6 @@ end end - action(:dump) do summary _("Outputs a dump of the internal parse tree for debugging") arguments "[--format ] [--pretty] { -e | [ ...] } " diff --git a/lib/puppet/face/plugin.rb b/lib/puppet/face/plugin.rb index ee4b2426ab0..78dcd336f2d 100644 --- a/lib/puppet/face/plugin.rb +++ b/lib/puppet/face/plugin.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/face' require_relative '../../puppet/configurer/plugin_handler' diff --git a/lib/puppet/face/report.rb b/lib/puppet/face/report.rb index a166e3055f5..19cfef5710d 100644 --- a/lib/puppet/face/report.rb +++ b/lib/puppet/face/report.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/indirector/face' Puppet::Indirector::Face.define(:report, '0.0.1') do diff --git a/lib/puppet/face/resource.rb b/lib/puppet/face/resource.rb index 364d2f6e2ab..3a7a29c0a34 100644 --- a/lib/puppet/face/resource.rb +++ b/lib/puppet/face/resource.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/indirector/face' Puppet::Indirector::Face.define(:resource, '0.0.1') do diff --git a/lib/puppet/feature/base.rb b/lib/puppet/feature/base.rb index d8f1647148f..c37eda00af6 100644 --- a/lib/puppet/feature/base.rb +++ b/lib/puppet/feature/base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' # Add the simple features, all in one file. diff --git a/lib/puppet/feature/bolt.rb b/lib/puppet/feature/bolt.rb index 7bfbf3e14cd..e202d5d8add 100644 --- a/lib/puppet/feature/bolt.rb +++ b/lib/puppet/feature/bolt.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add(:bolt, :libs => ['bolt']) diff --git a/lib/puppet/feature/cfpropertylist.rb b/lib/puppet/feature/cfpropertylist.rb index 2abf98406b8..a66c634f41f 100644 --- a/lib/puppet/feature/cfpropertylist.rb +++ b/lib/puppet/feature/cfpropertylist.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add(:cfpropertylist, :libs => ['cfpropertylist']) diff --git a/lib/puppet/feature/eventlog.rb b/lib/puppet/feature/eventlog.rb index 28ee44dadb1..07c256cbe65 100644 --- a/lib/puppet/feature/eventlog.rb +++ b/lib/puppet/feature/eventlog.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' if Puppet::Util::Platform.windows? diff --git a/lib/puppet/feature/hiera_eyaml.rb b/lib/puppet/feature/hiera_eyaml.rb index 887475e30b0..167319fdd38 100644 --- a/lib/puppet/feature/hiera_eyaml.rb +++ b/lib/puppet/feature/hiera_eyaml.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add(:hiera_eyaml, :libs => ['hiera/backend/eyaml/parser/parser']) diff --git a/lib/puppet/feature/hocon.rb b/lib/puppet/feature/hocon.rb index 039dac2d73b..2dd7295b8fa 100644 --- a/lib/puppet/feature/hocon.rb +++ b/lib/puppet/feature/hocon.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add(:hocon, :libs => ['hocon']) diff --git a/lib/puppet/feature/libuser.rb b/lib/puppet/feature/libuser.rb index 109058e1663..bb793453391 100644 --- a/lib/puppet/feature/libuser.rb +++ b/lib/puppet/feature/libuser.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' require_relative '../../puppet/util/libuser' diff --git a/lib/puppet/feature/msgpack.rb b/lib/puppet/feature/msgpack.rb index 5284c230f91..0dd2f0d162d 100644 --- a/lib/puppet/feature/msgpack.rb +++ b/lib/puppet/feature/msgpack.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add(:msgpack, :libs => ["msgpack"]) diff --git a/lib/puppet/feature/pe_license.rb b/lib/puppet/feature/pe_license.rb index 96f7644ae52..2cf9e0a47ec 100644 --- a/lib/puppet/feature/pe_license.rb +++ b/lib/puppet/feature/pe_license.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' #Is the pe license library installed providing the ability to read licenses. diff --git a/lib/puppet/feature/pson.rb b/lib/puppet/feature/pson.rb index 031732f20ed..4a2511b6d12 100644 --- a/lib/puppet/feature/pson.rb +++ b/lib/puppet/feature/pson.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' # PSON is deprecated, use JSON instead diff --git a/lib/puppet/feature/selinux.rb b/lib/puppet/feature/selinux.rb index ce1e9321e7a..bcfc4087465 100644 --- a/lib/puppet/feature/selinux.rb +++ b/lib/puppet/feature/selinux.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add(:selinux, :libs => ["selinux"]) diff --git a/lib/puppet/feature/ssh.rb b/lib/puppet/feature/ssh.rb index 3c9635c9142..49ca36f4cb6 100644 --- a/lib/puppet/feature/ssh.rb +++ b/lib/puppet/feature/ssh.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add(:ssh, :libs => %{net/ssh}) diff --git a/lib/puppet/feature/telnet.rb b/lib/puppet/feature/telnet.rb index 26115495a7a..71add4df6d6 100644 --- a/lib/puppet/feature/telnet.rb +++ b/lib/puppet/feature/telnet.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' Puppet.features.add :telnet do diff --git a/lib/puppet/feature/zlib.rb b/lib/puppet/feature/zlib.rb index 6a9b9873dbc..a2a4e2824e8 100644 --- a/lib/puppet/feature/zlib.rb +++ b/lib/puppet/feature/zlib.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/feature' # We want this to load if possible, but it's not automatically diff --git a/lib/puppet/ffi/posix.rb b/lib/puppet/ffi/posix.rb index 8c8185527c7..1fd2c91d851 100644 --- a/lib/puppet/ffi/posix.rb +++ b/lib/puppet/ffi/posix.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'ffi' module Puppet diff --git a/lib/puppet/ffi/posix/constants.rb b/lib/puppet/ffi/posix/constants.rb index 3f43d1570f5..c36f2d8b198 100644 --- a/lib/puppet/ffi/posix/constants.rb +++ b/lib/puppet/ffi/posix/constants.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/ffi/posix' module Puppet::FFI::POSIX diff --git a/lib/puppet/ffi/posix/functions.rb b/lib/puppet/ffi/posix/functions.rb index b5f8a8a5b2a..5688451720a 100644 --- a/lib/puppet/ffi/posix/functions.rb +++ b/lib/puppet/ffi/posix/functions.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true + require_relative '../../../puppet/ffi/posix' module Puppet::FFI::POSIX module Functions - extend FFI::Library ffi_convention :stdcall diff --git a/lib/puppet/ffi/windows.rb b/lib/puppet/ffi/windows.rb index 037e2cd7dc9..2d63264a580 100644 --- a/lib/puppet/ffi/windows.rb +++ b/lib/puppet/ffi/windows.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'ffi' module Puppet diff --git a/lib/puppet/ffi/windows/api_types.rb b/lib/puppet/ffi/windows/api_types.rb index 6fa26104aac..fc6485f89e3 100644 --- a/lib/puppet/ffi/windows/api_types.rb +++ b/lib/puppet/ffi/windows/api_types.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/ffi/windows' require_relative '../../../puppet/util/windows/string' diff --git a/lib/puppet/ffi/windows/constants.rb b/lib/puppet/ffi/windows/constants.rb index b054e6ea607..fc4a4ab15ae 100644 --- a/lib/puppet/ffi/windows/constants.rb +++ b/lib/puppet/ffi/windows/constants.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/ffi/windows' module Puppet::FFI::Windows @@ -203,7 +204,7 @@ module Constants :TokenSecurityAttributes, :TokenIsRestricted, :MaxTokenInfoClass - ) + ) # Service error codes # https://docs.microsoft.com/en-us/windows/desktop/debug/system-error-codes--1000-1299- diff --git a/lib/puppet/ffi/windows/functions.rb b/lib/puppet/ffi/windows/functions.rb index f69869a4f25..b9b9c1be270 100644 --- a/lib/puppet/ffi/windows/functions.rb +++ b/lib/puppet/ffi/windows/functions.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true + require_relative '../../../puppet/ffi/windows' module Puppet::FFI::Windows module Functions - extend FFI::Library include Puppet::FFI::Windows::Constants diff --git a/lib/puppet/ffi/windows/structs.rb b/lib/puppet/ffi/windows/structs.rb index 52ca771fb88..c37eb88acd3 100644 --- a/lib/puppet/ffi/windows/structs.rb +++ b/lib/puppet/ffi/windows/structs.rb @@ -1,10 +1,10 @@ # coding: utf-8 # frozen_string_literal: true + require_relative '../../../puppet/ffi/windows' module Puppet::FFI::Windows module Structs - extend FFI::Library extend Puppet::FFI::Windows::APITypes diff --git a/lib/puppet/file_bucket.rb b/lib/puppet/file_bucket.rb index 27c7e4c3f83..f7c11e5e032 100644 --- a/lib/puppet/file_bucket.rb +++ b/lib/puppet/file_bucket.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # stub module Puppet::FileBucket class BucketError < RuntimeError; end diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index b258da6b1f5..6186d4d067b 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'pathname' require_relative '../../puppet/file_bucket' require_relative '../../puppet/file_bucket/file' @@ -38,6 +39,7 @@ def local? def backup(file) file_handle = Puppet::FileSystem.pathname(file) raise(ArgumentError, _("File %{file} does not exist") % { file: file }) unless Puppet::FileSystem.exist?(file_handle) + begin file_bucket_file = Puppet::FileBucket::File.new(file_handle, :bucket_path => @local_path) files_original_path = absolutize_path(file) @@ -61,6 +63,7 @@ def backup(file) # Diffs two filebucket files identified by their sums def diff(checksum_a, checksum_b, file_a, file_b) raise RuntimeError, _("Diff is not supported on this platform") if Puppet[:diff] == "" + if checksum_a source_path = "#{@rest_path}#{@checksum_type}/#{checksum_a}" if checksum_b @@ -95,6 +98,7 @@ def diff(checksum_a, checksum_b, file_a, file_b) end end raise Puppet::Error, _("Failed to diff files") unless file_diff + file_diff.to_s end @@ -109,6 +113,7 @@ def get_bucket_file(sum) file_bucket_file = Puppet::FileBucket::File.indirection.find(source_path, :bucket_path => @local_path) raise Puppet::Error, _("File not found") unless file_bucket_file + file_bucket_file end @@ -164,12 +169,13 @@ def list(fromdate, todate) :fromdate => fromdate, :todate => todate) raise Puppet::Error, _("File not found") unless file_bucket_list + file_bucket_list.to_s end private + def absolutize_path( path ) Pathname.new(path).realpath end - end diff --git a/lib/puppet/file_bucket/file.rb b/lib/puppet/file_bucket/file.rb index d3778b6b1ab..1053e55d6d1 100644 --- a/lib/puppet/file_bucket/file.rb +++ b/lib/puppet/file_bucket/file.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/file_bucket' require_relative '../../puppet/indirector' require_relative '../../puppet/util/checksums' diff --git a/lib/puppet/file_serving.rb b/lib/puppet/file_serving.rb index ad951a03c7d..dc1536c72e5 100644 --- a/lib/puppet/file_serving.rb +++ b/lib/puppet/file_serving.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Just a stub class. class Puppet::FileServing # :nodoc: end diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb index 081494cb4ef..7ac9f5efca4 100644 --- a/lib/puppet/file_serving/base.rb +++ b/lib/puppet/file_serving/base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/file_serving' require_relative '../../puppet/util' @@ -44,26 +45,32 @@ def initialize(path, links: nil, relative_path: nil, source: nil) # Determine how we deal with links. attr_reader :links + def links=(value) value = value.to_sym value = :manage if value == :ignore #TRANSLATORS ':link', ':manage', ':follow' should not be translated raise(ArgumentError, _(":links can only be set to :manage or :follow")) unless [:manage, :follow].include?(value) + @links = value end # Set our base path. attr_reader :path + def path=(path) raise ArgumentError.new(_("Paths must be fully qualified")) unless Puppet::FileServing::Base.absolute?(path) + @path = path end # Set a relative path; this is used for recursion, and sets # the file's path relative to the initial recursion point. attr_reader :relative_path + def relative_path=(path) raise ArgumentError.new(_("Relative paths must not be fully qualified")) if Puppet::FileServing::Base.absolute?(path) + @relative_path = path end diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb index c29e56e300b..d6549f8ab46 100644 --- a/lib/puppet/file_serving/configuration.rb +++ b/lib/puppet/file_serving/configuration.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet' require_relative '../../puppet/file_serving' require_relative '../../puppet/file_serving/mount' @@ -22,6 +23,7 @@ def self.configuration private_class_method :new attr_reader :mounts + #private :mounts # Find the right mount. Does some shenanigans to support old-style module @@ -59,6 +61,7 @@ def split_path(request) mount = find_mount(mount_name, request.environment) return nil unless mount + if mount.name == "modules" and mount_name != "modules" # yay backward-compatibility path = "#{mount_name}/#{path}" @@ -106,7 +109,6 @@ def readconfig(check = true) rescue => detail Puppet.log_exception(detail, _("Error parsing fileserver configuration: %{detail}; using old configuration") % { detail: detail }) end - ensure # Make sure we've got our plugins and modules. mk_default_mounts diff --git a/lib/puppet/file_serving/configuration/parser.rb b/lib/puppet/file_serving/configuration/parser.rb index 04f041f3d38..18eed7551ef 100644 --- a/lib/puppet/file_serving/configuration/parser.rb +++ b/lib/puppet/file_serving/configuration/parser.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/file_serving/configuration' require_relative '../../../puppet/util/watched_file' @@ -30,6 +31,7 @@ def parse value = $2 value.strip! raise(ArgumentError, _("Fileserver configuration file does not use '=' as a separator")) if value =~ /^=/ + case var when "path" path(mount, value) diff --git a/lib/puppet/file_serving/content.rb b/lib/puppet/file_serving/content.rb index 088cf663d7c..c938768aa7a 100644 --- a/lib/puppet/file_serving/content.rb +++ b/lib/puppet/file_serving/content.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/indirector' require_relative '../../puppet/file_serving' require_relative '../../puppet/file_serving/base' diff --git a/lib/puppet/file_serving/fileset.rb b/lib/puppet/file_serving/fileset.rb index 54c0e6d4dfc..aab1a3573e0 100644 --- a/lib/puppet/file_serving/fileset.rb +++ b/lib/puppet/file_serving/fileset.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'find' require_relative '../../puppet/file_serving' require_relative '../../puppet/file_serving/metadata' @@ -91,6 +92,7 @@ def links=(links) links = links.to_sym #TRANSLATORS ":links" is a parameter name and should not be translated raise(ArgumentError, _("Invalid :links value '%{links}'") % { links: links }) unless [:manage, :follow].include?(links) + @links = links @stat_method = @links == :manage ? :lstat : :stat end @@ -116,6 +118,7 @@ def initialize_from_request(request) value = request.options[param.to_s] end next if value.nil? + value = true if value == "true" value = false if value == "false" value = Integer(value) if value.is_a?(String) and value =~ /^\d+$/ @@ -135,9 +138,9 @@ def basename def children return [] unless directory? - Dir.entries(path, encoding: Encoding::UTF_8). - reject { |child| ignore?(child) }. - collect { |child| down_level(child) } + Dir.entries(path, encoding: Encoding::UTF_8) + .reject { |child| ignore?(child) } + .collect { |child| down_level(child) } end def ignore?(child) diff --git a/lib/puppet/file_serving/http_metadata.rb b/lib/puppet/file_serving/http_metadata.rb index 6c13848aeeb..5c9a4bfb7bf 100644 --- a/lib/puppet/file_serving/http_metadata.rb +++ b/lib/puppet/file_serving/http_metadata.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true + require_relative '../../puppet/file_serving/metadata' # Simplified metadata representation, suitable for the information # that is available from HTTP headers. class Puppet::FileServing::HttpMetadata < Puppet::FileServing::Metadata - def initialize(http_response, path = '/dev/null') super(path) diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb index 2a92d5ea284..23c71a7753d 100644 --- a/lib/puppet/file_serving/metadata.rb +++ b/lib/puppet/file_serving/metadata.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet' require_relative '../../puppet/indirector' require_relative '../../puppet/file_serving' @@ -8,7 +9,6 @@ # A class that handles retrieving file metadata. class Puppet::FileServing::Metadata < Puppet::FileServing::Base - include Puppet::Util::Checksums extend Puppet::Indirector @@ -168,5 +168,4 @@ def to_data_hash def self.from_data_hash(data) new(data.delete('path'), data) end - end diff --git a/lib/puppet/file_serving/mount.rb b/lib/puppet/file_serving/mount.rb index 5e135db67a4..64a33187aff 100644 --- a/lib/puppet/file_serving/mount.rb +++ b/lib/puppet/file_serving/mount.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/util/logging' require_relative '../../puppet/file_serving' require_relative '../../puppet/file_serving/metadata' @@ -20,6 +21,7 @@ def initialize(name) unless name =~ %r{^[-\w]+$} raise ArgumentError, _("Invalid mount name format '%{name}'") % { name: name } end + @name = name super() diff --git a/lib/puppet/file_serving/mount/file.rb b/lib/puppet/file_serving/mount/file.rb index 545ac56c8a3..d71094b830b 100644 --- a/lib/puppet/file_serving/mount/file.rb +++ b/lib/puppet/file_serving/mount/file.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/file_serving/mount' class Puppet::FileServing::Mount::File < Puppet::FileServing::Mount @@ -55,6 +56,7 @@ def path=(path) else raise ArgumentError, _("%{path} does not exist or is not a directory") % { path: path } unless FileTest.directory?(path) raise ArgumentError, _("%{path} is not readable") % { path: path } unless FileTest.readable?(path) + @expandable = false end @path = path @@ -63,6 +65,7 @@ def path=(path) def search(path, request) path = complete_path(path, request.node) return nil unless path + [path] end diff --git a/lib/puppet/file_serving/mount/locales.rb b/lib/puppet/file_serving/mount/locales.rb index eb1e1bb2932..a2b44066cf2 100644 --- a/lib/puppet/file_serving/mount/locales.rb +++ b/lib/puppet/file_serving/mount/locales.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/file_serving/mount' # Find files in the modules' locales directories. diff --git a/lib/puppet/file_serving/mount/modules.rb b/lib/puppet/file_serving/mount/modules.rb index fdead3e20b5..bd982011d7c 100644 --- a/lib/puppet/file_serving/mount/modules.rb +++ b/lib/puppet/file_serving/mount/modules.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/file_serving/mount' # This is the modules-specific mount: it knows how to search through @@ -7,6 +8,7 @@ class Puppet::FileServing::Mount::Modules < Puppet::FileServing::Mount # Return an instance of the appropriate class. def find(path, request) raise _("No module specified") if path.to_s.empty? + module_name, relative_path = path.split("/", 2) mod = request.environment.module(module_name) return nil unless mod diff --git a/lib/puppet/file_serving/mount/pluginfacts.rb b/lib/puppet/file_serving/mount/pluginfacts.rb index eb7837d89fe..14455984cfb 100644 --- a/lib/puppet/file_serving/mount/pluginfacts.rb +++ b/lib/puppet/file_serving/mount/pluginfacts.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/file_serving/mount' # Find files in the modules' pluginfacts directories. diff --git a/lib/puppet/file_serving/mount/plugins.rb b/lib/puppet/file_serving/mount/plugins.rb index 78d7462c9ca..c7d32c09764 100644 --- a/lib/puppet/file_serving/mount/plugins.rb +++ b/lib/puppet/file_serving/mount/plugins.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../../puppet/file_serving/mount' # Find files in the modules' plugins directories. diff --git a/lib/puppet/file_serving/mount/scripts.rb b/lib/puppet/file_serving/mount/scripts.rb index 48d26998feb..ad5aa5ea97c 100644 --- a/lib/puppet/file_serving/mount/scripts.rb +++ b/lib/puppet/file_serving/mount/scripts.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true + require 'puppet/file_serving/mount' class Puppet::FileServing::Mount::Scripts < Puppet::FileServing::Mount # Return an instance of the appropriate class. def find(path, request) raise _("No module specified") if path.to_s.empty? + module_name, relative_path = path.split("/", 2) mod = request.environment.module(module_name) return nil unless mod diff --git a/lib/puppet/file_serving/mount/tasks.rb b/lib/puppet/file_serving/mount/tasks.rb index 045cb3c1f00..14035f3f00e 100644 --- a/lib/puppet/file_serving/mount/tasks.rb +++ b/lib/puppet/file_serving/mount/tasks.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true + require_relative '../../../puppet/file_serving/mount' class Puppet::FileServing::Mount::Tasks < Puppet::FileServing::Mount def find(path, request) raise _("No task specified") if path.to_s.empty? + module_name, task_path = path.split("/", 2) mod = request.environment.module(module_name) return nil unless mod diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/file_serving/terminus_helper.rb index 3b29ebf8ece..be1f7c58c7e 100644 --- a/lib/puppet/file_serving/terminus_helper.rb +++ b/lib/puppet/file_serving/terminus_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/file_serving' require_relative '../../puppet/file_serving/fileset' diff --git a/lib/puppet/file_serving/terminus_selector.rb b/lib/puppet/file_serving/terminus_selector.rb index c03d04a03e5..0fbb051e2a7 100644 --- a/lib/puppet/file_serving/terminus_selector.rb +++ b/lib/puppet/file_serving/terminus_selector.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/file_serving' # This module is used to pick the appropriate terminus diff --git a/lib/puppet/file_system.rb b/lib/puppet/file_system.rb index 85068cf3d5f..0c6dd4a2704 100644 --- a/lib/puppet/file_system.rb +++ b/lib/puppet/file_system.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Puppet::FileSystem require_relative '../puppet/util' require_relative 'file_system/path_pattern' diff --git a/lib/puppet/file_system/file_impl.rb b/lib/puppet/file_system/file_impl.rb index 857289c7204..6150217e1cf 100644 --- a/lib/puppet/file_system/file_impl.rb +++ b/lib/puppet/file_system/file_impl.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true + # Abstract implementation of the Puppet::FileSystem # class Puppet::FileSystem::FileImpl - def pathname(path) path.is_a?(Pathname) ? path : Pathname.new(path) end diff --git a/lib/puppet/file_system/jruby.rb b/lib/puppet/file_system/jruby.rb index 3458488ba90..cd8366a0e01 100644 --- a/lib/puppet/file_system/jruby.rb +++ b/lib/puppet/file_system/jruby.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/file_system/posix' class Puppet::FileSystem::JRuby < Puppet::FileSystem::Posix diff --git a/lib/puppet/file_system/memory_file.rb b/lib/puppet/file_system/memory_file.rb index b7eed544cf0..27805f0b5e0 100644 --- a/lib/puppet/file_system/memory_file.rb +++ b/lib/puppet/file_system/memory_file.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # An in-memory file abstraction. Commonly used with Puppet::FileSystem::File#overlay # @api private class Puppet::FileSystem::MemoryFile @@ -55,6 +56,7 @@ def each_line(&block) def handle raise Errno::ENOENT unless exist? + StringIO.new(@properties[:content] || '') end diff --git a/lib/puppet/file_system/memory_impl.rb b/lib/puppet/file_system/memory_impl.rb index 5493a0bb2a0..f2cc71b0093 100644 --- a/lib/puppet/file_system/memory_impl.rb +++ b/lib/puppet/file_system/memory_impl.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Puppet::FileSystem::MemoryImpl def initialize(*files) @files = files + all_children_of(files) @@ -32,8 +33,10 @@ def readlink(path) path = path.path link = find(path) return Puppet::FileSystem::MemoryFile.a_missing_file(path) unless link + source = link.source_path return Puppet::FileSystem::MemoryFile.a_missing_file(link) unless source + find(source) || Puppet::FileSystem::MemoryFile.a_missing_file(source) end diff --git a/lib/puppet/file_system/path_pattern.rb b/lib/puppet/file_system/path_pattern.rb index 6755ba427fa..cd16c1c2498 100644 --- a/lib/puppet/file_system/path_pattern.rb +++ b/lib/puppet/file_system/path_pattern.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'pathname' require_relative '../../puppet/error' diff --git a/lib/puppet/file_system/posix.rb b/lib/puppet/file_system/posix.rb index 7f690df6154..07fe60cd50a 100644 --- a/lib/puppet/file_system/posix.rb +++ b/lib/puppet/file_system/posix.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Puppet::FileSystem::Posix < Puppet::FileSystem::FileImpl def binread(path) path.binread @@ -26,9 +27,11 @@ def compare_stream(path, stream) end private + def stream_blksize(*streams) streams.each do |s| next unless s.respond_to?(:stat) + size = blksize(s.stat) return size if size end @@ -39,6 +42,7 @@ def blksize(st) s = st.blksize return nil unless s return nil if s == 0 + s end diff --git a/lib/puppet/file_system/uniquefile.rb b/lib/puppet/file_system/uniquefile.rb index e009f23906d..b076df56996 100644 --- a/lib/puppet/file_system/uniquefile.rb +++ b/lib/puppet/file_system/uniquefile.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/file_system' require 'delegate' require 'tmpdir' @@ -79,6 +80,7 @@ def close! def unlink return unless @tmpname + begin File.unlink(@tmpname) rescue Errno::ENOENT @@ -161,7 +163,6 @@ def tmpdir File.expand_path(tmp) end - class << self # yields with locking for +tmpname+ and returns the result of the # block. @@ -185,5 +186,4 @@ def rmdir(*args) Dir.rmdir(*args) end end - end diff --git a/lib/puppet/file_system/windows.rb b/lib/puppet/file_system/windows.rb index c69e209b4d5..f28ca8e6d41 100644 --- a/lib/puppet/file_system/windows.rb +++ b/lib/puppet/file_system/windows.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/file_system/posix' require_relative '../../puppet/util/windows' @@ -11,6 +12,7 @@ def open(path, mode, options, &block) # Ruby on Windows uses mode for setting file attributes like read-only and # archived, not for setting permissions like POSIX raise TypeError.new('mode must be specified as an Integer') if mode && !mode.is_a?(Numeric) + ::File.open(path, options, nil, &block) end @@ -60,6 +62,7 @@ def symlink(path, dest, options = {}) def symlink?(path) return false if ! Puppet.features.manages_symlinks? + Puppet::Util::Windows::File.symlink?(path) end @@ -102,6 +105,7 @@ def lstat(path) if ! Puppet.features.manages_symlinks? return Puppet::Util::Windows::File.stat(path) end + Puppet::Util::Windows::File.lstat(path) end @@ -144,7 +148,6 @@ def replace_file(path, mode = nil) raise ArgumentError, "#{mode} is invalid: Only modes 0644, 0640, 0660, and 0440 are allowed" end - tempfile = Puppet::FileSystem::Uniquefile.new(Puppet::FileSystem.basename_string(path), Puppet::FileSystem.dir_string(path)) begin tempdacl = Puppet::Util::Windows::AccessControlList.new @@ -210,5 +213,4 @@ def raise_if_symlinks_unsupported Puppet.warning _("The current user does not have the necessary permission to manage symlinks.") end end - end diff --git a/lib/puppet/forge.rb b/lib/puppet/forge.rb index 0e44c532d01..12ac34ab093 100644 --- a/lib/puppet/forge.rb +++ b/lib/puppet/forge.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../puppet/vendor' Puppet::Vendor.load_vendored diff --git a/lib/puppet/forge/cache.rb b/lib/puppet/forge/cache.rb index 3cc5db13f8c..bc5675f65ae 100644 --- a/lib/puppet/forge/cache.rb +++ b/lib/puppet/forge/cache.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'uri' require_relative '../../puppet/forge' @@ -8,7 +9,6 @@ class Puppet::Forge # # Provides methods for reading files from local cache, filesystem or network. class Cache - # Instantiate new cache for the +repository+ instance. def initialize(repository, options = {}) @repository = repository diff --git a/lib/puppet/forge/errors.rb b/lib/puppet/forge/errors.rb index d0b000338a4..18732ed5a93 100644 --- a/lib/puppet/forge/errors.rb +++ b/lib/puppet/forge/errors.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true + require_relative '../../puppet/util/json' require_relative '../../puppet/error' require_relative '../../puppet/forge' # Puppet::Forge specific exceptions module Puppet::Forge::Errors - # This exception is the parent for all Forge API errors class ForgeError < Puppet::Error # This is normally set by the child class, but if it is not this will @@ -102,7 +102,6 @@ def initialize(options) # # @return [String] the multiline version of the error message def multiline - message = [] message << _('Request to Puppet Forge failed.') message << _(' The server being queried was %{uri}') % { uri: @uri } @@ -111,5 +110,4 @@ def multiline message.join("\n") end end - end diff --git a/lib/puppet/forge/repository.rb b/lib/puppet/forge/repository.rb index af7664e7921..9203201ff54 100644 --- a/lib/puppet/forge/repository.rb +++ b/lib/puppet/forge/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative '../../puppet/ssl/openssl_loader' require 'digest/sha1' require 'uri' @@ -30,6 +31,7 @@ def initialize(host, for_agent) # Return a Net::HTTPResponse read for this +path+. def make_http_request(path, io = nil) raise ArgumentError, "Path must start with forward slash" unless path.start_with?('/') + begin str = @uri.to_s str.chomp!('/') diff --git a/lib/puppet/functions.rb b/lib/puppet/functions.rb index e1c85f3eb14..cad6970d080 100644 --- a/lib/puppet/functions.rb +++ b/lib/puppet/functions.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Functions in the puppet language can be written in Ruby and distributed in # puppet modules. The function is written by creating a file in the module's # `lib/puppet/functions/` directory, where `` is @@ -272,6 +273,7 @@ def self.default_dispatcher(the_class, func_name) unless the_class.method_defined?(func_name) raise ArgumentError, _("Function Creation Error, cannot create a default dispatcher for function '%{func_name}', no method with this name found") % { func_name: func_name } end + any_signature(*min_max_param(the_class.instance_method(func_name))) end @@ -303,7 +305,6 @@ def self.any_signature(from, to, names) # # @api public class Function < Puppet::Pops::Functions::Function - # @api private def self.builder DispatcherBuilder.new(dispatcher, Puppet::Pops::Types::PCallableType::DEFAULT, loader) @@ -350,6 +351,7 @@ def self.local_types(&block) if loader.nil? raise ArgumentError, _("No loader present. Call create_loaded_function(:myname, loader,...), instead of 'create_function' if running tests") end + aliases = LocalTypeAliasesBuilder.new(loader, name) aliases.instance_eval(&block) # Add the loaded types to the builder @@ -386,7 +388,6 @@ def self.init_dispatch(a_closure) end end - # Public api methods of the DispatcherBuilder are available within dispatch() # blocks declared in a Puppet::Function.create_function() call. # @@ -413,6 +414,7 @@ def initialize(dispatcher, all_callables, loader) def param(type, name) internal_param(type, name) raise ArgumentError, _('A required parameter cannot be added after an optional parameter') if @min != @max + @min += 1 @max += 1 end @@ -462,6 +464,7 @@ def repeated_param(type, name) def required_repeated_param(type, name) internal_param(type, name, true) raise ArgumentError, _('A required repeated parameter cannot be added after an optional parameter') if @min != @max + @min += 1 @max = :default end @@ -522,6 +525,7 @@ def return_type(type) unless type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType) raise ArgumentError, _("Argument to 'return_type' must be a String reference to a Puppet Data Type. Got %{type_class}") % { type_class: type.class } end + @return_type = type end @@ -599,7 +603,6 @@ def internal_type_parse(type_string, loader) private :internal_type_parse end - # The LocalTypeAliasBuilder is used by the 'local_types' method to collect the individual # type aliases given by the function's author. # @@ -681,7 +684,6 @@ def call_function_with_scope(scope, function_name, *args, &block) end class Function3x < InternalFunction - # Table of optimized parameter names - 0 to 5 parameters PARAM_NAMES = [ [], @@ -739,7 +741,6 @@ def method3x # When function is not an rvalue function, make sure it produces nil # the_class.class_eval do - # Bypasses making the call via the dispatcher to make sure errors # are reported exactly the same way as in 3x. The dispatcher is still needed as it is # used to support other features than calling. @@ -801,7 +802,6 @@ def self.from_to_names(func_info) end end - # Injection and Weaving of parameters # --- # It is possible to inject and weave a set of well known parameters into a call. diff --git a/lib/puppet/functions/abs.rb b/lib/puppet/functions/abs.rb index 816761114ac..c00157fff06 100644 --- a/lib/puppet/functions/abs.rb +++ b/lib/puppet/functions/abs.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Returns the absolute value of a Numeric value, for example -34.56 becomes # 34.56. Takes a single `Integer` or `Float` value as an argument. # diff --git a/lib/puppet/functions/alert.rb b/lib/puppet/functions/alert.rb index c5cefd28dac..82ca82c9296 100644 --- a/lib/puppet/functions/alert.rb +++ b/lib/puppet/functions/alert.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Logs a message on the server at level `alert`. Puppet::Functions.create_function(:alert, Puppet::Functions::InternalFunction) do # @param values The values to log. diff --git a/lib/puppet/functions/all.rb b/lib/puppet/functions/all.rb index e4efe6ffd89..1b6d8375c84 100644 --- a/lib/puppet/functions/all.rb +++ b/lib/puppet/functions/all.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Runs a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html) # repeatedly using each value in a data structure until the lambda returns a non "truthy" value which # makes the function return `false`, or if the end of the iteration is reached, `true` is returned. diff --git a/lib/puppet/functions/annotate.rb b/lib/puppet/functions/annotate.rb index e96afcb6f25..ce3f9d2ff3e 100644 --- a/lib/puppet/functions/annotate.rb +++ b/lib/puppet/functions/annotate.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Handles annotations on objects. The function can be used in four different ways. # # With two arguments, an `Annotation` type and an object, the function returns the annotation diff --git a/lib/puppet/functions/any.rb b/lib/puppet/functions/any.rb index ebfeea809fe..296a6044336 100644 --- a/lib/puppet/functions/any.rb +++ b/lib/puppet/functions/any.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Runs a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html) # repeatedly using each value in a data structure until the lambda returns a "truthy" value which # makes the function return `true`, or if the end of the iteration is reached, false is returned. diff --git a/lib/puppet/functions/assert_type.rb b/lib/puppet/functions/assert_type.rb index 2ed3e062ba9..9b862c792a3 100644 --- a/lib/puppet/functions/assert_type.rb +++ b/lib/puppet/functions/assert_type.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Returns the given value if it is of the given # [data type](https://puppet.com/docs/puppet/latest/lang_data.html), or # otherwise either raises an error or executes an optional two-parameter diff --git a/lib/puppet/functions/binary_file.rb b/lib/puppet/functions/binary_file.rb index ad1d68ee8f6..6cfe8374710 100644 --- a/lib/puppet/functions/binary_file.rb +++ b/lib/puppet/functions/binary_file.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Loads a binary file from a module or file system and returns its contents as a `Binary`. # The argument to this function should be a `/` # reference, which will load `` from a module's `files` @@ -28,6 +29,7 @@ def binary_file(scope, unresolved_path) #TRANSLATORS the string "binary_file()" should not be translated raise Puppet::ParseError, _("binary_file(): The given file '%{unresolved_path}' does not exist") % { unresolved_path: unresolved_path } end + Puppet::Pops::Types::PBinaryType::Binary.from_binary_string(Puppet::FileSystem.binread(path)) end end diff --git a/lib/puppet/functions/break.rb b/lib/puppet/functions/break.rb index abca3db3821..1a6a8f6c8c1 100644 --- a/lib/puppet/functions/break.rb +++ b/lib/puppet/functions/break.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Breaks an innermost iteration as if it encountered an end of input. # This function does not return to the caller. # diff --git a/lib/puppet/functions/call.rb b/lib/puppet/functions/call.rb index 47544056ce3..0d17370cfee 100644 --- a/lib/puppet/functions/call.rb +++ b/lib/puppet/functions/call.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Calls an arbitrary Puppet function by name. # # This function takes one mandatory argument and one or more optional arguments: @@ -77,5 +78,4 @@ def call_impl_block(scope, function_name, *args, &block) def call_deferred(scope, deferred) Puppet::Pops::Evaluator::DeferredResolver.resolve(deferred, scope.compiler) end - end diff --git a/lib/puppet/functions/camelcase.rb b/lib/puppet/functions/camelcase.rb index a4c35850052..4dfe6e70dbb 100644 --- a/lib/puppet/functions/camelcase.rb +++ b/lib/puppet/functions/camelcase.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Creates a Camel Case version of a String # # This function is compatible with the stdlib function with the same name. @@ -30,7 +31,6 @@ # Would both result in `['AbcDef', 'BcdXyz']` # Puppet::Functions.create_function(:camelcase) do - dispatch :on_numeric do param 'Numeric', :arg end diff --git a/lib/puppet/functions/capitalize.rb b/lib/puppet/functions/capitalize.rb index 7095451a833..b8507f402ca 100644 --- a/lib/puppet/functions/capitalize.rb +++ b/lib/puppet/functions/capitalize.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Capitalizes the first character of a String, or the first character of every String in an Iterable value (such as an Array). # # This function is compatible with the stdlib function with the same name. @@ -29,7 +30,6 @@ # Would both result in `['Abc', 'Bcd']` # Puppet::Functions.create_function(:capitalize) do - dispatch :on_numeric do param 'Numeric', :arg end diff --git a/lib/puppet/functions/ceiling.rb b/lib/puppet/functions/ceiling.rb index 632255d2f25..a46f507510f 100644 --- a/lib/puppet/functions/ceiling.rb +++ b/lib/puppet/functions/ceiling.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Returns the smallest `Integer` greater or equal to the argument. # Takes a single numeric value as an argument. # @@ -34,5 +35,4 @@ def on_string(x) raise(ArgumentError, _('ceiling(): cannot convert given value to a floating point value.')) end end - end diff --git a/lib/puppet/functions/chomp.rb b/lib/puppet/functions/chomp.rb index 32b0a87a613..a7b909e7ba4 100644 --- a/lib/puppet/functions/chomp.rb +++ b/lib/puppet/functions/chomp.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Returns a new string with the record separator character(s) removed. # The record separator is the line ending characters `\r` and `\n`. # @@ -25,7 +26,6 @@ # Would both result in `['hello', 'hi']` # Puppet::Functions.create_function(:chomp) do - dispatch :on_numeric do param 'Numeric', :arg end diff --git a/lib/puppet/functions/chop.rb b/lib/puppet/functions/chop.rb index bd13cd2d7b2..210937aafeb 100644 --- a/lib/puppet/functions/chop.rb +++ b/lib/puppet/functions/chop.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # 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 @@ -35,7 +36,6 @@ # Would both result in `['hello', 'hi']` # Puppet::Functions.create_function(:chop) do - dispatch :on_numeric do param 'Numeric', :arg end diff --git a/lib/puppet/functions/compare.rb b/lib/puppet/functions/compare.rb index c17cac7d6e3..6a322677743 100644 --- a/lib/puppet/functions/compare.rb +++ b/lib/puppet/functions/compare.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Compares two values and returns -1, 0 or 1 if first value is smaller, equal or larger than the second value. # The compare function accepts arguments of the data types `String`, `Numeric`, `Timespan`, `Timestamp`, and `Semver`, # such that: diff --git a/lib/puppet/functions/contain.rb b/lib/puppet/functions/contain.rb index e4d9bd36042..dea0ae79ac8 100644 --- a/lib/puppet/functions/contain.rb +++ b/lib/puppet/functions/contain.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Makes one or more classes be contained inside the current class. # If any of these classes are undeclared, they will be declared as if # there were declared with the `include` function. diff --git a/lib/puppet/functions/convert_to.rb b/lib/puppet/functions/convert_to.rb index bf19fae65dd..c21af06dc3c 100644 --- a/lib/puppet/functions/convert_to.rb +++ b/lib/puppet/functions/convert_to.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # The `convert_to(value, type)` is a convenience function that does the same as `new(type, value)`. # The difference in the argument ordering allows it to be used in chained style for # improved readability "left to right". diff --git a/lib/puppet/functions/crit.rb b/lib/puppet/functions/crit.rb index ed43adeb788..e71cdcf51b7 100644 --- a/lib/puppet/functions/crit.rb +++ b/lib/puppet/functions/crit.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Logs a message on the server at level `crit`. Puppet::Functions.create_function(:crit, Puppet::Functions::InternalFunction) do # @param values The values to log. diff --git a/lib/puppet/functions/debug.rb b/lib/puppet/functions/debug.rb index 2533f7a068f..2a643890dc2 100644 --- a/lib/puppet/functions/debug.rb +++ b/lib/puppet/functions/debug.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Logs a message on the server at level `debug`. Puppet::Functions.create_function(:debug, Puppet::Functions::InternalFunction) do # @param values The values to log. diff --git a/lib/puppet/functions/defined.rb b/lib/puppet/functions/defined.rb index 5c8cac35d05..1d07d914c74 100644 --- a/lib/puppet/functions/defined.rb +++ b/lib/puppet/functions/defined.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Determines whether a given class or resource type is defined and returns a Boolean # value. You can also use `defined` to determine whether a specific resource is defined, # or whether a variable has a value (including `undef`, as opposed to the variable never @@ -101,7 +102,6 @@ # @since 4.0.0 # Puppet::Functions.create_function(:'defined', Puppet::Functions::InternalFunction) do - dispatch :is_defined do scope_param required_repeated_param 'Variant[String, Type[CatalogEntry], Type[Type[CatalogEntry]]]', :vals @@ -131,11 +131,13 @@ def is_defined(scope, *vals) # rubocop:disable Naming/PredicateName when Puppet::Pops::Types::PResourceType raise ArgumentError, _('The given resource type is a reference to all kind of types') if val.type_name.nil? + type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type(scope, val.type_name) val.title.nil? ? type : scope.compiler.findresource(type, val.title) when Puppet::Pops::Types::PClassType raise ArgumentError, _('The given class type is a reference to all classes') if val.class_name.nil? + scope.compiler.findresource(:class, val.class_name) when Puppet::Pops::Types::PTypeType @@ -150,6 +152,7 @@ def is_defined(scope, *vals) # rubocop:disable Naming/PredicateName # (this is the same as asking for just the class' name, but with the added certainty that it cannot be a defined type. # raise ArgumentError, _('The given class type is a reference to all classes') if val.type.class_name.nil? + Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_hostclass(scope, val.type.class_name) end else diff --git a/lib/puppet/functions/dig.rb b/lib/puppet/functions/dig.rb index a95ddfb1f58..5cc2781a5b5 100644 --- a/lib/puppet/functions/dig.rb +++ b/lib/puppet/functions/dig.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Returns a value for a sequence of given keys/indexes into a structure, such as # an array or hash. # @@ -38,6 +39,7 @@ def dig(data, *args) walked_path = [] args.reduce(data) do | d, k | return nil if d.nil? || k.nil? + if !(d.is_a?(Array) || d.is_a?(Hash)) t = Puppet::Pops::Types::TypeCalculator.infer(d) msg = _("The given data does not contain a Collection at %{walked_path}, got '%{type}'") % { walked_path: walked_path, type: t } @@ -46,7 +48,7 @@ def dig(data, *args) 'SLICE_ERROR', {'walked_path' => walked_path, 'value_type' => t}, 'EXPECTED_COLLECTION' - ) + ) raise Puppet::ErrorWithData.new(error_data, msg) end @@ -59,7 +61,7 @@ def dig(data, *args) 'SLICE_ERROR', {'walked_path' => walked_path, 'index_type' => t}, 'EXPECTED_INTEGER_INDEX' - ) + ) raise Puppet::ErrorWithData.new(error_data, msg) end d[k] diff --git a/lib/puppet/functions/downcase.rb b/lib/puppet/functions/downcase.rb index a052387af92..98fb9fb1b4e 100644 --- a/lib/puppet/functions/downcase.rb +++ b/lib/puppet/functions/downcase.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Converts a String, Array or Hash (recursively) into lower case. # # This function is compatible with the stdlib function with the same name. diff --git a/lib/puppet/functions/each.rb b/lib/puppet/functions/each.rb index 2f42fdde9e1..a7c1ebda4a5 100644 --- a/lib/puppet/functions/each.rb +++ b/lib/puppet/functions/each.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Runs a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html) # repeatedly using each value in a data structure, then returns the values unchanged. # diff --git a/lib/puppet/functions/emerg.rb b/lib/puppet/functions/emerg.rb index d1c9d8eb672..716db8d7ea6 100644 --- a/lib/puppet/functions/emerg.rb +++ b/lib/puppet/functions/emerg.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Logs a message on the server at level `emerg`. Puppet::Functions.create_function(:emerg, Puppet::Functions::InternalFunction) do # @param values The values to log. diff --git a/lib/puppet/functions/empty.rb b/lib/puppet/functions/empty.rb index 4e4c1f91edb..1560a29877d 100644 --- a/lib/puppet/functions/empty.rb +++ b/lib/puppet/functions/empty.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Returns `true` if the given argument is an empty collection of values. # # This function can answer if one of the following is empty: diff --git a/lib/puppet/functions/epp.rb b/lib/puppet/functions/epp.rb index a59cf3b5b6b..4abe3dd7885 100644 --- a/lib/puppet/functions/epp.rb +++ b/lib/puppet/functions/epp.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Evaluates an Embedded Puppet (EPP) template file and returns the rendered text # result as a String. # @@ -36,7 +37,6 @@ # @since 4.0.0 # Puppet::Functions.create_function(:epp, Puppet::Functions::InternalFunction) do - dispatch :epp do scope_param param 'String', :path diff --git a/lib/puppet/functions/err.rb b/lib/puppet/functions/err.rb index 9d202ac54e5..c507fcf17b8 100644 --- a/lib/puppet/functions/err.rb +++ b/lib/puppet/functions/err.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Logs a message on the server at level `err`. Puppet::Functions.create_function(:err, Puppet::Functions::InternalFunction) do # @param values The values to log. diff --git a/lib/puppet/functions/eyaml_lookup_key.rb b/lib/puppet/functions/eyaml_lookup_key.rb index ca7262c15b3..a4de064d53f 100644 --- a/lib/puppet/functions/eyaml_lookup_key.rb +++ b/lib/puppet/functions/eyaml_lookup_key.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # The `eyaml_lookup_key` is a hiera 5 `lookup_key` data provider function. # See [the configuration guide documentation](https://puppet.com/docs/puppet/latest/hiera_config_yaml_5.html#configuring-a-hierarchy-level-hiera-eyaml) for # how to use this function. @@ -53,6 +54,7 @@ def load_data_hash(options, context) else msg = _("%{path}: file does not contain a valid yaml hash") % { path: path } raise Puppet::DataBinding::LookupError, msg if Puppet[:strict] == :error && data != false + Puppet.warning(msg) {} end diff --git a/lib/puppet/functions/filter.rb b/lib/puppet/functions/filter.rb index 33170afa141..4582934abff 100644 --- a/lib/puppet/functions/filter.rb +++ b/lib/puppet/functions/filter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Applies a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html) # to every value in a data structure and returns an array or hash containing any elements # for which the lambda evaluates to a truthy value (not `false` or `undef`). diff --git a/lib/puppet/functions/find_file.rb b/lib/puppet/functions/find_file.rb index 9ede5310a04..e930adfd37a 100644 --- a/lib/puppet/functions/find_file.rb +++ b/lib/puppet/functions/find_file.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Finds an existing file from a module and returns its path. # # This function accepts an argument that is a String as a `/` diff --git a/lib/puppet/functions/find_template.rb b/lib/puppet/functions/find_template.rb index 58730373184..127ad090aa4 100644 --- a/lib/puppet/functions/find_template.rb +++ b/lib/puppet/functions/find_template.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Finds an existing template from a module and returns its path. # # This function accepts an argument that is a String as a `/