diff --git a/.rubocop.yml b/.rubocop.yml index 2c3df93c09f..be8d072e377 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,6 +22,12 @@ Layout/ArgumentAlignment: Exclude: - 'lib/puppet/defaults.rb' +# The confine statements in package providers unexpectedly affect this cop. +Layout/BeginEndAlignment: + 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 fbbb61b4afc..873128789ad 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -22,87 +22,6 @@ I18n/GetText/DecorateStringFormattingUsingPercent: I18n/RailsI18n/DecorateString: Enabled: false -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: outdent, indent -Layout/AccessModifierIndentation: - Exclude: - - 'lib/puppet/module_tool/install_directory.rb' - - 'lib/puppet/pops/evaluator/collector_transformer.rb' - - 'lib/puppet/provider/service/init.rb' - - 'lib/puppet/provider/service/upstart.rb' - - 'lib/puppet/settings/config_file.rb' - - 'lib/puppet/settings/file_setting.rb' - - 'lib/puppet/util/command_line/trollop.rb' - - 'lib/puppet/util/run_mode.rb' - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_element, with_fixed_indentation -Layout/ArrayAlignment: - Exclude: - - 'lib/puppet/module/plan.rb' - - 'lib/puppet/pops/model/model_tree_dumper.rb' - - 'lib/puppet/pops/parser/heredoc_support.rb' - - 'lib/puppet/pops/parser/lexer2.rb' - - 'lib/puppet/provider/service/init.rb' - - 'lib/puppet/util/log/destinations.rb' - - 'lib/puppet/util/posix.rb' - - 'lib/puppet/util/windows/registry.rb' - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: IndentationWidth. -Layout/AssignmentIndentation: - Exclude: - - 'lib/puppet/application/apply.rb' - - 'lib/puppet/ffi/windows/constants.rb' - - 'lib/puppet/indirector/request.rb' - - 'lib/puppet/parser/e4_parser_adapter.rb' - - 'lib/puppet/pops/evaluator/evaluator_impl.rb' - - 'lib/puppet/pops/model/model_tree_dumper.rb' - - 'lib/puppet/pops/parser/lexer_support.rb' - - 'lib/puppet/pops/types/type_parser.rb' - - 'lib/puppet/resource/type.rb' - - 'lib/puppet/settings.rb' - - 'lib/puppet/settings/environment_conf.rb' - - 'lib/puppet/type/resources.rb' - - 'lib/puppet/util.rb' - - 'lib/puppet/util/windows/daemon.rb' - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyleAlignWith, Severity. -# SupportedStylesAlignWith: start_of_line, begin -Layout/BeginEndAlignment: - Exclude: - - 'lib/puppet/provider/package/apt.rb' - - 'lib/puppet/provider/package/aptrpm.rb' - - 'lib/puppet/provider/package/dnf.rb' - - 'lib/puppet/provider/package/rpm.rb' - - 'lib/puppet/provider/package/tdnf.rb' - - 'lib/puppet/provider/package/yum.rb' - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyleAlignWith. -# SupportedStylesAlignWith: either, start_of_block, start_of_line -Layout/BlockAlignment: - Exclude: - - 'lib/puppet/defaults.rb' - - 'lib/puppet/node/environment.rb' - - 'lib/puppet/parser/functions/lookup.rb' - - 'lib/puppet/provider/package/dnfmodule.rb' - - 'lib/puppet/type/file.rb' - - 'lib/puppet/util/windows/principal.rb' - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth. -# SupportedStyles: case, end -Layout/CaseIndentation: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Layout/ClosingHeredocIndentation: - Enabled: false - # This cop supports safe auto-correction (--auto-correct). Layout/ClosingParenthesisIndentation: Enabled: false diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 3292ee7dc77..1a7db86d2b1 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -234,12 +234,12 @@ def main # rule and gets logged. # catalog = - begin - Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node) - rescue Puppet::Error - # already logged and handled by the compiler, including Puppet::ParseErrorWithIssue - exit(1) - end + begin + Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node) + rescue Puppet::Error + # already logged and handled by the compiler, including Puppet::ParseErrorWithIssue + exit(1) + end # Resolve all deferred values and replace them / mutate the catalog Puppet::Pops::Evaluator::DeferredResolver.resolve_and_replace(node.facts, catalog, apply_environment, Puppet[:preprocess_deferred]) diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index 819e284e01d..2ceeb6f83c8 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -112,7 +112,7 @@ module - see https://github.com/puppetlabs/puppetlabs-strings for more informati --------- Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License -HELP + HELP end def handle_unknown( opt, arg ) diff --git a/lib/puppet/application/ssl.rb b/lib/puppet/application/ssl.rb index 163f0e9de93..65322e152e3 100644 --- a/lib/puppet/application/ssl.rb +++ b/lib/puppet/application/ssl.rb @@ -83,7 +83,7 @@ def help * show: Print the full-text version of this host's certificate. -HELP + HELP end option('--target CERTNAME') do |arg| diff --git a/lib/puppet/datatypes/error.rb b/lib/puppet/datatypes/error.rb index 27e035fb362..4cc48f6efa3 100644 --- a/lib/puppet/datatypes/error.rb +++ b/lib/puppet/datatypes/error.rb @@ -14,7 +14,7 @@ functions => { message => Callable[[], String[1]] } - PUPPET + PUPPET require_relative '../../puppet/datatypes/impl/error' diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 172731c1b06..cd275d430db 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -430,7 +430,7 @@ def self.initialize_default_settings!(settings) between the configured or resolved path. When set to false, the resolved paths are reported instead of the configured paths. - EOT + EOT }, :use_last_environment => { :type => :boolean, @@ -441,7 +441,7 @@ def self.initialize_default_settings!(settings) environment and skip the node request. When set to false, we will do the node request and ignore the environment data from the last_run_summary file. - EOT + EOT }, :always_retry_plugins => { :type => :boolean, @@ -462,7 +462,7 @@ def self.initialize_default_settings!(settings) feature. This behavior is almost always appropriate for the server, and can result in a significant performance improvement for types and features that are checked frequently. - EOT + EOT }, :diff_args => { :default => lambda { default_diffargs }, @@ -493,10 +493,10 @@ def self.initialize_default_settings!(settings) currently cannot daemonize).", :short => "D", :hook => proc do |value| - if value and Puppet::Util::Platform.windows? - raise "Cannot daemonize on Windows" - end - end + if value and Puppet::Util::Platform.windows? + raise "Cannot daemonize on Windows" + end + end }, :maximum_uid => { :default => 4294967290, @@ -709,7 +709,7 @@ def self.initialize_default_settings!(settings) releases this value will only determine if file content is cached. Valid values are 0 (never cache) and 15 (15 second minimum wait time). - WARNING + WARNING end end }, diff --git a/lib/puppet/ffi/windows/constants.rb b/lib/puppet/ffi/windows/constants.rb index 7452081be05..b054e6ea607 100644 --- a/lib/puppet/ffi/windows/constants.rb +++ b/lib/puppet/ffi/windows/constants.rb @@ -47,25 +47,25 @@ module Constants FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF FILE_GENERIC_READ = - STANDARD_RIGHTS_READ | - FILE_READ_DATA | - FILE_READ_ATTRIBUTES | - FILE_READ_EA | - SYNCHRONIZE + STANDARD_RIGHTS_READ | + FILE_READ_DATA | + FILE_READ_ATTRIBUTES | + FILE_READ_EA | + SYNCHRONIZE FILE_GENERIC_WRITE = - STANDARD_RIGHTS_WRITE | - FILE_WRITE_DATA | - FILE_WRITE_ATTRIBUTES | - FILE_WRITE_EA | - FILE_APPEND_DATA | - SYNCHRONIZE + STANDARD_RIGHTS_WRITE | + FILE_WRITE_DATA | + FILE_WRITE_ATTRIBUTES | + FILE_WRITE_EA | + FILE_APPEND_DATA | + SYNCHRONIZE FILE_GENERIC_EXECUTE = - STANDARD_RIGHTS_EXECUTE | - FILE_READ_ATTRIBUTES | - FILE_EXECUTE | - SYNCHRONIZE + STANDARD_RIGHTS_EXECUTE | + FILE_READ_ATTRIBUTES | + FILE_EXECUTE | + SYNCHRONIZE REPLACEFILE_WRITE_THROUGH = 0x1 REPLACEFILE_IGNORE_MERGE_ERRORS = 0x2 diff --git a/lib/puppet/file_system/uniquefile.rb b/lib/puppet/file_system/uniquefile.rb index eb9b2b9c600..e009f23906d 100644 --- a/lib/puppet/file_system/uniquefile.rb +++ b/lib/puppet/file_system/uniquefile.rb @@ -100,14 +100,14 @@ def path def make_tmpname(prefix_suffix, n) case prefix_suffix - when String - prefix = prefix_suffix - suffix = "" - when Array - prefix = prefix_suffix[0] - suffix = prefix_suffix[1] - else - raise ArgumentError, _("unexpected prefix_suffix: %{value}") % { value: prefix_suffix.inspect } + when String + prefix = prefix_suffix + suffix = "" + when Array + prefix = prefix_suffix[0] + suffix = prefix_suffix[1] + else + raise ArgumentError, _("unexpected prefix_suffix: %{value}") % { value: prefix_suffix.inspect } end t = Time.now.strftime("%Y%m%d") path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}" diff --git a/lib/puppet/http/dns.rb b/lib/puppet/http/dns.rb index 70280a8df60..d52c75881ab 100644 --- a/lib/puppet/http/dns.rb +++ b/lib/puppet/http/dns.rb @@ -49,9 +49,9 @@ def each_srv_record(domain, service_name = :puppet, &block) Puppet.debug "Searching for SRV records for domain: #{domain}" case service_name - when :puppet then service = '_x-puppet' - when :file then service = '_x-puppet-fileserver' - else service = "_x-puppet-#{service_name}" + when :puppet then service = '_x-puppet' + when :file then service = '_x-puppet-fileserver' + else service = "_x-puppet-#{service_name}" end record_name = "#{service}._tcp.#{domain}" diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index cf4e8c21974..9790b1158da 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -158,17 +158,17 @@ def get_content_uri(metadata, source, environment_path) # Also used to profile/log reasons for not inlining. def inlineable?(resource, sources) case - when resource[:ensure] == 'absent' - #TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) - return Puppet::Util::Profiler.profile(_("Not inlining absent resource"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :absent]) { false } - when sources.empty? - #TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) - return Puppet::Util::Profiler.profile(_("Not inlining resource without sources"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :no_sources]) { false } - when (not (sources.all? {|source| source =~ /^puppet:/})) - #TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) - return Puppet::Util::Profiler.profile(_("Not inlining unsupported source scheme"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :unsupported_scheme]) { false } - else - return true + when resource[:ensure] == 'absent' + #TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) + return Puppet::Util::Profiler.profile(_("Not inlining absent resource"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :absent]) { false } + when sources.empty? + #TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) + return Puppet::Util::Profiler.profile(_("Not inlining resource without sources"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :no_sources]) { false } + when (not (sources.all? {|source| source =~ /^puppet:/})) + #TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) + return Puppet::Util::Profiler.profile(_("Not inlining unsupported source scheme"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :unsupported_scheme]) { false } + else + return true end end diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index b8e1eb263b9..d8ab43b8f0e 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -36,11 +36,11 @@ def environment def environment=(env) @environment = - if env.is_a?(Puppet::Node::Environment) - env - else - Puppet.lookup(:environments).get!(env) - end + if env.is_a?(Puppet::Node::Environment) + env + else + Puppet.lookup(:environments).get!(env) + end end # LAK:NOTE This is a messy interface to the cache, and it's only diff --git a/lib/puppet/module/plan.rb b/lib/puppet/module/plan.rb index 2045ce20117..871ef554f49 100644 --- a/lib/puppet/module/plan.rb +++ b/lib/puppet/module/plan.rb @@ -46,11 +46,11 @@ def initialize(plan_name, module_name) ALLOWED_EXTENSIONS = %w{.pp .yaml} RESERVED_WORDS = %w{and application attr case class consumes default else - elsif environment false function if import in inherits node or private - produces site true type undef unless} + elsif environment false function if import in inherits node or private + produces site true type undef unless} RESERVED_DATA_TYPES = %w{any array boolean catalogentry class collection - callable data default enum float hash integer numeric optional pattern - resource runtime scalar string struct tuple type undef variant} + callable data default enum float hash integer numeric optional pattern + resource runtime scalar string struct tuple type undef variant} def self.is_plan_name?(name) return true if name =~ /^[a-z][a-z0-9_]*$/ diff --git a/lib/puppet/module_tool/install_directory.rb b/lib/puppet/module_tool/install_directory.rb index 0b1de5939d6..47570ae9208 100644 --- a/lib/puppet/module_tool/install_directory.rb +++ b/lib/puppet/module_tool/install_directory.rb @@ -26,7 +26,7 @@ def prepare(module_name, version) end end - private + private ERROR_MAPPINGS = { Errno::EACCES => PermissionDeniedCreateInstallDirectoryError, diff --git a/lib/puppet/module_tool/metadata.rb b/lib/puppet/module_tool/metadata.rb index 64752a2c6bf..9112768f075 100644 --- a/lib/puppet/module_tool/metadata.rb +++ b/lib/puppet/module_tool/metadata.rb @@ -172,14 +172,14 @@ def validate_name(name) modname = :namespace_missing if namespace == '' err = case modname - when nil, '', :namespace_missing - _("the field must be a namespaced module name") - when /[^a-z0-9_]/i - _("the module name contains non-alphanumeric (or underscore) characters") - when /^[^a-z]/i - _("the module name must begin with a letter") - else - _("the namespace contains non-alphanumeric characters") + when nil, '', :namespace_missing + _("the field must be a namespaced module name") + when /[^a-z0-9_]/i + _("the module name contains non-alphanumeric (or underscore) characters") + when /^[^a-z]/i + _("the module name must begin with a letter") + else + _("the namespace contains non-alphanumeric characters") end raise ArgumentError, _("Invalid 'name' field in metadata.json: %{err}") % { err: err } diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index a4b9881812b..f4032540859 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -597,7 +597,7 @@ def perform_initial_import parse_results = Puppet::FileSystem::PathPattern.absolute(File.join(file, '**/*')).glob.select {|globbed_file| globbed_file.end_with?('.pp')}.sort.map do | file_to_parse | parser.file = file_to_parse parser.parse - end + end # Use a parser type specific merger to concatenate the results Puppet::Parser::AST::Hostclass.new('', :code => Puppet::Parser::ParserFactory.code_merger.concatenate(parse_results)) else diff --git a/lib/puppet/parser/e4_parser_adapter.rb b/lib/puppet/parser/e4_parser_adapter.rb index c7efede25a4..15855a0dbaa 100644 --- a/lib/puppet/parser/e4_parser_adapter.rb +++ b/lib/puppet/parser/e4_parser_adapter.rb @@ -23,14 +23,14 @@ def parse(string = nil) self.string= string if string parser = Pops::Parser::EvaluatingParser.singleton model = - if @use == :string - # Parse with a source_file to set in created AST objects (it was either given, or it may be unknown - # if caller did not set a file and the present a string. - # - parser.parse_string(@string, @file || "unknown-source-location") - else - parser.parse_file(@file) - end + if @use == :string + # Parse with a source_file to set in created AST objects (it was either given, or it may be unknown + # if caller did not set a file and the present a string. + # + parser.parse_string(@string, @file || "unknown-source-location") + else + parser.parse_file(@file) + end # the parse_result may be # * empty / nil (no input) @@ -41,12 +41,12 @@ def parse(string = nil) Pops::Model::AstTransformer.new(@file).merge_location(args, model) ast_code = - if model.is_a? Pops::Model::Program - AST::PopsBridge::Program.new(model, args) - else - args[:value] = model - AST::PopsBridge::Expression.new(args) - end + if model.is_a? Pops::Model::Program + AST::PopsBridge::Program.new(model, args) + else + args[:value] = model + AST::PopsBridge::Expression.new(args) + end # Create the "main" class for the content - this content will get merged with all other "main" content AST::Hostclass.new('', :code => ast_code) diff --git a/lib/puppet/parser/functions/break.rb b/lib/puppet/parser/functions/break.rb index 123a7c600d6..275d30fa61c 100644 --- a/lib/puppet/parser/functions/break.rb +++ b/lib/puppet/parser/functions/break.rb @@ -34,7 +34,7 @@ * Also see functions `next` and `return` * Since 4.8.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('break') end diff --git a/lib/puppet/parser/functions/create_resources.rb b/lib/puppet/parser/functions/create_resources.rb index c4caf171967..08d14c4668d 100644 --- a/lib/puppet/parser/functions/create_resources.rb +++ b/lib/puppet/parser/functions/create_resources.rb @@ -51,7 +51,7 @@ data binding and Puppet default value expressions are considered (in that order) for the final value of a parameter (just as when setting a parameter to `undef` in a Puppet language resource declaration). - ENDHEREDOC +ENDHEREDOC if Puppet[:tasks] raise Puppet::ParseErrorWithIssue.from_issue_and_stack( Puppet::Pops::Issues::CATALOG_OPERATION_NOT_SUPPORTED_WHEN_SCRIPTING, diff --git a/lib/puppet/parser/functions/dig.rb b/lib/puppet/parser/functions/dig.rb index 56ec4975974..47c585a480d 100644 --- a/lib/puppet/parser/functions/dig.rb +++ b/lib/puppet/parser/functions/dig.rb @@ -33,7 +33,7 @@ exists in a structure without mandating that it always exists. * Since 4.5.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('dig') end diff --git a/lib/puppet/parser/functions/each.rb b/lib/puppet/parser/functions/each.rb index eb8ad8951e9..29c9ffa4447 100644 --- a/lib/puppet/parser/functions/each.rb +++ b/lib/puppet/parser/functions/each.rb @@ -99,7 +99,7 @@ documentation. - Since 4.0.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('each') end diff --git a/lib/puppet/parser/functions/filter.rb b/lib/puppet/parser/functions/filter.rb index 708ed708301..11337db38bf 100644 --- a/lib/puppet/parser/functions/filter.rb +++ b/lib/puppet/parser/functions/filter.rb @@ -74,7 +74,7 @@ ~~~ - Since 4.0.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('filter') end diff --git a/lib/puppet/parser/functions/hiera_array.rb b/lib/puppet/parser/functions/hiera_array.rb index 3a79bc429e7..707cb573f36 100644 --- a/lib/puppet/parser/functions/hiera_array.rb +++ b/lib/puppet/parser/functions/hiera_array.rb @@ -85,7 +85,7 @@ module Puppet::Parser::Functions for more information about Hiera lookup functions. - Since 4.0.0 -DOC + DOC ) do |*_args| Error.is4x('hiera_array') end diff --git a/lib/puppet/parser/functions/hiera_hash.rb b/lib/puppet/parser/functions/hiera_hash.rb index a948a1e827e..de8f6f2e267 100644 --- a/lib/puppet/parser/functions/hiera_hash.rb +++ b/lib/puppet/parser/functions/hiera_hash.rb @@ -95,7 +95,7 @@ module Puppet::Parser::Functions for more information about Hiera lookup functions. - Since 4.0.0 -DOC + DOC ) do |*_args| Error.is4x('hiera_hash') end diff --git a/lib/puppet/parser/functions/hiera_include.rb b/lib/puppet/parser/functions/hiera_include.rb index a5707f899d9..19792c23682 100644 --- a/lib/puppet/parser/functions/hiera_include.rb +++ b/lib/puppet/parser/functions/hiera_include.rb @@ -94,7 +94,7 @@ module Puppet::Parser::Functions with calls to stdlib's `deep_merge` function depending on kind of hiera call and setting of merge in hiera.yaml. - Since 4.0.0 -DOC + DOC ) do |*_args| Error.is4x('hiera_include') end diff --git a/lib/puppet/parser/functions/lest.rb b/lib/puppet/parser/functions/lest.rb index 7ffff2514fe..570319f7580 100644 --- a/lib/puppet/parser/functions/lest.rb +++ b/lib/puppet/parser/functions/lest.rb @@ -44,7 +44,7 @@ Would notice the value `20` * Since 4.5.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('lest') end diff --git a/lib/puppet/parser/functions/lookup.rb b/lib/puppet/parser/functions/lookup.rb index ac11b78e5f0..9e09dc0f58e 100644 --- a/lib/puppet/parser/functions/lookup.rb +++ b/lib/puppet/parser/functions/lookup.rb @@ -127,7 +127,7 @@ module Puppet::Parser::Functions }, }) -ENDHEREDOC + ENDHEREDOC Error.is4x('lookup') -end + end end diff --git a/lib/puppet/parser/functions/map.rb b/lib/puppet/parser/functions/map.rb index d1001760877..987d17f71cc 100644 --- a/lib/puppet/parser/functions/map.rb +++ b/lib/puppet/parser/functions/map.rb @@ -71,7 +71,7 @@ ~~~ - Since 4.0.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('map') end diff --git a/lib/puppet/parser/functions/match.rb b/lib/puppet/parser/functions/match.rb index 3ec89dc7318..8102944b953 100644 --- a/lib/puppet/parser/functions/match.rb +++ b/lib/puppet/parser/functions/match.rb @@ -38,7 +38,7 @@ ~~~ - Since 4.0.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('match') end diff --git a/lib/puppet/parser/functions/new.rb b/lib/puppet/parser/functions/new.rb index 4ddfb16898f..f12546dc2f6 100644 --- a/lib/puppet/parser/functions/new.rb +++ b/lib/puppet/parser/functions/new.rb @@ -985,7 +985,7 @@ notice($fmt(256)) # will notice '0x100' ``` -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('new') end diff --git a/lib/puppet/parser/functions/next.rb b/lib/puppet/parser/functions/next.rb index 0a8ffaf5df6..0d9eb6d3f50 100644 --- a/lib/puppet/parser/functions/next.rb +++ b/lib/puppet/parser/functions/next.rb @@ -33,7 +33,7 @@ * Also see functions `return` and `break` * Since 4.8.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('next') end diff --git a/lib/puppet/parser/functions/reduce.rb b/lib/puppet/parser/functions/reduce.rb index 6b6762866ac..b5aee4fa71b 100644 --- a/lib/puppet/parser/functions/reduce.rb +++ b/lib/puppet/parser/functions/reduce.rb @@ -132,7 +132,7 @@ ~~~ - Since 4.0.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('reduce') end diff --git a/lib/puppet/parser/functions/return.rb b/lib/puppet/parser/functions/return.rb index 504953c4fef..e7dc276cae8 100644 --- a/lib/puppet/parser/functions/return.rb +++ b/lib/puppet/parser/functions/return.rb @@ -87,7 +87,7 @@ class { example: x => [some_value] } * Also see functions `return` and `break` * Since 4.8.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('return') end diff --git a/lib/puppet/parser/functions/reverse_each.rb b/lib/puppet/parser/functions/reverse_each.rb index e2013e0f862..30063ca99fe 100644 --- a/lib/puppet/parser/functions/reverse_each.rb +++ b/lib/puppet/parser/functions/reverse_each.rb @@ -78,7 +78,7 @@ * Since 4.4.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('reverse_each') end diff --git a/lib/puppet/parser/functions/scanf.rb b/lib/puppet/parser/functions/scanf.rb index 53361067356..cc90b558f98 100644 --- a/lib/puppet/parser/functions/scanf.rb +++ b/lib/puppet/parser/functions/scanf.rb @@ -31,7 +31,7 @@ ``` - Since 4.0.0 -DOC + DOC ) do |args| data = args[0] format = args[1] diff --git a/lib/puppet/parser/functions/slice.rb b/lib/puppet/parser/functions/slice.rb index 051c7fccec4..85b9af7ecc6 100644 --- a/lib/puppet/parser/functions/slice.rb +++ b/lib/puppet/parser/functions/slice.rb @@ -34,7 +34,7 @@ $a.slice(2) |$first, $second| { ... } - Since 4.0.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('slice') end diff --git a/lib/puppet/parser/functions/step.rb b/lib/puppet/parser/functions/step.rb index bab068e4528..de1bf92b1ca 100644 --- a/lib/puppet/parser/functions/step.rb +++ b/lib/puppet/parser/functions/step.rb @@ -79,7 +79,7 @@ * Since 4.4.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('step') end diff --git a/lib/puppet/parser/functions/then.rb b/lib/puppet/parser/functions/then.rb index 573ce3571d7..ba8e422df9b 100644 --- a/lib/puppet/parser/functions/then.rb +++ b/lib/puppet/parser/functions/then.rb @@ -68,7 +68,7 @@ * Since 4.5.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('then') end diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb index 489951707a4..25513b17c23 100644 --- a/lib/puppet/parser/functions/type.rb +++ b/lib/puppet/parser/functions/type.rb @@ -48,7 +48,7 @@ * Since 4.4.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('type') end diff --git a/lib/puppet/parser/functions/with.rb b/lib/puppet/parser/functions/with.rb index 53082e34fd4..2e3f77501d1 100644 --- a/lib/puppet/parser/functions/with.rb +++ b/lib/puppet/parser/functions/with.rb @@ -23,7 +23,7 @@ ~~~ - Since 4.0.0 -DOC + DOC ) do |_args| Puppet::Parser::Functions::Error.is4x('with') end diff --git a/lib/puppet/pops/evaluator/access_operator.rb b/lib/puppet/pops/evaluator/access_operator.rb index 0acaa634a71..711d32f7f5e 100644 --- a/lib/puppet/pops/evaluator/access_operator.rb +++ b/lib/puppet/pops/evaluator/access_operator.rb @@ -43,36 +43,36 @@ def access_Binary(o, scope, keys) def access_String(o, scope, keys) keys.flatten! result = case keys.size - when 0 - fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size}) - when 1 - # Note that Ruby 1.8.7 requires a length of 1 to produce a String - k1 = Utils.to_n(keys[0]) - bad_string_access_key_type(o, 0, k1.nil? ? keys[0] : k1) unless k1.is_a?(Integer) - k2 = 1 - k1 = k1 < 0 ? o.length + k1 : k1 # abs pos - # if k1 is outside, a length of 1 always produces an empty string - if k1 < 0 - EMPTY_STRING - else - o[ k1, k2 ] - end - when 2 - k1 = Utils.to_n(keys[0]) - k2 = Utils.to_n(keys[1]) - [k1, k2].each_with_index { |k,i| bad_string_access_key_type(o, i, k.nil? ? keys[i] : k) unless k.is_a?(Integer) } - - k1 = k1 < 0 ? o.length + k1 : k1 # abs pos (negative is count from end) - k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count) - # if k1 is outside, adjust to first position, and adjust length - if k1 < 0 - k2 = k2 + k1 - k1 = 0 - end - o[ k1, k2 ] - else - fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size}) - end + when 0 + fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size}) + when 1 + # Note that Ruby 1.8.7 requires a length of 1 to produce a String + k1 = Utils.to_n(keys[0]) + bad_string_access_key_type(o, 0, k1.nil? ? keys[0] : k1) unless k1.is_a?(Integer) + k2 = 1 + k1 = k1 < 0 ? o.length + k1 : k1 # abs pos + # if k1 is outside, a length of 1 always produces an empty string + if k1 < 0 + EMPTY_STRING + else + o[ k1, k2 ] + end + when 2 + k1 = Utils.to_n(keys[0]) + k2 = Utils.to_n(keys[1]) + [k1, k2].each_with_index { |k,i| bad_string_access_key_type(o, i, k.nil? ? keys[i] : k) unless k.is_a?(Integer) } + + k1 = k1 < 0 ? o.length + k1 : k1 # abs pos (negative is count from end) + k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count) + # if k1 is outside, adjust to first position, and adjust length + if k1 < 0 + k2 = k2 + k1 + k1 = 0 + end + o[ k1, k2 ] + else + fail(Issues::BAD_STRING_SLICE_ARITY, @semantic.left_expr, {:actual => keys.size}) + end # Specified as: an index outside of range, or empty result == empty string (result.nil? || result.empty?) ? EMPTY_STRING : result end @@ -592,15 +592,15 @@ def access_PResourceType(o, scope, keys) # type_name is LHS type_name if set, else the first given arg type_name = o.type_name || Types::TypeFormatter.singleton.capitalize_segments(keys.shift) type_name = case type_name - when Types::PResourceType - type_name.type_name - when String - type_name - else - # blame given left expression if it defined the type, else the first given key expression - blame = o.type_name.nil? ? @semantic.keys[0] : @semantic.left_expr - fail(Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => bad_key_type_name(type_name)}) - end + when Types::PResourceType + type_name.type_name + when String + type_name + else + # blame given left expression if it defined the type, else the first given key expression + blame = o.type_name.nil? ? @semantic.keys[0] : @semantic.left_expr + fail(Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => bad_key_type_name(type_name)}) + end # type name must conform if type_name !~ Patterns::CLASSREF_EXT diff --git a/lib/puppet/pops/evaluator/collector_transformer.rb b/lib/puppet/pops/evaluator/collector_transformer.rb index 695bbde4a3e..65994331d01 100644 --- a/lib/puppet/pops/evaluator/collector_transformer.rb +++ b/lib/puppet/pops/evaluator/collector_transformer.rb @@ -50,7 +50,7 @@ def transform(o, scope) newcoll end -protected + protected def query(o, scope) @@query_visitor.visit_this_1(self, o, scope) diff --git a/lib/puppet/pops/evaluator/evaluator_impl.rb b/lib/puppet/pops/evaluator/evaluator_impl.rb index 3806d70826d..ff563c16597 100644 --- a/lib/puppet/pops/evaluator/evaluator_impl.rb +++ b/lib/puppet/pops/evaluator/evaluator_impl.rb @@ -766,45 +766,45 @@ def eval_ResourceExpression(o, scope) # Get the type name type_name = - if (tmp_name = o.type_name).is_a?(Model::QualifiedName) - tmp_name.value # already validated as a name - else - type_name_acceptable = - case o.type_name - when Model::QualifiedReference - true - when Model::AccessExpression - o.type_name.left_expr.is_a?(Model::QualifiedReference) - end - - evaluated_name = evaluate(tmp_name, scope) - unless type_name_acceptable - actual = type_calculator.generalize(type_calculator.infer(evaluated_name)).to_s - fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual => actual}) - end + if (tmp_name = o.type_name).is_a?(Model::QualifiedName) + tmp_name.value # already validated as a name + else + type_name_acceptable = + case o.type_name + when Model::QualifiedReference + true + when Model::AccessExpression + o.type_name.left_expr.is_a?(Model::QualifiedReference) + end - # must be a CatalogEntry subtype - case evaluated_name - when Types::PClassType - unless evaluated_name.class_name.nil? - fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual=> evaluated_name.to_s}) + evaluated_name = evaluate(tmp_name, scope) + unless type_name_acceptable + actual = type_calculator.generalize(type_calculator.infer(evaluated_name)).to_s + fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual => actual}) end - 'class' - when Types::PResourceType - unless evaluated_name.title().nil? - fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual=> evaluated_name.to_s}) - end - evaluated_name.type_name # assume validated + # must be a CatalogEntry subtype + case evaluated_name + when Types::PClassType + unless evaluated_name.class_name.nil? + fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual=> evaluated_name.to_s}) + end + 'class' + + when Types::PResourceType + unless evaluated_name.title().nil? + fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual=> evaluated_name.to_s}) + end + evaluated_name.type_name # assume validated - when Types::PTypeReferenceType - fail(Issues::UNKNOWN_RESOURCE_TYPE, o.type_string, {:type_name => evaluated_name.to_s}) + when Types::PTypeReferenceType + fail(Issues::UNKNOWN_RESOURCE_TYPE, o.type_string, {:type_name => evaluated_name.to_s}) - else - actual = type_calculator.generalize(type_calculator.infer(evaluated_name)).to_s - fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual=>actual}) + else + actual = type_calculator.generalize(type_calculator.infer(evaluated_name)).to_s + fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_name, {:actual=>actual}) + end end - end # This is a runtime check - the model is valid, but will have runtime issues when evaluated # and storeconfigs is not set. @@ -919,12 +919,12 @@ def eval_AttributesOperation(o, scope) def eval_ResourceDefaultsExpression(o, scope) type = evaluate(o.type_ref, scope) type_name = - if type.is_a?(Types::PResourceType) && !type.type_name.nil? && type.title.nil? - type.type_name # assume it is a valid name - else - actual = type_calculator.generalize(type_calculator.infer(type)) - fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_ref, {:actual => actual}) - end + if type.is_a?(Types::PResourceType) && !type.type_name.nil? && type.title.nil? + type.type_name # assume it is a valid name + else + actual = type_calculator.generalize(type_calculator.infer(type)) + fail(Issues::ILLEGAL_RESOURCE_TYPE, o.type_ref, {:actual => actual}) + end evaluated_parameters = o.operations.map {|op| evaluate(op, scope) } create_resource_defaults(o, scope, type_name, evaluated_parameters) # Produce the type @@ -1208,31 +1208,30 @@ def concatenate(x, y) case x when Array y = case y - when Array then y - when Hash then y.to_a - else - [y] - end + when Array then y + when Hash then y.to_a + else [y] + end x + y # new array with concatenation when Hash y = case y - when Hash then y - when Array - # Hash[[a, 1, b, 2]] => {} - # Hash[a,1,b,2] => {a => 1, b => 2} - # Hash[[a,1], [b,2]] => {[a,1] => [b,2]} - # Hash[[[a,1], [b,2]]] => {a => 1, b => 2} - # Use type calculator to determine if array is Array[Array[?]], and if so use second form - # of call - t = @@type_calculator.infer(y) - if t.element_type.is_a? Types::PArrayType - Hash[y] - else - Hash[*y] - end - else - raise ArgumentError.new(_('Can only append Array or Hash to a Hash')) - end + when Hash then y + when Array + # Hash[[a, 1, b, 2]] => {} + # Hash[a,1,b,2] => {a => 1, b => 2} + # Hash[[a,1], [b,2]] => {[a,1] => [b,2]} + # Hash[[[a,1], [b,2]]] => {a => 1, b => 2} + # Use type calculator to determine if array is Array[Array[?]], and if so use second form + # of call + t = @@type_calculator.infer(y) + if t.element_type.is_a? Types::PArrayType + Hash[y] + else + Hash[*y] + end + else + raise ArgumentError.new(_('Can only append Array or Hash to a Hash')) + end x.merge y # new hash with overwrite when URI raise ArgumentError.new(_('An URI can only be merged with an URI or String')) unless y.is_a?(String) || y.is_a?(URI) @@ -1256,16 +1255,16 @@ def delete(x, y) case x when Array y = case y - when Array then y - when Hash then y.to_a + when Array then y + when Hash then y.to_a else [y] end y.each {|e| result.delete(e) } when Hash y = case y - when Array then y - when Hash then y.keys + when Array then y + when Hash then y.keys else [y] end diff --git a/lib/puppet/pops/evaluator/runtime3_converter.rb b/lib/puppet/pops/evaluator/runtime3_converter.rb index 2686417b364..18b8b560943 100644 --- a/lib/puppet/pops/evaluator/runtime3_converter.rb +++ b/lib/puppet/pops/evaluator/runtime3_converter.rb @@ -133,23 +133,23 @@ def convert_PCatalogEntryType(o, scope, undef_value) def catalog_type_to_split_type_title(catalog_type) split_type = catalog_type.is_a?(Puppet::Pops::Types::PTypeType) ? catalog_type.type : catalog_type case split_type - when Puppet::Pops::Types::PClassType - class_name = split_type.class_name - ['class', class_name.nil? ? nil : class_name.sub(/^::/, '')] - when Puppet::Pops::Types::PResourceType - type_name = split_type.type_name - title = split_type.title - if type_name =~ /^(::)?[Cc]lass$/ - ['class', title.nil? ? nil : title.sub(/^::/, '')] - else - # Ensure that title is '' if nil - # Resources with absolute name always results in error because tagging does not support leading :: - [type_name.nil? ? nil : type_name.sub(/^::/, '').downcase, title.nil? ? '' : title] - end + when Puppet::Pops::Types::PClassType + class_name = split_type.class_name + ['class', class_name.nil? ? nil : class_name.sub(/^::/, '')] + when Puppet::Pops::Types::PResourceType + type_name = split_type.type_name + title = split_type.title + if type_name =~ /^(::)?[Cc]lass$/ + ['class', title.nil? ? nil : title.sub(/^::/, '')] else - #TRANSLATORS 'PClassType' and 'PResourceType' are Puppet types and should not be translated - raise ArgumentError, _("Cannot split the type %{class_name}, it represents neither a PClassType, nor a PResourceType.") % - { class_name: catalog_type.class } + # Ensure that title is '' if nil + # Resources with absolute name always results in error because tagging does not support leading :: + [type_name.nil? ? nil : type_name.sub(/^::/, '').downcase, title.nil? ? '' : title] + end + else + #TRANSLATORS 'PClassType' and 'PResourceType' are Puppet types and should not be translated + raise ArgumentError, _("Cannot split the type %{class_name}, it represents neither a PClassType, nor a PResourceType.") % + { class_name: catalog_type.class } end end diff --git a/lib/puppet/pops/lookup/explainer.rb b/lib/puppet/pops/lookup/explainer.rb index 62bd46fbf57..bacbb2b5e04 100644 --- a/lib/puppet/pops/lookup/explainer.rb +++ b/lib/puppet/pops/lookup/explainer.rb @@ -469,32 +469,32 @@ def initialize(explain_options = false, only_explain_options = false) def push(qualifier_type, qualifier) node = case (qualifier_type) - when :global - ExplainGlobal.new(@current, qualifier) - when :location - ExplainLocation.new(@current, qualifier) - when :interpolate - ExplainInterpolate.new(@current, qualifier) - when :data_provider - ExplainDataProvider.new(@current, qualifier) - when :merge - ExplainMerge.new(@current, qualifier) - when :module - ExplainModule.new(@current, qualifier) - when :scope - ExplainScope.new(@current, qualifier) - when :sub_lookup - ExplainSubLookup.new(@current, qualifier) - when :segment - ExplainKeySegment.new(@current, qualifier) - when :meta, :data - ExplainTop.new(@current, qualifier_type, qualifier) - when :invalid_key - ExplainInvalidKey.new(@current, qualifier) - else - #TRANSLATORS 'Explain' is referring to the 'Explainer' class and should not be translated - raise ArgumentError, _("Unknown Explain type %{qualifier_type}") % { qualifier_type: qualifier_type } - end + when :global + ExplainGlobal.new(@current, qualifier) + when :location + ExplainLocation.new(@current, qualifier) + when :interpolate + ExplainInterpolate.new(@current, qualifier) + when :data_provider + ExplainDataProvider.new(@current, qualifier) + when :merge + ExplainMerge.new(@current, qualifier) + when :module + ExplainModule.new(@current, qualifier) + when :scope + ExplainScope.new(@current, qualifier) + when :sub_lookup + ExplainSubLookup.new(@current, qualifier) + when :segment + ExplainKeySegment.new(@current, qualifier) + when :meta, :data + ExplainTop.new(@current, qualifier_type, qualifier) + when :invalid_key + ExplainInvalidKey.new(@current, qualifier) + else + #TRANSLATORS 'Explain' is referring to the 'Explainer' class and should not be translated + raise ArgumentError, _("Unknown Explain type %{qualifier_type}") % { qualifier_type: qualifier_type } + end @current.branches << node @current = node end diff --git a/lib/puppet/pops/lookup/hiera_config.rb b/lib/puppet/pops/lookup/hiera_config.rb index 4bc89875bc7..dfe92b09633 100644 --- a/lib/puppet/pops/lookup/hiera_config.rb +++ b/lib/puppet/pops/lookup/hiera_config.rb @@ -405,16 +405,24 @@ def create_configured_data_providers(lookup_invocation, parent_data_provider, _) ext = ".#{ext}" end paths = resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, ext) - data_providers[backend] = case - when backend == 'json', backend == 'yaml' - create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, "#{backend}_data", { KEY_DATADIR => datadir }, paths) - when backend == 'hocon' && Puppet.features.hocon? - create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, 'hocon_data', { KEY_DATADIR => datadir }, paths) - when backend == 'eyaml' && Puppet.features.hiera_eyaml? - create_data_provider(backend, parent_data_provider, KEY_V3_LOOKUP_KEY, 'eyaml_lookup_key', backend_config.merge(KEY_DATADIR => datadir), paths) - else - create_hiera3_backend_provider(backend, backend, parent_data_provider, datadir, paths, @loaded_config) - end + data_providers[backend] = + if %w[json yaml].include? backend + create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, + "#{backend}_data", { KEY_DATADIR => datadir }, + paths) + elsif backend == 'hocon' && Puppet.features.hocon? + create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, + 'hocon_data', { KEY_DATADIR => datadir }, paths) + elsif backend == 'eyaml' && Puppet.features.hiera_eyaml? + create_data_provider(backend, parent_data_provider, + KEY_V3_LOOKUP_KEY, 'eyaml_lookup_key', + backend_config.merge(KEY_DATADIR => datadir), + paths) + else + create_hiera3_backend_provider(backend, backend, + parent_data_provider, datadir, paths, + @loaded_config) + end end data_providers.values end @@ -511,16 +519,28 @@ def create_configured_data_providers(lookup_invocation, parent_data_provider, _) original_paths = he[KEY_PATHS] || [he[KEY_PATH] || name] datadir = @config_root + (he[KEY_DATADIR] || default_datadir) provider_name = he[KEY_BACKEND] - data_providers[name] = case - when provider_name == 'json', provider_name == 'yaml' - create_data_provider(name, parent_data_provider, KEY_DATA_HASH, "#{provider_name}_data", {}, - resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, ".#{provider_name}")) - when provider_name == 'hocon' && Puppet.features.hocon? - create_data_provider(name, parent_data_provider, KEY_DATA_HASH, 'hocon_data', {}, - resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, '.conf')) - else - fail(Issues::HIERA_NO_PROVIDER_FOR_BACKEND, { :name => provider_name }, find_line_matching(/[^\w]#{provider_name}(?:[^\w]|$)/)) - end + data_providers[name] = + if %w[json yaml].include?(provider_name) + create_data_provider(name, parent_data_provider, KEY_DATA_HASH, + "#{provider_name}_data", {}, + resolve_paths(datadir, + original_paths, + lookup_invocation, + @config_path.nil?, + ".#{provider_name}")) + elsif provider_name == 'hocon' && Puppet.features.hocon? + create_data_provider(name, parent_data_provider, KEY_DATA_HASH, + 'hocon_data', {}, + resolve_paths(datadir, + original_paths, + lookup_invocation, + @config_path.nil?, + '.conf')) + else + fail(Issues::HIERA_NO_PROVIDER_FOR_BACKEND, + { :name => provider_name }, + find_line_matching(/[^\w]#{provider_name}(?:[^\w]|$)/)) + end end data_providers.values end diff --git a/lib/puppet/pops/model/model_tree_dumper.rb b/lib/puppet/pops/model/model_tree_dumper.rb index bfc807515ec..cdb2dd54b3d 100644 --- a/lib/puppet/pops/model/model_tree_dumper.rb +++ b/lib/puppet/pops/model/model_tree_dumper.rb @@ -319,21 +319,21 @@ def dump_Program(o) def dump_IfExpression o result = ["if", do_dump(o.test), :indent, :break, - ["then", :indent, do_dump(o.then_expr), :dedent]] + ["then", :indent, do_dump(o.then_expr), :dedent]] result += - [:break, - ["else", :indent, do_dump(o.else_expr), :dedent], - :dedent] unless is_nop? o.else_expr + [:break, + ["else", :indent, do_dump(o.else_expr), :dedent], + :dedent] unless is_nop? o.else_expr result end def dump_UnlessExpression o result = ["unless", do_dump(o.test), :indent, :break, - ["then", :indent, do_dump(o.then_expr), :dedent]] + ["then", :indent, do_dump(o.then_expr), :dedent]] result += - [:break, - ["else", :indent, do_dump(o.else_expr), :dedent], - :dedent] unless is_nop? o.else_expr + [:break, + ["else", :indent, do_dump(o.else_expr), :dedent], + :dedent] unless is_nop? o.else_expr result end diff --git a/lib/puppet/pops/parser/heredoc_support.rb b/lib/puppet/pops/parser/heredoc_support.rb index 9077f786e77..ac93e2cbbeb 100644 --- a/lib/puppet/pops/parser/heredoc_support.rb +++ b/lib/puppet/pops/parser/heredoc_support.rb @@ -106,10 +106,10 @@ def heredoc # Emit a token that provides the grammar with location information about the lines on which the heredoc # content is based. enqueue([:SUBLOCATE, - LexerSupport::TokenValue.new([:SUBLOCATE, - lines, lines.reduce(0) {|size, s| size + s.length} ], - heredoc_offset, - locator)]) + LexerSupport::TokenValue.new([:SUBLOCATE, + lines, lines.reduce(0) {|size, s| size + s.length} ], + heredoc_offset, + locator)]) sublexer.lex_unquoted_string(str, locator, resulting_escapes, dqstring_style) sublexer.interpolate_uq_to(self) diff --git a/lib/puppet/pops/parser/lexer2.rb b/lib/puppet/pops/parser/lexer2.rb index f0ec9d42620..a48d1bdea65 100644 --- a/lib/puppet/pops/parser/lexer2.rb +++ b/lib/puppet/pops/parser/lexer2.rb @@ -524,7 +524,7 @@ def initialize() end end ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '_'].each do |c| + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '_'].each do |c| @selector[c] = lambda do scn = @scanner before = scn.pos @@ -547,7 +547,7 @@ def initialize() end ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'].each do |c| + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'].each do |c| @selector[c] = lambda do scn = @scanner before = scn.pos diff --git a/lib/puppet/pops/parser/lexer_support.rb b/lib/puppet/pops/parser/lexer_support.rb index 8465d28d36f..0a2a89275f1 100644 --- a/lib/puppet/pops/parser/lexer_support.rb +++ b/lib/puppet/pops/parser/lexer_support.rb @@ -167,35 +167,35 @@ def to_s def assert_not_bom(content) name, size = - case bom = get_bom(content) + case bom = get_bom(content) - when BOM_UTF_32_1, BOM_UTF_32_2 - ['UTF-32', 4] + when BOM_UTF_32_1, BOM_UTF_32_2 + ['UTF-32', 4] - when BOM_GB_18030 - ['GB-18030', 4] + when BOM_GB_18030 + ['GB-18030', 4] - when BOM_UTF_EBCDIC - ['UTF-EBCDIC', 4] + when BOM_UTF_EBCDIC + ['UTF-EBCDIC', 4] - when BOM_SCSU - ['SCSU', 3] + when BOM_SCSU + ['SCSU', 3] - when BOM_UTF_8 - ['UTF-8', 3] + when BOM_UTF_8 + ['UTF-8', 3] - when BOM_UTF_1 - ['UTF-1', 3] + when BOM_UTF_1 + ['UTF-1', 3] - when BOM_BOCU - ['BOCU', 3] + when BOM_BOCU + ['BOCU', 3] - when BOM_UTF_16_1, BOM_UTF_16_2 - ['UTF-16', 2] + when BOM_UTF_16_1, BOM_UTF_16_2 + ['UTF-16', 2] - else - return - end + else + return + end lex_error_without_pos( Puppet::Pops::Issues::ILLEGAL_BOM, diff --git a/lib/puppet/pops/types/string_converter.rb b/lib/puppet/pops/types/string_converter.rb index c2293929d5e..efd510b2f62 100644 --- a/lib/puppet/pops/types/string_converter.rb +++ b/lib/puppet/pops/types/string_converter.rb @@ -619,36 +619,37 @@ def string_PAnyType(val_type, val, format_map, _) def string_PDefaultType(val_type, val, format_map, _) f = get_format(val_type, format_map) apply_string_flags(f, case f.format - when :d, :s, :p - f.alt? ? '"default"' : 'default' - when :D - f.alt? ? '"Default"' : 'Default' - else - raise FormatError.new('Default', f.format, 'dDsp') - end) + when :d, :s, :p + f.alt? ? '"default"' : 'default' + when :D + f.alt? ? '"Default"' : 'Default' + else + raise FormatError.new('Default', f.format, 'dDsp') + end) end # @api private def string_PUndefType(val_type, val, format_map, _) f = get_format(val_type, format_map) apply_string_flags(f, case f.format - when :n - f.alt? ? 'null' : 'nil' - when :u - f.alt? ? 'undefined' : 'undef' - when :d, :x, :X, :o, :b, :B, :e, :E, :f, :g, :G, :a, :A - 'NaN' - when :v - 'n/a' - when :V - 'N/A' - when :s - f.alt? ? '""' : '' - when :p - f.alt? ? '"undef"' : 'undef' - else - raise FormatError.new('Undef', f.format, 'nudxXobBeEfgGaAvVsp') - end) + when :n + f.alt? ? 'null' : 'nil' + when :u + f.alt? ? 'undefined' : 'undef' + when :d, :x, :X, :o, :b, :B, :e, :E, :f, :g, :G, :a, :A + 'NaN' + when :v + 'n/a' + when :V + 'N/A' + when :s + f.alt? ? '""' : '' + when :p + f.alt? ? '"undef"' : 'undef' + else + raise FormatError.new('Undef', f.format, + 'nudxXobBeEfgGaAvVsp') + end) end # @api private diff --git a/lib/puppet/pops/types/type_parser.rb b/lib/puppet/pops/types/type_parser.rb index 0d4ffe90cd2..0eead75b528 100644 --- a/lib/puppet/pops/types/type_parser.rb +++ b/lib/puppet/pops/types/type_parser.rb @@ -371,20 +371,21 @@ def interpret_AccessExpression(ast, context) when 'collection' size_type = case parameters.size - when 1 - if parameters[0].is_a?(PIntegerType) - parameters[0] - else - assert_range_parameter(ast, parameters[0]) - TypeFactory.range(parameters[0], :default) - end - when 2 - assert_range_parameter(ast, parameters[0]) - assert_range_parameter(ast, parameters[1]) - TypeFactory.range(parameters[0], parameters[1]) - else - raise_invalid_parameters_error('Collection', '1 to 2', parameters.size) - end + when 1 + if parameters[0].is_a?(PIntegerType) + parameters[0] + else + assert_range_parameter(ast, parameters[0]) + TypeFactory.range(parameters[0], :default) + end + when 2 + assert_range_parameter(ast, parameters[0]) + assert_range_parameter(ast, parameters[1]) + TypeFactory.range(parameters[0], parameters[1]) + else + raise_invalid_parameters_error('Collection', '1 to 2', + parameters.size) + end TypeFactory.collection(size_type) when 'class' @@ -541,21 +542,21 @@ def interpret_AccessExpression(ast, context) when 'string' size_type = - case parameters.size - when 1 - if parameters[0].is_a?(PIntegerType) - parameters[0] - else + case parameters.size + when 1 + if parameters[0].is_a?(PIntegerType) + parameters[0] + else + assert_range_parameter(ast, parameters[0]) + TypeFactory.range(parameters[0], :default) + end + when 2 assert_range_parameter(ast, parameters[0]) - TypeFactory.range(parameters[0], :default) + assert_range_parameter(ast, parameters[1]) + TypeFactory.range(parameters[0], parameters[1]) + else + raise_invalid_parameters_error('String', '1 to 2', parameters.size) end - when 2 - assert_range_parameter(ast, parameters[0]) - assert_range_parameter(ast, parameters[1]) - TypeFactory.range(parameters[0], parameters[1]) - else - raise_invalid_parameters_error('String', '1 to 2', parameters.size) - end TypeFactory.string(size_type) when 'sensitive' diff --git a/lib/puppet/pops/types/types.rb b/lib/puppet/pops/types/types.rb index af029e28cf2..780775c4e2e 100644 --- a/lib/puppet/pops/types/types.rb +++ b/lib/puppet/pops/types/types.rb @@ -828,13 +828,13 @@ def _assignable?(o, guard) return true if o.is_a?(PStringType) || o.is_a?(PEnumType) || o.is_a?(PPatternType) end case o - when PStringType - # if the contained string is found in the set of enums - instance?(o.value, guard) - when PEnumType - !o.values.empty? && (case_insensitive? || !o.case_insensitive?) && o.values.all? { |s| instance?(s, guard) } - else - false + when PStringType + # if the contained string is found in the set of enums + instance?(o.value, guard) + when PEnumType + !o.values.empty? && (case_insensitive? || !o.case_insensitive?) && o.values.all? { |s| instance?(s, guard) } + else + false end end end @@ -1379,22 +1379,22 @@ def eql?(o) # def _assignable?(o, guard) case o - when PCollectionType - (@size_type || DEFAULT_SIZE).assignable?(o.size_type || DEFAULT_SIZE, guard) - when PTupleType - # compute the tuple's min/max size, and check if that size matches - size_s = size_type || DEFAULT_SIZE - size_o = o.size_type - if size_o.nil? - type_count = o.types.size - size_o = PIntegerType.new(type_count, type_count) - end - size_s.assignable?(size_o) - when PStructType - from = to = o.elements.size - (@size_type || DEFAULT_SIZE).assignable?(PIntegerType.new(from, to), guard) - else - false + when PCollectionType + (@size_type || DEFAULT_SIZE).assignable?(o.size_type || DEFAULT_SIZE, guard) + when PTupleType + # compute the tuple's min/max size, and check if that size matches + size_s = size_type || DEFAULT_SIZE + size_o = o.size_type + if size_o.nil? + type_count = o.types.size + size_o = PIntegerType.new(type_count, type_count) + end + size_s.assignable?(size_o) + when PStructType + from = to = o.elements.size + (@size_type || DEFAULT_SIZE).assignable?(PIntegerType.new(from, to), guard) + else + false end end end diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb index c684b7d837d..fcaaf103d0e 100644 --- a/lib/puppet/property.rb +++ b/lib/puppet/property.rb @@ -231,11 +231,10 @@ def event_name name == :ensure or return (name.to_s + "_changed").to_sym return (resource.type.to_s + case value - when :present; "_created" - when :absent; "_removed" - else - "_changed" - end).to_sym + when :present; "_created" + when :absent; "_removed" + else "_changed" + end).to_sym end # Produces an event describing a change of this property. diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index fb2aa834a87..0ed8f664076 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -273,12 +273,7 @@ def self.default_match def self.some_default_match(defaultlist) defaultlist.find do |default| default.all? do |key, values| - case key - when :feature - feature_match(values) - else - fact_match(key, values) - end + key == :feature ? feature_match(values) : fact_match(key, values) end end end diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index 89ee70b3c35..da24f3aa049 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -118,19 +118,19 @@ def self.generate_attribute_hash(input_hash, *type_properties) next unless (ds_to_ns_attribute_map.keys.include?(ds_attribute) and type_properties.include? ds_to_ns_attribute_map[ds_attribute]) ds_value = input_hash[key] case ds_to_ns_attribute_map[ds_attribute] - when :members - # do nothing, only members uses arrays so far - when :gid, :uid - # OS X stores objects like uid/gid as strings. - # Try casting to an integer for these cases to be - # consistent with the other providers and the group type - # validation - begin - ds_value = Integer(ds_value[0]) - rescue ArgumentError - ds_value = ds_value[0] - end - else ds_value = ds_value[0] + when :members + # do nothing, only members uses arrays so far + when :gid, :uid + # OS X stores objects like uid/gid as strings. + # Try casting to an integer for these cases to be + # consistent with the other providers and the group type + # validation + begin + ds_value = Integer(ds_value[0]) + rescue ArgumentError + ds_value = ds_value[0] + end + else ds_value = ds_value[0] end attribute_hash[ds_to_ns_attribute_map[ds_attribute]] = ds_value end diff --git a/lib/puppet/provider/package.rb b/lib/puppet/provider/package.rb index be338f0ca2f..05ad6e0fb15 100644 --- a/lib/puppet/provider/package.rb +++ b/lib/puppet/provider/package.rb @@ -48,12 +48,12 @@ def join_options(options) options.collect do |val| case val - when Hash - val.keys.sort.collect do |k| - "#{k}=#{val[k]}" - end - else - val + when Hash + val.keys.sort.collect do |k| + "#{k}=#{val[k]}" + end + else + val end end.flatten end diff --git a/lib/puppet/provider/package/dnfmodule.rb b/lib/puppet/provider/package/dnfmodule.rb index d6e00393859..8647293c11f 100644 --- a/lib/puppet/provider/package/dnfmodule.rb +++ b/lib/puppet/provider/package/dnfmodule.rb @@ -64,7 +64,7 @@ def self.instances def query pkg = self.class.instances.find do |package| @resource[:name] == package.name - end + end pkg ? pkg.properties : nil end diff --git a/lib/puppet/provider/package/nim.rb b/lib/puppet/provider/package/nim.rb index 6fd5cf6f7dc..b4f0965233a 100644 --- a/lib/puppet/provider/package/nim.rb +++ b/lib/puppet/provider/package/nim.rb @@ -249,12 +249,12 @@ def parse_showres_package_line(line) package_string = match.captures[1] case package_type_flag - when "I","S" - parse_installp_package_string(package_string) - when "R" - parse_rpm_package_string(package_string) - else - self.fail _("Unrecognized package type specifier: '%{package_type_flag}' in package line:\n'%{line}'") % { package_type_flag: package_type_flag, line: line } + when "I","S" + parse_installp_package_string(package_string) + when "R" + parse_rpm_package_string(package_string) + else + self.fail _("Unrecognized package type specifier: '%{package_type_flag}' in package line:\n'%{line}'") % { package_type_flag: package_type_flag, line: line } end end diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb index ec5ad627bdf..2c1237d9ec4 100644 --- a/lib/puppet/provider/package/pacman.rb +++ b/lib/puppet/provider/package/pacman.rb @@ -232,15 +232,15 @@ def install_from_file end source = case source_uri.scheme - when nil then source - when /https?/i then source - when /ftp/i then source - when /file/i then source_uri.path - when /puppet/i - fail _("puppet:// URL is not supported by pacman") - else - fail _("Source %{source} is not supported by pacman") % { source: source } - end + when nil then source + when /https?/i then source + when /ftp/i then source + when /file/i then source_uri.path + when /puppet/i + fail _("puppet:// URL is not supported by pacman") + else + fail _("Source %{source} is not supported by pacman") % { source: source } + end pacman "--noconfirm", "--noprogressbar", "-S" pacman "--noconfirm", "--noprogressbar", "-U", source end diff --git a/lib/puppet/provider/package/pkg.rb b/lib/puppet/provider/package/pkg.rb index 346f3640a34..f4c8f0753af 100644 --- a/lib/puppet/provider/package/pkg.rb +++ b/lib/puppet/provider/package/pkg.rb @@ -100,19 +100,19 @@ def self.pkg_state(state) # formats of output for different pkg versions. def self.parse_line(line) (case line.chomp - # FMRI IFO - # pkg://omnios/SUNWcs@0.5.11,5.11-0.151008:20131204T022241Z --- - when %r'^pkg://([^/]+)/([^@]+)@(\S+) +(...)$' - {:publisher => $1, :name => $2, :ensure => $3}.merge ifo_flag($4) - - # FMRI STATE UFOXI - # pkg://solaris/SUNWcs@0.5.11,5.11-0.151.0.1:20101105T001108Z installed u---- - when %r'^pkg://([^/]+)/([^@]+)@(\S+) +(\S+) +(.....)$' - {:publisher => $1, :name => $2, :ensure => $3}.merge pkg_state($4).merge(ufoxi_flag($5)) - - else - raise ArgumentError, _('Unknown line format %{resource_name}: %{parse_line}') % { resource_name: self.name, parse_line: line } - end).merge({:provider => self.name}) + # FMRI IFO + # pkg://omnios/SUNWcs@0.5.11,5.11-0.151008:20131204T022241Z --- + when %r'^pkg://([^/]+)/([^@]+)@(\S+) +(...)$' + {:publisher => $1, :name => $2, :ensure => $3}.merge ifo_flag($4) + + # FMRI STATE UFOXI + # pkg://solaris/SUNWcs@0.5.11,5.11-0.151.0.1:20101105T001108Z installed u---- + when %r'^pkg://([^/]+)/([^@]+)@(\S+) +(\S+) +(.....)$' + {:publisher => $1, :name => $2, :ensure => $3}.merge pkg_state($4).merge(ufoxi_flag($5)) + + else + raise ArgumentError, _('Unknown line format %{resource_name}: %{parse_line}') % { resource_name: self.name, parse_line: line } + end).merge({:provider => self.name}) end def hold diff --git a/lib/puppet/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb index 9ed6401ee7e..024811514de 100644 --- a/lib/puppet/provider/package/portage.rb +++ b/lib/puppet/provider/package/portage.rb @@ -222,12 +222,12 @@ def query end case packages.size - when 0 - raise Puppet::Error.new(_("No package found with the specified name [%{name}]") % { name: @resource[:name] }) - when 1 - @eix_result = packages[0] - else - raise Puppet::Error.new(_("More than one package with the specified name [%{search_value}], please use the category parameter to disambiguate") % { search_value: search_value }) + when 0 + raise Puppet::Error.new(_("No package found with the specified name [%{name}]") % { name: @resource[:name] }) + when 1 + @eix_result = packages[0] + else + raise Puppet::Error.new(_("More than one package with the specified name [%{search_value}], please use the category parameter to disambiguate") % { search_value: search_value }) end rescue Puppet::ExecutionFailure => detail raise Puppet::Error.new(detail) diff --git a/lib/puppet/provider/package/sun.rb b/lib/puppet/provider/package/sun.rb index f62fc2d3daa..77d38390970 100644 --- a/lib/puppet/provider/package/sun.rb +++ b/lib/puppet/provider/package/sun.rb @@ -69,11 +69,11 @@ def info2hash(device = nil) begin pkgs = self.class.parse_pkginfo(pkginfo(*args)) errmsg = case pkgs.size - when 0 - 'No message' - when 1 - pkgs[0]['ERROR'] - end + when 0 + 'No message' + when 1 + pkgs[0]['ERROR'] + end return self.class.namemap(pkgs[0]) if errmsg.nil? # according to commit 41356a7 some errors do not raise an exception # so even though pkginfo passed, we have to check the actual output diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index 67579beee1a..004a6cf17b0 100644 --- a/lib/puppet/provider/service/init.rb +++ b/lib/puppet/provider/service/init.rb @@ -54,9 +54,9 @@ def self.excludes # Prevent puppet failing on unsafe scripts from Yocto Linux if Puppet.runtime[:facter].value('os.family') == "cisco-wrlinux" excludes += %w{banner.sh bootmisc.sh checkroot.sh devpts.sh dmesg.sh - hostname.sh mountall.sh mountnfs.sh populate-volatile.sh - rmnologin.sh save-rtc.sh sendsigs sysfs.sh umountfs - umountnfs.sh} + hostname.sh mountall.sh mountnfs.sh populate-volatile.sh + rmnologin.sh save-rtc.sh sendsigs sysfs.sh umountfs + umountnfs.sh} end # Prevent puppet failing to get status of the new service introduced # by the fix for this (bug https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/982889) @@ -183,7 +183,7 @@ def statuscmd (@resource[:hasstatus] == :true) && [initscript, :status] end -private + private def self.is_init?(script = initscript) file = Puppet::FileSystem.pathname(script) diff --git a/lib/puppet/provider/service/src.rb b/lib/puppet/provider/service/src.rb index ca9465c144a..ff6dc45012c 100644 --- a/lib/puppet/provider/service/src.rb +++ b/lib/puppet/provider/service/src.rb @@ -101,10 +101,10 @@ def restart # While subsystems with -S (signals) must be stopped/started method = args[11] do_refresh = case method - when "-K" then :true - when "-S" then :false - else self.fail("Unknown service communication method #{method}") - end + when "-K" then :true + when "-S" then :false + else self.fail("Unknown service communication method #{method}") + end begin if do_refresh == :true @@ -133,9 +133,9 @@ def status # PID is the 3rd field, but inoperative subsystems # skip this so split doesn't work right state = case args[-1] - when "active" then :running - when "inoperative" then :stopped - end + when "active" then :running + when "inoperative" then :stopped + end Puppet.debug("Service #{@resource[:name]} is #{args[-1]}") return state end diff --git a/lib/puppet/provider/service/upstart.rb b/lib/puppet/provider/service/upstart.rb index 42fca395fab..4cc88d276f1 100644 --- a/lib/puppet/provider/service/upstart.rb +++ b/lib/puppet/provider/service/upstart.rb @@ -192,7 +192,7 @@ def status end end -private + private def is_upstart?(script = initscript) Puppet::FileSystem.exist?(script) && script.match(/\/etc\/init\/\S+\.conf/) end diff --git a/lib/puppet/provider/service/windows.rb b/lib/puppet/provider/service/windows.rb index 4712dd4b0ba..c5cbd5a602a 100644 --- a/lib/puppet/provider/service/windows.rb +++ b/lib/puppet/provider/service/windows.rb @@ -47,18 +47,16 @@ def enabled? start_type = Puppet::Util::Windows::Service.service_start_type(@resource[:name]) debug("Service #{@resource[:name]} start type is #{start_type}") case start_type - when :SERVICE_AUTO_START, - :SERVICE_BOOT_START, - :SERVICE_SYSTEM_START - :true - when :SERVICE_DEMAND_START - :manual - when :SERVICE_DELAYED_AUTO_START - :delayed - when :SERVICE_DISABLED - :false - else - raise Puppet::Error.new(_("Unknown start type: %{start_type}") % { start_type: start_type }) + when :SERVICE_AUTO_START, :SERVICE_BOOT_START, :SERVICE_SYSTEM_START + :true + when :SERVICE_DEMAND_START + :manual + when :SERVICE_DELAYED_AUTO_START + :delayed + when :SERVICE_DISABLED + :false + else + raise Puppet::Error.new(_("Unknown start type: %{start_type}") % { start_type: start_type }) end rescue => detail raise Puppet::Error.new(_("Cannot get start type %{resource_name}, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail ) @@ -96,19 +94,15 @@ def status current_state = Puppet::Util::Windows::Service.service_state(@resource[:name]) state = case current_state - when :SERVICE_STOPPED, - :SERVICE_STOP_PENDING - :stopped - when :SERVICE_PAUSED, - :SERVICE_PAUSE_PENDING - :paused - when :SERVICE_RUNNING, - :SERVICE_CONTINUE_PENDING, - :SERVICE_START_PENDING - :running - else - raise Puppet::Error.new(_("Unknown service state '%{current_state}' for service '%{resource_name}'") % { current_state: current_state, resource_name: @resource[:name] }) - end + when :SERVICE_STOPPED, :SERVICE_STOP_PENDING + :stopped + when :SERVICE_PAUSED, :SERVICE_PAUSE_PENDING + :paused + when :SERVICE_RUNNING, :SERVICE_CONTINUE_PENDING, :SERVICE_START_PENDING + :running + else + raise Puppet::Error.new(_("Unknown service state '%{current_state}' for service '%{resource_name}'") % { current_state: current_state, resource_name: @resource[:name] }) + end debug("Service #{@resource[:name]} is #{current_state}") state rescue => detail diff --git a/lib/puppet/provider/user/directoryservice.rb b/lib/puppet/provider/user/directoryservice.rb index 12bf4b6f84e..6ac6947e8fc 100644 --- a/lib/puppet/provider/user/directoryservice.rb +++ b/lib/puppet/provider/user/directoryservice.rb @@ -107,17 +107,17 @@ def self.generate_attribute_hash(input_hash) next unless ds_to_ns_attribute_map.keys.include?(ds_attribute) ds_value = input_hash[key] case ds_to_ns_attribute_map[ds_attribute] - when :gid, :uid - # OS X stores objects like uid/gid as strings. - # Try casting to an integer for these cases to be - # consistent with the other providers and the group type - # validation - begin - ds_value = Integer(ds_value[0]) - rescue ArgumentError - ds_value = ds_value[0] - end - else ds_value = ds_value[0] + when :gid, :uid + # OS X stores objects like uid/gid as strings. + # Try casting to an integer for these cases to be + # consistent with the other providers and the group type + # validation + begin + ds_value = Integer(ds_value[0]) + rescue ArgumentError + ds_value = ds_value[0] + end + else ds_value = ds_value[0] end attribute_hash[ds_to_ns_attribute_map[ds_attribute]] = ds_value end diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index a017cf86c82..1c9397924aa 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -153,14 +153,14 @@ def merge(other) # values. def ensure_in_catalog(scope, parameters=nil) resource_type = - case type - when :definition - raise ArgumentError, _('Cannot create resources for defined resource types') - when :hostclass - :class - when :node - :node - end + case type + when :definition + raise ArgumentError, _('Cannot create resources for defined resource types') + when :hostclass + :class + when :node + :node + end # Do nothing if the resource already exists; this makes sure we don't # get multiple copies of the class resource, which helps provide the diff --git a/lib/puppet/settings.rb b/lib/puppet/settings.rb index da6eeab39ea..d0bf0da678f 100644 --- a/lib/puppet/settings.rb +++ b/lib/puppet/settings.rb @@ -1507,20 +1507,20 @@ def convert(value, setting_name) interpolated_value = value.gsub(/\$(\w+)|\$\{(\w+)\}/) do |expression| varname = $2 || $1 interpolated_expression = - if varname != ENVIRONMENT_SETTING || ok_to_interpolate_environment(setting_name) - if varname == ENVIRONMENT_SETTING && @environment - @environment - elsif varname == "run_mode" - @mode - elsif !(pval = interpolate(varname.to_sym)).nil? - pval + if varname != ENVIRONMENT_SETTING || ok_to_interpolate_environment(setting_name) + if varname == ENVIRONMENT_SETTING && @environment + @environment + elsif varname == "run_mode" + @mode + elsif !(pval = interpolate(varname.to_sym)).nil? + pval + else + raise InterpolationError, _("Could not find value for %{expression}") % { expression: expression } + end else - raise InterpolationError, _("Could not find value for %{expression}") % { expression: expression } + failed_environment_interpolation = true + expression end - else - failed_environment_interpolation = true - expression - end interpolated_expression end if failed_environment_interpolation diff --git a/lib/puppet/settings/config_file.rb b/lib/puppet/settings/config_file.rb index 4776d5e1841..51434b5a101 100644 --- a/lib/puppet/settings/config_file.rb +++ b/lib/puppet/settings/config_file.rb @@ -78,7 +78,7 @@ def has_metadata? Meta = Struct.new(:owner, :group, :mode) NO_META = Meta.new(nil, nil, nil) -private + private def unique_sections_in(ini, file, allowed_section_names) ini.section_lines.collect do |section| diff --git a/lib/puppet/settings/environment_conf.rb b/lib/puppet/settings/environment_conf.rb index 9e387c1cebf..d4461ce14a9 100644 --- a/lib/puppet/settings/environment_conf.rb +++ b/lib/puppet/settings/environment_conf.rb @@ -58,11 +58,11 @@ def manifest disable_per_environment_manifest = Puppet.settings.value(:disable_per_environment_manifest) fallback_manifest_directory = - if puppet_conf_manifest.absolute? - puppet_conf_manifest.to_s - else - File.join(@path_to_env, puppet_conf_manifest.to_s) - end + if puppet_conf_manifest.absolute? + puppet_conf_manifest.to_s + else + File.join(@path_to_env, puppet_conf_manifest.to_s) + end if disable_per_environment_manifest environment_conf_manifest = absolute(raw_setting(:manifest)) diff --git a/lib/puppet/settings/file_setting.rb b/lib/puppet/settings/file_setting.rb index 1ef93106ed5..6fbba80add0 100644 --- a/lib/puppet/settings/file_setting.rb +++ b/lib/puppet/settings/file_setting.rb @@ -48,7 +48,7 @@ def value end end - private + private def safe_to_use_settings_value? @settings[:mkusers] or @settings.send(@available_method) end diff --git a/lib/puppet/settings/value_translator.rb b/lib/puppet/settings/value_translator.rb index d5abe8e6627..04e812806ef 100644 --- a/lib/puppet/settings/value_translator.rb +++ b/lib/puppet/settings/value_translator.rb @@ -4,12 +4,12 @@ class Puppet::Settings::ValueTranslator def [](value) # Handle different data types correctly return case value - when /^false$/i; false - when /^true$/i; true - when true; true - when false; false - else - value.gsub(/^["']|["']$/,'').sub(/\s+$/, '') - end + when /^false$/i; false + when /^true$/i; true + when true; true + when false; false + else + value.gsub(/^["']|["']$/,'').sub(/\s+$/, '') + end end end diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 695fdbebb56..367227ebda3 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -136,10 +136,10 @@ def self.attrclass(name) # of times (as in, hundreds of thousands in a given run). unless @attrclasses.include?(name) @attrclasses[name] = case self.attrtype(name) - when :property; @validproperties[name] - when :meta; @@metaparamhash[name] - when :param; @paramhash[name] - end + when :property; @validproperties[name] + when :meta; @@metaparamhash[name] + when :param; @paramhash[name] + end end @attrclasses[name] end @@ -153,10 +153,10 @@ def self.attrtype(attr) @attrtypes ||= {} unless @attrtypes.include?(attr) @attrtypes[attr] = case - when @validproperties.include?(attr); :property - when @paramhash.include?(attr); :param - when @@metaparamhash.include?(attr); :meta - end + when @validproperties.include?(attr); :property + when @paramhash.include?(attr); :param + when @@metaparamhash.include?(attr); :meta + end end @attrtypes[attr] @@ -1548,13 +1548,13 @@ def to_edges # i.e. before, after, subscribe, notify self.debug do relation = case self.class.name - when "subscribe" - "subscribes" - when "notify" - "notifies" - else - self.class.name - end + when "subscribe" + "subscribes" + when "notify" + "notifies" + else + self.class.name + end "#{relation} to #{related_resource.ref}" end diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index a7fb33c45fb..569c0ab3cfa 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -665,7 +665,7 @@ def self.remove_less_specific_files(files, parent_path, existing_files, &block) files.reject { |file| path = (yield file).split(::File::Separator) other_paths.any? { |p| path[0,p.length] == p } - } + } end # A simple method for determining whether we should be recursing. diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb index 457f09f289d..710ba396930 100644 --- a/lib/puppet/type/package.rb +++ b/lib/puppet/type/package.rb @@ -178,16 +178,16 @@ def insync?(is) end case - when is.is_a?(Array) && is.include?(@latest) - return true - when is == @latest - return true - when is == :present - # This will only happen on packaging systems - # that can't query versions. - return true - else - self.debug "#{@resource.name} #{is.inspect} is installed, latest is #{@latest.inspect}" + when is.is_a?(Array) && is.include?(@latest) + return true + when is == @latest + return true + when is == :present + # This will only happen on packaging systems + # that can't query versions. + return true + else + self.debug "#{@resource.name} #{is.inspect} is installed, latest is #{@latest.inspect}" end diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb index 27c9d8aec76..dacb538dc9a 100644 --- a/lib/puppet/type/resources.rb +++ b/lib/puppet/type/resources.rb @@ -78,12 +78,12 @@ value = [value] unless value.is_a? Array value.flatten.collect do |v| case v - when Integer - v - when String - Integer(v) - else - raise ArgumentError, _("Invalid value %{value}.") % { value: v.inspect } + when Integer + v + when String + Integer(v) + else + raise ArgumentError, _("Invalid value %{value}.") % { value: v.inspect } end end end @@ -92,8 +92,8 @@ WINDOWS_SYSTEM_SID_REGEXES = # Administrator, Guest, Domain Admins, Schema Admins, Enterprise Admins. # https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems - [/S-1-5-21.+-500/, /S-1-5-21.+-501/, /S-1-5-21.+-512/, /S-1-5-21.+-518/, - /S-1-5-21.+-519/] + [/S-1-5-21.+-500/, /S-1-5-21.+-501/, /S-1-5-21.+-512/, /S-1-5-21.+-518/, + /S-1-5-21.+-519/] def check(resource) @checkmethod ||= "#{self[:name]}_check" @@ -173,7 +173,7 @@ def self.system_users_max_uid # Otherwise, use a sensible default based on the OS family @system_users_max_uid ||= case Puppet.runtime[:facter].value('os.family') - when 'OpenBSD', 'FreeBSD' + when 'OpenBSD', 'FreeBSD' 999 else 499 diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb index ac29664c93d..be27da934e6 100644 --- a/lib/puppet/type/schedule.rb +++ b/lib/puppet/type/schedule.rb @@ -54,7 +54,7 @@ module Puppet resource could be checked & applied multiple times in the schedule as the information about when the resource was last checked will have expired from the cache. - EOT + EOT apply_to_all @@ -72,7 +72,7 @@ module Puppet schedule => 'everyday', } - EOT + EOT isnamevar end diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index e709949948a..26fee160b2e 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -611,17 +611,17 @@ def replace_file(file, default_mode, staging_location: nil, validate_callback: n effective_mode = - if !Puppet::Util::Platform.windows? - # Grab the current file mode, and fall back to the defaults. + if !Puppet::Util::Platform.windows? + # Grab the current file mode, and fall back to the defaults. - if Puppet::FileSystem.exist?(file) - stat = Puppet::FileSystem.lstat(file) - tempfile.chown(stat.uid, stat.gid) - stat.mode - else - mode + if Puppet::FileSystem.exist?(file) + stat = Puppet::FileSystem.lstat(file) + tempfile.chown(stat.uid, stat.gid) + stat.mode + else + mode + end end - end # OK, now allow the caller to write the content of the file. yield tempfile diff --git a/lib/puppet/util/command_line/puppet_option_parser.rb b/lib/puppet/util/command_line/puppet_option_parser.rb index d8e256c164b..5581c49495f 100644 --- a/lib/puppet/util/command_line/puppet_option_parser.rb +++ b/lib/puppet/util/command_line/puppet_option_parser.rb @@ -57,12 +57,12 @@ def on(*args, &block) } case type - when :REQUIRED - options[:type] = :string - when :NONE - options[:type] = :flag - else - raise PuppetOptionError.new(_("Unsupported type: '%{type}'") % { type: type }) + when :REQUIRED + options[:type] = :string + when :NONE + options[:type] = :flag + else + raise PuppetOptionError.new(_("Unsupported type: '%{type}'") % { type: type }) end @parser.opt long.sub("^--", "").intern, desc, options diff --git a/lib/puppet/util/command_line/trollop.rb b/lib/puppet/util/command_line/trollop.rb index b0602003793..ad64a200d7c 100644 --- a/lib/puppet/util/command_line/trollop.rb +++ b/lib/puppet/util/command_line/trollop.rb @@ -231,10 +231,10 @@ def opt name, desc="", opts={} ## fill in :short opts[:short] = opts[:short].to_s if opts[:short] unless opts[:short] == :none opts[:short] = case opts[:short] - when /^-(.)$/; $1 - when nil, :none, /^.$/; opts[:short] - else raise ArgumentError, _("invalid short option name '%{name}'") % { name: opts[:short].inspect } - end + when /^-(.)$/; $1 + when nil, :none, /^.$/; opts[:short] + else raise ArgumentError, _("invalid short option name '%{name}'") % { name: opts[:short].inspect } + end if opts[:short] raise ArgumentError, _("short option name %{value0} is already taken; please specify a (different) :short") % { value0: opts[:short].inspect } if @short[opts[:short]] @@ -327,15 +327,15 @@ def parse cmdline=ARGV given_args = {} @leftovers = each_arg cmdline do |arg, params| sym = case arg - when /^-([^-])$/ - @short[$1] - when /^--no-([^-]\S*)$/ - @long["[no-]#{$1}"] - when /^--([^-]\S*)$/ - @long[$1] ? @long[$1] : @long["[no-]#{$1}"] - else - raise CommandlineError, _("invalid argument syntax: '%{arg}'") % { arg: arg } - end + when /^-([^-])$/ + @short[$1] + when /^--no-([^-]\S*)$/ + @long["[no-]#{$1}"] + when /^--([^-]\S*)$/ + @long[$1] ? @long[$1] : @long["[no-]#{$1}"] + else + raise CommandlineError, _("invalid argument syntax: '%{arg}'") % { arg: arg } + end unless sym next 0 if ignore_invalid_options @@ -502,14 +502,14 @@ def educate stream=$stdout stream.printf " %#{leftcol_width}s: ", left[opt] desc = spec[:desc] + begin default_s = case spec[:default] - when $stdout; "" - when $stdin; "" - when $stderr; "" - when Array - spec[:default].join(", ") - else - spec[:default].to_s - end + when $stdout; "" + when $stdin; "" + when $stderr; "" + when Array + spec[:default].join(", ") + else + spec[:default].to_s + end if spec[:default] if spec[:desc] =~ /\.$/ @@ -560,7 +560,7 @@ def die arg, msg exit(-1) end -private + private ## yield successive arg, parameter pairs def each_arg args diff --git a/lib/puppet/util/log/destinations.rb b/lib/puppet/util/log/destinations.rb index c63551b0265..3b3d234680d 100644 --- a/lib/puppet/util/log/destinations.rb +++ b/lib/puppet/util/log/destinations.rb @@ -36,7 +36,7 @@ def handle(msg) else msg.to_s.split("\n").each do |line| @syslog.send(msg.level, "(%s) %s" % [msg.source.to_s.delete("%"), - line.gsub("%", '%%') + line.gsub("%", '%%') ] ) end diff --git a/lib/puppet/util/pidlock.rb b/lib/puppet/util/pidlock.rb index 0c2cdedec5e..84f125c5294 100644 --- a/lib/puppet/util/pidlock.rb +++ b/lib/puppet/util/pidlock.rb @@ -48,12 +48,12 @@ def file_path def ps_argument_for_current_kernel case Puppet.runtime[:facter].value(:kernel) - when "Linux" - "-eq" - when "AIX" - "-T" - else - "-p" + when "Linux" + "-eq" + when "AIX" + "-T" + else + "-p" end end diff --git a/lib/puppet/util/posix.rb b/lib/puppet/util/posix.rb index 31aa48e87c9..1b45cd92daf 100644 --- a/lib/puppet/util/posix.rb +++ b/lib/puppet/util/posix.rb @@ -4,7 +4,7 @@ module Puppet::Util::POSIX # This is a list of environment variables that we will set when we want to override the POSIX locale LOCALE_ENV_VARS = ['LANG', 'LC_ALL', 'LC_MESSAGES', 'LANGUAGE', - 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME'] + 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME'] # This is a list of user-related environment variables that we will unset when we want to provide a pristine # environment for "exec" runs diff --git a/lib/puppet/util/run_mode.rb b/lib/puppet/util/run_mode.rb index 366da348bb7..d0279ee8848 100644 --- a/lib/puppet/util/run_mode.rb +++ b/lib/puppet/util/run_mode.rb @@ -113,7 +113,7 @@ def log_dir which_dir(File.join(windows_common_base("puppet/var/log")), "~/.puppetlabs/var/log") end - private + private def windows_common_base(*extra) [ENV['ALLUSERSPROFILE'], "PuppetLabs"] + extra diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 2b9ade616fa..abd15263d31 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -117,16 +117,16 @@ def set_selinux_context(file, value, component = false) end context = context.split(':') case component - when :seluser - context[0] = value - when :selrole - context[1] = value - when :seltype - context[2] = value - when :selrange - context[3] = value - else - raise ArgumentError, _("set_selinux_context component must be one of :seluser, :selrole, :seltype, or :selrange") + when :seluser + context[0] = value + when :selrole + context[1] = value + when :seltype + context[2] = value + when :selrange + context[3] = value + else + raise ArgumentError, _("set_selinux_context component must be one of :seluser, :selrole, :seltype, or :selrange") end context = context.join(':') else diff --git a/lib/puppet/util/windows/daemon.rb b/lib/puppet/util/windows/daemon.rb index 3f490191cbc..cdbbb69b412 100644 --- a/lib/puppet/util/windows/daemon.rb +++ b/lib/puppet/util/windows/daemon.rb @@ -82,8 +82,8 @@ class Daemon ss[:dwControlsAccepted] = 0 else ss[:dwControlsAccepted] = - SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN| - SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_PARAMCHANGE + SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN| + SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_PARAMCHANGE end # Initialize ss structure. @@ -113,16 +113,16 @@ class Daemon dwState = SERVICE_RUNNING case dwCtrlCode - when SERVICE_CONTROL_STOP - dwState = SERVICE_STOP_PENDING - when SERVICE_CONTROL_SHUTDOWN - dwState = SERVICE_STOP_PENDING - when SERVICE_CONTROL_PAUSE - dwState = SERVICE_PAUSED - when SERVICE_CONTROL_CONTINUE - dwState = SERVICE_RUNNING - #else - # TODO: Handle other control codes? Retain the current state? + when SERVICE_CONTROL_STOP + dwState = SERVICE_STOP_PENDING + when SERVICE_CONTROL_SHUTDOWN + dwState = SERVICE_STOP_PENDING + when SERVICE_CONTROL_PAUSE + dwState = SERVICE_PAUSED + when SERVICE_CONTROL_CONTINUE + dwState = SERVICE_RUNNING + #else + # TODO: Handle other control codes? Retain the current state? end # Set the status of the service except on interrogation. @@ -284,24 +284,24 @@ def mainloop while(WaitForSingleObject(@@hStopEvent, 1000) == WAIT_TIMEOUT) # Check to see if anything interesting has been signaled case @@waiting_control_code - when SERVICE_CONTROL_PAUSE - service_pause() if respond_to?('service_pause') - when SERVICE_CONTROL_CONTINUE - service_resume() if respond_to?('service_resume') - when SERVICE_CONTROL_INTERROGATE - service_interrogate() if respond_to?('service_interrogate') - when SERVICE_CONTROL_SHUTDOWN - service_shutdown() if respond_to?('service_shutdown') - when SERVICE_CONTROL_PARAMCHANGE - service_paramchange() if respond_to?('service_paramchange') - when SERVICE_CONTROL_NETBINDADD - service_netbindadd() if respond_to?('service_netbindadd') - when SERVICE_CONTROL_NETBINDREMOVE - service_netbindremove() if respond_to?('service_netbindremove') - when SERVICE_CONTROL_NETBINDENABLE - service_netbindenable() if respond_to?('service_netbindenable') - when SERVICE_CONTROL_NETBINDDISABLE - service_netbinddisable() if respond_to?('service_netbinddisable') + when SERVICE_CONTROL_PAUSE + service_pause() if respond_to?('service_pause') + when SERVICE_CONTROL_CONTINUE + service_resume() if respond_to?('service_resume') + when SERVICE_CONTROL_INTERROGATE + service_interrogate() if respond_to?('service_interrogate') + when SERVICE_CONTROL_SHUTDOWN + service_shutdown() if respond_to?('service_shutdown') + when SERVICE_CONTROL_PARAMCHANGE + service_paramchange() if respond_to?('service_paramchange') + when SERVICE_CONTROL_NETBINDADD + service_netbindadd() if respond_to?('service_netbindadd') + when SERVICE_CONTROL_NETBINDREMOVE + service_netbindremove() if respond_to?('service_netbindremove') + when SERVICE_CONTROL_NETBINDENABLE + service_netbindenable() if respond_to?('service_netbindenable') + when SERVICE_CONTROL_NETBINDDISABLE + service_netbinddisable() if respond_to?('service_netbinddisable') end @@waiting_control_code = IDLE_CONTROL_CODE end diff --git a/lib/puppet/util/windows/file.rb b/lib/puppet/util/windows/file.rb index 2c8467dfdf3..d49257f4d6a 100644 --- a/lib/puppet/util/windows/file.rb +++ b/lib/puppet/util/windows/file.rb @@ -144,16 +144,16 @@ def self.get_reparse_point_data(handle, &block) reparse_tag = reparse_data_buffer_ptr.read_win32_ulong buffer_type = case reparse_tag - when IO_REPARSE_TAG_SYMLINK - SYMLINK_REPARSE_DATA_BUFFER - when IO_REPARSE_TAG_MOUNT_POINT - MOUNT_POINT_REPARSE_DATA_BUFFER - when IO_REPARSE_TAG_NFS - raise Puppet::Util::Windows::Error.new("Retrieving NFS reparse point data is unsupported") - else - raise Puppet::Util::Windows::Error.new("DeviceIoControl(#{handle}, " + - "FSCTL_GET_REPARSE_POINT) returned unknown tag 0x#{reparse_tag.to_s(16).upcase}") - end + when IO_REPARSE_TAG_SYMLINK + SYMLINK_REPARSE_DATA_BUFFER + when IO_REPARSE_TAG_MOUNT_POINT + MOUNT_POINT_REPARSE_DATA_BUFFER + when IO_REPARSE_TAG_NFS + raise Puppet::Util::Windows::Error.new("Retrieving NFS reparse point data is unsupported") + else + raise Puppet::Util::Windows::Error.new("DeviceIoControl(#{handle}, " + + "FSCTL_GET_REPARSE_POINT) returned unknown tag 0x#{reparse_tag.to_s(16).upcase}") + end yield buffer_type.new(reparse_data_buffer_ptr) end diff --git a/lib/puppet/util/windows/principal.rb b/lib/puppet/util/windows/principal.rb index dafe1b3f29e..a6947f433e3 100644 --- a/lib/puppet/util/windows/principal.rb +++ b/lib/puppet/util/windows/principal.rb @@ -81,7 +81,7 @@ def self.lookup_account_name(system_name = nil, sanitize = true, account_name) return lookup_account_sid( system_name, sid_ptr.read_bytes(sid_length_ptr.read_dword).unpack('C*')) - end + end end end end diff --git a/lib/puppet/util/windows/registry.rb b/lib/puppet/util/windows/registry.rb index 3e659b0a4fe..352ef8c0de8 100644 --- a/lib/puppet/util/windows/registry.rb +++ b/lib/puppet/util/windows/registry.rb @@ -239,22 +239,22 @@ def read(key, name_ptr, *rtype) string_length = (byte_length / FFI.type_size(:wchar)) - 1 if byte_length > 0 begin - case type - when Win32::Registry::REG_SZ, Win32::Registry::REG_EXPAND_SZ - result = [ type, data_ptr.read_wide_string(string_length, Encoding::UTF_8, true) ] - when Win32::Registry::REG_MULTI_SZ - result = [ type, data_ptr.read_wide_string(string_length).split(/\0/) ] - when Win32::Registry::REG_BINARY - result = [ type, data_ptr.read_bytes(byte_length) ] - when Win32::Registry::REG_DWORD - result = [ type, data_ptr.read_dword ] - when Win32::Registry::REG_DWORD_BIG_ENDIAN - result = [ type, data_ptr.order(:big).read_dword ] - when Win32::Registry::REG_QWORD - result = [ type, data_ptr.read_qword ] - else - raise TypeError, _("Type %{type} is not supported.") % { type: type } - end + result = case type + when Win32::Registry::REG_SZ, Win32::Registry::REG_EXPAND_SZ + [ type, data_ptr.read_wide_string(string_length, Encoding::UTF_8, true) ] + when Win32::Registry::REG_MULTI_SZ + [ type, data_ptr.read_wide_string(string_length).split(/\0/) ] + when Win32::Registry::REG_BINARY + [ type, data_ptr.read_bytes(byte_length) ] + when Win32::Registry::REG_DWORD + [ type, data_ptr.read_dword ] + when Win32::Registry::REG_DWORD_BIG_ENDIAN + [ type, data_ptr.order(:big).read_dword ] + when Win32::Registry::REG_QWORD + [ type, data_ptr.read_qword ] + else + raise TypeError, _("Type %{type} is not supported.") % { type: type } + end rescue IndexError => ex raise if (ex.message !~ /^Memory access .* is out of bounds$/i) parent_key_name = key.parent ? "#{key.parent.keyname}\\" : "" @@ -401,7 +401,8 @@ def reg_delete_key_ex(key, name, regsam = KEY64) # ); ffi_lib :advapi32 attach_function_private :RegQueryInfoKeyW, - [:handle, :lpwstr, :lpdword, :lpdword, :lpdword, :lpdword, :lpdword, - :lpdword, :lpdword, :lpdword, :lpdword, :pointer], :win32_long + [:handle, :lpwstr, :lpdword, :lpdword, :lpdword, + :lpdword, :lpdword, :lpdword, :lpdword, :lpdword, + :lpdword, :pointer], :win32_long end end diff --git a/lib/puppet/util/windows/user.rb b/lib/puppet/util/windows/user.rb index 3092a09d8ec..f1af5d86a1e 100644 --- a/lib/puppet/util/windows/user.rb +++ b/lib/puppet/util/windows/user.rb @@ -248,17 +248,17 @@ def self.check_lsa_nt_status_and_raise_failures(status, method_name) error_code = LsaNtStatusToWinError(status) error_reason = case error_code.to_s(16) - when '0' # ERROR_SUCCESS - return # Method call succeded - when '2' # ERROR_FILE_NOT_FOUND - return # No rights/privilleges assigned to given user - when '5' # ERROR_ACCESS_DENIED - "Access is denied. Please make sure that puppet is running as administrator." - when '521' # ERROR_NO_SUCH_PRIVILEGE - "One or more of the given rights/privilleges are incorrect." - when '6ba' # RPC_S_SERVER_UNAVAILABLE - "The RPC server is unavailable or given domain name is invalid." - end + when '0' # ERROR_SUCCESS + return # Method call succeded + when '2' # ERROR_FILE_NOT_FOUND + return # No rights/privilleges assigned to given user + when '5' # ERROR_ACCESS_DENIED + "Access is denied. Please make sure that puppet is running as administrator." + when '521' # ERROR_NO_SUCH_PRIVILEGE + "One or more of the given rights/privilleges are incorrect." + when '6ba' # RPC_S_SERVER_UNAVAILABLE + "The RPC server is unavailable or given domain name is invalid." + end raise Puppet::Error.new("Calling `#{method_name}` returned 'Win32 Error Code 0x%08X'. #{error_reason}" % error_code) end