diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-07-02 13:18:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-02 13:18:58 -0700 |
commit | 4ca23a0dd98c59e1cae29fd7ad6e485cbb12c2b3 (patch) | |
tree | c23401b04cc4184969ea7ab8d4ae5ad8760ee198 /lib/chef | |
parent | 28f9fa7713cd2788f259efc7ec5405365d07419c (diff) | |
parent | 865b2aac61aea10db31bae7dcedd6146c9526f74 (diff) | |
download | chef-4ca23a0dd98c59e1cae29fd7ad6e485cbb12c2b3.tar.gz |
Merge pull request #7414 from chef/lcg/chefstyle2
Chefstyle fixes
Diffstat (limited to 'lib/chef')
214 files changed, 2444 insertions, 2445 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb index 656a0e364f..3120b58cc0 100644 --- a/lib/chef/api_client.rb +++ b/lib/chef/api_client.rb @@ -53,7 +53,7 @@ class Chef set_or_return( :name, arg, - :regex => /^[\-[:alnum:]_\.]+$/ + regex: /^[\-[:alnum:]_\.]+$/ ) end @@ -65,7 +65,7 @@ class Chef set_or_return( :admin, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -77,7 +77,7 @@ class Chef set_or_return( :public_key, arg, - :kind_of => String + kind_of: String ) end @@ -90,7 +90,7 @@ class Chef set_or_return( :validator, arg, - :kind_of => [TrueClass, FalseClass] + kind_of: [TrueClass, FalseClass] ) end @@ -102,7 +102,7 @@ class Chef set_or_return( :private_key, arg, - :kind_of => [String, FalseClass] + kind_of: [String, FalseClass] ) end @@ -145,7 +145,7 @@ class Chef end def self.http_api - Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "0" }) + Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "0" }) end def self.reregister(name) @@ -183,18 +183,18 @@ class Chef # Save this client via the REST API, returns a hash including the private key def save - http_api.put("clients/#{name}", { :name => name, :admin => admin, :validator => validator }) + http_api.put("clients/#{name}", { name: name, admin: admin, validator: validator }) rescue Net::HTTPServerException => e # If that fails, go ahead and try and update it if e.response.code == "404" - http_api.post("clients", { :name => name, :admin => admin, :validator => validator }) + http_api.post("clients", { name: name, admin: admin, validator: validator }) else raise e end end def reregister - reregistered_self = http_api.put("clients/#{name}", { :name => name, :admin => admin, :validator => validator, :private_key => true }) + reregistered_self = http_api.put("clients/#{name}", { name: name, admin: admin, validator: validator, private_key: true }) if reregistered_self.respond_to?(:[]) private_key(reregistered_self["private_key"]) else @@ -219,7 +219,7 @@ class Chef end def http_api - @http_api ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "0" }) + @http_api ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "0" }) end end diff --git a/lib/chef/api_client/registration.rb b/lib/chef/api_client/registration.rb index 27e1f18c17..6cbb071020 100644 --- a/lib/chef/api_client/registration.rb +++ b/lib/chef/api_client/registration.rb @@ -139,7 +139,7 @@ class Chef end def put_data - base_put_data = { :name => name, :admin => false } + base_put_data = { name: name, admin: false } if self_generate_keys? base_put_data[:public_key] = generated_public_key else @@ -149,7 +149,7 @@ class Chef end def post_data - post_data = { :name => name, :admin => false } + post_data = { name: name, admin: false } post_data[:public_key] = generated_public_key if self_generate_keys? post_data end @@ -157,9 +157,9 @@ class Chef def http_api @http_api ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { - :api_version => "0", - :client_name => Chef::Config[:validation_client_name], - :signing_key_filename => Chef::Config[:validation_key], + api_version: "0", + client_name: Chef::Config[:validation_client_name], + signing_key_filename: Chef::Config[:validation_key], } ) end diff --git a/lib/chef/api_client_v1.rb b/lib/chef/api_client_v1.rb index 7fbff6d6ba..645016c5b9 100644 --- a/lib/chef/api_client_v1.rb +++ b/lib/chef/api_client_v1.rb @@ -57,15 +57,15 @@ class Chef end def chef_rest_v0 - @chef_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "0", :inflate_json_class => false }) + @chef_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "0", inflate_json_class: false }) end def chef_rest_v1 - @chef_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "1", :inflate_json_class => false }) + @chef_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "1", inflate_json_class: false }) end def self.http_api - Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "1", :inflate_json_class => false }) + Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "1", inflate_json_class: false }) end # Gets or sets the client name. @@ -76,7 +76,7 @@ class Chef set_or_return( :name, arg, - :regex => /^[\-[:alnum:]_\.]+$/ + regex: /^[\-[:alnum:]_\.]+$/ ) end @@ -88,7 +88,7 @@ class Chef set_or_return( :admin, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -100,7 +100,7 @@ class Chef set_or_return( :public_key, arg, - :kind_of => String + kind_of: String ) end @@ -113,7 +113,7 @@ class Chef set_or_return( :validator, arg, - :kind_of => [TrueClass, FalseClass] + kind_of: [TrueClass, FalseClass] ) end @@ -126,7 +126,7 @@ class Chef set_or_return( :private_key, arg, - :kind_of => [String, TrueClass, FalseClass] + kind_of: [String, TrueClass, FalseClass] ) end @@ -138,7 +138,7 @@ class Chef set_or_return( :create_key, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -226,7 +226,7 @@ class Chef def reregister # Try API V0 and if it fails due to V0 not being supported, raise the proper error message. # reregister only supported in API V0 or lesser. - reregistered_self = chef_rest_v0.put("clients/#{name}", { :name => name, :admin => admin, :validator => validator, :private_key => true }) + reregistered_self = chef_rest_v0.put("clients/#{name}", { name: name, admin: admin, validator: validator, private_key: true }) if reregistered_self.respond_to?(:[]) private_key(reregistered_self["private_key"]) else @@ -254,7 +254,7 @@ class Chef # it was never implemented, we will simply ignore that functionality # as it is being deprecated. # Delete this comment after V0 support is dropped. - payload = { :name => name } + payload = { name: name } payload[:validator] = validator unless validator.nil? # DEPRECATION @@ -277,11 +277,11 @@ class Chef # Create the client via the REST API def create payload = { - :name => name, - :validator => validator, + name: name, + validator: validator, # this field is ignored in API V1, but left for backwards-compat, # can remove after OSC 11 support is finished? - :admin => admin, + admin: admin, } begin # try API V1 diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb index ec627ada2e..7325d89e1e 100644 --- a/lib/chef/application/apply.rb +++ b/lib/chef/application/apply.rb @@ -32,86 +32,86 @@ class Chef::Application::Apply < Chef::Application banner "Usage: chef-apply [RECIPE_FILE | -e RECIPE_TEXT | -s] [OPTIONS]" option :execute, - :short => "-e RECIPE_TEXT", - :long => "--execute RECIPE_TEXT", - :description => "Execute resources supplied in a string", - :proc => nil + short: "-e RECIPE_TEXT", + long: "--execute RECIPE_TEXT", + description: "Execute resources supplied in a string", + proc: nil option :stdin, - :short => "-s", - :long => "--stdin", - :description => "Execute resources read from STDIN", - :boolean => true + short: "-s", + long: "--stdin", + description: "Execute resources read from STDIN", + boolean: true option :json_attribs, - :short => "-j JSON_ATTRIBS", - :long => "--json-attributes JSON_ATTRIBS", - :description => "Load attributes from a JSON file or URL", - :proc => nil + short: "-j JSON_ATTRIBS", + long: "--json-attributes JSON_ATTRIBS", + description: "Load attributes from a JSON file or URL", + proc: nil option :force_logger, - :long => "--force-logger", - :description => "Use logger output instead of formatter output", - :boolean => true, - :default => false + long: "--force-logger", + description: "Use logger output instead of formatter output", + boolean: true, + default: false option :force_formatter, - :long => "--force-formatter", - :description => "Use formatter output instead of logger output", - :boolean => true, - :default => false + long: "--force-formatter", + description: "Use formatter output instead of logger output", + boolean: true, + default: false option :formatter, - :short => "-F FORMATTER", - :long => "--format FORMATTER", - :description => "output format to use", - :proc => lambda { |format| Chef::Config.add_formatter(format) } + short: "-F FORMATTER", + long: "--format FORMATTER", + description: "output format to use", + proc: lambda { |format| Chef::Config.add_formatter(format) } option :log_level, - :short => "-l LEVEL", - :long => "--log_level LEVEL", - :description => "Set the log level (trace, debug, info, warn, error, fatal)", - :proc => lambda { |l| l.to_sym } + short: "-l LEVEL", + long: "--log_level LEVEL", + description: "Set the log level (trace, debug, info, warn, error, fatal)", + proc: lambda { |l| l.to_sym } option :help, - :short => "-h", - :long => "--help", - :description => "Show this message", - :on => :tail, - :boolean => true, - :show_options => true, - :exit => 0 + short: "-h", + long: "--help", + description: "Show this message", + on: :tail, + boolean: true, + show_options: true, + exit: 0 option :version, - :short => "-v", - :long => "--version", - :description => "Show chef version", - :boolean => true, - :proc => lambda { |v| puts "Chef: #{::Chef::VERSION}" }, - :exit => 0 + short: "-v", + long: "--version", + description: "Show chef version", + boolean: true, + proc: lambda { |v| puts "Chef: #{::Chef::VERSION}" }, + exit: 0 option :why_run, - :short => "-W", - :long => "--why-run", - :description => "Enable whyrun mode", - :boolean => true + short: "-W", + long: "--why-run", + description: "Enable whyrun mode", + boolean: true option :profile_ruby, - :long => "--[no-]profile-ruby", - :description => "Dump complete Ruby call graph stack of entire Chef run (expert only)", - :boolean => true, - :default => false + long: "--[no-]profile-ruby", + description: "Dump complete Ruby call graph stack of entire Chef run (expert only)", + boolean: true, + default: false option :color, - :long => "--[no-]color", - :boolean => true, - :default => true, - :description => "Use colored output, defaults to enabled" + long: "--[no-]color", + boolean: true, + default: true, + description: "Use colored output, defaults to enabled" option :minimal_ohai, - :long => "--minimal-ohai", - :description => "Only run the bare minimum ohai plugins chef needs to function", - :boolean => true + long: "--minimal-ohai", + description: "Only run the bare minimum ohai plugins chef needs to function", + boolean: true attr_reader :json_attribs diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index ffb997f187..6e574e682f 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -38,172 +38,171 @@ class Chef::Application::Client < Chef::Application SELF_PIPE = [] option :config_file, - :short => "-c CONFIG", - :long => "--config CONFIG", - :description => "The configuration file to use" + short: "-c CONFIG", + long: "--config CONFIG", + description: "The configuration file to use" option :config_option, - :long => "--config-option OPTION=VALUE", - :description => "Override a single configuration option", - :proc => lambda { |option, existing| + long: "--config-option OPTION=VALUE", + description: "Override a single configuration option", + proc: lambda { |option, existing| (existing ||= []) << option existing } option :formatter, - :short => "-F FORMATTER", - :long => "--format FORMATTER", - :description => "output format to use", - :proc => lambda { |format| Chef::Config.add_formatter(format) } + short: "-F FORMATTER", + long: "--format FORMATTER", + description: "output format to use", + proc: lambda { |format| Chef::Config.add_formatter(format) } option :force_logger, - :long => "--force-logger", - :description => "Use logger output instead of formatter output", - :boolean => true, - :default => false + long: "--force-logger", + description: "Use logger output instead of formatter output", + boolean: true, + default: false option :force_formatter, - :long => "--force-formatter", - :description => "Use formatter output instead of logger output", - :boolean => true, - :default => false + long: "--force-formatter", + description: "Use formatter output instead of logger output", + boolean: true, + default: false option :profile_ruby, - :long => "--[no-]profile-ruby", - :description => "Dump complete Ruby call graph stack of entire Chef run (expert only)", - :boolean => true, - :default => false + long: "--[no-]profile-ruby", + description: "Dump complete Ruby call graph stack of entire Chef run (expert only)", + boolean: true, + default: false option :color, - :long => "--[no-]color", - :boolean => true, - :default => true, - :description => "Use colored output, defaults to enabled" + long: "--[no-]color", + boolean: true, + default: true, + description: "Use colored output, defaults to enabled" option :log_level, - :short => "-l LEVEL", - :long => "--log_level LEVEL", - :description => "Set the log level (auto, trace, debug, info, warn, error, fatal)", - :proc => lambda { |l| l.to_sym } + short: "-l LEVEL", + long: "--log_level LEVEL", + description: "Set the log level (auto, trace, debug, info, warn, error, fatal)", + proc: lambda { |l| l.to_sym } option :log_location, - :short => "-L LOGLOCATION", - :long => "--logfile LOGLOCATION", - :description => "Set the log file location, defaults to STDOUT - recommended for daemonizing", - :proc => nil + short: "-L LOGLOCATION", + long: "--logfile LOGLOCATION", + description: "Set the log file location, defaults to STDOUT - recommended for daemonizing", + proc: nil option :help, - :short => "-h", - :long => "--help", - :description => "Show this message", - :on => :tail, - :boolean => true, - :show_options => true, - :exit => 0 + short: "-h", + long: "--help", + description: "Show this message", + on: :tail, + boolean: true, + show_options: true, + exit: 0 option :user, - :short => "-u USER", - :long => "--user USER", - :description => "User to set privilege to", - :proc => nil + short: "-u USER", + long: "--user USER", + description: "User to set privilege to", + proc: nil option :group, - :short => "-g GROUP", - :long => "--group GROUP", - :description => "Group to set privilege to", - :proc => nil + short: "-g GROUP", + long: "--group GROUP", + description: "Group to set privilege to", + proc: nil unless Chef::Platform.windows? option :daemonize, - :short => "-d [WAIT]", - :long => "--daemonize [WAIT]", - :description => - "Daemonize the process. Accepts an optional integer which is the " \ + short: "-d [WAIT]", + long: "--daemonize [WAIT]", + description: "Daemonize the process. Accepts an optional integer which is the " \ "number of seconds to wait before the first daemonized run.", - :proc => lambda { |wait| wait =~ /^\d+$/ ? wait.to_i : true } + proc: lambda { |wait| wait =~ /^\d+$/ ? wait.to_i : true } end option :pid_file, - :short => "-P PID_FILE", - :long => "--pid PIDFILE", - :description => "Set the PID file location, for the chef-client daemon process. Defaults to /tmp/chef-client.pid", - :proc => nil + short: "-P PID_FILE", + long: "--pid PIDFILE", + description: "Set the PID file location, for the chef-client daemon process. Defaults to /tmp/chef-client.pid", + proc: nil option :lockfile, - :long => "--lockfile LOCKFILE", - :description => "Set the lockfile location. Prevents multiple client processes from converging at the same time", - :proc => nil + long: "--lockfile LOCKFILE", + description: "Set the lockfile location. Prevents multiple client processes from converging at the same time", + proc: nil option :interval, - :short => "-i SECONDS", - :long => "--interval SECONDS", - :description => "Run chef-client periodically, in seconds", - :proc => lambda { |s| s.to_i } + short: "-i SECONDS", + long: "--interval SECONDS", + description: "Run chef-client periodically, in seconds", + proc: lambda { |s| s.to_i } option :once, - :long => "--once", - :description => "Cancel any interval or splay options, run chef once and exit", - :boolean => true + long: "--once", + description: "Cancel any interval or splay options, run chef once and exit", + boolean: true option :json_attribs, - :short => "-j JSON_ATTRIBS", - :long => "--json-attributes JSON_ATTRIBS", - :description => "Load attributes from a JSON file or URL", - :proc => nil + short: "-j JSON_ATTRIBS", + long: "--json-attributes JSON_ATTRIBS", + description: "Load attributes from a JSON file or URL", + proc: nil option :node_name, - :short => "-N NODE_NAME", - :long => "--node-name NODE_NAME", - :description => "The node name for this client", - :proc => nil + short: "-N NODE_NAME", + long: "--node-name NODE_NAME", + description: "The node name for this client", + proc: nil option :splay, - :short => "-s SECONDS", - :long => "--splay SECONDS", - :description => "The splay time for running at intervals, in seconds", - :proc => lambda { |s| s.to_i } + short: "-s SECONDS", + long: "--splay SECONDS", + description: "The splay time for running at intervals, in seconds", + proc: lambda { |s| s.to_i } option :chef_server_url, - :short => "-S CHEFSERVERURL", - :long => "--server CHEFSERVERURL", - :description => "The chef server URL", - :proc => nil + short: "-S CHEFSERVERURL", + long: "--server CHEFSERVERURL", + description: "The chef server URL", + proc: nil option :validation_key, - :short => "-K KEY_FILE", - :long => "--validation_key KEY_FILE", - :description => "Set the validation key file location, used for registering new clients", - :proc => nil + short: "-K KEY_FILE", + long: "--validation_key KEY_FILE", + description: "Set the validation key file location, used for registering new clients", + proc: nil option :client_key, - :short => "-k KEY_FILE", - :long => "--client_key KEY_FILE", - :description => "Set the client key file location", - :proc => nil + short: "-k KEY_FILE", + long: "--client_key KEY_FILE", + description: "Set the client key file location", + proc: nil option :named_run_list, - :short => "-n NAMED_RUN_LIST", - :long => "--named-run-list NAMED_RUN_LIST", - :description => "Use a policyfile's named run list instead of the default run list" + short: "-n NAMED_RUN_LIST", + long: "--named-run-list NAMED_RUN_LIST", + description: "Use a policyfile's named run list instead of the default run list" option :environment, - :short => "-E ENVIRONMENT", - :long => "--environment ENVIRONMENT", - :description => "Set the Chef Environment on the node" + short: "-E ENVIRONMENT", + long: "--environment ENVIRONMENT", + description: "Set the Chef Environment on the node" option :version, - :short => "-v", - :long => "--version", - :description => "Show chef version", - :boolean => true, - :proc => lambda { |v| puts "Chef: #{::Chef::VERSION}" }, - :exit => 0 + short: "-v", + long: "--version", + description: "Show chef version", + boolean: true, + proc: lambda { |v| puts "Chef: #{::Chef::VERSION}" }, + exit: 0 option :override_runlist, - :short => "-o RunlistItem,RunlistItem...", - :long => "--override-runlist RunlistItem,RunlistItem...", - :description => "Replace current run list with specified items for a single run", - :proc => lambda { |items| + short: "-o RunlistItem,RunlistItem...", + long: "--override-runlist RunlistItem,RunlistItem...", + description: "Replace current run list with specified items for a single run", + proc: lambda { |items| items = items.split(",") items.compact.map do |item| Chef::RunList::RunListItem.new(item) @@ -211,97 +210,97 @@ class Chef::Application::Client < Chef::Application } option :runlist, - :short => "-r RunlistItem,RunlistItem...", - :long => "--runlist RunlistItem,RunlistItem...", - :description => "Permanently replace current run list with specified items", - :proc => lambda { |items| + short: "-r RunlistItem,RunlistItem...", + long: "--runlist RunlistItem,RunlistItem...", + description: "Permanently replace current run list with specified items", + proc: lambda { |items| items = items.split(",") items.compact.map do |item| Chef::RunList::RunListItem.new(item) end } option :why_run, - :short => "-W", - :long => "--why-run", - :description => "Enable whyrun mode", - :boolean => true + short: "-W", + long: "--why-run", + description: "Enable whyrun mode", + boolean: true option :client_fork, - :short => "-f", - :long => "--[no-]fork", - :description => "Fork client" + short: "-f", + long: "--[no-]fork", + description: "Fork client" option :recipe_url, - :long => "--recipe-url=RECIPE_URL", - :description => "Pull down a remote archive of recipes and unpack it to the cookbook cache. Only used in local mode." + long: "--recipe-url=RECIPE_URL", + description: "Pull down a remote archive of recipes and unpack it to the cookbook cache. Only used in local mode." option :enable_reporting, - :short => "-R", - :long => "--enable-reporting", - :description => "Enable reporting data collection for chef runs", - :boolean => true + short: "-R", + long: "--enable-reporting", + description: "Enable reporting data collection for chef runs", + boolean: true option :local_mode, - :short => "-z", - :long => "--local-mode", - :description => "Point chef-client at local repository", - :boolean => true + short: "-z", + long: "--local-mode", + description: "Point chef-client at local repository", + boolean: true option :chef_zero_host, - :long => "--chef-zero-host HOST", - :description => "Host to start chef-zero on" + long: "--chef-zero-host HOST", + description: "Host to start chef-zero on" option :chef_zero_port, - :long => "--chef-zero-port PORT", - :description => "Port (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works." + long: "--chef-zero-port PORT", + description: "Port (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works." option :disable_config, - :long => "--disable-config", - :description => "Refuse to load a config file and use defaults. This is for development and not a stable API", - :boolean => true + long: "--disable-config", + description: "Refuse to load a config file and use defaults. This is for development and not a stable API", + boolean: true option :run_lock_timeout, - :long => "--run-lock-timeout SECONDS", - :description => "Set maximum duration to wait for another client run to finish, default is indefinitely.", - :proc => lambda { |s| s.to_i } + long: "--run-lock-timeout SECONDS", + description: "Set maximum duration to wait for another client run to finish, default is indefinitely.", + proc: lambda { |s| s.to_i } if Chef::Platform.windows? option :fatal_windows_admin_check, - :short => "-A", - :long => "--fatal-windows-admin-check", - :description => "Fail the run when chef-client doesn't have administrator privileges on Windows", - :boolean => true + short: "-A", + long: "--fatal-windows-admin-check", + description: "Fail the run when chef-client doesn't have administrator privileges on Windows", + boolean: true end option :audit_mode, - :long => "--audit-mode MODE", - :description => "Enable audit-mode with `enabled`. Disable audit-mode with `disabled`. Skip converge and only perform audits with `audit-only`", - :proc => lambda { |mo| mo.tr("-", "_").to_sym } + long: "--audit-mode MODE", + description: "Enable audit-mode with `enabled`. Disable audit-mode with `disabled`. Skip converge and only perform audits with `audit-only`", + proc: lambda { |mo| mo.tr("-", "_").to_sym } option :minimal_ohai, - :long => "--minimal-ohai", - :description => "Only run the bare minimum ohai plugins chef needs to function", - :boolean => true + long: "--minimal-ohai", + description: "Only run the bare minimum ohai plugins chef needs to function", + boolean: true option :listen, - :long => "--[no-]listen", - :description => "Whether a local mode (-z) server binds to a port", - :boolean => false + long: "--[no-]listen", + description: "Whether a local mode (-z) server binds to a port", + boolean: false option :fips, - :long => "--[no-]fips", - :description => "Enable fips mode", - :boolean => true + long: "--[no-]fips", + description: "Enable fips mode", + boolean: true option :delete_entire_chef_repo, - :long => "--delete-entire-chef-repo", - :description => "DANGEROUS: does what it says, only useful with --recipe-url", - :boolean => true + long: "--delete-entire-chef-repo", + description: "DANGEROUS: does what it says, only useful with --recipe-url", + boolean: true option :skip_cookbook_sync, - :long => "--[no-]skip-cookbook-sync", - :description => "Use cached cookbooks without overwriting local differences from the server", - :boolean => false + long: "--[no-]skip-cookbook-sync", + description: "Use cached cookbooks without overwriting local differences from the server", + boolean: false IMMEDIATE_RUN_SIGNAL = "1".freeze RECONFIGURE_SIGNAL = "H".freeze @@ -338,7 +337,7 @@ class Chef::Application::Client < Chef::Application else if Chef::Config[:delete_entire_chef_repo] Chef::Log.trace "Cleanup path #{Chef::Config.chef_repo_path} before extract recipes into it" - FileUtils.rm_rf(recipes_path, :secure => true) + FileUtils.rm_rf(recipes_path, secure: true) end Chef::Log.trace "Creating path #{Chef::Config.chef_repo_path} to extract recipes into" FileUtils.mkdir_p(Chef::Config.chef_repo_path) @@ -518,7 +517,7 @@ class Chef::Application::Client < Chef::Application def unforked_interval_error_message "Unforked chef-client interval runs are disabled in Chef 12." + "\nConfiguration settings:" + - "#{"\n interval = #{Chef::Config[:interval]} seconds" if Chef::Config[:interval]}" + + ("\n interval = #{Chef::Config[:interval]} seconds" if Chef::Config[:interval]).to_s + "\nEnable chef-client interval runs by setting `:client_fork = true` in your config file or adding `--fork` to your command line options." end diff --git a/lib/chef/application/knife.rb b/lib/chef/application/knife.rb index c972e9313e..2c8d886b27 100644 --- a/lib/chef/application/knife.rb +++ b/lib/chef/application/knife.rb @@ -28,129 +28,129 @@ class Chef::Application::Knife < Chef::Application banner "Usage: knife sub-command (options)" option :config_file, - :short => "-c CONFIG", - :long => "--config CONFIG", - :description => "The configuration file to use", - :proc => lambda { |path| File.expand_path(path, Dir.pwd) } + short: "-c CONFIG", + long: "--config CONFIG", + description: "The configuration file to use", + proc: lambda { |path| File.expand_path(path, Dir.pwd) } option :config_option, - :long => "--config-option OPTION=VALUE", - :description => "Override a single configuration option", - :proc => lambda { |option, existing| + long: "--config-option OPTION=VALUE", + description: "Override a single configuration option", + proc: lambda { |option, existing| (existing ||= []) << option existing } verbosity_level = 0 option :verbosity, - :short => "-V", - :long => "--verbose", - :description => "More verbose output. Use twice for max verbosity", - :proc => Proc.new { verbosity_level += 1 }, - :default => 0 + short: "-V", + long: "--verbose", + description: "More verbose output. Use twice for max verbosity", + proc: Proc.new { verbosity_level += 1 }, + default: 0 option :color, - :long => "--[no-]color", - :boolean => true, - :default => true, - :description => "Use colored output, defaults to enabled" + long: "--[no-]color", + boolean: true, + default: true, + description: "Use colored output, defaults to enabled" option :environment, - :short => "-E ENVIRONMENT", - :long => "--environment ENVIRONMENT", - :description => "Set the Chef environment (except for in searches, where this will be flagrantly ignored)" + short: "-E ENVIRONMENT", + long: "--environment ENVIRONMENT", + description: "Set the Chef environment (except for in searches, where this will be flagrantly ignored)" option :editor, - :short => "-e EDITOR", - :long => "--editor EDITOR", - :description => "Set the editor to use for interactive commands", - :default => ENV["EDITOR"] + short: "-e EDITOR", + long: "--editor EDITOR", + description: "Set the editor to use for interactive commands", + default: ENV["EDITOR"] option :disable_editing, - :short => "-d", - :long => "--disable-editing", - :description => "Do not open EDITOR, just accept the data as is", - :boolean => true, - :default => false + short: "-d", + long: "--disable-editing", + description: "Do not open EDITOR, just accept the data as is", + boolean: true, + default: false option :help, - :short => "-h", - :long => "--help", - :description => "Show this message", - :on => :tail, - :boolean => true + short: "-h", + long: "--help", + description: "Show this message", + on: :tail, + boolean: true option :node_name, - :short => "-u USER", - :long => "--user USER", - :description => "API Client Username" + short: "-u USER", + long: "--user USER", + description: "API Client Username" option :client_key, - :short => "-k KEY", - :long => "--key KEY", - :description => "API Client Key", - :proc => lambda { |path| File.expand_path(path, Dir.pwd) } + short: "-k KEY", + long: "--key KEY", + description: "API Client Key", + proc: lambda { |path| File.expand_path(path, Dir.pwd) } option :chef_server_url, - :short => "-s URL", - :long => "--server-url URL", - :description => "Chef Server URL" + short: "-s URL", + long: "--server-url URL", + description: "Chef Server URL" option :yes, - :short => "-y", - :long => "--yes", - :description => "Say yes to all prompts for confirmation" + short: "-y", + long: "--yes", + description: "Say yes to all prompts for confirmation" option :defaults, - :long => "--defaults", - :description => "Accept default values for all questions" + long: "--defaults", + description: "Accept default values for all questions" option :print_after, - :long => "--print-after", - :description => "Show the data after a destructive operation" + long: "--print-after", + description: "Show the data after a destructive operation" option :format, - :short => "-F FORMAT", - :long => "--format FORMAT", - :description => "Which format to use for output", - :default => "summary" + short: "-F FORMAT", + long: "--format FORMAT", + description: "Which format to use for output", + default: "summary" option :local_mode, - :short => "-z", - :long => "--local-mode", - :description => "Point knife commands at local repository instead of server", - :boolean => true + short: "-z", + long: "--local-mode", + description: "Point knife commands at local repository instead of server", + boolean: true option :chef_zero_host, - :long => "--chef-zero-host HOST", - :description => "Host to start chef-zero on" + long: "--chef-zero-host HOST", + description: "Host to start chef-zero on" option :chef_zero_port, - :long => "--chef-zero-port PORT", - :description => "Port (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works." + long: "--chef-zero-port PORT", + description: "Port (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works." option :listen, - :long => "--[no-]listen", - :description => "Whether a local mode (-z) server binds to a port", - :boolean => false + long: "--[no-]listen", + description: "Whether a local mode (-z) server binds to a port", + boolean: false option :version, - :short => "-v", - :long => "--version", - :description => "Show chef version", - :boolean => true, - :proc => lambda { |v| puts "Chef: #{::Chef::VERSION}" }, - :exit => 0 + short: "-v", + long: "--version", + description: "Show chef version", + boolean: true, + proc: lambda { |v| puts "Chef: #{::Chef::VERSION}" }, + exit: 0 option :fips, - :long => "--[no-]fips", - :description => "Enable fips mode", - :boolean => true, - :default => nil + long: "--[no-]fips", + description: "Enable fips mode", + boolean: true, + default: nil option :profile, - :long => "--profile PROFILE", - :description => "The credentials profile to select" + long: "--profile PROFILE", + description: "The credentials profile to select" # Run knife def run diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index 646d68182c..cd364dc6ae 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -35,137 +35,137 @@ class Chef::Application::Solo < Chef::Application include ChefConfig::Mixin::DotD option :config_file, - :short => "-c CONFIG", - :long => "--config CONFIG", - :default => Chef::Config.platform_specific_path("/etc/chef/solo.rb"), - :description => "The configuration file to use" + short: "-c CONFIG", + long: "--config CONFIG", + default: Chef::Config.platform_specific_path("/etc/chef/solo.rb"), + description: "The configuration file to use" option :config_option, - :long => "--config-option OPTION=VALUE", - :description => "Override a single configuration option", - :proc => lambda { |option, existing| + long: "--config-option OPTION=VALUE", + description: "Override a single configuration option", + proc: lambda { |option, existing| (existing ||= []) << option existing } option :formatter, - :short => "-F FORMATTER", - :long => "--format FORMATTER", - :description => "output format to use", - :proc => lambda { |format| Chef::Config.add_formatter(format) } + short: "-F FORMATTER", + long: "--format FORMATTER", + description: "output format to use", + proc: lambda { |format| Chef::Config.add_formatter(format) } option :force_logger, - :long => "--force-logger", - :description => "Use logger output instead of formatter output", - :boolean => true, - :default => false + long: "--force-logger", + description: "Use logger output instead of formatter output", + boolean: true, + default: false option :force_formatter, - :long => "--force-formatter", - :description => "Use formatter output instead of logger output", - :boolean => true, - :default => false + long: "--force-formatter", + description: "Use formatter output instead of logger output", + boolean: true, + default: false option :profile_ruby, - :long => "--[no-]profile-ruby", - :description => "Dump complete Ruby call graph stack of entire Chef run (expert only)", - :boolean => true, - :default => false + long: "--[no-]profile-ruby", + description: "Dump complete Ruby call graph stack of entire Chef run (expert only)", + boolean: true, + default: false option :color, - :long => "--[no-]color", - :boolean => true, - :default => !Chef::Platform.windows?, - :description => "Use colored output, defaults to enabled" + long: "--[no-]color", + boolean: true, + default: !Chef::Platform.windows?, + description: "Use colored output, defaults to enabled" option :log_level, - :short => "-l LEVEL", - :long => "--log_level LEVEL", - :description => "Set the log level (trace, debug, info, warn, error, fatal)", - :proc => lambda { |l| l.to_sym } + short: "-l LEVEL", + long: "--log_level LEVEL", + description: "Set the log level (trace, debug, info, warn, error, fatal)", + proc: lambda { |l| l.to_sym } option :log_location, - :short => "-L LOGLOCATION", - :long => "--logfile LOGLOCATION", - :description => "Set the log file location, defaults to STDOUT", - :proc => nil + short: "-L LOGLOCATION", + long: "--logfile LOGLOCATION", + description: "Set the log file location, defaults to STDOUT", + proc: nil option :help, - :short => "-h", - :long => "--help", - :description => "Show this message", - :on => :tail, - :boolean => true, - :show_options => true, - :exit => 0 + short: "-h", + long: "--help", + description: "Show this message", + on: :tail, + boolean: true, + show_options: true, + exit: 0 option :user, - :short => "-u USER", - :long => "--user USER", - :description => "User to set privilege to", - :proc => nil + short: "-u USER", + long: "--user USER", + description: "User to set privilege to", + proc: nil option :group, - :short => "-g GROUP", - :long => "--group GROUP", - :description => "Group to set privilege to", - :proc => nil + short: "-g GROUP", + long: "--group GROUP", + description: "Group to set privilege to", + proc: nil unless Chef::Platform.windows? option :daemonize, - :short => "-d", - :long => "--daemonize", - :description => "Daemonize the process", - :proc => lambda { |p| true } + short: "-d", + long: "--daemonize", + description: "Daemonize the process", + proc: lambda { |p| true } end option :lockfile, - :long => "--lockfile LOCKFILE", - :description => "Set the lockfile location. Prevents multiple processes from converging at the same time", - :proc => nil + long: "--lockfile LOCKFILE", + description: "Set the lockfile location. Prevents multiple processes from converging at the same time", + proc: nil option :interval, - :short => "-i SECONDS", - :long => "--interval SECONDS", - :description => "Run chef-client periodically, in seconds", - :proc => lambda { |s| s.to_i } + short: "-i SECONDS", + long: "--interval SECONDS", + description: "Run chef-client periodically, in seconds", + proc: lambda { |s| s.to_i } option :json_attribs, - :short => "-j JSON_ATTRIBS", - :long => "--json-attributes JSON_ATTRIBS", - :description => "Load attributes from a JSON file or URL", - :proc => nil + short: "-j JSON_ATTRIBS", + long: "--json-attributes JSON_ATTRIBS", + description: "Load attributes from a JSON file or URL", + proc: nil option :node_name, - :short => "-N NODE_NAME", - :long => "--node-name NODE_NAME", - :description => "The node name for this client", - :proc => nil + short: "-N NODE_NAME", + long: "--node-name NODE_NAME", + description: "The node name for this client", + proc: nil option :splay, - :short => "-s SECONDS", - :long => "--splay SECONDS", - :description => "The splay time for running at intervals, in seconds", - :proc => lambda { |s| s.to_i } + short: "-s SECONDS", + long: "--splay SECONDS", + description: "The splay time for running at intervals, in seconds", + proc: lambda { |s| s.to_i } option :recipe_url, - :short => "-r RECIPE_URL", - :long => "--recipe-url RECIPE_URL", - :description => "Pull down a remote gzipped tarball of recipes and untar it to the cookbook cache." + short: "-r RECIPE_URL", + long: "--recipe-url RECIPE_URL", + description: "Pull down a remote gzipped tarball of recipes and untar it to the cookbook cache." option :version, - :short => "-v", - :long => "--version", - :description => "Show chef version", - :boolean => true, - :proc => lambda { |v| puts "Chef: #{::Chef::VERSION}" }, - :exit => 0 + short: "-v", + long: "--version", + description: "Show chef version", + boolean: true, + proc: lambda { |v| puts "Chef: #{::Chef::VERSION}" }, + exit: 0 option :override_runlist, - :short => "-o RunlistItem,RunlistItem...", - :long => "--override-runlist RunlistItem,RunlistItem...", - :description => "Replace current run list with specified items", - :proc => lambda { |items| + short: "-o RunlistItem,RunlistItem...", + long: "--override-runlist RunlistItem,RunlistItem...", + description: "Replace current run list with specified items", + proc: lambda { |items| items = items.split(",") items.compact.map do |item| Chef::RunList::RunListItem.new(item) @@ -173,45 +173,45 @@ class Chef::Application::Solo < Chef::Application } option :client_fork, - :short => "-f", - :long => "--[no-]fork", - :description => "Fork client" + short: "-f", + long: "--[no-]fork", + description: "Fork client" option :why_run, - :short => "-W", - :long => "--why-run", - :description => "Enable whyrun mode", - :boolean => true + short: "-W", + long: "--why-run", + description: "Enable whyrun mode", + boolean: true option :ez, - :long => "--ez", - :description => "A memorial for Ezra Zygmuntowicz", - :boolean => true + long: "--ez", + description: "A memorial for Ezra Zygmuntowicz", + boolean: true option :environment, - :short => "-E ENVIRONMENT", - :long => "--environment ENVIRONMENT", - :description => "Set the Chef Environment on the node" + short: "-E ENVIRONMENT", + long: "--environment ENVIRONMENT", + description: "Set the Chef Environment on the node" option :run_lock_timeout, - :long => "--run-lock-timeout SECONDS", - :description => "Set maximum duration to wait for another client run to finish, default is indefinitely.", - :proc => lambda { |s| s.to_i } + long: "--run-lock-timeout SECONDS", + description: "Set maximum duration to wait for another client run to finish, default is indefinitely.", + proc: lambda { |s| s.to_i } option :minimal_ohai, - :long => "--minimal-ohai", - :description => "Only run the bare minimum ohai plugins chef needs to function", - :boolean => true + long: "--minimal-ohai", + description: "Only run the bare minimum ohai plugins chef needs to function", + boolean: true option :delete_entire_chef_repo, - :long => "--delete-entire-chef-repo", - :description => "DANGEROUS: does what it says, only useful with --recipe-url", - :boolean => true + long: "--delete-entire-chef-repo", + description: "DANGEROUS: does what it says, only useful with --recipe-url", + boolean: true option :solo_legacy_mode, - :long => "--legacy-mode", - :description => "Run chef-solo in legacy mode", - :boolean => true + long: "--legacy-mode", + description: "Run chef-solo in legacy mode", + boolean: true attr_reader :chef_client_json @@ -273,7 +273,7 @@ class Chef::Application::Solo < Chef::Application if Chef::Config[:delete_entire_chef_repo] Chef::Log.trace "Cleanup path #{recipes_path} before extract recipes into it" - FileUtils.rm_rf(recipes_path, :secure => true) + FileUtils.rm_rf(recipes_path, secure: true) end Chef::Log.trace "Creating path #{recipes_path} to extract recipes into" FileUtils.mkdir_p(recipes_path) @@ -315,12 +315,12 @@ class Chef::Application::Solo < Chef::Application private def for_ezra - puts <<-EOH -For Ezra Zygmuntowicz: - The man who brought you Chef Solo - Early contributor to Chef - Kind hearted open source advocate - Rest in peace, Ezra. + puts <<~EOH + For Ezra Zygmuntowicz: + The man who brought you Chef Solo + Early contributor to Chef + Kind hearted open source advocate + Rest in peace, Ezra. EOH end @@ -370,7 +370,7 @@ EOH def unforked_interval_error_message "Unforked chef-client interval runs are disabled in Chef 12." + "\nConfiguration settings:" + - "#{"\n interval = #{Chef::Config[:interval]} seconds" if Chef::Config[:interval]}" + + ("\n interval = #{Chef::Config[:interval]} seconds" if Chef::Config[:interval]).to_s + "\nEnable chef-client interval runs by setting `:client_fork = true` in your config file or adding `--fork` to your command line options." end end diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 41dcc55d70..5fe4dbb9b7 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -37,27 +37,27 @@ class Chef include Chef::Mixin::ShellOut option :config_file, - :short => "-c CONFIG", - :long => "--config CONFIG", - :default => "#{ENV['SYSTEMDRIVE']}/chef/client.rb", - :description => "" + short: "-c CONFIG", + long: "--config CONFIG", + default: "#{ENV['SYSTEMDRIVE']}/chef/client.rb", + description: "" option :log_location, - :short => "-L LOGLOCATION", - :long => "--logfile LOGLOCATION", - :description => "Set the log file location" + short: "-L LOGLOCATION", + long: "--logfile LOGLOCATION", + description: "Set the log file location" option :splay, - :short => "-s SECONDS", - :long => "--splay SECONDS", - :description => "The splay time for running at intervals, in seconds", - :proc => lambda { |s| s.to_i } + short: "-s SECONDS", + long: "--splay SECONDS", + description: "The splay time for running at intervals, in seconds", + proc: lambda { |s| s.to_i } option :interval, - :short => "-i SECONDS", - :long => "--interval SECONDS", - :description => "Set the number of seconds to wait between chef-client runs", - :proc => lambda { |s| s.to_i } + short: "-i SECONDS", + long: "--interval SECONDS", + description: "Set the number of seconds to wait between chef-client runs", + proc: lambda { |s| s.to_i } DEFAULT_LOG_LOCATION ||= "#{ENV['SYSTEMDRIVE']}/chef/client.log" @@ -197,11 +197,11 @@ class Chef result = shell_out( "chef-client.bat #{config_params}", - :timeout => Chef::Config[:windows_service][:watchdog_timeout], - :logger => Chef::Log + timeout: Chef::Config[:windows_service][:watchdog_timeout], + logger: Chef::Log ) - Chef::Log.trace "#{result.stdout}" - Chef::Log.trace "#{result.stderr}" + Chef::Log.trace (result.stdout).to_s + Chef::Log.trace (result.stderr).to_s rescue Mixlib::ShellOut::CommandTimeout => e Chef::Log.error "chef-client timed out\n(#{e})" Chef::Log.error(<<-EOF) diff --git a/lib/chef/application/windows_service_manager.rb b/lib/chef/application/windows_service_manager.rb index 5c572bc260..bff4a7511a 100644 --- a/lib/chef/application/windows_service_manager.rb +++ b/lib/chef/application/windows_service_manager.rb @@ -37,38 +37,38 @@ class Chef include Mixlib::CLI option :action, - :short => "-a ACTION", - :long => "--action ACTION", - :default => "status", - :description => "Action to carry out on chef-service (install, uninstall, status, start, stop, pause, or resume)" + short: "-a ACTION", + long: "--action ACTION", + default: "status", + description: "Action to carry out on chef-service (install, uninstall, status, start, stop, pause, or resume)" option :config_file, - :short => "-c CONFIG", - :long => "--config CONFIG", - :default => "#{ENV['SYSTEMDRIVE']}/chef/client.rb", - :description => "The configuration file to use for chef runs" + short: "-c CONFIG", + long: "--config CONFIG", + default: "#{ENV['SYSTEMDRIVE']}/chef/client.rb", + description: "The configuration file to use for chef runs" option :log_location, - :short => "-L LOGLOCATION", - :long => "--logfile LOGLOCATION", - :description => "Set the log file location for chef-service" + short: "-L LOGLOCATION", + long: "--logfile LOGLOCATION", + description: "Set the log file location for chef-service" option :help, - :short => "-h", - :long => "--help", - :description => "Show this message", - :on => :tail, - :boolean => true, - :show_options => true, - :exit => 0 + short: "-h", + long: "--help", + description: "Show this message", + on: :tail, + boolean: true, + show_options: true, + exit: 0 option :version, - :short => "-v", - :long => "--version", - :description => "Show chef version", - :boolean => true, - :proc => lambda { |v| puts "Chef: #{::Chef::VERSION}" }, - :exit => 0 + short: "-v", + long: "--version", + description: "Show chef version", + boolean: true, + proc: lambda { |v| puts "Chef: #{::Chef::VERSION}" }, + exit: 0 def initialize(service_options) # having to call super in initialize is the most annoying @@ -114,22 +114,22 @@ class Chef cmd = "\"#{ruby}\" \"#{@service_file_path}\" #{opts}".gsub(File::SEPARATOR, File::ALT_SEPARATOR) ::Win32::Service.new( - :service_name => @service_name, - :display_name => @service_display_name, - :description => @service_description, + service_name: @service_name, + display_name: @service_display_name, + description: @service_description, # Prior to 0.8.5, win32-service creates interactive services by default, # and we don't want that, so we need to override the service type. - :service_type => ::Win32::Service::SERVICE_WIN32_OWN_PROCESS, - :start_type => ::Win32::Service::SERVICE_AUTO_START, - :binary_path_name => cmd, - :service_start_name => @service_start_name, - :password => @password, - :dependencies => @dependencies + service_type: ::Win32::Service::SERVICE_WIN32_OWN_PROCESS, + start_type: ::Win32::Service::SERVICE_AUTO_START, + binary_path_name: cmd, + service_start_name: @service_start_name, + password: @password, + dependencies: @dependencies ) unless @delayed_start.nil? ::Win32::Service.configure( - :service_name => @service_name, - :delayed_start => @delayed_start + service_name: @service_name, + delayed_start: @delayed_start ) end puts "Service '#{@service_name}' has successfully been installed." diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb index e2e6ab1ede..1cb8545d28 100644 --- a/lib/chef/audit/audit_event_proxy.rb +++ b/lib/chef/audit/audit_event_proxy.rb @@ -79,12 +79,12 @@ class Chef outermost_group_desc = describe_groups.shift [outermost_group_desc, { - :name => example.description, - :desc => example.full_description, - :resource_type => resource_type, - :resource_name => resource_name, - :context => describe_groups, - :line_number => example.metadata[:line_number], + name: example.description, + desc: example.full_description, + resource_type: resource_type, + resource_name: resource_name, + context: describe_groups, + line_number: example.metadata[:line_number], }] end diff --git a/lib/chef/audit/control_group_data.rb b/lib/chef/audit/control_group_data.rb index 476ebe95e9..8825860023 100644 --- a/lib/chef/audit/control_group_data.rb +++ b/lib/chef/audit/control_group_data.rb @@ -37,11 +37,11 @@ class Chef def to_hash { - :node_name => node_name, - :run_id => run_id, - :start_time => start_time, - :end_time => end_time, - :control_groups => control_groups.collect { |c| c.to_hash }, + node_name: node_name, + run_id: run_id, + start_time: start_time, + end_time: end_time, + control_groups: control_groups.collect { |c| c.to_hash }, } end end @@ -81,11 +81,11 @@ class Chef # they appeared in the recipe controls.sort! { |x, y| x.line_number <=> y.line_number } h = { - :name => name, - :status => status, - :number_succeeded => number_succeeded, - :number_failed => number_failed, - :controls => controls.collect { |c| c.to_hash }, + name: name, + status: status, + number_succeeded: number_succeeded, + number_failed: number_failed, + controls: controls.collect { |c| c.to_hash }, } # If there is a duplicate key, metadata will overwrite it add_display_only_data(h).merge(metadata) @@ -124,11 +124,11 @@ class Chef def to_hash h = { - :name => name, - :status => status, - :details => details, - :resource_type => resource_type, - :resource_name => resource_name, + name: name, + status: status, + details: details, + resource_type: resource_type, + resource_name: resource_name, } h[:context] = context || [] h diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb index f6fed3fc64..847d5efbd5 100644 --- a/lib/chef/audit/runner.rb +++ b/lib/chef/audit/runner.rb @@ -148,7 +148,7 @@ class Chef def configure_specinfra if Chef::Platform.windows? Specinfra.configuration.backend = :cmd - Specinfra.configuration.os = { :family => "windows" } + Specinfra.configuration.os = { family: "windows" } else Specinfra.configuration.backend = :exec end diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 697c2db232..c42f08a462 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -537,9 +537,9 @@ class Chef if chef_fs.versioned_cookbooks || path[0] == "cookbook_artifacts" result = with_entry([ path[0] ]) do |entry| # list /cookbooks/name = filter /cookbooks/name-version down to name - entry.children.map { |child| split_name_version(child.name) }. - select { |name, version| name == path[1] }. - map { |name, version| version } + entry.children.map { |child| split_name_version(child.name) } + .select { |name, version| name == path[1] } + .map { |name, version| version } end if result.empty? raise ChefZero::DataStore::DataNotFoundError.new(path) diff --git a/lib/chef/chef_fs/config.rb b/lib/chef/chef_fs/config.rb index 0725426275..2a41fb5870 100644 --- a/lib/chef/chef_fs/config.rb +++ b/lib/chef/chef_fs/config.rb @@ -173,7 +173,7 @@ class Chef def create_chef_fs require "chef/chef_fs/file_system/chef_server/chef_server_root_dir" - Chef::ChefFS::FileSystem::ChefServer::ChefServerRootDir.new("remote", @chef_config, :cookbook_version => @cookbook_version) + Chef::ChefFS::FileSystem::ChefServer::ChefServerRootDir.new("remote", @chef_config, cookbook_version: @cookbook_version) end def local_fs diff --git a/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb b/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb index 63ce71ef40..3447e3500a 100644 --- a/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb @@ -99,7 +99,7 @@ class Chef end def rest - Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key, :raw_output => true, :api_version => "0") + Chef::ServerAPI.new(chef_server_url, client_name: chef_username, signing_key_filename: chef_private_key, raw_output: true, api_version: "0") end def get_json(path) @@ -107,7 +107,7 @@ class Chef end def chef_rest - Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key, :api_version => "0") + Chef::ServerAPI.new(chef_server_url, client_name: chef_username, signing_key_filename: chef_private_key, api_version: "0") end def api_path diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb index 4e8e68e364..e0eca5f6de 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb @@ -74,7 +74,7 @@ class Chef def upload_cookbook(other, options) cookbook_to_upload = other.chef_object cookbook_to_upload.freeze_version if options[:freeze] - uploader = Chef::CookbookUploader.new(cookbook_to_upload, :force => options[:force], :rest => chef_rest) + uploader = Chef::CookbookUploader.new(cookbook_to_upload, force: options[:force], rest: chef_rest) with_actual_cookbooks_dir(other.parent.file_path) do uploader.upload_cookbooks diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb index adaffb99a7..344a3deecc 100644 --- a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb @@ -40,7 +40,7 @@ class Chef end def write(contents) - desired_invites = minimize_value(Chef::JSONCompat.parse(contents, :create_additions => false)) + desired_invites = minimize_value(Chef::JSONCompat.parse(contents, create_additions: false)) actual_invites = _read_json.inject({}) { |h, val| h[val["username"]] = val["id"]; h } invites = actual_invites.keys (desired_invites - invites).each do |invite| diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb index 7e9c7141c4..a780ddd97b 100644 --- a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb @@ -40,7 +40,7 @@ class Chef end def write(contents) - desired_members = minimize_value(Chef::JSONCompat.parse(contents, :create_additions => false)) + desired_members = minimize_value(Chef::JSONCompat.parse(contents, create_additions: false)) members = minimize_value(_read_json) (desired_members - members).each do |member| begin diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb index c16c5ad4d7..876ad7282b 100644 --- a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb @@ -177,7 +177,7 @@ class Chef if data_handler object = data_handler.normalize_for_put(object, self) data_handler.verify_integrity(object, self) do |error| - raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, nil, "#{error}") + raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, nil, error.to_s) end end diff --git a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb index 8da3718136..94c1a5b695 100644 --- a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb @@ -78,7 +78,7 @@ class Chef cookbook_to_upload.freeze_version if options[:freeze] # Instantiate a new uploader based on the proxy loader - uploader = Chef::CookbookUploader.new(cookbook_to_upload, :force => options[:force], :rest => chef_rest) + uploader = Chef::CookbookUploader.new(cookbook_to_upload, force: options[:force], rest: chef_rest) with_actual_cookbooks_dir(temp_cookbooks_path) do uploader.upload_cookbooks diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb index b296901dd1..8e64e3ca06 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb @@ -64,7 +64,7 @@ class Chef def write(cookbook_path, cookbook_version_json, from_fs) # Use the copy/diff algorithm to copy it down so we don't destroy # chefignored data. This is terribly un-thread-safe. - Chef::ChefFS::FileSystem.copy_to(Chef::ChefFS::FilePattern.new("/#{cookbook_path}"), from_fs, self, nil, { :purge => true }) + Chef::ChefFS::FileSystem.copy_to(Chef::ChefFS::FilePattern.new("/#{cookbook_path}"), from_fs, self, nil, { purge: true }) # Write out .uploaded-cookbook-version.json # cookbook_file_path = File.join(file_path, cookbook_name) <- this should be the same as self.file_path diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb index 90b8c88cff..c840fad126 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb @@ -52,9 +52,9 @@ class Chef end def children - entries = Dir.entries(file_path).sort. - map { |child_name| make_child_entry(child_name) }. - select { |child| child && can_have_child?(child.name, child.dir?) } + entries = Dir.entries(file_path).sort + .map { |child_name| make_child_entry(child_name) } + .select { |child| child && can_have_child?(child.name, child.dir?) } entries.select { |entry| !(entry.dir? && entry.children.size == 0 ) } rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) diff --git a/lib/chef/chef_fs/file_system/repository/directory.rb b/lib/chef/chef_fs/file_system/repository/directory.rb index 328cf92b03..d3f8d84324 100644 --- a/lib/chef/chef_fs/file_system/repository/directory.rb +++ b/lib/chef/chef_fs/file_system/repository/directory.rb @@ -71,9 +71,9 @@ class Chef def children return FileSystemCache.instance.children(file_path) if FileSystemCache.instance.exist?(file_path) - children = dir_ls.sort. - map { |child_name| make_child_entry(child_name) }. - select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } + children = dir_ls.sort + .map { |child_name| make_child_entry(child_name) } + .select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } FileSystemCache.instance.set_children(file_path, children) rescue Errno::ENOENT => e raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) diff --git a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb index 45ae002521..183fcda26d 100644 --- a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb @@ -80,9 +80,9 @@ class Chef def children # Except cookbooks and data bag dirs, all things must be json files - Dir.entries(file_path).sort. - map { |child_name| make_child_entry(child_name) }. - select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } + Dir.entries(file_path).sort + .map { |child_name| make_child_entry(child_name) } + .select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb index 1731e19ce1..36445e5680 100644 --- a/lib/chef/chef_fs/knife.rb +++ b/lib/chef/chef_fs/knife.rb @@ -45,16 +45,16 @@ class Chef end option :repo_mode, - :long => "--repo-mode MODE", - :description => "Specifies the local repository layout. Values: static, everything, hosted_everything. Default: everything/hosted_everything" + long: "--repo-mode MODE", + description: "Specifies the local repository layout. Values: static, everything, hosted_everything. Default: everything/hosted_everything" option :chef_repo_path, - :long => "--chef-repo-path PATH", - :description => "Overrides the location of chef repo. Default is specified by chef_repo_path in the config" + long: "--chef-repo-path PATH", + description: "Overrides the location of chef repo. Default is specified by chef_repo_path in the config" option :concurrency, - :long => "--concurrency THREADS", - :description => "Maximum number of simultaneous requests to send (default: 10)" + long: "--concurrency THREADS", + description: "Maximum number of simultaneous requests to send (default: 10)" def configure_chef super diff --git a/lib/chef/chef_fs/parallelizer.rb b/lib/chef/chef_fs/parallelizer.rb index 32de61e048..eee555fc93 100644 --- a/lib/chef/chef_fs/parallelizer.rb +++ b/lib/chef/chef_fs/parallelizer.rb @@ -45,7 +45,7 @@ class Chef end def parallel_do(enumerable, options = {}, &block) - ParallelEnumerable.new(@tasks, enumerable, options.merge(:ordered => false), &block).wait + ParallelEnumerable.new(@tasks, enumerable, options.merge(ordered: false), &block).wait end def stop(wait = true, timeout = nil) diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index b139a8d489..c864c30505 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -34,7 +34,7 @@ class Chef @relative_path = /#{Regexp.escape(@cookbook_path)}\/(.+)$/ @metadata_loaded = false @cookbook_settings = { - :all_files => {}, + all_files: {}, } @metadata_filenames = [] diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index c378cb75b6..03e2d7a090 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -61,10 +61,10 @@ class Chef :source_url, :issues_url, :privacy, :chef_versions, :ohai_versions, :gems ] - VERSION_CONSTRAINTS = { :depends => DEPENDENCIES, - :provides => PROVIDING, - :chef_version => CHEF_VERSIONS, - :ohai_version => OHAI_VERSIONS } + VERSION_CONSTRAINTS = { depends: DEPENDENCIES, + provides: PROVIDING, + chef_version: CHEF_VERSIONS, + ohai_version: OHAI_VERSIONS } include Chef::Mixin::ParamsValidate include Chef::Mixin::FromFile @@ -161,7 +161,7 @@ class Chef set_or_return( :maintainer, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -176,7 +176,7 @@ class Chef set_or_return( :maintainer_email, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -191,7 +191,7 @@ class Chef set_or_return( :license, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -206,7 +206,7 @@ class Chef set_or_return( :description, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -221,7 +221,7 @@ class Chef set_or_return( :long_description, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -252,7 +252,7 @@ class Chef set_or_return( :name, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -409,17 +409,17 @@ class Chef validate( options, { - :display_name => { :kind_of => String }, - :description => { :kind_of => String }, - :choice => { :kind_of => [ Array ], :default => [] }, - :calculated => { :equal_to => [ true, false ], :default => false }, - :type => { :equal_to => %w{string array hash symbol boolean numeric}, :default => "string" }, - :required => { :equal_to => [ "required", "recommended", "optional", true, false ], :default => "optional" }, - :recipes => { :kind_of => [ Array ], :default => [] }, - :default => { :kind_of => [ String, Array, Hash, Symbol, Numeric, TrueClass, FalseClass ] }, - :source_url => { :kind_of => String }, - :issues_url => { :kind_of => String }, - :privacy => { :kind_of => [ TrueClass, FalseClass ] }, + display_name: { kind_of: String }, + description: { kind_of: String }, + choice: { kind_of: [ Array ], default: [] }, + calculated: { equal_to: [ true, false ], default: false }, + type: { equal_to: %w{string array hash symbol boolean numeric}, default: "string" }, + required: { equal_to: [ "required", "recommended", "optional", true, false ], default: "optional" }, + recipes: { kind_of: [ Array ], default: [] }, + default: { kind_of: [ String, Array, Hash, Symbol, Numeric, TrueClass, FalseClass ] }, + source_url: { kind_of: String }, + issues_url: { kind_of: String }, + privacy: { kind_of: [ TrueClass, FalseClass ] }, } ) options[:required] = remap_required_attribute(options[:required]) unless options[:required].nil? @@ -556,7 +556,7 @@ class Chef set_or_return( :source_url, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -571,7 +571,7 @@ class Chef set_or_return( :issues_url, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -588,7 +588,7 @@ class Chef set_or_return( :privacy, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -649,14 +649,14 @@ class Chef elsif version_constraints.size == 1 version_constraints.first else - msg = <<-OBSOLETED -The dependency specification syntax you are using is no longer valid. You may not -specify more than one version constraint for a particular cookbook. -Consult https://docs.chef.io/config_rb_metadata.html for the updated syntax. - -Called by: #{caller_name} '#{dep_name}', #{version_constraints.map { |vc| vc.inspect }.join(", ")} -Called from: -#{caller[0...5].map { |line| " " + line }.join("\n")} + msg = <<~OBSOLETED + The dependency specification syntax you are using is no longer valid. You may not + specify more than one version constraint for a particular cookbook. + Consult https://docs.chef.io/config_rb_metadata.html for the updated syntax. + + Called by: #{caller_name} '#{dep_name}', #{version_constraints.map { |vc| vc.inspect }.join(", ")} + Called from: + #{caller[0...5].map { |line| " " + line }.join("\n")} OBSOLETED raise Exceptions::ObsoleteDependencySyntax, msg end @@ -667,15 +667,15 @@ OBSOLETED rescue Chef::Exceptions::InvalidVersionConstraint => e Log.debug(e) - msg = <<-INVALID -The version constraint syntax you are using is not valid. If you recently -upgraded to Chef 0.10.0, be aware that you no may longer use "<<" and ">>" for -'less than' and 'greater than'; use '<' and '>' instead. -Consult https://docs.chef.io/config_rb_metadata.html for more information. + msg = <<~INVALID + The version constraint syntax you are using is not valid. If you recently + upgraded to Chef 0.10.0, be aware that you no may longer use "<<" and ">>" for + 'less than' and 'greater than'; use '<' and '>' instead. + Consult https://docs.chef.io/config_rb_metadata.html for more information. -Called by: #{caller_name} '#{dep_name}', '#{constraint_str}' -Called from: -#{caller[0...5].map { |line| " " + line }.join("\n")} + Called by: #{caller_name} '#{dep_name}', '#{constraint_str}' + Called from: + #{caller[0...5].map { |line| " " + line }.join("\n")} INVALID raise Exceptions::InvalidVersionConstraint, msg end @@ -689,7 +689,7 @@ INVALID def validate_string_array(arry) if arry.kind_of?(Array) arry.each do |choice| - validate( { :choice => choice }, { :choice => { :kind_of => String } } ) + validate( { choice: choice }, { choice: { kind_of: String } } ) end end end @@ -717,7 +717,7 @@ INVALID end opts[:choice].each do |choice| - validate( { :choice => choice }, { :choice => { :kind_of => validator } } ) + validate( { choice: choice }, { choice: { kind_of: validator } } ) end end end diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb index 6df39fece3..6955abd6d7 100644 --- a/lib/chef/cookbook/synchronizer.rb +++ b/lib/chef/cookbook/synchronizer.rb @@ -143,7 +143,7 @@ class Chef end # Synchronizes all the cookbooks from the chef-server. - #) + # ) # === Returns # true:: Always returns true def sync_cookbooks diff --git a/lib/chef/cookbook_manifest.rb b/lib/chef/cookbook_manifest.rb index 9adcee6b78..c0c5b57a60 100644 --- a/lib/chef/cookbook_manifest.rb +++ b/lib/chef/cookbook_manifest.rb @@ -236,13 +236,13 @@ class Chef csum = checksum_cookbook_file(file) @checksums[csum] = file rs = Mash.new({ - :name => name, - :path => path, - :checksum => csum, - :specificity => specificity, + name: name, + path: path, + checksum: csum, + specificity: specificity, # full_path is not a part of the normal manifest, but is very useful to keep around. # uploaders should strip this out. - :full_path => file, + full_path: file, }) manifest[:all_files] << rs diff --git a/lib/chef/cookbook_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb index e4b45532f0..8611357e1a 100644 --- a/lib/chef/cookbook_site_streaming_uploader.rb +++ b/lib/chef/cookbook_site_streaming_uploader.rb @@ -115,10 +115,10 @@ class Chef content_file.rewind if content_file # we consumed the file for the above operation, so rewind it. signing_options = { - :http_method => http_verb, - :path => url.path, - :user_id => user_id, - :timestamp => timestamp } + http_method: http_verb, + path: url.path, + user_id: user_id, + timestamp: timestamp } (content_file && signing_options[:file] = content_file) || (signing_options[:body] = (content_body || "")) headers.merge!(Mixlib::Authentication::SignedHeaderAuth.signing_object(signing_options).sign(secret_key)) diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb index e79a7774eb..5780c61cc9 100644 --- a/lib/chef/cookbook_uploader.rb +++ b/lib/chef/cookbook_uploader.rb @@ -56,7 +56,7 @@ class Chef end checksums = checksum_files.inject({}) { |memo, elt| memo[elt.first] = nil; memo } - new_sandbox = rest.post("sandboxes", { :checksums => checksums }) + new_sandbox = rest.post("sandboxes", { checksums: checksums }) Chef::Log.info("Uploading files") @@ -83,7 +83,7 @@ class Chef # in eventual consistency) retries = 0 begin - rest.put(sandbox_url, { :is_completed => true }) + rest.put(sandbox_url, { is_completed: true }) rescue Net::HTTPServerException => e if e.message =~ /^400/ && (retries += 1) <= 5 sleep 2 diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb index c5e2b38c94..9a71d89abb 100644 --- a/lib/chef/data_bag.rb +++ b/lib/chef/data_bag.rb @@ -54,7 +54,7 @@ class Chef set_or_return( :name, arg, - :regex => VALID_NAME + regex: VALID_NAME ) end @@ -157,7 +157,7 @@ class Chef self end - #create a data bag via RESTful API + # create a data bag via RESTful API def create chef_server_rest.post("data", self) self diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb index 388da78dad..01ec4cf77e 100644 --- a/lib/chef/data_bag_item.rb +++ b/lib/chef/data_bag_item.rb @@ -81,7 +81,7 @@ class Chef set_or_return( :data_bag, arg, - :regex => /^[\-[:alnum:]_]+$/ + regex: /^[\-[:alnum:]_]+$/ ) end diff --git a/lib/chef/dsl/reboot_pending.rb b/lib/chef/dsl/reboot_pending.rb index 2ebad7e039..1dc0a8d41b 100644 --- a/lib/chef/dsl/reboot_pending.rb +++ b/lib/chef/dsl/reboot_pending.rb @@ -37,7 +37,7 @@ class Chef # due to a file being in use (usually a temporary file and a system file) # \??\c:\temp\test.sys!\??\c:\winnt\system32\test.sys # http://technet.microsoft.com/en-us/library/cc960241.aspx - registry_value_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager', { :name => "PendingFileRenameOperations" }) || + registry_value_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager', { name: "PendingFileRenameOperations" }) || # RebootRequired key contains Update IDs with a value of 1 if they require a reboot. # The existence of RebootRequired alone is sufficient on my Windows 8.1 workstation in Windows Update diff --git a/lib/chef/encrypted_data_bag_item/encryptor.rb b/lib/chef/encrypted_data_bag_item/encryptor.rb index 8d34033db6..21783503f4 100644 --- a/lib/chef/encrypted_data_bag_item/encryptor.rb +++ b/lib/chef/encrypted_data_bag_item/encryptor.rb @@ -123,7 +123,7 @@ class Chef::EncryptedDataBagItem # Strings) that do not produce valid JSON when serialized without the # wrapper. def serialized_data - FFI_Yajl::Encoder.encode(:json_wrapper => plaintext_data) + FFI_Yajl::Encoder.encode(json_wrapper: plaintext_data) end def self.encryptor_keys diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index be05b58989..61777fb7b4 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -57,7 +57,7 @@ class Chef set_or_return( :name, arg, - { :regex => /^[\-[:alnum:]_]+$/, :kind_of => String } + { regex: /^[\-[:alnum:]_]+$/, kind_of: String } ) end @@ -65,7 +65,7 @@ class Chef set_or_return( :description, arg, - :kind_of => String + kind_of: String ) end @@ -73,7 +73,7 @@ class Chef set_or_return( :default_attributes, arg, - :kind_of => Hash + kind_of: Hash ) end @@ -85,7 +85,7 @@ class Chef set_or_return( :override_attributes, arg, - :kind_of => Hash + kind_of: Hash ) end @@ -98,8 +98,8 @@ class Chef :cookbook_versions, arg, { - :kind_of => Hash, - :callbacks => { + kind_of: Hash, + callbacks: { "should be a valid set of cookbook version requirements" => lambda { |cv| Chef::Environment.validate_cookbook_versions(cv) }, }, } @@ -108,10 +108,10 @@ class Chef def cookbook(cookbook, version) validate({ - :version => version, + version: version, }, { - :version => { - :callbacks => { "should be a valid version requirement" => lambda { |v| Chef::Environment.validate_cookbook_version(v) } }, + version: { + callbacks: { "should be a valid version requirement" => lambda { |v| Chef::Environment.validate_cookbook_version(v) } }, }, }) @cookbook_versions[cookbook] = version diff --git a/lib/chef/event_loggers/windows_eventlog.rb b/lib/chef/event_loggers/windows_eventlog.rb index 1ff87945e7..860d049314 100644 --- a/lib/chef/event_loggers/windows_eventlog.rb +++ b/lib/chef/event_loggers/windows_eventlog.rb @@ -47,36 +47,36 @@ class Chef def run_start(version) @eventlog.report_event( - :event_type => ::Win32::EventLog::INFO_TYPE, - :source => SOURCE, - :event_id => RUN_START_EVENT_ID, - :data => [version] + event_type: ::Win32::EventLog::INFO_TYPE, + source: SOURCE, + event_id: RUN_START_EVENT_ID, + data: [version] ) end def run_started(run_status) @run_status = run_status @eventlog.report_event( - :event_type => ::Win32::EventLog::INFO_TYPE, - :source => SOURCE, - :event_id => RUN_STARTED_EVENT_ID, - :data => [run_status.run_id] + event_type: ::Win32::EventLog::INFO_TYPE, + source: SOURCE, + event_id: RUN_STARTED_EVENT_ID, + data: [run_status.run_id] ) end def run_completed(node) @eventlog.report_event( - :event_type => ::Win32::EventLog::INFO_TYPE, - :source => SOURCE, - :event_id => RUN_COMPLETED_EVENT_ID, - :data => [@run_status.run_id, @run_status.elapsed_time.to_s] + event_type: ::Win32::EventLog::INFO_TYPE, + source: SOURCE, + event_id: RUN_COMPLETED_EVENT_ID, + data: [@run_status.run_id, @run_status.elapsed_time.to_s] ) end - #Failed chef-client run %1 in %2 seconds. - #Exception type: %3 - #Exception message: %4 - #Exception backtrace: %5 + # Failed chef-client run %1 in %2 seconds. + # Exception type: %3 + # Exception message: %4 + # Exception backtrace: %5 def run_failed(e) data = if @run_status @@ -87,10 +87,10 @@ class Chef end @eventlog.report_event( - :event_type => ::Win32::EventLog::ERROR_TYPE, - :source => SOURCE, - :event_id => RUN_FAILED_EVENT_ID, - :data => data + [e.class.name, + event_type: ::Win32::EventLog::ERROR_TYPE, + source: SOURCE, + event_id: RUN_FAILED_EVENT_ID, + data: data + [e.class.name, e.message, e.backtrace.join("\n")] ) diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index 1ed71d2a55..ca388d33cd 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -398,9 +398,9 @@ class Chef # length declared in the http response. class ContentLengthMismatch < RuntimeError def initialize(response_length, content_length) - super <<-EOF -Response body length #{response_length} does not match HTTP Content-Length header #{content_length}. -This error is most often caused by network issues (proxies, etc) outside of chef-client. + super <<~EOF + Response body length #{response_length} does not match HTTP Content-Length header #{content_length}. + This error is most often caused by network issues (proxies, etc) outside of chef-client. EOF end end diff --git a/lib/chef/file_cache.rb b/lib/chef/file_cache.rb index 8e9bb1e3e4..f1c261ecd0 100644 --- a/lib/chef/file_cache.rb +++ b/lib/chef/file_cache.rb @@ -42,12 +42,12 @@ class Chef def store(path, contents, perm = 0640) validate( { - :path => path, - :contents => contents, + path: path, + contents: contents, }, { - :path => { :kind_of => String }, - :contents => { :kind_of => String }, + path: { kind_of: String }, + contents: { kind_of: String }, } ) @@ -68,12 +68,12 @@ class Chef def move_to(file, path) validate( { - :file => file, - :path => path, + file: file, + path: path, }, { - :file => { :kind_of => String }, - :path => { :kind_of => String }, + file: { kind_of: String }, + path: { kind_of: String }, } ) @@ -105,10 +105,10 @@ class Chef def load(path, read = true) validate( { - :path => path, + path: path, }, { - :path => { :kind_of => String }, + path: { kind_of: String }, } ) cache_path = create_cache_path(path, false) @@ -131,10 +131,10 @@ class Chef def delete(path) validate( { - :path => path, + path: path, }, { - :path => { :kind_of => String }, + path: { kind_of: String }, } ) cache_path = create_cache_path(path, false) @@ -178,10 +178,10 @@ class Chef def has_key?(path) validate( { - :path => path, + path: path, }, { - :path => { :kind_of => String }, + path: { kind_of: String }, } ) full_path = create_cache_path(path, false) diff --git a/lib/chef/formatters/base.rb b/lib/chef/formatters/base.rb index 997577aa7b..fa309b67e7 100644 --- a/lib/chef/formatters/base.rb +++ b/lib/chef/formatters/base.rb @@ -96,7 +96,7 @@ class Chef if @output.indent < 0 # This is left commented out for now. We need to uncomment it and fix at least one bug in # the formatter, and then leave this line uncommented in the future. - #Chef::Log.warn "Internal Formatter Error -- Attempt to indent by negative number of spaces" + # Chef::Log.warn "Internal Formatter Error -- Attempt to indent by negative number of spaces" @output.indent = 0 end @output.indent @@ -110,7 +110,7 @@ class Chef end def registration_failed(node_name, exception, config) - #A Formatters::ErrorDescription object + # A Formatters::ErrorDescription object description = ErrorMapper.registration_failed(node_name, exception, config) display_error(description) end diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb index d47ab73a30..19a6fafae6 100644 --- a/lib/chef/formatters/doc.rb +++ b/lib/chef/formatters/doc.rb @@ -254,7 +254,7 @@ class Chef puts_line "" puts_line "Audit phase exception:" indent - puts_line "#{error.message}" + puts_line (error.message).to_s if error.backtrace error.backtrace.each do |l| puts_line l @@ -285,7 +285,7 @@ class Chef indent end # TODO: info about notifies - start_line "* #{resource} action #{action}", :stream => resource + start_line "* #{resource} action #{action}", stream: resource indent end @@ -318,7 +318,7 @@ class Chef def resource_skipped(resource, action, conditional) @skipped_resources += 1 # TODO: more info about conditional - puts " (skipped due to #{conditional.short_description})", :stream => resource + puts " (skipped due to #{conditional.short_description})", stream: resource unindent end @@ -329,12 +329,12 @@ class Chef # Called when a resource has no converge actions, e.g., it was already correct. def resource_up_to_date(resource, action) @up_to_date_resources += 1 - puts " (up to date)", :stream => resource + puts " (up to date)", stream: resource unindent end def resource_bypassed(resource, action, provider) - puts " (Skipped: whyrun not supported by provider #{provider.class.name})", :stream => resource + puts " (Skipped: whyrun not supported by provider #{provider.class.name})", stream: resource unindent end @@ -375,7 +375,7 @@ class Chef end def stream_output(stream, output, options = {}) - print(output, { :stream => stream }.merge(options)) + print(output, { stream: stream }.merge(options)) end # Called before handlers run diff --git a/lib/chef/formatters/error_inspectors/api_error_formatting.rb b/lib/chef/formatters/error_inspectors/api_error_formatting.rb index 53549ee77c..954eebafdb 100644 --- a/lib/chef/formatters/error_inspectors/api_error_formatting.rb +++ b/lib/chef/formatters/error_inspectors/api_error_formatting.rb @@ -26,79 +26,79 @@ class Chef NETWORK_ERROR_CLASSES = [Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError] def describe_network_errors(error_description) - error_description.section("Networking Error:", <<-E) -#{exception.message} + error_description.section("Networking Error:", <<~E) + #{exception.message} -Your chef_server_url may be misconfigured, or the network could be down. + Your chef_server_url may be misconfigured, or the network could be down. E - error_description.section("Relevant Config Settings:", <<-E) -chef_server_url "#{server_url}" + error_description.section("Relevant Config Settings:", <<~E) + chef_server_url "#{server_url}" E end def describe_eof_error(error_description) - error_description.section("Authentication Error:", <<-E) -Received an EOF on transport socket. This almost always indicates a network -error external to chef-client. Some causes include: + error_description.section("Authentication Error:", <<~E) + Received an EOF on transport socket. This almost always indicates a network + error external to chef-client. Some causes include: - - Blocking ICMP Dest Unreachable (breaking Path MTU Discovery) - - IPsec or VPN tunnelling / TCP Encapsulation MTU issues - - Jumbo frames configured only on one side (breaking Path MTU) - - Jumbo frames configured on a LAN that does not support them - - Proxies or Load Balancers breaking large POSTs - - Broken TCP offload in network drivers/hardware + - Blocking ICMP Dest Unreachable (breaking Path MTU Discovery) + - IPsec or VPN tunnelling / TCP Encapsulation MTU issues + - Jumbo frames configured only on one side (breaking Path MTU) + - Jumbo frames configured on a LAN that does not support them + - Proxies or Load Balancers breaking large POSTs + - Broken TCP offload in network drivers/hardware -Try sending large pings to the destination: + Try sending large pings to the destination: - windows: ping server.example.com -f -l 9999 - unix: ping server.example.com -s 9999 + windows: ping server.example.com -f -l 9999 + unix: ping server.example.com -s 9999 -Try sending large POSTs to the destination (any HTTP code returned is success): + Try sending large POSTs to the destination (any HTTP code returned is success): - e.g.: curl http://server.example.com/`printf '%*s' 9999 '' | tr ' ' 'a'` + e.g.: curl http://server.example.com/`printf '%*s' 9999 '' | tr ' ' 'a'` -Try disabling TCP Offload Engines (TOE) in your ethernet drivers. + Try disabling TCP Offload Engines (TOE) in your ethernet drivers. - windows: - Disable-NetAdapterChecksumOffload * -TcpIPv4 -UdpIPv4 -IpIPv4 -NoRestart - Disable-NetAdapterLso * -IPv4 -NoRestart - Set-NetAdapterAdvancedProperty * -DisplayName "Large Receive Offload (IPv4)" -DisplayValue Disabled –NoRestart - Restart-NetAdapter * - unix(bash): - for i in rx tx sg tso ufo gso gro lro rxvlan txvlan rxhash; do /sbin/ethtool -K eth0 $i off; done + windows: + Disable-NetAdapterChecksumOffload * -TcpIPv4 -UdpIPv4 -IpIPv4 -NoRestart + Disable-NetAdapterLso * -IPv4 -NoRestart + Set-NetAdapterAdvancedProperty * -DisplayName "Large Receive Offload (IPv4)" -DisplayValue Disabled –NoRestart + Restart-NetAdapter * + unix(bash): + for i in rx tx sg tso ufo gso gro lro rxvlan txvlan rxhash; do /sbin/ethtool -K eth0 $i off; done -In some cases the underlying virtualization layer (Xen, VMware, KVM, Hyper-V, etc) may have -broken virtual networking code. + In some cases the underlying virtualization layer (Xen, VMware, KVM, Hyper-V, etc) may have + broken virtual networking code. E end def describe_401_error(error_description) if clock_skew? - error_description.section("Authentication Error:", <<-E) -Failed to authenticate to the chef server (http 401). -The request failed because your clock has drifted by more than 15 minutes. -Syncing your clock to an NTP Time source should resolve the issue. + error_description.section("Authentication Error:", <<~E) + Failed to authenticate to the chef server (http 401). + The request failed because your clock has drifted by more than 15 minutes. + Syncing your clock to an NTP Time source should resolve the issue. E else - error_description.section("Authentication Error:", <<-E) -Failed to authenticate to the chef server (http 401). + error_description.section("Authentication Error:", <<~E) + Failed to authenticate to the chef server (http 401). E error_description.section("Server Response:", format_rest_error) - error_description.section("Relevant Config Settings:", <<-E) -chef_server_url "#{server_url}" -node_name "#{username}" -client_key "#{api_key}" + error_description.section("Relevant Config Settings:", <<~E) + chef_server_url "#{server_url}" + node_name "#{username}" + client_key "#{api_key}" -If these settings are correct, your client_key may be invalid, or -you may have a chef user with the same client name as this node. + If these settings are correct, your client_key may be invalid, or + you may have a chef user with the same client name as this node. E end end def describe_400_error(error_description) - error_description.section("Invalid Request Data:", <<-E) -The data in your request was invalid (HTTP 400). + error_description.section("Invalid Request Data:", <<~E) + The data in your request was invalid (HTTP 400). E error_description.section("Server Response:", format_rest_error) end @@ -110,11 +110,11 @@ E min_server_version = version_header["min_version"] max_server_version = version_header["max_version"] - error_description.section("Incompatible server API version:", <<-E) -This version of the API that this Chef request specified is not supported by the Chef server you sent this request to. -The server supports a min API version of #{min_server_version} and a max API version of #{max_server_version}. -Chef just made a request with an API version of #{client_api_version}. -Please either update your Chef client or server to be a compatible set. + error_description.section("Incompatible server API version:", <<~E) + This version of the API that this Chef request specified is not supported by the Chef server you sent this request to. + The server supports a min API version of #{min_server_version} and a max API version of #{max_server_version}. + Chef just made a request with an API version of #{client_api_version}. + Please either update your Chef client or server to be a compatible set. E else describe_http_error(error_description) @@ -122,8 +122,8 @@ E end def describe_500_error(error_description) - error_description.section("Unknown Server Error:", <<-E) -The server had a fatal error attempting to load the node data. + error_description.section("Unknown Server Error:", <<~E) + The server had a fatal error attempting to load the node data. E error_description.section("Server Response:", format_rest_error) end diff --git a/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb b/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb index eb1aa629ff..a046f1a277 100644 --- a/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb @@ -56,12 +56,12 @@ class Chef # TODO: we're rescuing errors from Node.find_or_create # * could be no write on nodes container # * could be no read on the node - error_description.section("Authorization Error", <<-E) -This client is not authorized to read some of the information required to -access its cookbooks (HTTP 403). + error_description.section("Authorization Error", <<~E) + This client is not authorized to read some of the information required to + access its cookbooks (HTTP 403). -To access its cookbooks, a client needs to be able to read its environment and -all of the cookbooks in its expanded run list. + To access its cookbooks, a client needs to be able to read its environment and + all of the cookbooks in its expanded run list. E error_description.section("Expanded Run List:", expanded_run_list_ul) error_description.section("Server Response:", format_rest_error) @@ -115,11 +115,11 @@ E explanation << "Error message: #{error_reasons["message"]}\n" end - explanation << <<EOM -You might be able to resolve this issue with: - 1-) Removing cookbook versions that depend on deleted cookbooks. - 2-) Removing unused cookbook versions. - 3-) Pinning exact cookbook versions using environments. + explanation << <<~EOM + You might be able to resolve this issue with: + 1-) Removing cookbook versions that depend on deleted cookbooks. + 2-) Removing unused cookbook versions. + 3-) Pinning exact cookbook versions using environments. EOM error_description.section("Cookbook dependency resolution error:", explanation) end diff --git a/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb b/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb index c52dad4c09..a2f77c8287 100644 --- a/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb @@ -43,12 +43,12 @@ class Chef when Net::HTTPServerException, Net::HTTPFatalError humanize_http_exception(error_description) when Chef::Exceptions::PrivateKeyMissing - error_description.section("Private Key Not Found:", <<-E) -Your private key could not be loaded. If the key file exists, ensure that it is -readable by chef-client. + error_description.section("Private Key Not Found:", <<~E) + Your private key could not be loaded. If the key file exists, ensure that it is + readable by chef-client. E - error_description.section("Relevant Config Settings:", <<-E) -client_key "#{api_key}" + error_description.section("Relevant Config Settings:", <<~E) + client_key "#{api_key}" E when EOFError describe_eof_error(error_description) @@ -69,13 +69,13 @@ E # TODO: we're rescuing errors from Node.find_or_create # * could be no write on nodes container # * could be no read on the node - error_description.section("Authorization Error", <<-E) -Your client is not authorized to load the node data (HTTP 403). + error_description.section("Authorization Error", <<~E) + Your client is not authorized to load the node data (HTTP 403). E error_description.section("Server Response:", format_rest_error) - error_description.section("Possible Causes:", <<-E) -* Your client (#{username}) may have misconfigured authorization permissions. + error_description.section("Possible Causes:", <<~E) + * Your client (#{username}) may have misconfigured authorization permissions. E when Net::HTTPBadRequest describe_400_error(error_description) @@ -97,11 +97,11 @@ E # one, e.g., PUT http://wrong.url/nodes/node-name becomes a GET after a # redirect. def describe_404_error(error_description) - error_description.section("Resource Not Found:", <<-E) -The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect. + error_description.section("Resource Not Found:", <<~E) + The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect. E - error_description.section("Relevant Config Settings:", <<-E) -chef_server_url "#{server_url}" + error_description.section("Relevant Config Settings:", <<~E) + chef_server_url "#{server_url}" E end diff --git a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb index c7c1454311..02e8b0d61a 100644 --- a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb @@ -26,26 +26,26 @@ class Chef when Net::HTTPServerException, Net::HTTPFatalError humanize_http_exception(error_description) when Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError - error_description.section("Network Error:", <<-E) -There was a network error connecting to the Chef Server: -#{exception.message} + error_description.section("Network Error:", <<~E) + There was a network error connecting to the Chef Server: + #{exception.message} E - error_description.section("Relevant Config Settings:", <<-E) -chef_server_url "#{server_url}" + error_description.section("Relevant Config Settings:", <<~E) + chef_server_url "#{server_url}" -If your chef_server_url is correct, your network could be down. + If your chef_server_url is correct, your network could be down. E when Chef::Exceptions::PrivateKeyMissing - error_description.section("Private Key Not Found:", <<-E) -Your private key could not be loaded. If the key file exists, ensure that it is -readable by chef-client. + error_description.section("Private Key Not Found:", <<~E) + Your private key could not be loaded. If the key file exists, ensure that it is + readable by chef-client. E - error_description.section("Relevant Config Settings:", <<-E) -validation_key "#{api_key}" + error_description.section("Relevant Config Settings:", <<~E) + validation_key "#{api_key}" E when Chef::Exceptions::InvalidRedirect - error_description.section("Invalid Redirect:", <<-E) -Change your server location in client.rb to the server's FQDN to avoid unwanted redirections. + error_description.section("Invalid Redirect:", <<~E) + Change your server location in client.rb to the server's FQDN to avoid unwanted redirections. E when EOFError describe_eof_error(error_description) @@ -59,50 +59,50 @@ E case response when Net::HTTPUnauthorized if clock_skew? - error_description.section("Authentication Error:", <<-E) -Failed to authenticate to the chef server (http 401). -The request failed because your clock has drifted by more than 15 minutes. -Syncing your clock to an NTP Time source should resolve the issue. + error_description.section("Authentication Error:", <<~E) + Failed to authenticate to the chef server (http 401). + The request failed because your clock has drifted by more than 15 minutes. + Syncing your clock to an NTP Time source should resolve the issue. E else - error_description.section("Authentication Error:", <<-E) -Failed to authenticate to the chef server (http 401). + error_description.section("Authentication Error:", <<~E) + Failed to authenticate to the chef server (http 401). E error_description.section("Server Response:", format_rest_error) - error_description.section("Relevant Config Settings:", <<-E) -chef_server_url "#{server_url}" -validation_client_name "#{username}" -validation_key "#{api_key}" + error_description.section("Relevant Config Settings:", <<~E) + chef_server_url "#{server_url}" + validation_client_name "#{username}" + validation_key "#{api_key}" -If these settings are correct, your validation_key may be invalid. + If these settings are correct, your validation_key may be invalid. E end when Net::HTTPForbidden - error_description.section("Authorization Error:", <<-E) -Your validation client is not authorized to create the client for this node (HTTP 403). + error_description.section("Authorization Error:", <<~E) + Your validation client is not authorized to create the client for this node (HTTP 403). E - error_description.section("Possible Causes:", <<-E) -* There may already be a client named "#{config[:node_name]}" -* Your validation client (#{username}) may have misconfigured authorization permissions. + error_description.section("Possible Causes:", <<~E) + * There may already be a client named "#{config[:node_name]}" + * Your validation client (#{username}) may have misconfigured authorization permissions. E when Net::HTTPBadRequest - error_description.section("Invalid Request Data:", <<-E) -The data in your request was invalid (HTTP 400). + error_description.section("Invalid Request Data:", <<~E) + The data in your request was invalid (HTTP 400). E error_description.section("Server Response:", format_rest_error) when Net::HTTPNotFound - error_description.section("Resource Not Found:", <<-E) -The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect. + error_description.section("Resource Not Found:", <<~E) + The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect. E - error_description.section("Relevant Config Settings:", <<-E) -chef_server_url "#{server_url}" + error_description.section("Relevant Config Settings:", <<~E) + chef_server_url "#{server_url}" E when Net::HTTPNotAcceptable describe_406_error(error_description, response) when Net::HTTPInternalServerError - error_description.section("Unknown Server Error:", <<-E) -The server had a fatal error attempting to load the node data. + error_description.section("Unknown Server Error:", <<~E) + The server had a fatal error attempting to load the node data. E error_description.section("Server Response:", format_rest_error) when Net::HTTPBadGateway, Net::HTTPServiceUnavailable @@ -114,13 +114,13 @@ E end def username - #config[:node_name] + # config[:node_name] config[:validation_client_name] end def api_key config[:validation_key] - #config[:client_key] + # config[:client_key] end def server_url diff --git a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb index 94ecce88de..1cc147db7a 100644 --- a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +++ b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb @@ -43,7 +43,7 @@ class Chef error_description.section("Resource Declaration:", resource.sensitive ? "suppressed sensitive resource output" : recipe_snippet) end - error_description.section("Compiled Resource:", "#{resource.to_text}") + error_description.section("Compiled Resource:", (resource.to_text).to_s) # Template errors get wrapped in an exception class that can show the relevant template code, # so add them to the error output. diff --git a/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb b/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb index e94b347378..9d46465947 100644 --- a/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb @@ -36,10 +36,10 @@ class Chef def add_explanation(error_description) case exception when Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError - error_description.section("Networking Error:", <<-E) -#{exception.message} + error_description.section("Networking Error:", <<~E) + #{exception.message} -Your chef_server_url may be misconfigured, or the network could be down. + Your chef_server_url may be misconfigured, or the network could be down. E when Net::HTTPServerException, Net::HTTPFatalError humanize_http_exception(error_description) @@ -76,35 +76,35 @@ E response = exception.response case response when Net::HTTPUnauthorized - error_description.section("Authentication Error:", <<-E) -Failed to authenticate to the chef server (http 401). + error_description.section("Authentication Error:", <<~E) + Failed to authenticate to the chef server (http 401). E error_description.section("Server Response:", format_rest_error) - error_description.section("Relevant Config Settings:", <<-E) -chef_server_url "#{server_url}" -node_name "#{username}" -client_key "#{api_key}" + error_description.section("Relevant Config Settings:", <<~E) + chef_server_url "#{server_url}" + node_name "#{username}" + client_key "#{api_key}" -If these settings are correct, your client_key may be invalid. + If these settings are correct, your client_key may be invalid. E when Net::HTTPForbidden # TODO: we're rescuing errors from Node.find_or_create # * could be no write on nodes container # * could be no read on the node - error_description.section("Authorization Error", <<-E) -Your client is not authorized to load one or more of your roles (HTTP 403). + error_description.section("Authorization Error", <<~E) + Your client is not authorized to load one or more of your roles (HTTP 403). E error_description.section("Server Response:", format_rest_error) - error_description.section("Possible Causes:", <<-E) -* Your client (#{username}) may have misconfigured authorization permissions. + error_description.section("Possible Causes:", <<~E) + * Your client (#{username}) may have misconfigured authorization permissions. E when Net::HTTPNotAcceptable describe_406_error(error_description, response) when Net::HTTPInternalServerError - error_description.section("Unknown Server Error:", <<-E) -The server had a fatal error attempting to load a role. + error_description.section("Unknown Server Error:", <<~E) + The server had a fatal error attempting to load a role. E error_description.section("Server Response:", format_rest_error) when Net::HTTPBadGateway, Net::HTTPServiceUnavailable diff --git a/lib/chef/formatters/indentable_output_stream.rb b/lib/chef/formatters/indentable_output_stream.rb index e5e84e0f65..7882527327 100644 --- a/lib/chef/formatters/indentable_output_stream.rb +++ b/lib/chef/formatters/indentable_output_stream.rb @@ -35,19 +35,19 @@ class Chef # cause indentation but will not move to the next line yet (future 'print' # and 'puts' statements will stay on this line). def start_line(string, *args) - print(string, from_args(args, :start_line => true)) + print(string, from_args(args, start_line: true)) end # Print a line. This will continue from the last start_line or print, # or start a new line and indent if necessary. def puts(string, *args) - print(string, from_args(args, :end_line => true)) + print(string, from_args(args, end_line: true)) end # Print an entire line from start to end. This will terminate any existing # lines and cause indentation. def puts_line(string, *args) - print(string, from_args(args, :start_line => true, :end_line => true)) + print(string, from_args(args, start_line: true, end_line: true)) end # Print a raw chunk @@ -103,7 +103,7 @@ class Chef if colors.size == 1 && colors[0].kind_of?(Hash) merge_options.merge(colors[0]) else - merge_options.merge({ :colors => colors }) + merge_options.merge({ colors: colors }) end end diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb index e245eab2c7..b1d497181b 100644 --- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb +++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb @@ -42,9 +42,9 @@ class Chef # We need to make sure we check for Script first because any resource # that can get to here is an Execute resource. if @resource.is_a? Chef::Resource::Script - block_attributes = @command_opts.merge({ :code => @command }) + block_attributes = @command_opts.merge({ code: @command }) else - block_attributes = @command_opts.merge({ :command => @command }) + block_attributes = @command_opts.merge({ command: @command }) end # Handles cases like powershell_script where default diff --git a/lib/chef/handler/json_file.rb b/lib/chef/handler/json_file.rb index 7f29b91449..3dc7c51274 100644 --- a/lib/chef/handler/json_file.rb +++ b/lib/chef/handler/json_file.rb @@ -41,7 +41,7 @@ class Chef savetime = Time.now.strftime("%Y%m%d%H%M%S") File.open(File.join(config[:path], "chef-run-report-#{savetime}.json"), "w") do |file| - #ensure start time and end time are output in the json properly in the event activesupport happens to be on the system + # ensure start time and end time are output in the json properly in the event activesupport happens to be on the system run_data = data run_data[:start_time] = run_data[:start_time].to_s run_data[:end_time] = run_data[:end_time].to_s diff --git a/lib/chef/http/auth_credentials.rb b/lib/chef/http/auth_credentials.rb index eeb9136607..547b5c8a83 100644 --- a/lib/chef/http/auth_credentials.rb +++ b/lib/chef/http/auth_credentials.rb @@ -50,8 +50,8 @@ class Chef host = request_params.delete(:host) || "localhost" sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params) - signed = sign_obj.sign(key, use_ssh_agent: @use_ssh_agent).merge({ :host => host }) - signed.inject({}) { |memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1]; memo } + signed = sign_obj.sign(key, use_ssh_agent: @use_ssh_agent).merge({ host: host }) + signed.inject({}) { |memo, kv| memo[(kv[0].to_s.upcase).to_s] = kv[1]; memo } end end diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb index 8e050832f0..bfb85785c8 100644 --- a/lib/chef/http/authenticator.rb +++ b/lib/chef/http/authenticator.rb @@ -104,11 +104,11 @@ class Chef def authentication_headers(method, url, json_body = nil, headers = nil) request_params = { - :http_method => method, - :path => url.path, - :body => json_body, - :host => "#{url.host}:#{url.port}", - :headers => headers, + http_method: method, + path: url.path, + body: json_body, + host: "#{url.host}:#{url.port}", + headers: headers, } request_params[:body] ||= "" auth_credentials.signature_headers(request_params) diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb index de589e429e..774419a58c 100644 --- a/lib/chef/http/http_request.rb +++ b/lib/chef/http/http_request.rb @@ -27,7 +27,7 @@ require "net/http" # However, in ohai before 0.6.0, the version is defined # in ohai, not ohai/version begin - require "ohai/version" #used in user agent string. + require "ohai/version" # used in user agent string. rescue LoadError require "ohai" end @@ -152,7 +152,7 @@ class Chef end def configure_http_request(request_body = nil) - req_path = "#{path}" + req_path = (path).to_s req_path << "?#{query}" if query @http_request = case method.to_s.downcase diff --git a/lib/chef/key.rb b/lib/chef/key.rb index bf8e533d62..1020d60ac6 100644 --- a/lib/chef/key.rb +++ b/lib/chef/key.rb @@ -77,23 +77,23 @@ class Chef def actor(arg = nil) set_or_return(:actor, arg, - :regex => /^[a-z0-9\-_]+$/) + regex: /^[a-z0-9\-_]+$/) end def name(arg = nil) set_or_return(:name, arg, - :kind_of => String) + kind_of: String) end def public_key(arg = nil) raise Chef::Exceptions::InvalidKeyAttribute, "you cannot set the public_key if create_key is true" if !arg.nil? && @create_key set_or_return(:public_key, arg, - :kind_of => String) + kind_of: String) end def private_key(arg = nil) set_or_return(:private_key, arg, - :kind_of => String) + kind_of: String) end def delete_public_key @@ -107,12 +107,12 @@ class Chef def create_key(arg = nil) raise Chef::Exceptions::InvalidKeyAttribute, "you cannot set create_key to true if the public_key field exists" if arg == true && !@public_key.nil? set_or_return(:create_key, arg, - :kind_of => [TrueClass, FalseClass]) + kind_of: [TrueClass, FalseClass]) end def expiration_date(arg = nil) set_or_return(:expiration_date, arg, - :regex => /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|infinity)$/) + regex: /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|infinity)$/) end def to_hash @@ -140,7 +140,7 @@ class Chef # defaults the key name to the fingerprint of the key if @name.nil? # if they didn't pass a public_key, - #then they must supply a name because we can't generate a fingerprint + # then they must supply a name because we can't generate a fingerprint unless @public_key.nil? @name = fingerprint else diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 15d0f1be18..797080abe3 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -45,180 +45,180 @@ class Chef banner "knife bootstrap [SSH_USER@]FQDN (options)" option :ssh_user, - :short => "-x USERNAME", - :long => "--ssh-user USERNAME", - :description => "The ssh username", - :default => "root" + short: "-x USERNAME", + long: "--ssh-user USERNAME", + description: "The ssh username", + default: "root" option :ssh_password, - :short => "-P PASSWORD", - :long => "--ssh-password PASSWORD", - :description => "The ssh password" + short: "-P PASSWORD", + long: "--ssh-password PASSWORD", + description: "The ssh password" option :ssh_port, - :short => "-p PORT", - :long => "--ssh-port PORT", - :description => "The ssh port", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key } + short: "-p PORT", + long: "--ssh-port PORT", + description: "The ssh port", + proc: Proc.new { |key| Chef::Config[:knife][:ssh_port] = key } option :ssh_gateway, - :short => "-G GATEWAY", - :long => "--ssh-gateway GATEWAY", - :description => "The ssh gateway", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key } + short: "-G GATEWAY", + long: "--ssh-gateway GATEWAY", + description: "The ssh gateway", + proc: Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key } option :ssh_gateway_identity, - :long => "--ssh-gateway-identity SSH_GATEWAY_IDENTITY", - :description => "The SSH identity file used for gateway authentication", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway_identity] = key } + long: "--ssh-gateway-identity SSH_GATEWAY_IDENTITY", + description: "The SSH identity file used for gateway authentication", + proc: Proc.new { |key| Chef::Config[:knife][:ssh_gateway_identity] = key } option :forward_agent, - :short => "-A", - :long => "--forward-agent", - :description => "Enable SSH agent forwarding", - :boolean => true + short: "-A", + long: "--forward-agent", + description: "Enable SSH agent forwarding", + boolean: true option :identity_file, - :long => "--identity-file IDENTITY_FILE", - :description => "The SSH identity file used for authentication. [DEPRECATED] Use --ssh-identity-file instead." + long: "--identity-file IDENTITY_FILE", + description: "The SSH identity file used for authentication. [DEPRECATED] Use --ssh-identity-file instead." option :ssh_identity_file, - :short => "-i IDENTITY_FILE", - :long => "--ssh-identity-file IDENTITY_FILE", - :description => "The SSH identity file used for authentication" + short: "-i IDENTITY_FILE", + long: "--ssh-identity-file IDENTITY_FILE", + description: "The SSH identity file used for authentication" option :chef_node_name, - :short => "-N NAME", - :long => "--node-name NAME", - :description => "The Chef node name for your new node" + short: "-N NAME", + long: "--node-name NAME", + description: "The Chef node name for your new node" option :prerelease, - :long => "--prerelease", - :description => "Install the pre-release chef gems" + long: "--prerelease", + description: "Install the pre-release chef gems" option :bootstrap_version, - :long => "--bootstrap-version VERSION", - :description => "The version of Chef to install", - :proc => lambda { |v| Chef::Config[:knife][:bootstrap_version] = v } + long: "--bootstrap-version VERSION", + description: "The version of Chef to install", + proc: lambda { |v| Chef::Config[:knife][:bootstrap_version] = v } option :bootstrap_proxy, - :long => "--bootstrap-proxy PROXY_URL", - :description => "The proxy server for the node being bootstrapped", - :proc => Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p } + long: "--bootstrap-proxy PROXY_URL", + description: "The proxy server for the node being bootstrapped", + proc: Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p } option :bootstrap_proxy_user, - :long => "--bootstrap-proxy-user PROXY_USER", - :description => "The proxy authentication username for the node being bootstrapped" + long: "--bootstrap-proxy-user PROXY_USER", + description: "The proxy authentication username for the node being bootstrapped" option :bootstrap_proxy_pass, - :long => "--bootstrap-proxy-pass PROXY_PASS", - :description => "The proxy authentication password for the node being bootstrapped" + long: "--bootstrap-proxy-pass PROXY_PASS", + description: "The proxy authentication password for the node being bootstrapped" option :bootstrap_no_proxy, - :long => "--bootstrap-no-proxy [NO_PROXY_URL|NO_PROXY_IP]", - :description => "Do not proxy locations for the node being bootstrapped; this option is used internally by Opscode", - :proc => Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np } + long: "--bootstrap-no-proxy [NO_PROXY_URL|NO_PROXY_IP]", + description: "Do not proxy locations for the node being bootstrapped; this option is used internally by Opscode", + proc: Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np } option :bootstrap_template, - :short => "-t TEMPLATE", - :long => "--bootstrap-template TEMPLATE", - :description => "Bootstrap Chef using a built-in or custom template. Set to the full path of an erb template or use one of the built-in templates." + short: "-t TEMPLATE", + long: "--bootstrap-template TEMPLATE", + description: "Bootstrap Chef using a built-in or custom template. Set to the full path of an erb template or use one of the built-in templates." option :use_sudo, - :long => "--sudo", - :description => "Execute the bootstrap via sudo", - :boolean => true + long: "--sudo", + description: "Execute the bootstrap via sudo", + boolean: true option :preserve_home, - :long => "--sudo-preserve-home", - :description => "Preserve non-root user HOME environment variable with sudo", - :boolean => true + long: "--sudo-preserve-home", + description: "Preserve non-root user HOME environment variable with sudo", + boolean: true option :use_sudo_password, - :long => "--use-sudo-password", - :description => "Execute the bootstrap via sudo with password", - :boolean => false + long: "--use-sudo-password", + description: "Execute the bootstrap via sudo with password", + boolean: false option :run_list, - :short => "-r RUN_LIST", - :long => "--run-list RUN_LIST", - :description => "Comma separated list of roles/recipes to apply", - :proc => lambda { |o| o.split(/[\s,]+/) }, - :default => [] + short: "-r RUN_LIST", + long: "--run-list RUN_LIST", + description: "Comma separated list of roles/recipes to apply", + proc: lambda { |o| o.split(/[\s,]+/) }, + default: [] option :policy_name, - :long => "--policy-name POLICY_NAME", - :description => "Policyfile name to use (--policy-group must also be given)", - :default => nil + long: "--policy-name POLICY_NAME", + description: "Policyfile name to use (--policy-group must also be given)", + default: nil option :policy_group, - :long => "--policy-group POLICY_GROUP", - :description => "Policy group name to use (--policy-name must also be given)", - :default => nil + long: "--policy-group POLICY_GROUP", + description: "Policy group name to use (--policy-name must also be given)", + default: nil option :tags, - :long => "--tags TAGS", - :description => "Comma separated list of tags to apply to the node", - :proc => lambda { |o| o.split(/[\s,]+/) }, - :default => [] + long: "--tags TAGS", + description: "Comma separated list of tags to apply to the node", + proc: lambda { |o| o.split(/[\s,]+/) }, + default: [] option :first_boot_attributes, - :short => "-j JSON_ATTRIBS", - :long => "--json-attributes", - :description => "A JSON string to be added to the first run of chef-client", - :proc => lambda { |o| Chef::JSONCompat.parse(o) }, - :default => nil + short: "-j JSON_ATTRIBS", + long: "--json-attributes", + description: "A JSON string to be added to the first run of chef-client", + proc: lambda { |o| Chef::JSONCompat.parse(o) }, + default: nil option :first_boot_attributes_from_file, - :long => "--json-attribute-file FILE", - :description => "A JSON file to be used to the first run of chef-client", - :proc => lambda { |o| Chef::JSONCompat.parse(File.read(o)) }, - :default => nil + long: "--json-attribute-file FILE", + description: "A JSON file to be used to the first run of chef-client", + proc: lambda { |o| Chef::JSONCompat.parse(File.read(o)) }, + default: nil option :host_key_verify, - :long => "--[no-]host-key-verify", - :description => "Verify host key, enabled by default.", - :boolean => true, - :default => true + long: "--[no-]host-key-verify", + description: "Verify host key, enabled by default.", + boolean: true, + default: true option :hint, - :long => "--hint HINT_NAME[=HINT_FILE]", - :description => "Specify Ohai Hint to be set on the bootstrap target. Use multiple --hint options to specify multiple hints.", - :proc => Proc.new { |h| + long: "--hint HINT_NAME[=HINT_FILE]", + description: "Specify Ohai Hint to be set on the bootstrap target. Use multiple --hint options to specify multiple hints.", + proc: Proc.new { |h| Chef::Config[:knife][:hints] ||= Hash.new name, path = h.split("=") Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new } option :bootstrap_url, - :long => "--bootstrap-url URL", - :description => "URL to a custom installation script", - :proc => Proc.new { |u| Chef::Config[:knife][:bootstrap_url] = u } + long: "--bootstrap-url URL", + description: "URL to a custom installation script", + proc: Proc.new { |u| Chef::Config[:knife][:bootstrap_url] = u } option :bootstrap_install_command, - :long => "--bootstrap-install-command COMMANDS", - :description => "Custom command to install chef-client", - :proc => Proc.new { |ic| Chef::Config[:knife][:bootstrap_install_command] = ic } + long: "--bootstrap-install-command COMMANDS", + description: "Custom command to install chef-client", + proc: Proc.new { |ic| Chef::Config[:knife][:bootstrap_install_command] = ic } option :bootstrap_preinstall_command, - :long => "--bootstrap-preinstall-command COMMANDS", - :description => "Custom commands to run before installing chef-client", - :proc => Proc.new { |preic| Chef::Config[:knife][:bootstrap_preinstall_command] = preic } + long: "--bootstrap-preinstall-command COMMANDS", + description: "Custom commands to run before installing chef-client", + proc: Proc.new { |preic| Chef::Config[:knife][:bootstrap_preinstall_command] = preic } option :bootstrap_wget_options, - :long => "--bootstrap-wget-options OPTIONS", - :description => "Add options to wget when installing chef-client", - :proc => Proc.new { |wo| Chef::Config[:knife][:bootstrap_wget_options] = wo } + long: "--bootstrap-wget-options OPTIONS", + description: "Add options to wget when installing chef-client", + proc: Proc.new { |wo| Chef::Config[:knife][:bootstrap_wget_options] = wo } option :bootstrap_curl_options, - :long => "--bootstrap-curl-options OPTIONS", - :description => "Add options to curl when install chef-client", - :proc => Proc.new { |co| Chef::Config[:knife][:bootstrap_curl_options] = co } + long: "--bootstrap-curl-options OPTIONS", + description: "Add options to curl when install chef-client", + proc: Proc.new { |co| Chef::Config[:knife][:bootstrap_curl_options] = co } option :node_ssl_verify_mode, - :long => "--node-ssl-verify-mode [peer|none]", - :description => "Whether or not to verify the SSL cert for all HTTPS requests.", - :proc => Proc.new { |v| + long: "--node-ssl-verify-mode [peer|none]", + description: "Whether or not to verify the SSL cert for all HTTPS requests.", + proc: Proc.new { |v| valid_values = %w{none peer} unless valid_values.include?(v) raise "Invalid value '#{v}' for --node-ssl-verify-mode. Valid values are: #{valid_values.join(", ")}" @@ -227,22 +227,22 @@ class Chef } option :node_verify_api_cert, - :long => "--[no-]node-verify-api-cert", - :description => "Verify the SSL cert for HTTPS requests to the Chef server API.", - :boolean => true + long: "--[no-]node-verify-api-cert", + description: "Verify the SSL cert for HTTPS requests to the Chef server API.", + boolean: true option :bootstrap_vault_file, - :long => "--bootstrap-vault-file VAULT_FILE", - :description => "A JSON file with a list of vault(s) and item(s) to be updated" + long: "--bootstrap-vault-file VAULT_FILE", + description: "A JSON file with a list of vault(s) and item(s) to be updated" option :bootstrap_vault_json, - :long => "--bootstrap-vault-json VAULT_JSON", - :description => "A JSON string with the vault(s) and item(s) to be updated" + long: "--bootstrap-vault-json VAULT_JSON", + description: "A JSON string with the vault(s) and item(s) to be updated" option :bootstrap_vault_item, - :long => "--bootstrap-vault-item VAULT_ITEM", - :description => 'A single vault and item to update as "vault:item"', - :proc => Proc.new { |i| + long: "--bootstrap-vault-item VAULT_ITEM", + description: 'A single vault and item to update as "vault:item"', + proc: Proc.new { |i| (vault, item) = i.split(/:/) Chef::Config[:knife][:bootstrap_vault_item] ||= {} Chef::Config[:knife][:bootstrap_vault_item][vault] ||= [] diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb index cab33cd811..f5c49ab620 100644 --- a/lib/chef/knife/bootstrap/client_builder.rb +++ b/lib/chef/knife/bootstrap/client_builder.rb @@ -194,7 +194,7 @@ class Chef # @return [Chef::ServerAPI] REST client using the client credentials def client_rest - @client_rest ||= Chef::ServerAPI.new(chef_server_url, :client_name => node_name, :signing_key_filename => client_path) + @client_rest ||= Chef::ServerAPI.new(chef_server_url, client_name: node_name, signing_key_filename: client_path) end # @return [Chef::ServerAPI] REST client using the cli user's knife credentials diff --git a/lib/chef/knife/client_bulk_delete.rb b/lib/chef/knife/client_bulk_delete.rb index a7fa7142c8..a5fe94681d 100644 --- a/lib/chef/knife/client_bulk_delete.rb +++ b/lib/chef/knife/client_bulk_delete.rb @@ -28,9 +28,9 @@ class Chef end option :delete_validators, - :short => "-D", - :long => "--delete-validators", - :description => "Force deletion of clients if they're validators" + short: "-D", + long: "--delete-validators", + description: "Force deletion of clients if they're validators" banner "knife client bulk delete REGEX (options)" diff --git a/lib/chef/knife/client_create.rb b/lib/chef/knife/client_create.rb index e28378cd4a..b821a8a56b 100644 --- a/lib/chef/knife/client_create.rb +++ b/lib/chef/knife/client_create.rb @@ -28,31 +28,31 @@ class Chef end option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the private key to a file if the server generated one." + short: "-f FILE", + long: "--file FILE", + description: "Write the private key to a file if the server generated one." option :admin, - :short => "-a", - :long => "--admin", - :description => "Open Source Chef Server 11 only. Create the client as an admin.", - :boolean => true + short: "-a", + long: "--admin", + description: "Open Source Chef Server 11 only. Create the client as an admin.", + boolean: true option :validator, - :long => "--validator", - :description => "Create the client as a validator.", - :boolean => true + long: "--validator", + description: "Create the client as a validator.", + boolean: true option :public_key, - :short => "-p FILE", - :long => "--public-key", - :description => "Set the initial default key for the client from a file on disk (cannot pass with --prevent-keygen)." + short: "-p FILE", + long: "--public-key", + description: "Set the initial default key for the client from a file on disk (cannot pass with --prevent-keygen)." option :prevent_keygen, - :short => "-k", - :long => "--prevent-keygen", - :description => "API V1 (Chef Server 12.1+) only. Prevent server from generating a default key pair for you. Cannot be passed with --public-key.", - :boolean => true + short: "-k", + long: "--prevent-keygen", + description: "API V1 (Chef Server 12.1+) only. Prevent server from generating a default key pair for you. Cannot be passed with --public-key.", + boolean: true banner "knife client create CLIENTNAME (options)" diff --git a/lib/chef/knife/client_delete.rb b/lib/chef/knife/client_delete.rb index 82b521c7d1..a043b6f731 100644 --- a/lib/chef/knife/client_delete.rb +++ b/lib/chef/knife/client_delete.rb @@ -28,9 +28,9 @@ class Chef end option :delete_validators, - :short => "-D", - :long => "--delete-validators", - :description => "Force deletion of client if it's a validator" + short: "-D", + long: "--delete-validators", + description: "Force deletion of client if it's a validator" banner "knife client delete [CLIENT [CLIENT]] (options)" diff --git a/lib/chef/knife/client_list.rb b/lib/chef/knife/client_list.rb index b17de0f3ad..794d8c9411 100644 --- a/lib/chef/knife/client_list.rb +++ b/lib/chef/knife/client_list.rb @@ -30,9 +30,9 @@ class Chef banner "knife client list (options)" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run output(format_list_for_display(Chef::ApiClientV1.list)) diff --git a/lib/chef/knife/client_reregister.rb b/lib/chef/knife/client_reregister.rb index cc2b218e87..ce34884803 100644 --- a/lib/chef/knife/client_reregister.rb +++ b/lib/chef/knife/client_reregister.rb @@ -30,9 +30,9 @@ class Chef banner "knife client reregister CLIENT (options)" option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the key to a file" + short: "-f FILE", + long: "--file FILE", + description: "Write the key to a file" def run @client_name = @name_args[0] diff --git a/lib/chef/knife/configure.rb b/lib/chef/knife/configure.rb index df021826ae..4b33998eaa 100644 --- a/lib/chef/knife/configure.rb +++ b/lib/chef/knife/configure.rb @@ -34,31 +34,31 @@ class Chef banner "knife configure (options)" option :repository, - :short => "-r REPO", - :long => "--repository REPO", - :description => "The path to the chef-repo" + short: "-r REPO", + long: "--repository REPO", + description: "The path to the chef-repo" option :initial, - :short => "-i", - :long => "--initial", - :boolean => true, - :description => "Use to create a API client, typically an administrator client on a freshly-installed server" + short: "-i", + long: "--initial", + boolean: true, + description: "Use to create a API client, typically an administrator client on a freshly-installed server" option :admin_client_name, - :long => "--admin-client-name NAME", - :description => "The name of the client, typically the name of the admin client" + long: "--admin-client-name NAME", + description: "The name of the client, typically the name of the admin client" option :admin_client_key, - :long => "--admin-client-key PATH", - :description => "The path to the private key used by the client, typically a file named admin.pem" + long: "--admin-client-key PATH", + description: "The path to the private key used by the client, typically a file named admin.pem" option :validation_client_name, - :long => "--validation-client-name NAME", - :description => "The name of the validation client, typically a client named chef-validator" + long: "--validation-client-name NAME", + description: "The name of the validation client, typically a client named chef-validator" option :validation_key, - :long => "--validation-key PATH", - :description => "The path to the validation key used by the client, typically a file named validation.pem" + long: "--validation-key PATH", + description: "The path to the validation key used by the client, typically a file named validation.pem" def configure_chef # We are just faking out the system so that you can do this without a key specified @@ -75,11 +75,11 @@ class Chef confirm("Overwrite #{config_file_path}") if ::File.exist?(config_file_path) ::File.open(config_file_path, "w") do |f| - f.puts <<-EOH -[default] -client_name = '#{new_client_name}' -client_key = '#{new_client_key}' -chef_server_url = '#{chef_server}' + f.puts <<~EOH + [default] + client_name = '#{new_client_name}' + client_key = '#{new_client_key}' + chef_server_url = '#{chef_server}' EOH end @@ -112,14 +112,14 @@ EOH def ask_user_for_config server_name = guess_servername - @chef_server = config[:chef_server_url] || ask_question("Please enter the chef server URL: ", :default => "https://#{server_name}/organizations/myorg") + @chef_server = config[:chef_server_url] || ask_question("Please enter the chef server URL: ", default: "https://#{server_name}/organizations/myorg") if config[:initial] - @new_client_name = config[:node_name] || ask_question("Please enter a name for the new user: ", :default => Etc.getlogin) - @admin_client_name = config[:admin_client_name] || ask_question("Please enter the existing admin name: ", :default => "admin") - @admin_client_key = config[:admin_client_key] || ask_question("Please enter the location of the existing admin's private key: ", :default => "/etc/chef-server/admin.pem") + @new_client_name = config[:node_name] || ask_question("Please enter a name for the new user: ", default: Etc.getlogin) + @admin_client_name = config[:admin_client_name] || ask_question("Please enter the existing admin name: ", default: "admin") + @admin_client_key = config[:admin_client_key] || ask_question("Please enter the location of the existing admin's private key: ", default: "/etc/chef-server/admin.pem") @admin_client_key = File.expand_path(@admin_client_key) else - @new_client_name = config[:node_name] || ask_question("Please enter an existing username or clientname for the API: ", :default => Etc.getlogin) + @new_client_name = config[:node_name] || ask_question("Please enter an existing username or clientname for the API: ", default: Etc.getlogin) end @new_client_key = config[:client_key] || File.join(chef_config_path, "#{@new_client_name}.pem") diff --git a/lib/chef/knife/cookbook_bulk_delete.rb b/lib/chef/knife/cookbook_bulk_delete.rb index cdd1584e36..a68e8f00f4 100644 --- a/lib/chef/knife/cookbook_bulk_delete.rb +++ b/lib/chef/knife/cookbook_bulk_delete.rb @@ -28,7 +28,7 @@ class Chef require "chef/cookbook_version" end - option :purge, :short => "-p", :long => "--purge", :boolean => true, :description => "Permanently remove files from backing data store" + option :purge, short: "-p", long: "--purge", boolean: true, description: "Permanently remove files from backing data store" banner "knife cookbook bulk delete REGEX (options)" diff --git a/lib/chef/knife/cookbook_delete.rb b/lib/chef/knife/cookbook_delete.rb index b1bb88b388..4f2ada53cb 100644 --- a/lib/chef/knife/cookbook_delete.rb +++ b/lib/chef/knife/cookbook_delete.rb @@ -28,9 +28,9 @@ class Chef require "chef/cookbook_version" end - option :all, :short => "-a", :long => "--all", :boolean => true, :description => "delete all versions" + option :all, short: "-a", long: "--all", boolean: true, description: "delete all versions" - option :purge, :short => "-p", :long => "--purge", :boolean => true, :description => "Permanently remove files from backing data store" + option :purge, short: "-p", long: "--purge", boolean: true, description: "Permanently remove files from backing data store" banner "knife cookbook delete COOKBOOK VERSION (options)" diff --git a/lib/chef/knife/cookbook_download.rb b/lib/chef/knife/cookbook_download.rb index 77e7aa0d09..a321d217db 100644 --- a/lib/chef/knife/cookbook_download.rb +++ b/lib/chef/knife/cookbook_download.rb @@ -33,21 +33,21 @@ class Chef banner "knife cookbook download COOKBOOK [VERSION] (options)" option :latest, - :short => "-N", - :long => "--latest", - :description => "The version of the cookbook to download", - :boolean => true + short: "-N", + long: "--latest", + description: "The version of the cookbook to download", + boolean: true option :download_directory, - :short => "-d DOWNLOAD_DIRECTORY", - :long => "--dir DOWNLOAD_DIRECTORY", - :description => "The directory to download the cookbook into", - :default => Dir.pwd + short: "-d DOWNLOAD_DIRECTORY", + long: "--dir DOWNLOAD_DIRECTORY", + description: "The directory to download the cookbook into", + default: Dir.pwd option :force, - :short => "-f", - :long => "--force", - :description => "Force download over the download directory if it exists" + short: "-f", + long: "--force", + description: "Force download over the download directory if it exists" # TODO: tim/cw: 5-23-2010: need to implement knife-side # specificity for downloads - need to implement --platform and diff --git a/lib/chef/knife/cookbook_list.rb b/lib/chef/knife/cookbook_list.rb index ea81f5d286..deb36baef4 100644 --- a/lib/chef/knife/cookbook_list.rb +++ b/lib/chef/knife/cookbook_list.rb @@ -26,14 +26,14 @@ class Chef banner "knife cookbook list (options)" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" option :all_versions, - :short => "-a", - :long => "--all", - :description => "Show all available versions." + short: "-a", + long: "--all", + description: "Show all available versions." def run env = config[:environment] diff --git a/lib/chef/knife/cookbook_metadata.rb b/lib/chef/knife/cookbook_metadata.rb index babb4ac4d1..8a9c57f1c3 100644 --- a/lib/chef/knife/cookbook_metadata.rb +++ b/lib/chef/knife/cookbook_metadata.rb @@ -30,15 +30,15 @@ class Chef banner "knife cookbook metadata COOKBOOK (options)" option :cookbook_path, - :short => "-o PATH:PATH", - :long => "--cookbook-path PATH:PATH", - :description => "A colon-separated path to look for cookbooks in", - :proc => lambda { |o| o.split(":") } + short: "-o PATH:PATH", + long: "--cookbook-path PATH:PATH", + description: "A colon-separated path to look for cookbooks in", + proc: lambda { |o| o.split(":") } option :all, - :short => "-a", - :long => "--all", - :description => "Generate metadata for all cookbooks, rather than just a single cookbook" + short: "-a", + long: "--all", + description: "Generate metadata for all cookbooks, rather than just a single cookbook" def run config[:cookbook_path] ||= Chef::Config[:cookbook_path] diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb index 1d9983632d..78951d00c7 100644 --- a/lib/chef/knife/cookbook_show.rb +++ b/lib/chef/knife/cookbook_show.rb @@ -31,24 +31,24 @@ class Chef banner "knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)" option :fqdn, - :short => "-f FQDN", - :long => "--fqdn FQDN", - :description => "The FQDN of the host to see the file for" + short: "-f FQDN", + long: "--fqdn FQDN", + description: "The FQDN of the host to see the file for" option :platform, - :short => "-p PLATFORM", - :long => "--platform PLATFORM", - :description => "The platform to see the file for" + short: "-p PLATFORM", + long: "--platform PLATFORM", + description: "The platform to see the file for" option :platform_version, - :short => "-V VERSION", - :long => "--platform-version VERSION", - :description => "The platform version to see the file for" + short: "-V VERSION", + long: "--platform-version VERSION", + description: "The platform version to see the file for" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run cookbook_name, cookbook_version, segment, filename = @name_args diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb index b957b0a362..ad4a2a83a2 100644 --- a/lib/chef/knife/cookbook_site_download.rb +++ b/lib/chef/knife/cookbook_site_download.rb @@ -30,20 +30,20 @@ class Chef category "cookbook site" option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "The filename to write to" + short: "-f FILE", + long: "--file FILE", + description: "The filename to write to" option :force, - :long => "--force", - :description => "Force download deprecated version" + long: "--force", + description: "Force download deprecated version" option :supermarket_site, - :short => "-m SUPERMARKET_SITE", - :long => "--supermarket-site SUPERMARKET_SITE", - :description => "Supermarket Site", - :default => "https://supermarket.chef.io", - :proc => Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } def run if current_cookbook_deprecated? diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb index f4d692e13c..18cddb19f4 100644 --- a/lib/chef/knife/cookbook_site_install.rb +++ b/lib/chef/knife/cookbook_site_install.rb @@ -35,37 +35,37 @@ class Chef category "cookbook site" option :no_deps, - :short => "-D", - :long => "--skip-dependencies", - :boolean => true, - :default => false, - :description => "Skips automatic dependency installation." + short: "-D", + long: "--skip-dependencies", + boolean: true, + default: false, + description: "Skips automatic dependency installation." option :cookbook_path, - :short => "-o PATH:PATH", - :long => "--cookbook-path PATH:PATH", - :description => "A colon-separated path to look for cookbooks in", - :proc => lambda { |o| o.split(":") } + short: "-o PATH:PATH", + long: "--cookbook-path PATH:PATH", + description: "A colon-separated path to look for cookbooks in", + proc: lambda { |o| o.split(":") } option :default_branch, - :short => "-B BRANCH", - :long => "--branch BRANCH", - :description => "Default branch to work with", - :default => "master" + short: "-B BRANCH", + long: "--branch BRANCH", + description: "Default branch to work with", + default: "master" option :use_current_branch, - :short => "-b", - :long => "--use-current-branch", - :description => "Use the current branch", - :boolean => true, - :default => false + short: "-b", + long: "--use-current-branch", + description: "Use the current branch", + boolean: true, + default: false option :supermarket_site, - :short => "-m SUPERMARKET_SITE", - :long => "--supermarket-site SUPERMARKET_SITE", - :description => "Supermarket Site", - :default => "https://supermarket.chef.io", - :proc => Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } attr_reader :cookbook_name attr_reader :vendor_path @@ -86,7 +86,7 @@ class Chef ui.info "Installing #{@cookbook_name} to #{@install_path}" @repo = CookbookSCMRepo.new(@install_path, ui, config) - #cookbook_path = File.join(vendor_path, name_args[0]) + # cookbook_path = File.join(vendor_path, name_args[0]) upstream_file = File.join(@install_path, "#{@cookbook_name}.tar.gz") @repo.sanity_check diff --git a/lib/chef/knife/cookbook_site_list.rb b/lib/chef/knife/cookbook_site_list.rb index 3bdef8abe5..3b0b20a4df 100644 --- a/lib/chef/knife/cookbook_site_list.rb +++ b/lib/chef/knife/cookbook_site_list.rb @@ -26,16 +26,16 @@ class Chef category "cookbook site" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" option :supermarket_site, - :short => "-m SUPERMARKET_SITE", - :long => "--supermarket-site SUPERMARKET_SITE", - :description => "Supermarket Site", - :default => "https://supermarket.chef.io", - :proc => Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } def run if config[:with_uri] diff --git a/lib/chef/knife/cookbook_site_search.rb b/lib/chef/knife/cookbook_site_search.rb index 0fee993f30..6a598bd22b 100644 --- a/lib/chef/knife/cookbook_site_search.rb +++ b/lib/chef/knife/cookbook_site_search.rb @@ -26,11 +26,11 @@ class Chef category "cookbook site" option :supermarket_site, - :short => "-m SUPERMARKET_SITE", - :long => "--supermarket-site SUPERMARKET_SITE", - :description => "Supermarket Site", - :default => "https://supermarket.chef.io", - :proc => Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } def run output(search_cookbook(name_args[0])) diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index 5d5b3ddcc4..dcfd224295 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -39,24 +39,24 @@ class Chef category "cookbook site" option :cookbook_path, - :short => "-o PATH:PATH", - :long => "--cookbook-path PATH:PATH", - :description => "A colon-separated path to look for cookbooks in", - :proc => lambda { |o| Chef::Config.cookbook_path = o.split(":") } + short: "-o PATH:PATH", + long: "--cookbook-path PATH:PATH", + description: "A colon-separated path to look for cookbooks in", + proc: lambda { |o| Chef::Config.cookbook_path = o.split(":") } option :dry_run, - :long => "--dry-run", - :short => "-n", - :boolean => true, - :default => false, - :description => "Don't take action, only print what files will be uploaded to Supermarket." + long: "--dry-run", + short: "-n", + boolean: true, + default: false, + description: "Don't take action, only print what files will be uploaded to Supermarket." option :supermarket_site, - :short => "-m SUPERMARKET_SITE", - :long => "--supermarket-site SUPERMARKET_SITE", - :description => "Supermarket Site", - :default => "https://supermarket.chef.io", - :proc => Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } def run config[:cookbook_path] ||= Chef::Config[:cookbook_path] @@ -81,7 +81,7 @@ class Chef begin Chef::Log.trace("Temp cookbook directory is #{tmp_cookbook_dir.inspect}") ui.info("Making tarball #{cookbook_name}.tgz") - shell_out!("#{tar_cmd} -czf #{cookbook_name}.tgz #{cookbook_name}", :cwd => tmp_cookbook_dir) + shell_out!("#{tar_cmd} -czf #{cookbook_name}.tgz #{cookbook_name}", cwd: tmp_cookbook_dir) rescue => e ui.error("Error making tarball #{cookbook_name}.tgz: #{e.message}. Increase log verbosity (-VV) for more information.") Chef::Log.trace("\n#{e.backtrace.join("\n")}") @@ -90,7 +90,7 @@ class Chef if config[:dry_run] ui.info("Not uploading #{cookbook_name}.tgz due to --dry-run flag.") - result = shell_out!("#{tar_cmd} -tzf #{cookbook_name}.tgz", :cwd => tmp_cookbook_dir) + result = shell_out!("#{tar_cmd} -tzf #{cookbook_name}.tgz", cwd: tmp_cookbook_dir) ui.info(result.stdout) FileUtils.rm_rf tmp_cookbook_dir return @@ -129,8 +129,8 @@ class Chef category_string = Chef::JSONCompat.to_json({ "category" => cookbook_category }) http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, { - :tarball => File.open(cookbook_filename), - :cookbook => category_string, + tarball: File.open(cookbook_filename), + cookbook: category_string, }) res = Chef::JSONCompat.from_json(http_resp.body) @@ -140,7 +140,7 @@ class Chef ui.error "The same version of this cookbook already exists on Supermarket." exit(1) else - ui.error "#{res['error_messages'][0]}" + ui.error (res["error_messages"][0]).to_s exit(1) end else diff --git a/lib/chef/knife/cookbook_site_show.rb b/lib/chef/knife/cookbook_site_show.rb index 397d0067ad..1ae242d051 100644 --- a/lib/chef/knife/cookbook_site_show.rb +++ b/lib/chef/knife/cookbook_site_show.rb @@ -26,11 +26,11 @@ class Chef category "cookbook site" option :supermarket_site, - :short => "-m SUPERMARKET_SITE", - :long => "--supermarket-site SUPERMARKET_SITE", - :description => "Supermarket Site", - :default => "https://supermarket.chef.io", - :proc => Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } def run output(format_for_display(get_cookbook_data)) diff --git a/lib/chef/knife/cookbook_site_unshare.rb b/lib/chef/knife/cookbook_site_unshare.rb index bdabff0b94..5f24781f38 100644 --- a/lib/chef/knife/cookbook_site_unshare.rb +++ b/lib/chef/knife/cookbook_site_unshare.rb @@ -31,11 +31,11 @@ class Chef category "cookbook site" option :supermarket_site, - :short => "-m SUPERMARKET_SITE", - :long => "--supermarket-site SUPERMARKET_SITE", - :description => "Supermarket Site", - :default => "https://supermarket.chef.io", - :proc => Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } + short: "-m SUPERMARKET_SITE", + long: "--supermarket-site SUPERMARKET_SITE", + description: "Supermarket Site", + default: "https://supermarket.chef.io", + proc: Proc.new { |supermarket| Chef::Config[:knife][:supermarket_site] = supermarket } def run @cookbook_name = @name_args[0] diff --git a/lib/chef/knife/cookbook_test.rb b/lib/chef/knife/cookbook_test.rb index b4adf6c84f..2f600bf964 100644 --- a/lib/chef/knife/cookbook_test.rb +++ b/lib/chef/knife/cookbook_test.rb @@ -32,15 +32,15 @@ class Chef banner "knife cookbook test [COOKBOOKS...] (options)" option :cookbook_path, - :short => "-o PATH:PATH", - :long => "--cookbook-path PATH:PATH", - :description => "A colon-separated path to look for cookbooks in", - :proc => lambda { |o| o.split(":") } + short: "-o PATH:PATH", + long: "--cookbook-path PATH:PATH", + description: "A colon-separated path to look for cookbooks in", + proc: lambda { |o| o.split(":") } option :all, - :short => "-a", - :long => "--all", - :description => "Test all cookbooks, rather than just a single cookbook" + short: "-a", + long: "--all", + description: "Test all cookbooks, rather than just a single cookbook" def run ui.warn("DEPRECATED: Please use ChefSpec or Cookstyle to syntax-check cookbooks.") diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb index f67a26dc9a..b19c352b79 100644 --- a/lib/chef/knife/cookbook_upload.rb +++ b/lib/chef/knife/cookbook_upload.rb @@ -37,42 +37,42 @@ class Chef banner "knife cookbook upload [COOKBOOKS...] (options)" option :cookbook_path, - :short => "-o PATH:PATH", - :long => "--cookbook-path PATH:PATH", - :description => "A colon-separated path to look for cookbooks in", - :proc => lambda { |o| o.split(":") } + short: "-o PATH:PATH", + long: "--cookbook-path PATH:PATH", + description: "A colon-separated path to look for cookbooks in", + proc: lambda { |o| o.split(":") } option :freeze, - :long => "--freeze", - :description => "Freeze this version of the cookbook so that it cannot be overwritten", - :boolean => true + long: "--freeze", + description: "Freeze this version of the cookbook so that it cannot be overwritten", + boolean: true option :all, - :short => "-a", - :long => "--all", - :description => "Upload all cookbooks, rather than just a single cookbook" + short: "-a", + long: "--all", + description: "Upload all cookbooks, rather than just a single cookbook" option :force, - :long => "--force", - :boolean => true, - :description => "Update cookbook versions even if they have been frozen" + long: "--force", + boolean: true, + description: "Update cookbook versions even if they have been frozen" option :concurrency, - :long => "--concurrency NUMBER_OF_THREADS", - :description => "How many concurrent threads will be used", - :default => 10, - :proc => lambda { |o| o.to_i } + long: "--concurrency NUMBER_OF_THREADS", + description: "How many concurrent threads will be used", + default: 10, + proc: lambda { |o| o.to_i } option :environment, - :short => "-E", - :long => "--environment ENVIRONMENT", - :description => "Set ENVIRONMENT's version dependency match the version you're uploading.", - :default => nil + short: "-E", + long: "--environment ENVIRONMENT", + description: "Set ENVIRONMENT's version dependency match the version you're uploading.", + default: nil option :depends, - :short => "-d", - :long => "--include-dependencies", - :description => "Also upload cookbook dependencies" + short: "-d", + long: "--include-dependencies", + description: "Also upload cookbook dependencies" def run # Sanity check before we load anything from the server @@ -209,12 +209,12 @@ class Chef unless cookbook_repo.merged_cookbooks.empty? ui.warn "* " * 40 - ui.warn(<<-WARNING) -The cookbooks: #{cookbook_repo.merged_cookbooks.join(', ')} exist in multiple places in your cookbook_path. -A composite version of these cookbooks has been compiled for uploading. + ui.warn(<<~WARNING) + The cookbooks: #{cookbook_repo.merged_cookbooks.join(', ')} exist in multiple places in your cookbook_path. + A composite version of these cookbooks has been compiled for uploading. -#{ui.color('IMPORTANT:', :red, :bold)} In a future version of Chef, this behavior will be removed and you will no longer -be able to have the same version of a cookbook in multiple places in your cookbook_path. + #{ui.color('IMPORTANT:', :red, :bold)} In a future version of Chef, this behavior will be removed and you will no longer + be able to have the same version of a cookbook in multiple places in your cookbook_path. WARNING ui.warn "The affected cookbooks are located:" ui.output ui.format_for_display(cookbook_repo.merged_cookbook_paths) @@ -242,7 +242,7 @@ WARNING check_for_broken_links!(cb) check_for_dependencies!(cb) end - Chef::CookbookUploader.new(cookbooks, :force => config[:force], :concurrency => config[:concurrency]).upload_cookbooks + Chef::CookbookUploader.new(cookbooks, force: config[:force], concurrency: config[:concurrency]).upload_cookbooks rescue Chef::Exceptions::CookbookFrozen => e ui.error e raise diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index deb7f8a3b4..bb20780590 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -86,9 +86,9 @@ class Chef end def config_content - client_rb = <<-CONFIG -chef_server_url "#{@chef_config[:chef_server_url]}" -validation_client_name "#{@chef_config[:validation_client_name]}" + client_rb = <<~CONFIG + chef_server_url "#{@chef_config[:chef_server_url]}" + validation_client_name "#{@chef_config[:validation_client_name]}" CONFIG if !(@chef_config[:config_log_level].nil? || @chef_config[:config_log_level].empty?) @@ -228,7 +228,7 @@ validation_client_name "#{@chef_config[:validation_client_name]}" end attributes.delete(:run_list) if attributes[:policy_name] && !attributes[:policy_name].empty? - attributes.merge!(:tags => @config[:tags]) if @config[:tags] && !@config[:tags].empty? + attributes.merge!(tags: @config[:tags]) if @config[:tags] && !@config[:tags].empty? end end diff --git a/lib/chef/knife/core/cookbook_scm_repo.rb b/lib/chef/knife/core/cookbook_scm_repo.rb index 38f432e5bb..f583f0bd8e 100644 --- a/lib/chef/knife/core/cookbook_scm_repo.rb +++ b/lib/chef/knife/core/cookbook_scm_repo.rb @@ -151,7 +151,7 @@ class Chef end def git(command) - shell_out!("git #{command}", :cwd => repo_path) + shell_out!("git #{command}", cwd: repo_path) end end diff --git a/lib/chef/knife/core/generic_presenter.rb b/lib/chef/knife/core/generic_presenter.rb index 861bf1510d..7b3fee00b5 100644 --- a/lib/chef/knife/core/generic_presenter.rb +++ b/lib/chef/knife/core/generic_presenter.rb @@ -29,15 +29,15 @@ class Chef def self.included(includer) includer.class_eval do option :field_separator, - :short => "-S SEPARATOR", - :long => "--field-separator SEPARATOR", - :description => "Character separator used to delineate nesting in --attribute filters (default \".\")" + short: "-S SEPARATOR", + long: "--field-separator SEPARATOR", + description: "Character separator used to delineate nesting in --attribute filters (default \".\")" option :attribute, - :short => "-a ATTR1 [-a ATTR2]", - :long => "--attribute ATTR1 [--attribute ATTR2] ", - :description => "Show one or more attributes", - :proc => Proc.new { |a| + short: "-a ATTR1 [-a ATTR2]", + long: "--attribute ATTR1 [--attribute ATTR2] ", + description: "Show one or more attributes", + proc: Proc.new { |a| Chef::Config[:knife][:attribute] ||= [] Chef::Config[:knife][:attribute].push(a) } diff --git a/lib/chef/knife/core/node_presenter.rb b/lib/chef/knife/core/node_presenter.rb index cdb664ec33..7cb0e4d6fe 100644 --- a/lib/chef/knife/core/node_presenter.rb +++ b/lib/chef/knife/core/node_presenter.rb @@ -32,18 +32,18 @@ class Chef def self.included(includer) includer.class_eval do option :medium_output, - :short => "-m", - :long => "--medium", - :boolean => true, - :default => false, - :description => "Include normal attributes in the output" + short: "-m", + long: "--medium", + boolean: true, + default: false, + description: "Include normal attributes in the output" option :long_output, - :short => "-l", - :long => "--long", - :boolean => true, - :default => false, - :description => "Include all attributes in the output" + short: "-l", + long: "--long", + boolean: true, + default: false, + description: "Include all attributes in the output" end end end @@ -98,49 +98,49 @@ class Chef # special case ec2 with their split horizon whatsis. ip = (node[:ec2] && node[:ec2][:public_ipv4]) || node[:ipaddress] - summarized = <<-SUMMARY -#{ui.color('Node Name:', :bold)} #{ui.color(node.name, :bold)} + summarized = <<~SUMMARY + #{ui.color('Node Name:', :bold)} #{ui.color(node.name, :bold)} SUMMARY show_policy = !(node.policy_name.nil? && node.policy_group.nil?) if show_policy - summarized << <<-POLICY -#{key('Policy Name:')} #{node.policy_name} -#{key('Policy Group:')} #{node.policy_group} + summarized << <<~POLICY + #{key('Policy Name:')} #{node.policy_name} + #{key('Policy Group:')} #{node.policy_group} POLICY else - summarized << <<-ENV -#{key('Environment:')} #{node.chef_environment} + summarized << <<~ENV + #{key('Environment:')} #{node.chef_environment} ENV end - summarized << <<-SUMMARY -#{key('FQDN:')} #{node[:fqdn]} -#{key('IP:')} #{ip} -#{key('Run List:')} #{node.run_list} + summarized << <<~SUMMARY + #{key('FQDN:')} #{node[:fqdn]} + #{key('IP:')} #{ip} + #{key('Run List:')} #{node.run_list} SUMMARY unless show_policy - summarized << <<-ROLES -#{key('Roles:')} #{Array(node[:roles]).join(', ')} + summarized << <<~ROLES + #{key('Roles:')} #{Array(node[:roles]).join(', ')} ROLES end - summarized << <<-SUMMARY -#{key('Recipes:')} #{Array(node[:recipes]).join(', ')} -#{key('Platform:')} #{node[:platform]} #{node[:platform_version]} -#{key('Tags:')} #{node.tags.join(', ')} + summarized << <<~SUMMARY + #{key('Recipes:')} #{Array(node[:recipes]).join(', ')} + #{key('Platform:')} #{node[:platform]} #{node[:platform_version]} + #{key('Tags:')} #{node.tags.join(', ')} SUMMARY if config[:medium_output] || config[:long_output] - summarized += <<-MORE -#{key('Attributes:')} -#{text_format(node.normal_attrs)} + summarized += <<~MORE + #{key('Attributes:')} + #{text_format(node.normal_attrs)} MORE end if config[:long_output] - summarized += <<-MOST -#{key('Default Attributes:')} -#{text_format(node.default_attrs)} -#{key('Override Attributes:')} -#{text_format(node.override_attrs)} -#{key('Automatic Attributes (Ohai Data):')} -#{text_format(node.automatic_attrs)} + summarized += <<~MOST + #{key('Default Attributes:')} + #{text_format(node.default_attrs)} + #{key('Override Attributes:')} + #{text_format(node.override_attrs)} + #{key('Automatic Attributes (Ohai Data):')} + #{text_format(node.automatic_attrs)} MOST end summarized diff --git a/lib/chef/knife/core/status_presenter.rb b/lib/chef/knife/core/status_presenter.rb index 1e2d9b41b6..5672124007 100644 --- a/lib/chef/knife/core/status_presenter.rb +++ b/lib/chef/knife/core/status_presenter.rb @@ -32,18 +32,18 @@ class Chef def self.included(includer) includer.class_eval do option :medium_output, - :short => "-m", - :long => "--medium", - :boolean => true, - :default => false, - :description => "Include normal attributes in the output" + short: "-m", + long: "--medium", + boolean: true, + default: false, + description: "Include normal attributes in the output" option :long_output, - :short => "-l", - :long => "--long", - :boolean => true, - :default => false, - :description => "Include all attributes in the output" + short: "-l", + long: "--long", + boolean: true, + default: false, + description: "Include all attributes in the output" end end end @@ -101,7 +101,7 @@ class Chef fqdn = (node[:ec2] && node[:ec2][:public_hostname]) || node[:fqdn] name = node["name"] || node.name - run_list = "#{node['run_list']}" if config[:run_list] + run_list = (node["run_list"]).to_s if config[:run_list] line_parts = Array.new if node["ohai_time"] diff --git a/lib/chef/knife/data_bag_from_file.rb b/lib/chef/knife/data_bag_from_file.rb index 30b9de3386..91adcb3129 100644 --- a/lib/chef/knife/data_bag_from_file.rb +++ b/lib/chef/knife/data_bag_from_file.rb @@ -38,9 +38,9 @@ class Chef category "data bag" option :all, - :short => "-a", - :long => "--all", - :description => "Upload all data bags or all items for specified data bags" + short: "-a", + long: "--all", + description: "Upload all data bags or all items for specified data bags" def loader @loader ||= Knife::Core::ObjectLoader.new(DataBagItem, ui) @@ -84,7 +84,7 @@ class Chef items ||= find_all_data_bag_items(data_bag) item_paths = normalize_item_paths(items) item_paths.each do |item_path| - item = loader.load_from("#{data_bags_path}", data_bag, item_path) + item = loader.load_from((data_bags_path).to_s, data_bag, item_path) item = if encryption_secret_provided? Chef::EncryptedDataBagItem.encrypt_data_bag_item(item, read_secret) else diff --git a/lib/chef/knife/data_bag_list.rb b/lib/chef/knife/data_bag_list.rb index d507925ec8..454b0a4908 100644 --- a/lib/chef/knife/data_bag_list.rb +++ b/lib/chef/knife/data_bag_list.rb @@ -30,9 +30,9 @@ class Chef category "data bag" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run output(format_list_for_display(Chef::DataBag.list)) diff --git a/lib/chef/knife/data_bag_secret_options.rb b/lib/chef/knife/data_bag_secret_options.rb index a612004e15..62a3e71ec5 100644 --- a/lib/chef/knife/data_bag_secret_options.rb +++ b/lib/chef/knife/data_bag_secret_options.rb @@ -35,23 +35,23 @@ class Chef def self.included(base) base.option :secret, - :short => "-s SECRET", - :long => "--secret ", - :description => "The secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret'", + short: "-s SECRET", + long: "--secret ", + description: "The secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret'", # Need to store value from command line in separate variable - knife#merge_configs populates same keys # on config object from - :proc => Proc.new { |s| set_cl_secret(s) } + proc: Proc.new { |s| set_cl_secret(s) } base.option :secret_file, - :long => "--secret-file SECRET_FILE", - :description => "A file containing the secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret_file'", - :proc => Proc.new { |sf| set_cl_secret_file(sf) } + long: "--secret-file SECRET_FILE", + description: "A file containing the secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret_file'", + proc: Proc.new { |sf| set_cl_secret_file(sf) } base.option :encrypt, - :long => "--encrypt", - :description => "If 'secret' or 'secret_file' is present in your config, then encrypt data bags using it", - :boolean => true, - :default => false + long: "--encrypt", + description: "If 'secret' or 'secret_file' is present in your config, then encrypt data bags using it", + boolean: true, + default: false end def encryption_secret_provided? diff --git a/lib/chef/knife/delete.rb b/lib/chef/knife/delete.rb index 19f75df012..1c05fba3cf 100644 --- a/lib/chef/knife/delete.rb +++ b/lib/chef/knife/delete.rb @@ -28,21 +28,21 @@ class Chef end option :recurse, - :short => "-r", - :long => "--[no-]recurse", - :boolean => true, - :default => false, - :description => "Delete directories recursively." + short: "-r", + long: "--[no-]recurse", + boolean: true, + default: false, + description: "Delete directories recursively." option :both, - :long => "--both", - :boolean => true, - :default => false, - :description => "Delete both the local and remote copies." + long: "--both", + boolean: true, + default: false, + description: "Delete both the local and remote copies." option :local, - :long => "--local", - :boolean => true, - :default => false, - :description => "Delete the local copy (leave the remote copy)." + long: "--local", + boolean: true, + default: false, + description: "Delete the local copy (leave the remote copy)." def run if name_args.length == 0 diff --git a/lib/chef/knife/deps.rb b/lib/chef/knife/deps.rb index fb2a8bb40f..4cb77eea46 100644 --- a/lib/chef/knife/deps.rb +++ b/lib/chef/knife/deps.rb @@ -29,17 +29,17 @@ class Chef end option :recurse, - :long => "--[no-]recurse", - :boolean => true, - :description => "List dependencies recursively (default: true). Only works with --tree." + long: "--[no-]recurse", + boolean: true, + description: "List dependencies recursively (default: true). Only works with --tree." option :tree, - :long => "--tree", - :boolean => true, - :description => "Show dependencies in a visual tree. May show duplicates." + long: "--tree", + boolean: true, + description: "Show dependencies in a visual tree. May show duplicates." option :remote, - :long => "--remote", - :boolean => true, - :description => "List dependencies on the server instead of the local filesystem" + long: "--remote", + boolean: true, + description: "List dependencies on the server instead of the local filesystem" attr_accessor :exit_code diff --git a/lib/chef/knife/diff.rb b/lib/chef/knife/diff.rb index a14335c296..aac42ed5c5 100644 --- a/lib/chef/knife/diff.rb +++ b/lib/chef/knife/diff.rb @@ -28,29 +28,29 @@ class Chef end option :recurse, - :long => "--[no-]recurse", - :boolean => true, - :default => true, - :description => "List directories recursively." + long: "--[no-]recurse", + boolean: true, + default: true, + description: "List directories recursively." option :name_only, - :long => "--name-only", - :boolean => true, - :description => "Only show names of modified files." + long: "--name-only", + boolean: true, + description: "Only show names of modified files." option :name_status, - :long => "--name-status", - :boolean => true, - :description => "Only show names and statuses of modified files: Added, Deleted, Modified, and Type Changed." + long: "--name-status", + boolean: true, + description: "Only show names and statuses of modified files: Added, Deleted, Modified, and Type Changed." option :diff_filter, - :long => "--diff-filter=[(A|D|M|T)...[*]]", - :description => "Select only files that are Added (A), Deleted (D), Modified (M), or have their type (i.e. regular file, directory) changed (T). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if + long: "--diff-filter=[(A|D|M|T)...[*]]", + description: "Select only files that are Added (A), Deleted (D), Modified (M), or have their type (i.e. regular file, directory) changed (T). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected." option :cookbook_version, - :long => "--cookbook-version VERSION", - :description => "Version of cookbook to download (if there are multiple versions and cookbook_versions is false)" + long: "--cookbook-version VERSION", + description: "Version of cookbook to download (if there are multiple versions and cookbook_versions is false)" def run if config[:name_only] diff --git a/lib/chef/knife/download.rb b/lib/chef/knife/download.rb index 942d17d330..f1dfd13326 100644 --- a/lib/chef/knife/download.rb +++ b/lib/chef/knife/download.rb @@ -28,39 +28,39 @@ class Chef end option :recurse, - :long => "--[no-]recurse", - :boolean => true, - :default => true, - :description => "List directories recursively." + long: "--[no-]recurse", + boolean: true, + default: true, + description: "List directories recursively." option :purge, - :long => "--[no-]purge", - :boolean => true, - :default => false, - :description => "Delete matching local files and directories that do not exist remotely." + long: "--[no-]purge", + boolean: true, + default: false, + description: "Delete matching local files and directories that do not exist remotely." option :force, - :long => "--[no-]force", - :boolean => true, - :default => false, - :description => "Force upload of files even if they match (quicker and harmless, but doesn't print out what it changed)" + long: "--[no-]force", + boolean: true, + default: false, + description: "Force upload of files even if they match (quicker and harmless, but doesn't print out what it changed)" option :dry_run, - :long => "--dry-run", - :short => "-n", - :boolean => true, - :default => false, - :description => "Don't take action, only print what would happen" + long: "--dry-run", + short: "-n", + boolean: true, + default: false, + description: "Don't take action, only print what would happen" option :diff, - :long => "--[no-]diff", - :boolean => true, - :default => true, - :description => "Turn off to avoid uploading existing files; only new (and possibly deleted) files with --no-diff" + long: "--[no-]diff", + boolean: true, + default: true, + description: "Turn off to avoid uploading existing files; only new (and possibly deleted) files with --no-diff" option :cookbook_version, - :long => "--cookbook-version VERSION", - :description => "Version of cookbook to download (if there are multiple versions and cookbook_versions is false)" + long: "--cookbook-version VERSION", + description: "Version of cookbook to download (if there are multiple versions and cookbook_versions is false)" def run if name_args.length == 0 diff --git a/lib/chef/knife/edit.rb b/lib/chef/knife/edit.rb index 597b284356..e150babc31 100644 --- a/lib/chef/knife/edit.rb +++ b/lib/chef/knife/edit.rb @@ -29,9 +29,9 @@ class Chef end option :local, - :long => "--local", - :boolean => true, - :description => "Show local files instead of remote" + long: "--local", + boolean: true, + description: "Show local files instead of remote" def run # Get the matches (recursively) diff --git a/lib/chef/knife/environment_compare.rb b/lib/chef/knife/environment_compare.rb index 9131f06068..1395db3f34 100644 --- a/lib/chef/knife/environment_compare.rb +++ b/lib/chef/knife/environment_compare.rb @@ -29,16 +29,16 @@ class Chef banner "knife environment compare [ENVIRONMENT..] (options)" option :all, - :short => "-a", - :long => "--all", - :description => "Show all cookbooks", - :boolean => true + short: "-a", + long: "--all", + description: "Show all cookbooks", + boolean: true option :mismatch, - :short => "-m", - :long => "--mismatch", - :description => "Only show mismatching versions", - :boolean => true + short: "-m", + long: "--mismatch", + description: "Only show mismatching versions", + boolean: true def run # Get the commandline environments or all if none are provided. diff --git a/lib/chef/knife/environment_create.rb b/lib/chef/knife/environment_create.rb index cfc1bc268c..e533a70172 100644 --- a/lib/chef/knife/environment_create.rb +++ b/lib/chef/knife/environment_create.rb @@ -30,9 +30,9 @@ class Chef banner "knife environment create ENVIRONMENT (options)" option :description, - :short => "-d DESCRIPTION", - :long => "--description DESCRIPTION", - :description => "The environment description" + short: "-d DESCRIPTION", + long: "--description DESCRIPTION", + description: "The environment description" def run env_name = @name_args[0] diff --git a/lib/chef/knife/environment_from_file.rb b/lib/chef/knife/environment_from_file.rb index b16c3331bd..6e22e8b0f6 100644 --- a/lib/chef/knife/environment_from_file.rb +++ b/lib/chef/knife/environment_from_file.rb @@ -30,9 +30,9 @@ class Chef banner "knife environment from file FILE [FILE..] (options)" option :all, - :short => "-a", - :long => "--all", - :description => "Upload all environments" + short: "-a", + long: "--all", + description: "Upload all environments" def loader @loader ||= Knife::Core::ObjectLoader.new(Chef::Environment, ui) diff --git a/lib/chef/knife/environment_list.rb b/lib/chef/knife/environment_list.rb index f278046bf9..c3f2ef2e39 100644 --- a/lib/chef/knife/environment_list.rb +++ b/lib/chef/knife/environment_list.rb @@ -30,9 +30,9 @@ class Chef banner "knife environment list (options)" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run output(format_list_for_display(Chef::Environment.list)) diff --git a/lib/chef/knife/exec.rb b/lib/chef/knife/exec.rb index 7b27a51b85..ed7101c0cc 100644 --- a/lib/chef/knife/exec.rb +++ b/lib/chef/knife/exec.rb @@ -24,15 +24,15 @@ class Chef::Knife::Exec < Chef::Knife banner "knife exec [SCRIPT] (options)" option :exec, - :short => "-E CODE", - :long => "--exec CODE", - :description => "a string of Chef code to execute" + short: "-E CODE", + long: "--exec CODE", + description: "a string of Chef code to execute" option :script_path, - :short => "-p PATH:PATH", - :long => "--script-path PATH:PATH", - :description => "A colon-separated path to look for scripts in", - :proc => lambda { |o| o.split(":") } + short: "-p PATH:PATH", + long: "--script-path PATH:PATH", + description: "A colon-separated path to look for scripts in", + proc: lambda { |o| o.split(":") } deps do require "chef/shell/ext" diff --git a/lib/chef/knife/key_create.rb b/lib/chef/knife/key_create.rb index a9f9da97a7..395bbc4bfd 100644 --- a/lib/chef/knife/key_create.rb +++ b/lib/chef/knife/key_create.rb @@ -40,10 +40,10 @@ class Chef end def public_key_or_key_name_error_msg - <<EOS -You must pass either --public-key or --key-name, or both. -If you only pass --public-key, a key name will be generated from the fingerprint of your key. -If you only pass --key-name, a key pair will be generated by the server. + <<~EOS + You must pass either --public-key or --key-name, or both. + If you only pass --public-key, a key name will be generated from the fingerprint of your key. + If you only pass --key-name, a key pair will be generated by the server. EOS end diff --git a/lib/chef/knife/key_create_base.rb b/lib/chef/knife/key_create_base.rb index d02d5ee180..d69f442e71 100644 --- a/lib/chef/knife/key_create_base.rb +++ b/lib/chef/knife/key_create_base.rb @@ -25,24 +25,24 @@ class Chef def self.included(includer) includer.class_eval do option :public_key, - :short => "-p FILENAME", - :long => "--public-key FILENAME", - :description => "Public key for newly created key. If not passed, the server will create a key pair for you, but you must pass --key-name NAME in that case." + short: "-p FILENAME", + long: "--public-key FILENAME", + description: "Public key for newly created key. If not passed, the server will create a key pair for you, but you must pass --key-name NAME in that case." option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the private key to a file, if you requested the server to create one." + short: "-f FILE", + long: "--file FILE", + description: "Write the private key to a file, if you requested the server to create one." option :key_name, - :short => "-k NAME", - :long => "--key-name NAME", - :description => "The name for your key. If you do not pass a name, you must pass --public-key, and the name will default to the fingerprint of the public key passed." + short: "-k NAME", + long: "--key-name NAME", + description: "The name for your key. If you do not pass a name, you must pass --public-key, and the name will default to the fingerprint of the public key passed." option :expiration_date, - :short => "-e DATE", - :long => "--expiration-date DATE", - :description => "Optionally pass the expiration date for the key in ISO 8601 fomatted string: YYYY-MM-DDTHH:MM:SSZ e.g. 2013-12-24T21:00:00Z. Defaults to infinity if not passed. UTC timezone assumed." + short: "-e DATE", + long: "--expiration-date DATE", + description: "Optionally pass the expiration date for the key in ISO 8601 fomatted string: YYYY-MM-DDTHH:MM:SSZ e.g. 2013-12-24T21:00:00Z. Defaults to infinity if not passed. UTC timezone assumed." end end end diff --git a/lib/chef/knife/key_edit.rb b/lib/chef/knife/key_edit.rb index 8490d10fa5..d05ee11d1c 100644 --- a/lib/chef/knife/key_edit.rb +++ b/lib/chef/knife/key_edit.rb @@ -41,11 +41,11 @@ class Chef end def public_key_and_create_key_error_msg - <<EOS -You passed both --public-key and --create-key. Only pass one, or the other, or neither. -Do not pass either if you do not want to change the public_key field of your key. -Pass --public-key if you want to update the public_key field of your key from a specific public key. -Pass --create-key if you want the server to generate a new key and use that to update the public_key field of your key. + <<~EOS + You passed both --public-key and --create-key. Only pass one, or the other, or neither. + Do not pass either if you do not want to change the public_key field of your key. + Pass --public-key if you want to update the public_key field of your key from a specific public key. + Pass --create-key if you want the server to generate a new key and use that to update the public_key field of your key. EOS end diff --git a/lib/chef/knife/key_edit_base.rb b/lib/chef/knife/key_edit_base.rb index 1a613ef1bc..ecdb4b0038 100644 --- a/lib/chef/knife/key_edit_base.rb +++ b/lib/chef/knife/key_edit_base.rb @@ -25,29 +25,29 @@ class Chef def self.included(includer) includer.class_eval do option :public_key, - :short => "-p FILENAME", - :long => "--public-key FILENAME", - :description => "Replace the public_key field from a file on disk. If not passed, the public_key field will not change." + short: "-p FILENAME", + long: "--public-key FILENAME", + description: "Replace the public_key field from a file on disk. If not passed, the public_key field will not change." option :create_key, - :short => "-c", - :long => "--create-key", - :description => "Replace the public_key field with a key generated by the server. The private key will be returned." + short: "-c", + long: "--create-key", + description: "Replace the public_key field with a key generated by the server. The private key will be returned." option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the private key to a file, if you requested the server to create one via --create-key." + short: "-f FILE", + long: "--file FILE", + description: "Write the private key to a file, if you requested the server to create one via --create-key." option :key_name, - :short => "-k NAME", - :long => "--key-name NAME", - :description => "The new name for your key. Pass if you wish to update the name field of your key." + short: "-k NAME", + long: "--key-name NAME", + description: "The new name for your key. Pass if you wish to update the name field of your key." option :expiration_date, - :short => "-e DATE", - :long => "--expiration-date DATE", - :description => "Updates the expiration_date field of your key if passed. Pass in ISO 8601 fomatted string: YYYY-MM-DDTHH:MM:SSZ e.g. 2013-12-24T21:00:00Z or infinity. UTC timezone assumed." + short: "-e DATE", + long: "--expiration-date DATE", + description: "Updates the expiration_date field of your key if passed. Pass in ISO 8601 fomatted string: YYYY-MM-DDTHH:MM:SSZ e.g. 2013-12-24T21:00:00Z or infinity. UTC timezone assumed." end end end diff --git a/lib/chef/knife/key_list.rb b/lib/chef/knife/key_list.rb index 9a820b7a50..9d3a2c0c26 100644 --- a/lib/chef/knife/key_list.rb +++ b/lib/chef/knife/key_list.rb @@ -40,9 +40,9 @@ class Chef end def expired_and_non_expired_msg - <<EOS -You cannot pass both --only-expired and --only-non-expired. -Please pass one or none. + <<~EOS + You cannot pass both --only-expired and --only-non-expired. + Please pass one or none. EOS end diff --git a/lib/chef/knife/key_list_base.rb b/lib/chef/knife/key_list_base.rb index 95858e9ba1..6470bf78ad 100644 --- a/lib/chef/knife/key_list_base.rb +++ b/lib/chef/knife/key_list_base.rb @@ -25,19 +25,19 @@ class Chef def self.included(includer) includer.class_eval do option :with_details, - :short => "-w", - :long => "--with-details", - :description => "Show corresponding URIs and whether the key has expired or not." + short: "-w", + long: "--with-details", + description: "Show corresponding URIs and whether the key has expired or not." option :only_expired, - :short => "-e", - :long => "--only-expired", - :description => "Only show expired keys." + short: "-e", + long: "--only-expired", + description: "Only show expired keys." option :only_non_expired, - :short => "-n", - :long => "--only-non-expired", - :description => "Only show non-expired keys." + short: "-n", + long: "--only-non-expired", + description: "Only show non-expired keys." end end end diff --git a/lib/chef/knife/list.rb b/lib/chef/knife/list.rb index 7dc91d7266..9452478ddb 100644 --- a/lib/chef/knife/list.rb +++ b/lib/chef/knife/list.rb @@ -29,30 +29,30 @@ class Chef end option :recursive, - :short => "-R", - :boolean => true, - :description => "List directories recursively" + short: "-R", + boolean: true, + description: "List directories recursively" option :bare_directories, - :short => "-d", - :boolean => true, - :description => "When directories match the pattern, do not show the directories' children" + short: "-d", + boolean: true, + description: "When directories match the pattern, do not show the directories' children" option :local, - :long => "--local", - :boolean => true, - :description => "List local directory instead of remote" + long: "--local", + boolean: true, + description: "List local directory instead of remote" option :flat, - :short => "-f", - :long => "--flat", - :boolean => true, - :description => "Show a list of filenames rather than the prettified ls-like output normally produced" + short: "-f", + long: "--flat", + boolean: true, + description: "Show a list of filenames rather than the prettified ls-like output normally produced" option :one_column, - :short => "-1", - :boolean => true, - :description => "Show only one column of results" + short: "-1", + boolean: true, + description: "Show only one column of results" option :trailing_slashes, - :short => "-p", - :boolean => true, - :description => "Show trailing slashes after directories" + short: "-p", + boolean: true, + description: "Show trailing slashes after directories" attr_accessor :exit_code diff --git a/lib/chef/knife/node_edit.rb b/lib/chef/knife/node_edit.rb index 4632c0a5b4..7551a8a7da 100644 --- a/lib/chef/knife/node_edit.rb +++ b/lib/chef/knife/node_edit.rb @@ -32,10 +32,10 @@ class Chef banner "knife node edit NODE (options)" option :all_attributes, - :short => "-a", - :long => "--all", - :boolean => true, - :description => "Display all attributes when editing" + short: "-a", + long: "--all", + boolean: true, + description: "Display all attributes when editing" def run if node_name.nil? diff --git a/lib/chef/knife/node_list.rb b/lib/chef/knife/node_list.rb index 4885208136..4bc2c34508 100644 --- a/lib/chef/knife/node_list.rb +++ b/lib/chef/knife/node_list.rb @@ -30,9 +30,9 @@ class Chef banner "knife node list (options)" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run env = Chef::Config[:environment] diff --git a/lib/chef/knife/node_run_list_add.rb b/lib/chef/knife/node_run_list_add.rb index fb4ce3bc12..3fc28c041d 100644 --- a/lib/chef/knife/node_run_list_add.rb +++ b/lib/chef/knife/node_run_list_add.rb @@ -30,14 +30,14 @@ class Chef banner "knife node run_list add [NODE] [ENTRY [ENTRY]] (options)" option :after, - :short => "-a ITEM", - :long => "--after ITEM", - :description => "Place the ENTRY in the run list after ITEM" + short: "-a ITEM", + long: "--after ITEM", + description: "Place the ENTRY in the run list after ITEM" option :before, - :short => "-b ITEM", - :long => "--before ITEM", - :description => "Place the ENTRY in the run list before ITEM" + short: "-b ITEM", + long: "--before ITEM", + description: "Place the ENTRY in the run list before ITEM" def run node = Chef::Node.load(@name_args[0]) diff --git a/lib/chef/knife/node_show.rb b/lib/chef/knife/node_show.rb index 3092b3fc27..43e7e9dbee 100644 --- a/lib/chef/knife/node_show.rb +++ b/lib/chef/knife/node_show.rb @@ -34,14 +34,14 @@ class Chef banner "knife node show NODE (options)" option :run_list, - :short => "-r", - :long => "--run-list", - :description => "Show only the run list" + short: "-r", + long: "--run-list", + description: "Show only the run list" option :environment, - :short => "-E", - :long => "--environment", - :description => "Show only the Chef environment" + short: "-E", + long: "--environment", + description: "Show only the Chef environment" def run ui.use_presenter Knife::Core::NodePresenter diff --git a/lib/chef/knife/osc_user_create.rb b/lib/chef/knife/osc_user_create.rb index 74b50a4ef4..9ebf268110 100644 --- a/lib/chef/knife/osc_user_create.rb +++ b/lib/chef/knife/osc_user_create.rb @@ -32,25 +32,25 @@ class Chef end option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the private key to a file" + short: "-f FILE", + long: "--file FILE", + description: "Write the private key to a file" option :admin, - :short => "-a", - :long => "--admin", - :description => "Create the user as an admin", - :boolean => true + short: "-a", + long: "--admin", + description: "Create the user as an admin", + boolean: true option :user_password, - :short => "-p PASSWORD", - :long => "--password PASSWORD", - :description => "Password for newly created user", - :default => "" + short: "-p PASSWORD", + long: "--password PASSWORD", + description: "Password for newly created user", + default: "" option :user_key, - :long => "--user-key FILENAME", - :description => "Public key for newly created user. By default a key will be created for you." + long: "--user-key FILENAME", + description: "Public key for newly created user. By default a key will be created for you." banner "knife osc_user create USER (options)" diff --git a/lib/chef/knife/osc_user_list.rb b/lib/chef/knife/osc_user_list.rb index f1002c4f54..17a7a781d9 100644 --- a/lib/chef/knife/osc_user_list.rb +++ b/lib/chef/knife/osc_user_list.rb @@ -35,9 +35,9 @@ class Chef banner "knife osc_user list (options)" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run output(format_list_for_display(Chef::User.list)) diff --git a/lib/chef/knife/osc_user_reregister.rb b/lib/chef/knife/osc_user_reregister.rb index dee1cf41b1..5f5d3fb246 100644 --- a/lib/chef/knife/osc_user_reregister.rb +++ b/lib/chef/knife/osc_user_reregister.rb @@ -35,9 +35,9 @@ class Chef banner "knife osc_user reregister USER (options)" option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the private key to a file" + short: "-f FILE", + long: "--file FILE", + description: "Write the private key to a file" def run @user_name = @name_args[0] diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb index dfbf423e92..2d49c457fc 100644 --- a/lib/chef/knife/raw.rb +++ b/lib/chef/knife/raw.rb @@ -33,27 +33,27 @@ class Chef end option :method, - :long => "--method METHOD", - :short => "-m METHOD", - :default => "GET", - :description => "Request method (GET, POST, PUT or DELETE). Default: GET" + long: "--method METHOD", + short: "-m METHOD", + default: "GET", + description: "Request method (GET, POST, PUT or DELETE). Default: GET" option :pretty, - :long => "--[no-]pretty", - :boolean => true, - :default => true, - :description => "Pretty-print JSON output. Default: true" + long: "--[no-]pretty", + boolean: true, + default: true, + description: "Pretty-print JSON output. Default: true" option :input, - :long => "--input FILE", - :short => "-i FILE", - :description => "Name of file to use for PUT or POST" + long: "--input FILE", + short: "-i FILE", + description: "Name of file to use for PUT or POST" option :proxy_auth, - :long => "--proxy-auth", - :boolean => true, - :default => false, - :description => "Use webui proxy authentication. Client key must be the webui key." + long: "--proxy-auth", + boolean: true, + default: false, + description: "Use webui proxy authentication. Client key must be the webui key." # We need a custom HTTP client class here because we don't want to even # try to decode the body, in case we get back corrupted JSON or whatnot. @@ -105,7 +105,7 @@ class Chef result = Chef::JSONCompat.to_json_pretty(result) end else - chef_rest = RawInputServerAPI.new(:raw_output => true) + chef_rest = RawInputServerAPI.new(raw_output: true) result = chef_rest.request(method, name_args[0], headers, data) end output result diff --git a/lib/chef/knife/role_create.rb b/lib/chef/knife/role_create.rb index a389d849f7..6b953f31c8 100644 --- a/lib/chef/knife/role_create.rb +++ b/lib/chef/knife/role_create.rb @@ -30,9 +30,9 @@ class Chef banner "knife role create ROLE (options)" option :description, - :short => "-d DESC", - :long => "--description DESC", - :description => "The role description" + short: "-d DESC", + long: "--description DESC", + description: "The role description" def run @role_name = @name_args[0] diff --git a/lib/chef/knife/role_env_run_list_add.rb b/lib/chef/knife/role_env_run_list_add.rb index c24ae3d331..0f4bee9dbf 100644 --- a/lib/chef/knife/role_env_run_list_add.rb +++ b/lib/chef/knife/role_env_run_list_add.rb @@ -31,9 +31,9 @@ class Chef banner "knife role env_run_list add [ROLE] [ENVIRONMENT] [ENTRY [ENTRY]] (options)" option :after, - :short => "-a ITEM", - :long => "--after ITEM", - :description => "Place the ENTRY in the run list after ITEM" + short: "-a ITEM", + long: "--after ITEM", + description: "Place the ENTRY in the run list after ITEM" def add_to_env_run_list(role, environment, entries, after = nil) if after diff --git a/lib/chef/knife/role_env_run_list_remove.rb b/lib/chef/knife/role_env_run_list_remove.rb index 576e32e2a9..f31f40b58a 100644 --- a/lib/chef/knife/role_env_run_list_remove.rb +++ b/lib/chef/knife/role_env_run_list_remove.rb @@ -33,9 +33,9 @@ class Chef nlist = [] role.run_list_for(environment).each do |entry| nlist << entry unless entry == item_to_remove - #unless entry == @name_args[2] + # unless entry == @name_args[2] # nlist << entry - #end + # end end role.env_run_lists_add(environment => nlist) end diff --git a/lib/chef/knife/role_list.rb b/lib/chef/knife/role_list.rb index 1247478ef5..3d6c3b4574 100644 --- a/lib/chef/knife/role_list.rb +++ b/lib/chef/knife/role_list.rb @@ -30,9 +30,9 @@ class Chef banner "knife role list (options)" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run output(format_list_for_display(Chef::Role.list)) diff --git a/lib/chef/knife/role_run_list_add.rb b/lib/chef/knife/role_run_list_add.rb index df06d91725..c6564f9d04 100644 --- a/lib/chef/knife/role_run_list_add.rb +++ b/lib/chef/knife/role_run_list_add.rb @@ -31,9 +31,9 @@ class Chef banner "knife role run_list add [ROLE] [ENTRY [ENTRY]] (options)" option :after, - :short => "-a ITEM", - :long => "--after ITEM", - :description => "Place the ENTRY in the run list after ITEM" + short: "-a ITEM", + long: "--after ITEM", + description: "Place the ENTRY in the run list after ITEM" def add_to_env_run_list(role, environment, entries, after = nil) if after diff --git a/lib/chef/knife/role_run_list_remove.rb b/lib/chef/knife/role_run_list_remove.rb index 0dacfee051..6fd35c6aaa 100644 --- a/lib/chef/knife/role_run_list_remove.rb +++ b/lib/chef/knife/role_run_list_remove.rb @@ -33,9 +33,9 @@ class Chef nlist = [] role.run_list_for(environment).each do |entry| nlist << entry unless entry == item_to_remove - #unless entry == @name_args[2] + # unless entry == @name_args[2] # nlist << entry - #end + # end end role.env_run_lists_add(environment => nlist) end diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index 94c33aa594..1bc9ce9f7e 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -38,38 +38,38 @@ class Chef banner "knife search INDEX QUERY (options)" option :start, - :short => "-b ROW", - :long => "--start ROW", - :description => "The row to start returning results at", - :default => 0, - :proc => lambda { |i| i.to_i } + short: "-b ROW", + long: "--start ROW", + description: "The row to start returning results at", + default: 0, + proc: lambda { |i| i.to_i } option :rows, - :short => "-R INT", - :long => "--rows INT", - :description => "The number of rows to return", - :default => nil, - :proc => lambda { |i| i.to_i } + short: "-R INT", + long: "--rows INT", + description: "The number of rows to return", + default: nil, + proc: lambda { |i| i.to_i } option :run_list, - :short => "-r", - :long => "--run-list", - :description => "Show only the run list" + short: "-r", + long: "--run-list", + description: "Show only the run list" option :id_only, - :short => "-i", - :long => "--id-only", - :description => "Show only the ID of matching objects" + short: "-i", + long: "--id-only", + description: "Show only the ID of matching objects" option :query, - :short => "-q QUERY", - :long => "--query QUERY", - :description => "The search query; useful to protect queries starting with -" + short: "-q QUERY", + long: "--query QUERY", + description: "The search query; useful to protect queries starting with -" option :filter_result, - :short => "-f FILTER", - :long => "--filter-result FILTER", - :description => "Only return specific attributes of the matching objects; for example: \"ServerName=name, Kernel=kernel.version\"" + short: "-f FILTER", + long: "--filter-result FILTER", + description: "Only return specific attributes of the matching objects; for example: \"ServerName=name, Kernel=kernel.version\"" def run read_cli_args @@ -116,7 +116,7 @@ class Chef end if ui.interchange? - output({ :results => result_count, :rows => result_items }) + output({ results: result_count, rows: result_items }) else ui.log "#{result_count} items found" ui.log("\n") diff --git a/lib/chef/knife/serve.rb b/lib/chef/knife/serve.rb index cac7fe8884..eb5c98963c 100644 --- a/lib/chef/knife/serve.rb +++ b/lib/chef/knife/serve.rb @@ -24,16 +24,16 @@ class Chef banner "knife serve (options)" option :repo_mode, - :long => "--repo-mode MODE", - :description => "Specifies the local repository layout. Values: static (only environments/roles/data_bags/cookbooks), everything (includes nodes/clients/users), hosted_everything (includes acls/groups/etc. for Enterprise/Hosted Chef). Default: everything/hosted_everything" + long: "--repo-mode MODE", + description: "Specifies the local repository layout. Values: static (only environments/roles/data_bags/cookbooks), everything (includes nodes/clients/users), hosted_everything (includes acls/groups/etc. for Enterprise/Hosted Chef). Default: everything/hosted_everything" option :chef_repo_path, - :long => "--chef-repo-path PATH", - :description => "Overrides the location of chef repo. Default is specified by chef_repo_path in the config" + long: "--chef-repo-path PATH", + description: "Overrides the location of chef repo. Default is specified by chef_repo_path in the config" option :chef_zero_host, - :long => "--chef-zero-host IP", - :description => "Overrides the host upon which chef-zero listens. Default is 127.0.0.1." + long: "--chef-zero-host IP", + description: "Overrides the host upon which chef-zero listens. Default is 127.0.0.1." def configure_chef super diff --git a/lib/chef/knife/show.rb b/lib/chef/knife/show.rb index 92b7ce1483..4511a86004 100644 --- a/lib/chef/knife/show.rb +++ b/lib/chef/knife/show.rb @@ -29,9 +29,9 @@ class Chef end option :local, - :long => "--local", - :boolean => true, - :description => "Show local files instead of remote" + long: "--local", + boolean: true, + description: "Show local files instead of remote" def run # Get the matches (recursively) diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index c38dc43e74..74e457ac8e 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -40,105 +40,105 @@ class Chef banner "knife ssh QUERY COMMAND (options)" option :concurrency, - :short => "-C NUM", - :long => "--concurrency NUM", - :description => "The number of concurrent connections", - :default => nil, - :proc => lambda { |o| o.to_i } + short: "-C NUM", + long: "--concurrency NUM", + description: "The number of concurrent connections", + default: nil, + proc: lambda { |o| o.to_i } option :ssh_attribute, - :short => "-a ATTR", - :long => "--attribute ATTR", - :description => "The attribute to use for opening the connection - default depends on the context" + short: "-a ATTR", + long: "--attribute ATTR", + description: "The attribute to use for opening the connection - default depends on the context" option :manual, - :short => "-m", - :long => "--manual-list", - :boolean => true, - :description => "QUERY is a space separated list of servers", - :default => false + short: "-m", + long: "--manual-list", + boolean: true, + description: "QUERY is a space separated list of servers", + default: false option :prefix_attribute, - :long => "--prefix-attribute ATTR", - :description => "The attribute to use for prefixing the ouput - default depends on the context" + long: "--prefix-attribute ATTR", + description: "The attribute to use for prefixing the ouput - default depends on the context" option :ssh_user, - :short => "-x USERNAME", - :long => "--ssh-user USERNAME", - :description => "The ssh username" + short: "-x USERNAME", + long: "--ssh-user USERNAME", + description: "The ssh username" option :ssh_password_ng, - :short => "-P [PASSWORD]", - :long => "--ssh-password [PASSWORD]", - :description => "The ssh password - will prompt if flag is specified but no password is given", + short: "-P [PASSWORD]", + long: "--ssh-password [PASSWORD]", + description: "The ssh password - will prompt if flag is specified but no password is given", # default to a value that can not be a password (boolean) # so we can effectively test if this parameter was specified # without a value - :default => false + default: false option :ssh_port, - :short => "-p PORT", - :long => "--ssh-port PORT", - :description => "The ssh port", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key.strip } + short: "-p PORT", + long: "--ssh-port PORT", + description: "The ssh port", + proc: Proc.new { |key| Chef::Config[:knife][:ssh_port] = key.strip } option :ssh_timeout, - :short => "-t SECONDS", - :long => "--ssh-timeout SECONDS", - :description => "The ssh connection timeout", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_timeout] = key.strip.to_i }, - :default => 120 + short: "-t SECONDS", + long: "--ssh-timeout SECONDS", + description: "The ssh connection timeout", + proc: Proc.new { |key| Chef::Config[:knife][:ssh_timeout] = key.strip.to_i }, + default: 120 option :ssh_gateway, - :short => "-G GATEWAY", - :long => "--ssh-gateway GATEWAY", - :description => "The ssh gateway", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key.strip } + short: "-G GATEWAY", + long: "--ssh-gateway GATEWAY", + description: "The ssh gateway", + proc: Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key.strip } option :ssh_gateway_identity, - :long => "--ssh-gateway-identity SSH_GATEWAY_IDENTITY", - :description => "The SSH identity file used for gateway authentication" + long: "--ssh-gateway-identity SSH_GATEWAY_IDENTITY", + description: "The SSH identity file used for gateway authentication" option :forward_agent, - :short => "-A", - :long => "--forward-agent", - :description => "Enable SSH agent forwarding", - :boolean => true + short: "-A", + long: "--forward-agent", + description: "Enable SSH agent forwarding", + boolean: true option :ssh_identity_file, - :short => "-i IDENTITY_FILE", - :long => "--ssh-identity-file IDENTITY_FILE", - :description => "The SSH identity file used for authentication" + short: "-i IDENTITY_FILE", + long: "--ssh-identity-file IDENTITY_FILE", + description: "The SSH identity file used for authentication" option :host_key_verify, - :long => "--[no-]host-key-verify", - :description => "Verify host key, enabled by default.", - :boolean => true, - :default => true + long: "--[no-]host-key-verify", + description: "Verify host key, enabled by default.", + boolean: true, + default: true option :on_error, - :short => "-e", - :long => "--exit-on-error", - :description => "Immediately exit if an error is encountered", - :boolean => true, - :default => false + short: "-e", + long: "--exit-on-error", + description: "Immediately exit if an error is encountered", + boolean: true, + default: false option :duplicated_fqdns, - :long => "--duplicated-fqdns", - :description => "Behavior if FQDNs are duplicated, ignored by default", - :proc => Proc.new { |key| Chef::Config[:knife][:duplicated_fqdns] = key.strip.to_sym }, - :default => :ignore + long: "--duplicated-fqdns", + description: "Behavior if FQDNs are duplicated, ignored by default", + proc: Proc.new { |key| Chef::Config[:knife][:duplicated_fqdns] = key.strip.to_sym }, + default: :ignore option :tmux_split, - :long => "--tmux-split", - :description => "Split tmux window.", - :boolean => true, - :default => false + long: "--tmux-split", + description: "Split tmux window.", + boolean: true, + default: false def session ssh_error_handler = Proc.new do |server| if config[:on_error] - #Net::SSH::Multi magic to force exception to be re-raised. + # Net::SSH::Multi magic to force exception to be re-raised. throw :go, :raise else ui.warn "Failed to connect to #{server.host} -- #{$!.class.name}: #{$!.message}" @@ -146,7 +146,7 @@ class Chef end end - @session ||= Net::SSH::Multi.start(:concurrent_connections => config[:concurrency], :on_error => ssh_error_handler) + @session ||= Net::SSH::Multi.start(concurrent_connections: config[:concurrency], on_error: ssh_error_handler) end def configure_gateway @@ -505,18 +505,18 @@ class Chef end Appscript.app("/Applications/Utilities/Terminal.app").windows.first.activate - Appscript.app("System Events").application_processes["Terminal.app"].keystroke("n", :using => :command_down) + Appscript.app("System Events").application_processes["Terminal.app"].keystroke("n", using: :command_down) term = Appscript.app("Terminal") window = term.windows.first.get (session.servers_for.size - 1).times do |i| window.activate - Appscript.app("System Events").application_processes["Terminal.app"].keystroke("t", :using => :command_down) + Appscript.app("System Events").application_processes["Terminal.app"].keystroke("t", using: :command_down) end session.servers_for.each_with_index do |server, tab_number| cmd = "unset PROMPT_COMMAND; echo -e \"\\033]0;#{server.host}\\007\"; ssh #{server.user ? "#{server.user}@#{server.host}" : server.host}" - Appscript.app("Terminal").do_script(cmd, :in => window.tabs[tab_number + 1].get) + Appscript.app("Terminal").do_script(cmd, in: window.tabs[tab_number + 1].get) end end diff --git a/lib/chef/knife/ssl_check.rb b/lib/chef/knife/ssl_check.rb index c864ef52ec..858ab3cf89 100644 --- a/lib/chef/knife/ssl_check.rb +++ b/lib/chef/knife/ssl_check.rb @@ -151,25 +151,25 @@ class Chef debug_ssl_settings debug_chef_ssl_config - ui.warn(<<-BAD_CERTS) -There are invalid certificates in your trusted_certs_dir. -OpenSSL will not use the following certificates when verifying SSL connections: + ui.warn(<<~BAD_CERTS) + There are invalid certificates in your trusted_certs_dir. + OpenSSL will not use the following certificates when verifying SSL connections: -#{cert_debug_msg} + #{cert_debug_msg} -#{ui.color("TO FIX THESE WARNINGS:", :bold)} + #{ui.color("TO FIX THESE WARNINGS:", :bold)} -We are working on documentation for resolving common issues uncovered here. + We are working on documentation for resolving common issues uncovered here. -* If the certificate is generated by the server, you may try redownloading the -server's certificate. By default, the certificate is stored in the following -location on the host where your chef-server runs: + * If the certificate is generated by the server, you may try redownloading the + server's certificate. By default, the certificate is stored in the following + location on the host where your chef-server runs: - /var/opt/opscode/nginx/ca/SERVER_HOSTNAME.crt + /var/opt/opscode/nginx/ca/SERVER_HOSTNAME.crt -Copy that file to your trusted_certs_dir (currently: #{configuration.trusted_certs_dir}) -using SSH/SCP or some other secure method, then re-run this command to confirm -that the server's certificate is now trusted. + Copy that file to your trusted_certs_dir (currently: #{configuration.trusted_certs_dir}) + using SSH/SCP or some other secure method, then re-run this command to confirm + that the server's certificate is now trusted. BAD_CERTS # @TODO: ^ needs URL once documentation is posted. @@ -184,21 +184,21 @@ BAD_CERTS debug_ssl_settings debug_chef_ssl_config - ui.err(<<-ADVICE) + ui.err(<<~ADVICE) -#{ui.color("TO FIX THIS ERROR:", :bold)} + #{ui.color("TO FIX THIS ERROR:", :bold)} -If the server you are connecting to uses a self-signed certificate, you must -configure chef to trust that server's certificate. + If the server you are connecting to uses a self-signed certificate, you must + configure chef to trust that server's certificate. -By default, the certificate is stored in the following location on the host -where your chef-server runs: + By default, the certificate is stored in the following location on the host + where your chef-server runs: - /var/opt/opscode/nginx/ca/SERVER_HOSTNAME.crt + /var/opt/opscode/nginx/ca/SERVER_HOSTNAME.crt -Copy that file to your trusted_certs_dir (currently: #{configuration.trusted_certs_dir}) -using SSH/SCP or some other secure method, then re-run this command to confirm -that the server's certificate is now trusted. + Copy that file to your trusted_certs_dir (currently: #{configuration.trusted_certs_dir}) + using SSH/SCP or some other secure method, then re-run this command to confirm + that the server's certificate is now trusted. ADVICE end @@ -211,17 +211,17 @@ ADVICE ui.error("You are attempting to connect to: '#{host}'") ui.error("The server's certificate belongs to '#{cn}'") - ui.err(<<-ADVICE) + ui.err(<<~ADVICE) -#{ui.color("TO FIX THIS ERROR:", :bold)} + #{ui.color("TO FIX THIS ERROR:", :bold)} -The solution for this issue depends on your networking configuration. If you -are able to connect to this server using the hostname #{cn} -instead of #{host}, then you can resolve this issue by updating chef_server_url -in your configuration file. + The solution for this issue depends on your networking configuration. If you + are able to connect to this server using the hostname #{cn} + instead of #{host}, then you can resolve this issue by updating chef_server_url + in your configuration file. -If you are not able to connect to the server using the hostname #{cn} -you will have to update the certificate on the server to use the correct hostname. + If you are not able to connect to the server using the hostname #{cn} + you will have to update the certificate on the server to use the correct hostname. ADVICE end diff --git a/lib/chef/knife/ssl_fetch.rb b/lib/chef/knife/ssl_fetch.rb index 98c98d06ae..88eb95e97d 100644 --- a/lib/chef/knife/ssl_fetch.rb +++ b/lib/chef/knife/ssl_fetch.rb @@ -130,12 +130,12 @@ class Chef def run validate_uri - ui.warn(<<-TRUST_TRUST) -Certificates from #{host} will be fetched and placed in your trusted_cert -directory (#{trusted_certs_dir}). + ui.warn(<<~TRUST_TRUST) + Certificates from #{host} will be fetched and placed in your trusted_cert + directory (#{trusted_certs_dir}). -Knife has no means to verify these are the correct certificates. You should -verify the authenticity of these certificates after downloading. + Knife has no means to verify these are the correct certificates. You should + verify the authenticity of these certificates after downloading. TRUST_TRUST remote_cert_chain.each do |cert| diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb index 0e3cd7e7d6..413bff4f66 100644 --- a/lib/chef/knife/status.rb +++ b/lib/chef/knife/status.rb @@ -32,23 +32,23 @@ class Chef banner "knife status QUERY (options)" option :run_list, - :short => "-r", - :long => "--run-list", - :description => "Show the run list" + short: "-r", + long: "--run-list", + description: "Show the run list" option :sort_reverse, - :short => "-s", - :long => "--sort-reverse", - :description => "Sort the status list by last run time descending" + short: "-s", + long: "--sort-reverse", + description: "Sort the status list by last run time descending" option :hide_healthy, - :short => "-H", - :long => "--hide-healthy", - :description => "Hide nodes that have run chef in the last hour. [DEPRECATED] Use --hide-by-mins MINS instead" + short: "-H", + long: "--hide-healthy", + description: "Hide nodes that have run chef in the last hour. [DEPRECATED] Use --hide-by-mins MINS instead" option :hide_by_mins, - :long => "--hide-by-mins MINS", - :description => "Hide nodes that have run chef in the last MINS minutes" + long: "--hide-by-mins MINS", + description: "Hide nodes that have run chef in the last MINS minutes" def append_to_query(term) @query << " AND " unless @query.empty? diff --git a/lib/chef/knife/upload.rb b/lib/chef/knife/upload.rb index 063ed26892..e4e0a74b28 100644 --- a/lib/chef/knife/upload.rb +++ b/lib/chef/knife/upload.rb @@ -28,41 +28,41 @@ class Chef end option :recurse, - :long => "--[no-]recurse", - :boolean => true, - :default => true, - :description => "List directories recursively." + long: "--[no-]recurse", + boolean: true, + default: true, + description: "List directories recursively." option :purge, - :long => "--[no-]purge", - :boolean => true, - :default => false, - :description => "Delete matching local files and directories that do not exist remotely." + long: "--[no-]purge", + boolean: true, + default: false, + description: "Delete matching local files and directories that do not exist remotely." option :force, - :long => "--[no-]force", - :boolean => true, - :default => false, - :description => "Force upload of files even if they match (quicker for many files). Will overwrite frozen cookbooks." + long: "--[no-]force", + boolean: true, + default: false, + description: "Force upload of files even if they match (quicker for many files). Will overwrite frozen cookbooks." option :freeze, - :long => "--[no-]freeze", - :boolean => true, - :default => false, - :description => "Freeze cookbooks that get uploaded." + long: "--[no-]freeze", + boolean: true, + default: false, + description: "Freeze cookbooks that get uploaded." option :dry_run, - :long => "--dry-run", - :short => "-n", - :boolean => true, - :default => false, - :description => "Don't take action, only print what would happen" + long: "--dry-run", + short: "-n", + boolean: true, + default: false, + description: "Don't take action, only print what would happen" option :diff, - :long => "--[no-]diff", - :boolean => true, - :default => true, - :description => "Turn off to avoid uploading existing files; only new (and possibly deleted) files with --no-diff" + long: "--[no-]diff", + boolean: true, + default: true, + description: "Turn off to avoid uploading existing files; only new (and possibly deleted) files with --no-diff" def run if name_args.length == 0 diff --git a/lib/chef/knife/user_create.rb b/lib/chef/knife/user_create.rb index c4a89f3707..a1761de979 100644 --- a/lib/chef/knife/user_create.rb +++ b/lib/chef/knife/user_create.rb @@ -32,31 +32,31 @@ class Chef end option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the private key to a file if the server generated one." + short: "-f FILE", + long: "--file FILE", + description: "Write the private key to a file if the server generated one." option :user_key, - :long => "--user-key FILENAME", - :description => "Set the initial default key for the user from a file on disk (cannot pass with --prevent-keygen)." + long: "--user-key FILENAME", + description: "Set the initial default key for the user from a file on disk (cannot pass with --prevent-keygen)." option :prevent_keygen, - :short => "-k", - :long => "--prevent-keygen", - :description => "API V1 (Chef Server 12.1+) only. Prevent server from generating a default key pair for you. Cannot be passed with --user-key.", - :boolean => true + short: "-k", + long: "--prevent-keygen", + description: "API V1 (Chef Server 12.1+) only. Prevent server from generating a default key pair for you. Cannot be passed with --user-key.", + boolean: true option :admin, - :short => "-a", - :long => "--admin", - :description => "DEPRECATED: Open Source Chef 11 only. Create the user as an admin.", - :boolean => true + short: "-a", + long: "--admin", + description: "DEPRECATED: Open Source Chef 11 only. Create the user as an admin.", + boolean: true option :user_password, - :short => "-p PASSWORD", - :long => "--password PASSWORD", - :description => "DEPRECATED: Open Source Chef 11 only. Password for newly created user.", - :default => "" + short: "-p PASSWORD", + long: "--password PASSWORD", + description: "DEPRECATED: Open Source Chef 11 only. Password for newly created user.", + default: "" banner "knife user create USERNAME DISPLAY_NAME FIRST_NAME LAST_NAME EMAIL PASSWORD (options)" @@ -69,17 +69,17 @@ class Chef end def osc_11_warning - <<-EOF -IF YOU ARE USING CHEF SERVER 12+, PLEASE FOLLOW THE INSTRUCTIONS UNDER knife user create --help. -You only passed a single argument to knife user create. -For backwards compatibility, when only a single argument is passed, -knife user create assumes you want Open Source 11 Server user creation. -knife user create for Open Source 11 Server is being deprecated. -Open Source 11 Server user commands now live under the knife osc_user namespace. -For backwards compatibility, we will forward this request to knife osc_user create. -If you are using an Open Source 11 Server, please use that command to avoid this warning. -NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed -in Chef 15 which will be released April 2019. + <<~EOF + IF YOU ARE USING CHEF SERVER 12+, PLEASE FOLLOW THE INSTRUCTIONS UNDER knife user create --help. + You only passed a single argument to knife user create. + For backwards compatibility, when only a single argument is passed, + knife user create assumes you want Open Source 11 Server user creation. + knife user create for Open Source 11 Server is being deprecated. + Open Source 11 Server user commands now live under the knife osc_user namespace. + For backwards compatibility, we will forward this request to knife osc_user create. + If you are using an Open Source 11 Server, please use that command to avoid this warning. + NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed + in Chef 15 which will be released April 2019. EOF end diff --git a/lib/chef/knife/user_delete.rb b/lib/chef/knife/user_delete.rb index abfb45253e..b0a2ece065 100644 --- a/lib/chef/knife/user_delete.rb +++ b/lib/chef/knife/user_delete.rb @@ -30,15 +30,15 @@ class Chef banner "knife user delete USER (options)" def osc_11_warning - <<-EOF -The Chef Server you are using does not support the username field. -This means it is an Open Source 11 Server. -knife user delete for Open Source 11 Server is being deprecated. -Open Source 11 Server user commands now live under the knife osc_user namespace. -For backwards compatibility, we will forward this request to knife osc_user delete. -If you are using an Open Source 11 Server, please use that command to avoid this warning. -NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed -in Chef 15 which will be released April 2019. + <<~EOF + The Chef Server you are using does not support the username field. + This means it is an Open Source 11 Server. + knife user delete for Open Source 11 Server is being deprecated. + Open Source 11 Server user commands now live under the knife osc_user namespace. + For backwards compatibility, we will forward this request to knife osc_user delete. + If you are using an Open Source 11 Server, please use that command to avoid this warning. + NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed + in Chef 15 which will be released April 2019. EOF end diff --git a/lib/chef/knife/user_edit.rb b/lib/chef/knife/user_edit.rb index d184b85a6c..8b89b847a9 100644 --- a/lib/chef/knife/user_edit.rb +++ b/lib/chef/knife/user_edit.rb @@ -30,15 +30,15 @@ class Chef banner "knife user edit USER (options)" def osc_11_warning - <<-EOF -The Chef Server you are using does not support the username field. -This means it is an Open Source 11 Server. -knife user edit for Open Source 11 Server is being deprecated. -Open Source 11 Server user commands now live under the knife oc_user namespace. -For backwards compatibility, we will forward this request to knife osc_user edit. -If you are using an Open Source 11 Server, please use that command to avoid this warning. -NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed -in Chef 15 which will be released April 2019. + <<~EOF + The Chef Server you are using does not support the username field. + This means it is an Open Source 11 Server. + knife user edit for Open Source 11 Server is being deprecated. + Open Source 11 Server user commands now live under the knife oc_user namespace. + For backwards compatibility, we will forward this request to knife osc_user edit. + If you are using an Open Source 11 Server, please use that command to avoid this warning. + NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed + in Chef 15 which will be released April 2019. EOF end diff --git a/lib/chef/knife/user_list.rb b/lib/chef/knife/user_list.rb index 88e834025d..eccb8d15a4 100644 --- a/lib/chef/knife/user_list.rb +++ b/lib/chef/knife/user_list.rb @@ -32,9 +32,9 @@ class Chef banner "knife user list (options)" option :with_uri, - :short => "-w", - :long => "--with-uri", - :description => "Show corresponding URIs" + short: "-w", + long: "--with-uri", + description: "Show corresponding URIs" def run output(format_list_for_display(Chef::UserV1.list)) diff --git a/lib/chef/knife/user_reregister.rb b/lib/chef/knife/user_reregister.rb index fec6792134..c79deb09a7 100644 --- a/lib/chef/knife/user_reregister.rb +++ b/lib/chef/knife/user_reregister.rb @@ -30,15 +30,15 @@ class Chef banner "knife user reregister USER (options)" def osc_11_warning - <<-EOF -The Chef Server you are using does not support the username field. -This means it is an Open Source 11 Server. -knife user reregister for Open Source 11 Server is being deprecated. -Open Source 11 Server user commands now live under the knife osc_user namespace. -For backwards compatibility, we will forward this request to knife osc_user reregister. -If you are using an Open Source 11 Server, please use that command to avoid this warning. -NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed -in Chef 15 which will be released April 2019. + <<~EOF + The Chef Server you are using does not support the username field. + This means it is an Open Source 11 Server. + knife user reregister for Open Source 11 Server is being deprecated. + Open Source 11 Server user commands now live under the knife osc_user namespace. + For backwards compatibility, we will forward this request to knife osc_user reregister. + If you are using an Open Source 11 Server, please use that command to avoid this warning. + NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed + in Chef 15 which will be released April 2019. EOF end @@ -50,9 +50,9 @@ EOF end option :file, - :short => "-f FILE", - :long => "--file FILE", - :description => "Write the private key to a file" + short: "-f FILE", + long: "--file FILE", + description: "Write the private key to a file" def run @user_name = @name_args[0] diff --git a/lib/chef/knife/user_show.rb b/lib/chef/knife/user_show.rb index 6ba4ab5016..c2842aa576 100644 --- a/lib/chef/knife/user_show.rb +++ b/lib/chef/knife/user_show.rb @@ -32,15 +32,15 @@ class Chef banner "knife user show USER (options)" def osc_11_warning - <<-EOF -The Chef Server you are using does not support the username field. -This means it is an Open Source 11 Server. -knife user show for Open Source 11 Server is being deprecated. -Open Source 11 Server user commands now live under the knife osc_user namespace. -For backwards compatibility, we will forward this request to knife osc_user show. -If you are using an Open Source 11 Server, please use that command to avoid this warning. -NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed -in Chef 15 which will be released April 2019. + <<~EOF + The Chef Server you are using does not support the username field. + This means it is an Open Source 11 Server. + knife user show for Open Source 11 Server is being deprecated. + Open Source 11 Server user commands now live under the knife osc_user namespace. + For backwards compatibility, we will forward this request to knife osc_user show. + If you are using an Open Source 11 Server, please use that command to avoid this warning. + NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed + in Chef 15 which will be released April 2019. EOF end diff --git a/lib/chef/knife/xargs.rb b/lib/chef/knife/xargs.rb index f663b480e8..bb3ce39717 100644 --- a/lib/chef/knife/xargs.rb +++ b/lib/chef/knife/xargs.rb @@ -30,61 +30,61 @@ class Chef # TODO modify to remote-only / local-only pattern (more like delete) option :local, - :long => "--local", - :boolean => true, - :description => "Xargs local files instead of remote" + long: "--local", + boolean: true, + description: "Xargs local files instead of remote" option :patterns, - :long => "--pattern [PATTERN]", - :short => "-p [PATTERN]", - :description => "Pattern on command line (if these are not specified, a list of patterns is expected on standard input). Multiple patterns may be passed in this way.", - :arg_arity => [1, -1] + long: "--pattern [PATTERN]", + short: "-p [PATTERN]", + description: "Pattern on command line (if these are not specified, a list of patterns is expected on standard input). Multiple patterns may be passed in this way.", + arg_arity: [1, -1] option :diff, - :long => "--[no-]diff", - :default => true, - :boolean => true, - :description => "Whether to show a diff when files change (default: true)" + long: "--[no-]diff", + default: true, + boolean: true, + description: "Whether to show a diff when files change (default: true)" option :dry_run, - :long => "--dry-run", - :boolean => true, - :description => "Prevents changes from actually being uploaded to the server." + long: "--dry-run", + boolean: true, + description: "Prevents changes from actually being uploaded to the server." option :force, - :long => "--[no-]force", - :boolean => true, - :default => false, - :description => "Force upload of files even if they are not changed (quicker and harmless, but doesn't print out what it changed)" + long: "--[no-]force", + boolean: true, + default: false, + description: "Force upload of files even if they are not changed (quicker and harmless, but doesn't print out what it changed)" option :replace_first, - :long => "--replace-first REPLACESTR", - :short => "-J REPLACESTR", - :description => "String to replace with filenames. -J will only replace the FIRST occurrence of the replacement string." + long: "--replace-first REPLACESTR", + short: "-J REPLACESTR", + description: "String to replace with filenames. -J will only replace the FIRST occurrence of the replacement string." option :replace_all, - :long => "--replace REPLACESTR", - :short => "-I REPLACESTR", - :description => "String to replace with filenames. -I will replace ALL occurrence of the replacement string." + long: "--replace REPLACESTR", + short: "-I REPLACESTR", + description: "String to replace with filenames. -I will replace ALL occurrence of the replacement string." option :max_arguments_per_command, - :long => "--max-args MAXARGS", - :short => "-n MAXARGS", - :description => "Maximum number of arguments per command line." + long: "--max-args MAXARGS", + short: "-n MAXARGS", + description: "Maximum number of arguments per command line." option :max_command_line, - :long => "--max-chars LENGTH", - :short => "-s LENGTH", - :description => "Maximum size of command line, in characters" + long: "--max-chars LENGTH", + short: "-s LENGTH", + description: "Maximum size of command line, in characters" option :verbose_commands, - :short => "-t", - :description => "Print command to be run on the command line" + short: "-t", + description: "Print command to be run on the command line" option :null_separator, - :short => "-0", - :boolean => true, - :description => "Use the NULL character (\0) as a separator, instead of whitespace" + short: "-0", + boolean: true, + description: "Use the NULL character (\0) as a separator, instead of whitespace" def run error = false @@ -175,7 +175,7 @@ class Chef # Create the temporary files files.each do |file| tempfile = Tempfile.new(file.name) - tempfiles[tempfile] = { :file => file } + tempfiles[tempfile] = { file: file } end rescue destroy_tempfiles(files) diff --git a/lib/chef/log/winevt.rb b/lib/chef/log/winevt.rb index 506d4c9a6c..a35f99c52c 100644 --- a/lib/chef/log/winevt.rb +++ b/lib/chef/log/winevt.rb @@ -51,46 +51,46 @@ class Chef def info(msg) @eventlog.report_event( - :event_type => ::Win32::EventLog::INFO_TYPE, - :source => SOURCE, - :event_id => INFO_EVENT_ID, - :data => [msg] + event_type: ::Win32::EventLog::INFO_TYPE, + source: SOURCE, + event_id: INFO_EVENT_ID, + data: [msg] ) end def warn(msg) @eventlog.report_event( - :event_type => ::Win32::EventLog::WARN_TYPE, - :source => SOURCE, - :event_id => WARN_EVENT_ID, - :data => [msg] + event_type: ::Win32::EventLog::WARN_TYPE, + source: SOURCE, + event_id: WARN_EVENT_ID, + data: [msg] ) end def debug(msg) @eventlog.report_event( - :event_type => ::Win32::EventLog::INFO_TYPE, - :source => SOURCE, - :event_id => DEBUG_EVENT_ID, - :data => [msg] + event_type: ::Win32::EventLog::INFO_TYPE, + source: SOURCE, + event_id: DEBUG_EVENT_ID, + data: [msg] ) end def error(msg) @eventlog.report_event( - :event_type => ::Win32::EventLog::ERROR_TYPE, - :source => SOURCE, - :event_id => ERROR_EVENT_ID, - :data => [msg] + event_type: ::Win32::EventLog::ERROR_TYPE, + source: SOURCE, + event_id: ERROR_EVENT_ID, + data: [msg] ) end def fatal(msg) @eventlog.report_event( - :event_type => ::Win32::EventLog::ERROR_TYPE, - :source => SOURCE, - :event_id => FATAL_EVENT_ID, - :data => [msg] + event_type: ::Win32::EventLog::ERROR_TYPE, + source: SOURCE, + event_id: FATAL_EVENT_ID, + data: [msg] ) end diff --git a/lib/chef/mixin/api_version_request_handling.rb b/lib/chef/mixin/api_version_request_handling.rb index 5566addf1d..5b9a588cac 100644 --- a/lib/chef/mixin/api_version_request_handling.rb +++ b/lib/chef/mixin/api_version_request_handling.rb @@ -50,12 +50,12 @@ class Chef end def reregister_only_v0_supported_error_msg(max_version, min_version) - <<-EOH -The reregister command only supports server API version 0. -The server that received the request supports a min version of #{min_version} and a max version of #{max_version}. -User keys are now managed via the key rotation commmands. -Please refer to the documentation on how to manage your keys via the key rotation commands: -https://docs.chef.io/server_security.html#key-rotation + <<~EOH + The reregister command only supports server API version 0. + The server that received the request supports a min version of #{min_version} and a max version of #{max_version}. + User keys are now managed via the key rotation commmands. + Please refer to the documentation on how to manage your keys via the key rotation commands: + https://docs.chef.io/server_security.html#key-rotation EOH end diff --git a/lib/chef/mixin/deprecation.rb b/lib/chef/mixin/deprecation.rb index 6621555585..06726b5252 100644 --- a/lib/chef/mixin/deprecation.rb +++ b/lib/chef/mixin/deprecation.rb @@ -33,7 +33,7 @@ class Chef # Chef::Mixin::RecipeDefinitionDSLCore is deprecated, use Chef::DSL::Recipe instead. # EOM def self.deprecate_constant(name, replacement, message) - deprecated_constants[name] = { :replacement => replacement, :message => message } + deprecated_constants[name] = { replacement: replacement, message: message } end # Const missing hook to look up deprecated constants defined with diff --git a/lib/chef/mixin/securable.rb b/lib/chef/mixin/securable.rb index 788b236d94..eb59f184d1 100644 --- a/lib/chef/mixin/securable.rb +++ b/lib/chef/mixin/securable.rb @@ -24,7 +24,7 @@ class Chef set_or_return( :owner, arg, - :regex => Chef::Config[:user_valid_regex] + regex: Chef::Config[:user_valid_regex] ) end @@ -34,7 +34,7 @@ class Chef set_or_return( :group, arg, - :regex => Chef::Config[:group_valid_regex] + regex: Chef::Config[:group_valid_regex] ) end @@ -42,7 +42,7 @@ class Chef set_or_return( :mode, arg, - :callbacks => { + callbacks: { "not in valid numeric range" => lambda do |m| if m.kind_of?(String) m =~ /^0/ || m = "0#{m}" @@ -110,16 +110,16 @@ class Chef rights = instance_variable_get("@#{name}".to_sym) unless permissions.nil? input = { - :permissions => permissions, - :principals => principals, + permissions: permissions, + principals: principals, } input.merge!(args_hash) unless args_hash.nil? - validations = { :permissions => { :required => true }, - :principals => { :required => true, :kind_of => [String, Array] }, - :applies_to_children => { :equal_to => [ true, false, :containers_only, :objects_only ] }, - :applies_to_self => { :kind_of => [ TrueClass, FalseClass ] }, - :one_level_deep => { :kind_of => [ TrueClass, FalseClass ] }, + validations = { permissions: { required: true }, + principals: { required: true, kind_of: [String, Array] }, + applies_to_children: { equal_to: [ true, false, :containers_only, :objects_only ] }, + applies_to_self: { kind_of: [ TrueClass, FalseClass ] }, + one_level_deep: { kind_of: [ TrueClass, FalseClass ] }, } validate(input, validations) @@ -167,7 +167,7 @@ class Chef set_or_return( :inherits, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end end diff --git a/lib/chef/mixin/windows_env_helper.rb b/lib/chef/mixin/windows_env_helper.rb index 65b4b33cf0..610c0cd075 100644 --- a/lib/chef/mixin/windows_env_helper.rb +++ b/lib/chef/mixin/windows_env_helper.rb @@ -32,7 +32,7 @@ class Chef include Chef::ReservedNames::Win32::API::System end - #see: http://msdn.microsoft.com/en-us/library/ms682653%28VS.85%29.aspx + # see: http://msdn.microsoft.com/en-us/library/ms682653%28VS.85%29.aspx HWND_BROADCAST = 0xffff WM_SETTINGCHANGE = 0x001A SMTO_BLOCK = 0x0001 diff --git a/lib/chef/node.rb b/lib/chef/node.rb index f03e0ca0b1..b9a005e419 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -115,10 +115,10 @@ class Chef def name(arg = nil) if !arg.nil? validate( - { :name => arg }, - { :name => { :kind_of => String, - :cannot_be => :blank, - :regex => /^[\-[:alnum:]_:.]+$/ }, + { name: arg }, + { name: { kind_of: String, + cannot_be: :blank, + regex: /^[\-[:alnum:]_:.]+$/ }, }) @name = arg else @@ -130,7 +130,7 @@ class Chef set_or_return( :chef_environment, arg, - { :regex => /^[\-[:alnum:]_]+$/, :kind_of => String } + { regex: /^[\-[:alnum:]_]+$/, kind_of: String } ) end @@ -495,7 +495,7 @@ class Chef "chef_type" => "node", "default" => attributes.combined_default, "override" => attributes.combined_override, - #Render correctly for run_list items so malformed json does not result + # Render correctly for run_list items so malformed json does not result "run_list" => @primary_runlist.run_list.map { |item| item.to_s }, } # Chef Server rejects node JSON with extra keys; prior to 12.3, diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index c0066bfce5..6496d91de7 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -37,20 +37,20 @@ # class Chef class NodeMap - COLLISION_WARNING_14 = <<-EOH.gsub(/\s+/, " ").strip -%{type_caps} %{key} has been loaded from a cookbook. The %{type} %{key} is now -included in Chef and will take precedence over the existing cookbook %{type} in the -next major release of Chef (15.0, April 2019). You may be able to remove this cookbook dependency from -your runlist if you do not use other recipes/resources/libraries from the cookbook. -Alternatively there may be a newer version of this cookbook without the %{key} %{type}. + COLLISION_WARNING_14 = <<~EOH.gsub(/\s+/, " ").strip + %{type_caps} %{key} has been loaded from a cookbook. The %{type} %{key} is now + included in Chef and will take precedence over the existing cookbook %{type} in the + next major release of Chef (15.0, April 2019). You may be able to remove this cookbook dependency from + your runlist if you do not use other recipes/resources/libraries from the cookbook. + Alternatively there may be a newer version of this cookbook without the %{key} %{type}. EOH - COLLISION_WARNING_15 = <<-EOH.gsub(/\s+/, " ").strip -%{type_caps} %{key} attempted to load from a cookbook. The %{type} %{key} is now -included in Chef and takes precedence over the existing cookbook %{type} -which will be ignored. You may be able to remove this cookbook dependency from -your runlist if you do not use other recipes/resources/libraries from the cookbook. -Alternatively there may be a newer version of this cookbook without the %{key} %{type}. + COLLISION_WARNING_15 = <<~EOH.gsub(/\s+/, " ").strip + %{type_caps} %{key} attempted to load from a cookbook. The %{type} %{key} is now + included in Chef and takes precedence over the existing cookbook %{type} + which will be ignored. You may be able to remove this cookbook dependency from + your runlist if you do not use other recipes/resources/libraries from the cookbook. + Alternatively there may be a newer version of this cookbook without the %{key} %{type}. EOH # diff --git a/lib/chef/org.rb b/lib/chef/org.rb index 73a129c7c1..ea1c411b67 100644 --- a/lib/chef/org.rb +++ b/lib/chef/org.rb @@ -40,22 +40,22 @@ class Chef def name(arg = nil) set_or_return(:name, arg, - :regex => /^[a-z0-9\-_]+$/) + regex: /^[a-z0-9\-_]+$/) end def full_name(arg = nil) set_or_return(:full_name, - arg, :kind_of => String) + arg, kind_of: String) end def private_key(arg = nil) set_or_return(:private_key, - arg, :kind_of => String) + arg, kind_of: String) end def guid(arg = nil) set_or_return(:guid, - arg, :kind_of => String) + arg, kind_of: String) end def to_hash @@ -73,13 +73,13 @@ class Chef end def create - payload = { :name => name, :full_name => full_name } + payload = { name: name, full_name: full_name } new_org = chef_rest.post("organizations", payload) Chef::Org.from_hash(to_hash.merge(new_org)) end def update - payload = { :name => name, :full_name => full_name } + payload = { name: name, full_name: full_name } new_org = chef_rest.put("organizations/#{name}", payload) Chef::Org.from_hash(to_hash.merge(new_org)) end @@ -99,10 +99,10 @@ class Chef end def associate_user(username) - request_body = { :user => username } + request_body = { user: username } response = chef_rest.post "organizations/#{@name}/association_requests", request_body association_id = response["uri"].split("/").last - chef_rest.put "users/#{username}/association_requests/#{association_id}", { :response => "accept" } + chef_rest.put "users/#{username}/association_requests/#{association_id}", { response: "accept" } end def dissociate_user(username) diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb index b390042ea7..c91c74b047 100644 --- a/lib/chef/policy_builder/expand_node_object.rb +++ b/lib/chef/policy_builder/expand_node_object.rb @@ -175,7 +175,7 @@ class Chef begin events.cookbook_resolution_start(@expanded_run_list_with_versions) cookbook_hash = api_service.post("environments/#{node.chef_environment}/cookbook_versions", - { :run_list => @expanded_run_list_with_versions }) + { run_list: @expanded_run_list_with_versions }) cookbook_hash = cookbook_hash.inject({}) do |memo, (key, value)| memo[key] = Chef::CookbookVersion.from_hash(value) diff --git a/lib/chef/provider/cron/unix.rb b/lib/chef/provider/cron/unix.rb index 15195dbb88..4edd5ba206 100644 --- a/lib/chef/provider/cron/unix.rb +++ b/lib/chef/provider/cron/unix.rb @@ -33,7 +33,7 @@ class Chef private def read_crontab - crontab = shell_out("/usr/bin/crontab -l", :user => @new_resource.user) + crontab = shell_out("/usr/bin/crontab -l", user: @new_resource.user) status = crontab.status.exitstatus logger.trace crontab.format_for_exception if status > 0 @@ -53,7 +53,7 @@ class Chef exit_status = 0 error_message = "" begin - crontab_write = shell_out("/usr/bin/crontab #{tempcron.path}", :user => @new_resource.user) + crontab_write = shell_out("/usr/bin/crontab #{tempcron.path}", user: @new_resource.user) stderr = crontab_write.stderr exit_status = crontab_write.status.exitstatus # solaris9, 10 on some failures for example invalid 'mins' in crontab fails with exit code of zero :( diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb index 9c147cb634..3a209a08a1 100644 --- a/lib/chef/provider/dsc_resource.rb +++ b/lib/chef/provider/dsc_resource.rb @@ -169,7 +169,7 @@ class Chef "Invoke-DscResource #{switches}", output_format ) - cmdlet.run!({}, { :timeout => new_resource.timeout }) + cmdlet.run!({}, { timeout: new_resource.timeout }) end def return_dsc_resource_result(result, property_name) diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb index 7a101fa68b..fd20f34786 100644 --- a/lib/chef/provider/dsc_script.rb +++ b/lib/chef/provider/dsc_script.rb @@ -32,10 +32,10 @@ class Chef @dsc_resource = dsc_resource @resource_converged = false @operations = { - :set => Proc.new do |config_manager, document, shellout_flags| + set: Proc.new do |config_manager, document, shellout_flags| config_manager.set_configuration(document, shellout_flags) end, - :test => Proc.new do |config_manager, document, shellout_flags| + test: Proc.new do |config_manager, document, shellout_flags| config_manager.test_configuration(document, shellout_flags) end } end @@ -86,9 +86,9 @@ class Chef config_manager = Chef::Util::DSC::LocalConfigurationManager.new(@run_context.node, config_directory) shellout_flags = { - :cwd => @dsc_resource.cwd, - :environment => @dsc_resource.environment, - :timeout => @dsc_resource.timeout, + cwd: @dsc_resource.cwd, + environment: @dsc_resource.environment, + timeout: @dsc_resource.timeout, } begin @@ -113,9 +113,9 @@ class Chef def generate_configuration_document(config_directory, configuration_flags) shellout_flags = { - :cwd => @dsc_resource.cwd, - :environment => @dsc_resource.environment, - :timeout => @dsc_resource.timeout, + cwd: @dsc_resource.cwd, + environment: @dsc_resource.environment, + timeout: @dsc_resource.timeout, } generator = Chef::Util::DSC::ConfigurationGenerator.new(@run_context.node, config_directory) diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb index 3d3255260f..1b97dbf464 100644 --- a/lib/chef/provider/execute.rb +++ b/lib/chef/provider/execute.rb @@ -102,7 +102,7 @@ class Chef opts[:log_tag] = new_resource.to_s if (logger.info? || live_stream?) && !sensitive? if run_context.events.formatter? - opts[:live_stream] = Chef::EventDispatch::EventsOutputStream.new(run_context.events, :name => :execute) + opts[:live_stream] = Chef::EventDispatch::EventsOutputStream.new(run_context.events, name: :execute) elsif stream_to_stdout? opts[:live_stream] = STDOUT end diff --git a/lib/chef/provider/http_request.rb b/lib/chef/provider/http_request.rb index 885d473a7a..e8aad1e896 100644 --- a/lib/chef/provider/http_request.rb +++ b/lib/chef/provider/http_request.rb @@ -37,7 +37,7 @@ class Chef # CHEF-4762: we expect a nil return value from Chef::HTTP for a "200 Success" response # and false for a "304 Not Modified" response modified = @http.head( - "#{new_resource.url}", + (new_resource.url).to_s, new_resource.headers ) logger.info("#{new_resource} HEAD to #{new_resource.url} successful") @@ -54,7 +54,7 @@ class Chef message = check_message(new_resource.message) body = @http.get( - "#{new_resource.url}", + (new_resource.url).to_s, new_resource.headers ) logger.info("#{new_resource} GET to #{new_resource.url} successful") @@ -67,7 +67,7 @@ class Chef converge_by("#{new_resource} PATCH to #{new_resource.url}") do message = check_message(new_resource.message) body = @http.patch( - "#{new_resource.url}", + (new_resource.url).to_s, message, new_resource.headers ) @@ -81,7 +81,7 @@ class Chef converge_by("#{new_resource} PUT to #{new_resource.url}") do message = check_message(new_resource.message) body = @http.put( - "#{new_resource.url}", + (new_resource.url).to_s, message, new_resource.headers ) @@ -95,7 +95,7 @@ class Chef converge_by("#{new_resource} POST to #{new_resource.url}") do message = check_message(new_resource.message) body = @http.post( - "#{new_resource.url}", + (new_resource.url).to_s, message, new_resource.headers ) @@ -108,7 +108,7 @@ class Chef def action_delete converge_by("#{new_resource} DELETE to #{new_resource.url}") do body = @http.delete( - "#{new_resource.url}", + (new_resource.url).to_s, new_resource.headers ) new_resource.updated_by_last_action(true) diff --git a/lib/chef/provider/mdadm.rb b/lib/chef/provider/mdadm.rb index c5f15a851a..9b023b1a65 100644 --- a/lib/chef/provider/mdadm.rb +++ b/lib/chef/provider/mdadm.rb @@ -31,7 +31,7 @@ class Chef logger.trace("#{new_resource} checking for software raid device #{current_resource.raid_device}") device_not_found = 4 - mdadm = shell_out!("mdadm --detail --test #{new_resource.raid_device}", :returns => [0, device_not_found]) + mdadm = shell_out!("mdadm --detail --test #{new_resource.raid_device}", returns: [0, device_not_found]) exists = (mdadm.status == 0) current_resource.exists(exists) end diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index d0da30a30a..52d55f5404 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -232,7 +232,7 @@ class Chef def device_logstring case @new_resource.device_type when :device - "#{device_real}" + (device_real).to_s when :label "#{device_real} with label #{@new_resource.device}" when :uuid diff --git a/lib/chef/provider/mount/windows.rb b/lib/chef/provider/mount/windows.rb index 590b2bfa52..1650d1e43a 100644 --- a/lib/chef/provider/mount/windows.rb +++ b/lib/chef/provider/mount/windows.rb @@ -41,7 +41,7 @@ class Chef def load_current_resource if is_volume(@new_resource.device) @mount = Chef::Util::Windows::Volume.new(@new_resource.mount_point) - else #assume network drive + else # assume network drive @mount = Chef::Util::Windows::NetUse.new(@new_resource.mount_point) end @@ -61,10 +61,10 @@ class Chef def mount_fs unless @current_resource.mounted - @mount.add(:remote => @new_resource.device, - :username => @new_resource.username, - :domainname => @new_resource.domain, - :password => @new_resource.password) + @mount.add(remote: @new_resource.device, + username: @new_resource.username, + domainname: @new_resource.domain, + password: @new_resource.password) logger.trace("#{@new_resource} is mounted at #{@new_resource.mount_point}") else logger.trace("#{@new_resource} is already mounted at #{@new_resource.mount_point}") diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 0af4f87d7f..01d8829dd2 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -307,7 +307,7 @@ class Chef # used by subclasses. deprecated. use #a_to_s instead. def expand_options(options) # its deprecated but still work to do to deprecate it fully - #Chef.deprecated(:package_misc, "expand_options is deprecated, use shell_out instead") + # Chef.deprecated(:package_misc, "expand_options is deprecated, use shell_out instead") if options " #{options.is_a?(Array) ? Shellwords.join(options) : options}" else diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb index c60483d0dc..eb27b23408 100644 --- a/lib/chef/provider/package/chocolatey.rb +++ b/lib/chef/provider/package/chocolatey.rb @@ -31,12 +31,12 @@ class Chef use_multipackage_api PATHFINDING_POWERSHELL_COMMAND = "[System.Environment]::GetEnvironmentVariable('ChocolateyInstall', 'MACHINE')".freeze - CHOCO_MISSING_MSG = <<-EOS.freeze -Could not locate your Chocolatey install. To install chocolatey, we recommend -the 'chocolatey' cookbook (https://github.com/chocolatey/chocolatey-cookbook). -If Chocolatey is installed, ensure that the 'ChocolateyInstall' environment -variable is correctly set. You can verify this with the PowerShell command -'#{PATHFINDING_POWERSHELL_COMMAND}'. + CHOCO_MISSING_MSG = <<~EOS.freeze + Could not locate your Chocolatey install. To install chocolatey, we recommend + the 'chocolatey' cookbook (https://github.com/chocolatey/chocolatey-cookbook). + If Chocolatey is installed, ensure that the 'ChocolateyInstall' environment + variable is correctly set. You can verify this with the PowerShell command + '#{PATHFINDING_POWERSHELL_COMMAND}'. EOS # Responsible for building the current_resource. diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 5af73b8b69..31521c3675 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -85,10 +85,10 @@ class Chef # in that block will still trigger a syntax error which is # exactly what we want here -- verify the syntax without # actually running the script. - user_code_wrapped_in_powershell_script_block = <<-EOH -{ - #{new_resource.code} -} + user_code_wrapped_in_powershell_script_block = <<~EOH + { + #{new_resource.code} + } EOH user_script_file.puts user_code_wrapped_in_powershell_script_block @@ -146,75 +146,75 @@ EOH # executed, otherwise 0 or 1 based on whether $? is set to true # (success, where we return 0) or false (where we return 1). def wrapper_script - <<-EOH -# Chef Client wrapper for powershell_script resources - -# In rare cases, such as when PowerShell is executed -# as an alternate user, the new-variable cmdlet is not -# available, so import it just in case -if ( get-module -ListAvailable Microsoft.PowerShell.Utility ) -{ - Import-Module Microsoft.PowerShell.Utility -} - -# LASTEXITCODE can be uninitialized -- make it explictly 0 -# to avoid incorrect detection of failure (non-zero) codes -$global:LASTEXITCODE = 0 - -# Catch any exceptions -- without this, exceptions will result -# In a zero return code instead of the desired non-zero code -# that indicates a failure -trap [Exception] {write-error ($_.Exception.Message);exit 1} - -# Variable state that should not be accessible to the user code -new-variable -name interpolatedexitcode -visibility private -value $#{new_resource.convert_boolean_return} -new-variable -name chefscriptresult -visibility private - -# Initialize a variable we use to capture $? inside a block -$global:lastcmdlet = $null - -# Execute the user's code in a script block -- -$chefscriptresult = -{ - #{new_resource.code} - - # This assignment doesn't affect the block's return value - $global:lastcmdlet = $? -}.invokereturnasis() - -# Assume failure status of 1 -- success cases -# will have to override this -$exitstatus = 1 - -# If convert_boolean_return is enabled, the block's return value -# gets precedence in determining our exit status -if ($interpolatedexitcode -and $chefscriptresult -ne $null -and $chefscriptresult.gettype().name -eq 'boolean') -{ - $exitstatus = [int32](!$chefscriptresult) -} -elseif ($lastcmdlet) -{ - # Otherwise, a successful cmdlet execution defines the status - $exitstatus = 0 -} -elseif ( $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0 ) -{ - # If the cmdlet status is failed, allow the Win32 status - # in $LASTEXITCODE to define exit status. This handles the case - # where no cmdlets, only Win32 processes have run since $? - # will be set to $false whenever a Win32 process returns a non-zero - # status. - $exitstatus = $LASTEXITCODE -} - -# Print STDOUT for the script execution -Write-Output $chefscriptresult - -# If this script is launched with -File, the process exit -# status of PowerShell.exe will be $exitstatus. If it was -# launched with -Command, it will be 0 if $exitstatus was 0, -# 1 (i.e. failed) otherwise. -exit $exitstatus + <<~EOH + # Chef Client wrapper for powershell_script resources + + # In rare cases, such as when PowerShell is executed + # as an alternate user, the new-variable cmdlet is not + # available, so import it just in case + if ( get-module -ListAvailable Microsoft.PowerShell.Utility ) + { + Import-Module Microsoft.PowerShell.Utility + } + + # LASTEXITCODE can be uninitialized -- make it explictly 0 + # to avoid incorrect detection of failure (non-zero) codes + $global:LASTEXITCODE = 0 + + # Catch any exceptions -- without this, exceptions will result + # In a zero return code instead of the desired non-zero code + # that indicates a failure + trap [Exception] {write-error ($_.Exception.Message);exit 1} + + # Variable state that should not be accessible to the user code + new-variable -name interpolatedexitcode -visibility private -value $#{new_resource.convert_boolean_return} + new-variable -name chefscriptresult -visibility private + + # Initialize a variable we use to capture $? inside a block + $global:lastcmdlet = $null + + # Execute the user's code in a script block -- + $chefscriptresult = + { + #{new_resource.code} + + # This assignment doesn't affect the block's return value + $global:lastcmdlet = $? + }.invokereturnasis() + + # Assume failure status of 1 -- success cases + # will have to override this + $exitstatus = 1 + + # If convert_boolean_return is enabled, the block's return value + # gets precedence in determining our exit status + if ($interpolatedexitcode -and $chefscriptresult -ne $null -and $chefscriptresult.gettype().name -eq 'boolean') + { + $exitstatus = [int32](!$chefscriptresult) + } + elseif ($lastcmdlet) + { + # Otherwise, a successful cmdlet execution defines the status + $exitstatus = 0 + } + elseif ( $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0 ) + { + # If the cmdlet status is failed, allow the Win32 status + # in $LASTEXITCODE to define exit status. This handles the case + # where no cmdlets, only Win32 processes have run since $? + # will be set to $false whenever a Win32 process returns a non-zero + # status. + $exitstatus = $LASTEXITCODE + } + + # Print STDOUT for the script execution + Write-Output $chefscriptresult + + # If this script is launched with -File, the process exit + # status of PowerShell.exe will be $exitstatus. If it was + # launched with -Command, it will be 0 if $exitstatus was 0, + # 1 (i.e. failed) otherwise. + exit $exitstatus EOH end diff --git a/lib/chef/provider/reboot.rb b/lib/chef/provider/reboot.rb index f054af0567..dd07e7448d 100644 --- a/lib/chef/provider/reboot.rb +++ b/lib/chef/provider/reboot.rb @@ -45,10 +45,10 @@ class Chef # @return [void] def request_reboot node.run_context.request_reboot( - :delay_mins => new_resource.delay_mins, - :reason => new_resource.reason, - :timestamp => Time.now, - :requested_by => new_resource.name + delay_mins: new_resource.delay_mins, + reason: new_resource.reason, + timestamp: Time.now, + requested_by: new_resource.name ) end diff --git a/lib/chef/provider/remote_file/sftp.rb b/lib/chef/provider/remote_file/sftp.rb index 21c5c4ca04..66540fea8c 100644 --- a/lib/chef/provider/remote_file/sftp.rb +++ b/lib/chef/provider/remote_file/sftp.rb @@ -58,7 +58,7 @@ class Chef def sftp host = port ? "#{hostname}:#{port}" : hostname - @sftp ||= Net::SFTP.start(host, user, :password => pass) + @sftp ||= Net::SFTP.start(host, user, password: pass) end def pass diff --git a/lib/chef/provider/resource_update.rb b/lib/chef/provider/resource_update.rb index e069a8201c..d3c674dd22 100644 --- a/lib/chef/provider/resource_update.rb +++ b/lib/chef/provider/resource_update.rb @@ -31,7 +31,7 @@ class Chef attr_accessor :type attr_accessor :name - attr_accessor :duration #ms + attr_accessor :duration # ms attr_accessor :status attr_accessor :initial_state attr_accessor :final_state diff --git a/lib/chef/provider/service/openbsd.rb b/lib/chef/provider/service/openbsd.rb index 552173fbee..126a431742 100644 --- a/lib/chef/provider/service/openbsd.rb +++ b/lib/chef/provider/service/openbsd.rb @@ -116,7 +116,7 @@ class Chef old_list = rc_conf_local.match(/^pkg_scripts="(.*)"/) old_list = old_list ? old_list[1].split(" ") : [] new_list = old_list - [new_resource.service_name] - update_rcl rc_conf_local.sub(/^pkg_scripts="(.*)"/, pkg_scripts = "#{new_list.join(' ')}") + update_rcl rc_conf_local.sub(/^pkg_scripts="(.*)"/, pkg_scripts = (new_list.join(" ")).to_s) end end end diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb index 1da3d7c01a..18ef245083 100644 --- a/lib/chef/provider/service/redhat.rb +++ b/lib/chef/provider/service/redhat.rb @@ -81,7 +81,7 @@ class Chef super if ::File.exists?("/sbin/chkconfig") - chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", :returns => [0, 1]) + chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", returns: [0, 1]) unless run_levels.nil? || run_levels.empty? all_levels_match = true chkconfig.stdout.split(/\s+/)[1..-1].each do |level| diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb index f2b1ec4262..51105bd06f 100644 --- a/lib/chef/provider/service/solaris.rb +++ b/lib/chef/provider/service/solaris.rb @@ -80,7 +80,7 @@ class Chef end def service_status - cmd = shell_out!(@status_command, "-l", @current_resource.service_name, :returns => [0, 1]) + cmd = shell_out!(@status_command, "-l", @current_resource.service_name, returns: [0, 1]) # Example output # $ svcs -l rsyslog # fmri svc:/application/rsyslog:default diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb index badd7695a5..6d5bc338c7 100644 --- a/lib/chef/provider/service/systemd.rb +++ b/lib/chef/provider/service/systemd.rb @@ -79,10 +79,10 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple if new_resource.user uid = Etc.getpwnam(new_resource.user).uid options = { - :environment => { + environment: { "DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{uid}/bus", }, - :user => new_resource.user, + user: new_resource.user, } args = "--user" else diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index 487940e84e..2482ce6a5c 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -33,12 +33,12 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service include Chef::ReservedNames::Win32::API::Error rescue LoadError include Chef::Win32ServiceConstants - #Win32::Service.get_start_type + # Win32::Service.get_start_type AUTO_START = "auto start" MANUAL = "demand start" DISABLED = "disabled" - #Win32::Service.get_current_state + # Win32::Service.get_current_state RUNNING = "running" STOPPED = "stopped" CONTINUE_PENDING = "continue pending" @@ -361,8 +361,8 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service logger.trace "#{@new_resource.name} setting start_type to #{type}" Win32::Service.configure( - :service_name => @new_resource.service_name, - :start_type => startup_type + service_name: @new_resource.service_name, + start_type: startup_type ) @new_resource.updated_by_last_action(true) end diff --git a/lib/chef/provider/subversion.rb b/lib/chef/provider/subversion.rb index abcc260a78..dec9e06f87 100644 --- a/lib/chef/provider/subversion.rb +++ b/lib/chef/provider/subversion.rb @@ -16,7 +16,7 @@ # limitations under the License. # -#TODO subversion and git should both extend from a base SCM provider. +# TODO subversion and git should both extend from a base SCM provider. require "chef/log" require "chef/provider" @@ -126,7 +126,7 @@ class Chef new_resource.revision else command = scm(:info, new_resource.repository, new_resource.svn_info_args, authentication, "-r#{new_resource.revision}") - svn_info = shell_out!(command, run_options(:cwd => cwd, :returns => [0, 1])).stdout + svn_info = shell_out!(command, run_options(cwd: cwd, returns: [0, 1])).stdout extract_revision_info(svn_info) end @@ -138,7 +138,7 @@ class Chef def find_current_revision return nil unless ::File.exist?(::File.join(new_resource.destination, ".svn")) command = scm(:info) - svn_info = shell_out!(command, run_options(:cwd => cwd, :returns => [0, 1])).stdout + svn_info = shell_out!(command, run_options(cwd: cwd, returns: [0, 1])).stdout extract_revision_info(svn_info) end diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb index 0450516d58..44f34fb8d7 100644 --- a/lib/chef/provider/systemd_unit.rb +++ b/lib/chef/provider/systemd_unit.rb @@ -247,8 +247,8 @@ class Chef if new_resource.user uid = Etc.getpwnam(new_resource.user).uid { - :user => new_resource.user, - :environment => { + user: new_resource.user, + environment: { "DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{uid}/bus", }, } diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb index b40794564a..9ac5a89b3e 100644 --- a/lib/chef/provider/template/content.rb +++ b/lib/chef/provider/template/content.rb @@ -29,7 +29,7 @@ class Chef def template_location @template_file_cache_location ||= begin - template_finder.find(new_resource.source, :local => new_resource.local, :cookbook => new_resource.cookbook) + template_finder.find(new_resource.source, local: new_resource.local, cookbook: new_resource.cookbook) end end diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index c22329d0d6..9584e20656 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -326,7 +326,7 @@ user password using shadow hash.") end def ditto_home - shell_out!("/usr/sbin/createhomedir", "-c", "-u", "#{new_resource.username}") + shell_out!("/usr/sbin/createhomedir", "-c", "-u", (new_resource.username).to_s) end def move_home diff --git a/lib/chef/provider/windows_env.rb b/lib/chef/provider/windows_env.rb index 4e7fa34216..e5af49fa8f 100644 --- a/lib/chef/provider/windows_env.rb +++ b/lib/chef/provider/windows_env.rb @@ -63,7 +63,7 @@ class Chef # <false>:: If a change is not required def requires_modify_or_create? if new_resource.delim - #e.g. check for existing value within PATH + # e.g. check for existing value within PATH new_values.inject(0) do |index, val| next_index = current_values.find_index val return true if next_index.nil? || next_index < index @@ -91,18 +91,18 @@ class Chef end end - #e.g. delete a PATH element + # e.g. delete a PATH element # # ==== Returns # <true>:: If we handled the element case and caller should not delete the key # <false>:: Caller should delete the key, either no :delim was specific or value was empty # after we removed the element. def delete_element - return false unless new_resource.delim #no delim: delete the key + return false unless new_resource.delim # no delim: delete the key needs_delete = new_values.any? { |v| current_values.include?(v) } if !needs_delete logger.trace("#{new_resource} element '#{new_resource.value}' does not exist") - return true #do not delete the key + return true # do not delete the key else new_value = current_values.select do |item| @@ -110,13 +110,13 @@ class Chef end.join(new_resource.delim) if new_value.empty? - return false #nothing left here, delete the key + return false # nothing left here, delete the key else old_value = new_resource.value(new_value) create_env logger.trace("#{new_resource} deleted #{old_value} element") new_resource.updated_by_last_action(true) - return true #we removed the element and updated; do not delete the key + return true # we removed the element and updated; do not delete the key end end end diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index 1676ec3f6b..f8df5dc9a8 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -46,7 +46,7 @@ class Chef SEP: TaskScheduler::SEPTEMBER, OCT: TaskScheduler::OCTOBER, NOV: TaskScheduler::NOVEMBER, - DEC: TaskScheduler::DECEMBER + DEC: TaskScheduler::DECEMBER, } DAYS_OF_WEEK = { MON: TaskScheduler::MONDAY, @@ -61,7 +61,7 @@ class Chef FIRST: TaskScheduler::FIRST_WEEK, SECOND: TaskScheduler::SECOND_WEEK, THIRD: TaskScheduler::THIRD_WEEK, - FOURTH: TaskScheduler::FOURTH_WEEK + FOURTH: TaskScheduler::FOURTH_WEEK, } DAYS_OF_MONTH = { @@ -95,7 +95,7 @@ class Chef 28 => TaskScheduler::TASK_TWENTY_EIGHTH, 29 => TaskScheduler::TASK_TWENTY_NINTH, 30 => TaskScheduler::TASK_THIRTYETH, - 31 => TaskScheduler::TASK_THIRTY_FIRST + 31 => TaskScheduler::TASK_THIRTY_FIRST, } def load_current_resource @@ -195,7 +195,7 @@ class Chef logger.trace "#{new_resource} task exists" if current_resource.task.status == "not scheduled" converge_by("#{new_resource} task enabled") do - #TODO wind32-taskscheduler currently not having any method to handle this so using schtasks.exe here + # TODO wind32-taskscheduler currently not having any method to handle this so using schtasks.exe here run_schtasks "CHANGE", "ENABLE" => "" end else @@ -212,7 +212,7 @@ class Chef logger.info "#{new_resource} task exists" if %w{ready running}.include?(current_resource.task.status) converge_by("#{new_resource} task disabled") do - #TODO: in win32-taskscheduler there is no method whcih disbales the task so currently calling disable with schtasks.exe + # TODO: in win32-taskscheduler there is no method whcih disbales the task so currently calling disable with schtasks.exe run_schtasks "CHANGE", "DISABLE" => "" end else @@ -256,7 +256,7 @@ class Chef def trigger start_month, start_day, start_year = new_resource.start_day.to_s.split("/") start_hour, start_minute = new_resource.start_time.to_s.split(":") - #TODO currently end_month, end_year and end_year needs to be set to 0. If not set win32-taskscheduler throwing nil into integer error. + # TODO currently end_month, end_year and end_year needs to be set to 0. If not set win32-taskscheduler throwing nil into integer error. trigger_hash = { start_year: start_year.to_i, start_month: start_month.to_i, @@ -268,7 +268,7 @@ class Chef end_year: 0, trigger_type: trigger_type, type: type, - random_minutes_interval: new_resource.random_delay + random_minutes_interval: new_resource.random_delay, } if new_resource.frequency == :minute @@ -318,7 +318,7 @@ class Chef hours.to_i * 60 if hours end - #TODO : Try to optimize this method + # TODO : Try to optimize this method # known issue : Since start_day and time is not mandatory while updating weekly frequency for which start_day is not mentioned by user idempotency # is not gettting maintained as new_resource.start_day is nil and we fetch the day of week from start_day to set and its currently coming as nil and don't match with current_task def task_needs_update?(task) @@ -452,7 +452,7 @@ class Chef def days_of_week if new_resource.day - #this line of code is just to support backward compatibility of wild card * + # this line of code is just to support backward compatibility of wild card * new_resource.day = "mon, tue, wed, thu, fri, sat, sun" if new_resource.day == "*" && new_resource.frequency == :weekly days = new_resource.day.split(",") days.map! { |day| day.to_s.strip.upcase } @@ -475,7 +475,7 @@ class Chef end if new_resource.months - #this line of code is just to support backward compatibility of wild card * + # this line of code is just to support backward compatibility of wild card * new_resource.months = "jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec" if new_resource.months == "*" && new_resource.frequency == :monthly months = new_resource.months.split(",") months.map! { |month| month.to_s.strip.upcase } @@ -539,11 +539,11 @@ class Chef end end - #TODO: while creating the configuration settings win32-taskscheduler it accepts execution time limit values in ISO8601 formata + # TODO: while creating the configuration settings win32-taskscheduler it accepts execution time limit values in ISO8601 formata def config_settings settings = { execution_time_limit: new_resource.execution_time_limit, - enabled: true + enabled: true, } settings[:idle_duration] = new_resource.idle_time if new_resource.idle_time settings[:run_only_if_idle] = true if new_resource.idle_time diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 478637ff4e..a30504bc91 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -469,7 +469,7 @@ class Chef if arg.nil? @guard_interpreter || @default_guard_interpreter else - set_or_return(:guard_interpreter, arg, :kind_of => Symbol) + set_or_return(:guard_interpreter, arg, kind_of: Symbol) end end diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index ea6d692709..57cc483c8a 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -55,7 +55,7 @@ class Chef set_or_return( :minute, converted_arg, - :kind_of => String + kind_of: String ) end @@ -72,7 +72,7 @@ class Chef set_or_return( :hour, converted_arg, - :kind_of => String + kind_of: String ) end @@ -89,7 +89,7 @@ class Chef set_or_return( :day, converted_arg, - :kind_of => String + kind_of: String ) end @@ -106,7 +106,7 @@ class Chef set_or_return( :month, converted_arg, - :kind_of => String + kind_of: String ) end @@ -130,7 +130,7 @@ class Chef set_or_return( :weekday, converted_arg, - :kind_of => [String, Symbol] + kind_of: [String, Symbol] ) end diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb index f3fa5d0314..7d1e11b659 100644 --- a/lib/chef/resource/dsc_script.rb +++ b/lib/chef/resource/dsc_script.rb @@ -54,7 +54,7 @@ class Chef set_or_return( :code, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -65,7 +65,7 @@ class Chef set_or_return( :configuration_name, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -76,7 +76,7 @@ class Chef set_or_return( :command, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -87,7 +87,7 @@ class Chef set_or_return( :configuration_data, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -98,7 +98,7 @@ class Chef set_or_return( :configuration_data_script, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index 7003b546fe..dfccfeb138 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -52,7 +52,7 @@ class Chef set_or_return( :command, arg, - :kind_of => [ String, Array ] + kind_of: [ String, Array ] ) end property :umask, [ String, Integer ] diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb index 578e6066a2..ae4f9043b2 100644 --- a/lib/chef/resource/file/verification.rb +++ b/lib/chef/resource/file/verification.rb @@ -113,7 +113,7 @@ class Chef if @command.include?("%{file}") raise ArgumentError, "The %{file} expansion for verify commands has been removed. Please use %{path} instead." end - command = @command % { :path => path } + command = @command % { path: path } interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts) interpreter.evaluate end diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb index e85a75e906..f5e4010ee7 100644 --- a/lib/chef/resource/freebsd_package.rb +++ b/lib/chef/resource/freebsd_package.rb @@ -46,7 +46,7 @@ class Chef # # @return [Boolean] do we support pkgng def supports_pkgng? - ships_with_pkgng? || !!shell_out!("make", "-V", "WITH_PKGNG", :env => nil).stdout.match(/yes/i) + ships_with_pkgng? || !!shell_out!("make", "-V", "WITH_PKGNG", env: nil).stdout.match(/yes/i) end private diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index 9298fbc150..b67bfe188e 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -41,7 +41,7 @@ class Chef set_or_return( :members, converted_members, - :kind_of => [ Array ] + kind_of: [ Array ] ) end @@ -52,7 +52,7 @@ class Chef set_or_return( :excluded_members, converted_members, - :kind_of => [ Array ] + kind_of: [ Array ] ) end diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb index 02996f4464..f213ae47ad 100644 --- a/lib/chef/resource/hostname.rb +++ b/lib/chef/resource/hostname.rb @@ -132,7 +132,7 @@ class Chef # this must come before other methods like /etc/hostname and /etc/sysconfig/network declare_resource(:execute, "hostnamectl set-hostname #{new_resource.hostname}") do notifies :reload, "ohai[reload hostname]" - not_if { shell_out!("hostnamectl status", { :returns => [0, 1] }).stdout =~ /Static hostname:\s*#{new_resource.hostname}\s*$/ } + not_if { shell_out!("hostnamectl status", { returns: [0, 1] }).stdout =~ /Static hostname:\s*#{new_resource.hostname}\s*$/ } end when ::File.exist?("/etc/hostname") # debian family uses /etc/hostname diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb index 3493cec9db..6e92fb821c 100644 --- a/lib/chef/resource/http_request.rb +++ b/lib/chef/resource/http_request.rb @@ -48,7 +48,7 @@ class Chef set_or_return( :message, args, - :kind_of => Object + kind_of: Object ) end diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb index 99821bcefd..95efadd4e6 100644 --- a/lib/chef/resource/powershell_script.rb +++ b/lib/chef/resource/powershell_script.rb @@ -40,7 +40,7 @@ class Chef set_or_return( :convert_boolean_return, arg, - :kind_of => [ FalseClass, TrueClass ] + kind_of: [ FalseClass, TrueClass ] ) end @@ -52,7 +52,7 @@ class Chef # guard context and recipe resource context will have the # same behavior. def self.get_default_attributes(opts) - { :convert_boolean_return => true } + { convert_boolean_return: true } end end end diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index daeb7b35bb..f03b13ef02 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -63,7 +63,7 @@ class Chef set_or_return( :files_group, arg, - :regex => Chef::Config[:group_valid_regex] + regex: Chef::Config[:group_valid_regex] ) end @@ -71,7 +71,7 @@ class Chef set_or_return( :files_mode, arg, - :regex => /^\d{3,4}$/ + regex: /^\d{3,4}$/ ) end @@ -79,7 +79,7 @@ class Chef set_or_return( :files_owner, arg, - :regex => Chef::Config[:user_valid_regex] + regex: Chef::Config[:user_valid_regex] ) end end diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index 832fd3568e..3607a3cbc5 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -48,8 +48,8 @@ class Chef arg = parse_source_args(args) ret = set_or_return(:source, arg, - { :callbacks => { - :validate_source => method(:validate_source), + { callbacks: { + validate_source: method(:validate_source), } }) if ret.is_a? String Array(ret) diff --git a/lib/chef/resource/resource_notification.rb b/lib/chef/resource/resource_notification.rb index 24f8821b6b..a3475e3301 100644 --- a/lib/chef/resource/resource_notification.rb +++ b/lib/chef/resource/resource_notification.rb @@ -79,18 +79,18 @@ class Chef self.resource = matching_resource rescue Chef::Exceptions::ResourceNotFound => e - err = Chef::Exceptions::ResourceNotFound.new(<<-FAIL) -resource #{notifying_resource} is configured to notify resource #{resource} with action #{action}, \ -but #{resource} cannot be found in the resource collection. #{notifying_resource} is defined in \ -#{notifying_resource.source_line} + err = Chef::Exceptions::ResourceNotFound.new(<<~FAIL) + resource #{notifying_resource} is configured to notify resource #{resource} with action #{action}, \ + but #{resource} cannot be found in the resource collection. #{notifying_resource} is defined in \ + #{notifying_resource.source_line} FAIL err.set_backtrace(e.backtrace) raise err rescue Chef::Exceptions::InvalidResourceSpecification => e - err = Chef::Exceptions::InvalidResourceSpecification.new(<<-F) -Resource #{notifying_resource} is configured to notify resource #{resource} with action #{action}, \ -but #{resource.inspect} is not valid syntax to look up a resource in the resource collection. Notification \ -is defined near #{notifying_resource.source_line} + err = Chef::Exceptions::InvalidResourceSpecification.new(<<~F) + Resource #{notifying_resource} is configured to notify resource #{resource} with action #{action}, \ + but #{resource.inspect} is not valid syntax to look up a resource in the resource collection. Notification \ + is defined near #{notifying_resource.source_line} F err.set_backtrace(e.backtrace) raise err @@ -112,18 +112,18 @@ is defined near #{notifying_resource.source_line} self.notifying_resource = matching_notifier rescue Chef::Exceptions::ResourceNotFound => e - err = Chef::Exceptions::ResourceNotFound.new(<<-FAIL) -Resource #{resource} is configured to receive notifications from #{notifying_resource} with action #{action}, \ -but #{notifying_resource} cannot be found in the resource collection. #{resource} is defined in \ -#{resource.source_line} + err = Chef::Exceptions::ResourceNotFound.new(<<~FAIL) + Resource #{resource} is configured to receive notifications from #{notifying_resource} with action #{action}, \ + but #{notifying_resource} cannot be found in the resource collection. #{resource} is defined in \ + #{resource.source_line} FAIL err.set_backtrace(e.backtrace) raise err rescue Chef::Exceptions::InvalidResourceSpecification => e - err = Chef::Exceptions::InvalidResourceSpecification.new(<<-F) -Resource #{resource} is configured to receive notifications from #{notifying_resource} with action #{action}, \ -but #{notifying_resource.inspect} is not valid syntax to look up a resource in the resource collection. Notification \ -is defined near #{resource.source_line} + err = Chef::Exceptions::InvalidResourceSpecification.new(<<~F) + Resource #{resource} is configured to receive notifications from #{notifying_resource} with action #{action}, \ + but #{notifying_resource.inspect} is not valid syntax to look up a resource in the resource collection. Notification \ + is defined near #{resource.source_line} F err.set_backtrace(e.backtrace) raise err diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 07473c9709..fe13c433cb 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -62,7 +62,7 @@ class Chef set_or_return( :service_name, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -71,7 +71,7 @@ class Chef set_or_return( :pattern, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -80,7 +80,7 @@ class Chef set_or_return( :start_command, arg, - :kind_of => [ String, NilClass, FalseClass ] + kind_of: [ String, NilClass, FalseClass ] ) end @@ -89,7 +89,7 @@ class Chef set_or_return( :stop_command, arg, - :kind_of => [ String, NilClass, FalseClass ] + kind_of: [ String, NilClass, FalseClass ] ) end @@ -98,7 +98,7 @@ class Chef set_or_return( :status_command, arg, - :kind_of => [ String, NilClass, FalseClass ] + kind_of: [ String, NilClass, FalseClass ] ) end @@ -107,7 +107,7 @@ class Chef set_or_return( :restart_command, arg, - :kind_of => [ String, NilClass, FalseClass ] + kind_of: [ String, NilClass, FalseClass ] ) end @@ -115,7 +115,7 @@ class Chef set_or_return( :reload_command, arg, - :kind_of => [ String, NilClass, FalseClass ] + kind_of: [ String, NilClass, FalseClass ] ) end @@ -128,7 +128,7 @@ class Chef set_or_return( :init_command, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -137,7 +137,7 @@ class Chef set_or_return( :enabled, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -146,7 +146,7 @@ class Chef set_or_return( :running, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -155,7 +155,7 @@ class Chef set_or_return( :masked, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -163,7 +163,7 @@ class Chef set_or_return( :options, arg.respond_to?(:split) ? arg.shellsplit : arg, - :kind_of => [ Array, String ] + kind_of: [ Array, String ] ) end @@ -181,7 +181,7 @@ class Chef set_or_return( :priority, arg, - :kind_of => [ Integer, String, Hash ] + kind_of: [ Integer, String, Hash ] ) end @@ -190,7 +190,7 @@ class Chef set_or_return( :timeout, arg, - :kind_of => Integer + kind_of: Integer ) end @@ -198,7 +198,7 @@ class Chef set_or_return( :parameters, arg, - :kind_of => [ Hash ] + kind_of: [ Hash ] ) end @@ -206,14 +206,14 @@ class Chef set_or_return( :run_levels, arg, - :kind_of => [ Array ] ) + kind_of: [ Array ] ) end def user(arg = nil) set_or_return( :user, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end end diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb index 5fc29ec1c6..45879db8e6 100644 --- a/lib/chef/resource/template.rb +++ b/lib/chef/resource/template.rb @@ -53,7 +53,7 @@ class Chef set_or_return( :source, file, - :kind_of => [ String, Array ] + kind_of: [ String, Array ] ) end diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb index 39d8159d4f..df52ebb083 100644 --- a/lib/chef/resource/user.rb +++ b/lib/chef/resource/user.rb @@ -51,7 +51,7 @@ class Chef set_or_return( :username, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -59,7 +59,7 @@ class Chef set_or_return( :comment, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -67,8 +67,8 @@ class Chef set_or_return( :uid, arg, - :kind_of => [ String, Integer, NilClass ], - :coerce => proc { |x| x || nil } + kind_of: [ String, Integer, NilClass ], + coerce: proc { |x| x || nil } ) end @@ -76,8 +76,8 @@ class Chef set_or_return( :gid, arg, - :kind_of => [ String, Integer, NilClass ], - :coerce => proc { |x| x || nil } + kind_of: [ String, Integer, NilClass ], + coerce: proc { |x| x || nil } ) end @@ -87,7 +87,7 @@ class Chef set_or_return( :home, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -95,7 +95,7 @@ class Chef set_or_return( :shell, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -103,7 +103,7 @@ class Chef set_or_return( :password, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -111,7 +111,7 @@ class Chef set_or_return( :salt, arg, - :kind_of => [ String ] + kind_of: [ String ] ) end @@ -119,7 +119,7 @@ class Chef set_or_return( :iterations, arg, - :kind_of => [ Integer ] + kind_of: [ Integer ] ) end @@ -127,7 +127,7 @@ class Chef set_or_return( :system, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -135,7 +135,7 @@ class Chef set_or_return( :manage_home, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -143,7 +143,7 @@ class Chef set_or_return( :force, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end @@ -151,7 +151,7 @@ class Chef set_or_return( :non_unique, arg, - :kind_of => [ TrueClass, FalseClass ] + kind_of: [ TrueClass, FalseClass ] ) end end diff --git a/lib/chef/resource/windows_script.rb b/lib/chef/resource/windows_script.rb index 7c39d9fba0..fe3e37989d 100644 --- a/lib/chef/resource/windows_script.rb +++ b/lib/chef/resource/windows_script.rb @@ -45,7 +45,7 @@ class Chef result = set_or_return( :architecture, arg, - :kind_of => Symbol + kind_of: Symbol ) end diff --git a/lib/chef/resource_definition.rb b/lib/chef/resource_definition.rb index aa114af46c..af22a5389e 100644 --- a/lib/chef/resource_definition.rb +++ b/lib/chef/resource_definition.rb @@ -62,7 +62,7 @@ class Chef end def to_s - "#{name}" + (name).to_s end end end diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index c76ac0a4a3..1ec25fc79a 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -72,7 +72,7 @@ class Chef as_hash["result"] = action.to_s if success? else - #as_hash["result"] = "failed" + # as_hash["result"] = "failed" end if new_resource.cookbook_name as_hash["cookbook_name"] = new_resource.cookbook_name @@ -120,8 +120,8 @@ class Chef if reporting_enabled? begin resource_history_url = "reports/nodes/#{node_name}/runs" - server_response = @rest_client.post(resource_history_url, { :action => :start, :run_id => run_id, - :start_time => start_time.to_s }, headers) + server_response = @rest_client.post(resource_history_url, { action: :start, run_id: run_id, + start_time: start_time.to_s }, headers) rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e handle_error_starting_run(e, resource_history_url) end diff --git a/lib/chef/role.rb b/lib/chef/role.rb index ad01e9fa26..f0c4cdd542 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -55,7 +55,7 @@ class Chef set_or_return( :name, arg, - :regex => /^[\-[:alnum:]_]+$/ + regex: /^[\-[:alnum:]_]+$/ ) end @@ -63,7 +63,7 @@ class Chef set_or_return( :description, arg, - :kind_of => String + kind_of: String ) end @@ -118,7 +118,7 @@ class Chef set_or_return( :default_attributes, arg, - :kind_of => Hash + kind_of: Hash ) end @@ -126,7 +126,7 @@ class Chef set_or_return( :override_attributes, arg, - :kind_of => Hash + kind_of: Hash ) end @@ -141,8 +141,8 @@ class Chef "override_attributes" => @override_attributes, "chef_type" => "role", - #Render to_json correctly for run_list items (both run_list and evn_run_lists) - #so malformed json does not result + # Render to_json correctly for run_list items (both run_list and evn_run_lists) + # so malformed json does not result "run_list" => run_list.run_list.map { |item| item.to_s }, "env_run_lists" => env_run_lists_without_default.inject({}) do |accumulator, (k, v)| accumulator[k] = v.map { |x| x.to_s } diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 2b8c7cda30..a11cc676eb 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -331,12 +331,12 @@ class Chef cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name, current_cookbook: current_cookbook) if unreachable_cookbook?(cookbook_name) # CHEF-4367 - logger.warn(<<-ERROR_MESSAGE) -MissingCookbookDependency: -Recipe `#{recipe_name}` is not in the run_list, and cookbook '#{cookbook_name}' -is not a dependency of any cookbook in the run_list. To load this recipe, -first add a dependency on cookbook '#{cookbook_name}' in the cookbook you're -including it from in that cookbook's metadata. + logger.warn(<<~ERROR_MESSAGE) + MissingCookbookDependency: + Recipe `#{recipe_name}` is not in the run_list, and cookbook '#{cookbook_name}' + is not a dependency of any cookbook in the run_list. To load this recipe, + first add a dependency on cookbook '#{cookbook_name}' in the cookbook you're + including it from in that cookbook's metadata. ERROR_MESSAGE end diff --git a/lib/chef/run_list/run_list_expansion.rb b/lib/chef/run_list/run_list_expansion.rb index b895b53523..085dd9f6be 100644 --- a/lib/chef/run_list/run_list_expansion.rb +++ b/lib/chef/run_list/run_list_expansion.rb @@ -148,8 +148,8 @@ class Chef end def to_hash - seen_items = { :recipe => {}, :role => {} } - { :id => @environment, :run_list => convert_run_list_trace("top level", seen_items) } + seen_items = { recipe: {}, role: {} } + { id: @environment, run_list: convert_run_list_trace("top level", seen_items) } end private @@ -185,12 +185,12 @@ class Chef seen_items[item.type][item.name] = true case item.type when :recipe - { :type => "recipe", :name => item.name, :version => item.version, :skipped => !!skipped } + { type: "recipe", name: item.name, version: item.version, skipped: !!skipped } when :role error = @role_errors[item.name] missing = @all_missing_roles[item.name] - { :type => :role, :name => item.name, :children => (missing || error || skipped) ? [] : convert_run_list_trace(item.to_s, seen_items), - :missing => missing, :error => error, :skipped => skipped } + { type: :role, name: item.name, children: (missing || error || skipped) ? [] : convert_run_list_trace(item.to_s, seen_items), + missing: missing, error: error, skipped: skipped } end end end diff --git a/lib/chef/run_list/versioned_recipe_list.rb b/lib/chef/run_list/versioned_recipe_list.rb index ad769ee952..d9b3c17db3 100644 --- a/lib/chef/run_list/versioned_recipe_list.rb +++ b/lib/chef/run_list/versioned_recipe_list.rb @@ -40,7 +40,7 @@ class Chef end def with_versions - map { |recipe_name| { :name => recipe_name, :version => @versions[recipe_name] } } + map { |recipe_name| { name: recipe_name, version: @versions[recipe_name] } } end # Return an Array of Hashes, each of the form: @@ -48,7 +48,7 @@ class Chef def with_version_constraints map do |recipe_name| constraint = Chef::VersionConstraint.new(@versions[recipe_name]) - { :name => recipe_name, :version_constraint => constraint } + { name: recipe_name, version_constraint: constraint } end end diff --git a/lib/chef/run_status.rb b/lib/chef/run_status.rb index c3b7945bc9..9a52f846c7 100644 --- a/lib/chef/run_status.rb +++ b/lib/chef/run_status.rb @@ -104,16 +104,16 @@ class Chef::RunStatus # * :backtrace def to_hash # use a flat hash here so we can't errors from intermediate values being nil - { :node => node, - :success => success?, - :start_time => start_time, - :end_time => end_time, - :elapsed_time => elapsed_time, - :all_resources => all_resources, - :updated_resources => updated_resources, - :exception => formatted_exception, - :backtrace => backtrace, - :run_id => run_id } + { node: node, + success: success?, + start_time: start_time, + end_time: end_time, + elapsed_time: elapsed_time, + all_resources: all_resources, + updated_resources: updated_resources, + exception: formatted_exception, + backtrace: backtrace, + run_id: run_id } end # Returns a string of the format "ExceptionClass: message" or +nil+ if no diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb index 88d26e78fc..6c5f70edcc 100644 --- a/lib/chef/shell.rb +++ b/lib/chef/shell.rb @@ -207,91 +207,91 @@ module Shell banner("chef-shell #{Chef::VERSION}\n\nUsage: chef-shell [NAMED_CONF] (OPTIONS)") - footer(<<-FOOTER) -When no CONFIG is specified, chef-shell attempts to load a default configuration file: -* If a NAMED_CONF is given, chef-shell will load ~/.chef/NAMED_CONF/chef_shell.rb -* If no NAMED_CONF is given chef-shell will load ~/.chef/chef_shell.rb if it exists -* If no chef_shell.rb can be found, chef-shell falls back to load: - /etc/chef/client.rb if -z option is given. - /etc/chef/solo.rb if --solo-legacy-mode option is given. - .chef/knife.rb if -s option is given. + footer(<<~FOOTER) + When no CONFIG is specified, chef-shell attempts to load a default configuration file: + * If a NAMED_CONF is given, chef-shell will load ~/.chef/NAMED_CONF/chef_shell.rb + * If no NAMED_CONF is given chef-shell will load ~/.chef/chef_shell.rb if it exists + * If no chef_shell.rb can be found, chef-shell falls back to load: + /etc/chef/client.rb if -z option is given. + /etc/chef/solo.rb if --solo-legacy-mode option is given. + .chef/knife.rb if -s option is given. FOOTER option :config_file, - :short => "-c CONFIG", - :long => "--config CONFIG", - :description => "The configuration file to use" + short: "-c CONFIG", + long: "--config CONFIG", + description: "The configuration file to use" option :help, - :short => "-h", - :long => "--help", - :description => "Show this message", - :on => :tail, - :boolean => true, - :proc => proc { print_help } + short: "-h", + long: "--help", + description: "Show this message", + on: :tail, + boolean: true, + proc: proc { print_help } option :log_level, - :short => "-l LOG_LEVEL", - :long => "--log-level LOG_LEVEL", - :description => "Set the logging level", - :proc => proc { |level| Chef::Config.log_level = level.to_sym; Shell.setup_logger } + short: "-l LOG_LEVEL", + long: "--log-level LOG_LEVEL", + description: "Set the logging level", + proc: proc { |level| Chef::Config.log_level = level.to_sym; Shell.setup_logger } option :standalone, - :short => "-a", - :long => "--standalone", - :description => "standalone session", - :default => true, - :boolean => true + short: "-a", + long: "--standalone", + description: "standalone session", + default: true, + boolean: true option :solo_shell, - :short => "-s", - :long => "--solo", - :description => "chef-solo session", - :boolean => true, - :proc => proc { Chef::Config[:solo] = true } + short: "-s", + long: "--solo", + description: "chef-solo session", + boolean: true, + proc: proc { Chef::Config[:solo] = true } option :client, - :short => "-z", - :long => "--client", - :description => "chef-client session", - :boolean => true + short: "-z", + long: "--client", + description: "chef-client session", + boolean: true option :solo_legacy_shell, - :long => "--solo-legacy-mode", - :description => "chef-solo legacy session", - :boolean => true, - :proc => proc { Chef::Config[:solo_legacy_mode] = true } + long: "--solo-legacy-mode", + description: "chef-solo legacy session", + boolean: true, + proc: proc { Chef::Config[:solo_legacy_mode] = true } option :json_attribs, - :short => "-j JSON_ATTRIBS", - :long => "--json-attributes JSON_ATTRIBS", - :description => "Load attributes from a JSON file or URL", - :proc => nil + short: "-j JSON_ATTRIBS", + long: "--json-attributes JSON_ATTRIBS", + description: "Load attributes from a JSON file or URL", + proc: nil option :chef_server_url, - :short => "-S CHEFSERVERURL", - :long => "--server CHEFSERVERURL", - :description => "The chef server URL", - :proc => nil + short: "-S CHEFSERVERURL", + long: "--server CHEFSERVERURL", + description: "The chef server URL", + proc: nil option :version, - :short => "-v", - :long => "--version", - :description => "Show chef version", - :boolean => true, - :proc => lambda { |v| puts "Chef: #{::Chef::VERSION}" }, - :exit => 0 + short: "-v", + long: "--version", + description: "Show chef version", + boolean: true, + proc: lambda { |v| puts "Chef: #{::Chef::VERSION}" }, + exit: 0 option :override_runlist, - :short => "-o RunlistItem,RunlistItem...", - :long => "--override-runlist RunlistItem,RunlistItem...", - :description => "Replace current run list with specified items", - :proc => lambda { |items| items.split(",").map { |item| Chef::RunList::RunListItem.new(item) } } + short: "-o RunlistItem,RunlistItem...", + long: "--override-runlist RunlistItem,RunlistItem...", + description: "Replace current run list with specified items", + proc: lambda { |items| items.split(",").map { |item| Chef::RunList::RunListItem.new(item) } } option :skip_cookbook_sync, - :long => "--[no-]skip-cookbook-sync", - :description => "Use cached cookbooks without overwriting local differences from the server", - :boolean => false + long: "--[no-]skip-cookbook-sync", + description: "Use cached cookbooks without overwriting local differences from the server", + boolean: false def self.print_help instance = new diff --git a/lib/chef/shell/ext.rb b/lib/chef/shell/ext.rb index fb0733e96e..cb1fb9041b 100644 --- a/lib/chef/shell/ext.rb +++ b/lib/chef/shell/ext.rb @@ -190,12 +190,12 @@ module Shell extend Shell::Extensions::ObjectCoreExtensions desc "prints this help message" - explain(<<-E) -## SUMMARY ## - When called with no argument, +help+ prints a table of all - chef-shell commands. When called with an argument COMMAND, +help+ - prints a detailed explanation of the command if available, or the - description if no explanation is available. + explain(<<~E) + ## SUMMARY ## + When called with no argument, +help+ prints a table of all + chef-shell commands. When called with an argument COMMAND, +help+ + prints a detailed explanation of the command if available, or the + description if no explanation is available. E def help(commmand = nil) if commmand @@ -239,10 +239,10 @@ module Shell end desc "returns an object to control a paused chef run" - subcommands :resume => "resume the chef run", - :step => "run only the next resource", - :skip_back => "move back in the run list", - :skip_forward => "move forward in the run list" + subcommands resume: "resume the chef run", + step: "run only the next resource", + skip_back: "move back in the run list", + skip_forward: "move forward in the run list" def chef_run Shell.session.resource_collection.iterator end @@ -302,18 +302,18 @@ module Shell RESTApiExtensions = Proc.new do desc "edit an object in your EDITOR" - explain(<<-E) -## SUMMARY ## - +edit(object)+ allows you to edit any object that can be converted to JSON. - When finished editing, this method will return the edited object: - - new_node = edit(existing_node) - -## EDITOR SELECTION ## - chef-shell looks for an editor using the following logic - 1. Looks for an EDITOR set by Shell.editor = "EDITOR" - 2. Looks for an EDITOR configured in your chef-shell config file - 3. Uses the value of the EDITOR environment variable + explain(<<~E) + ## SUMMARY ## + +edit(object)+ allows you to edit any object that can be converted to JSON. + When finished editing, this method will return the edited object: + + new_node = edit(existing_node) + + ## EDITOR SELECTION ## + chef-shell looks for an editor using the following logic + 1. Looks for an EDITOR set by Shell.editor = "EDITOR" + 2. Looks for an EDITOR configured in your chef-shell config file + 3. Uses the value of the EDITOR environment variable E def edit(object) unless Shell.editor @@ -340,196 +340,196 @@ module Shell end desc "Find and edit API clients" - explain(<<-E) -## SUMMARY ## - +clients+ allows you to query you chef server for information about your api - clients. + explain(<<~E) + ## SUMMARY ## + +clients+ allows you to query you chef server for information about your api + clients. -## LIST ALL CLIENTS ## - To see all clients on the system, use + ## LIST ALL CLIENTS ## + To see all clients on the system, use - clients.all #=> [<Chef::ApiClient...>, ...] + clients.all #=> [<Chef::ApiClient...>, ...] - If the output from all is too verbose, or you're only interested in a specific - value from each of the objects, you can give a code block to +all+: + If the output from all is too verbose, or you're only interested in a specific + value from each of the objects, you can give a code block to +all+: - clients.all { |client| client.name } #=> [CLIENT1_NAME, CLIENT2_NAME, ...] + clients.all { |client| client.name } #=> [CLIENT1_NAME, CLIENT2_NAME, ...] -## SHOW ONE CLIENT ## - To see a specific client, use + ## SHOW ONE CLIENT ## + To see a specific client, use - clients.show(CLIENT_NAME) + clients.show(CLIENT_NAME) -## SEARCH FOR CLIENTS ## - You can also search for clients using +find+ or +search+. You can use the - familiar string search syntax: + ## SEARCH FOR CLIENTS ## + You can also search for clients using +find+ or +search+. You can use the + familiar string search syntax: - clients.search("KEY:VALUE") + clients.search("KEY:VALUE") - Just as the +all+ subcommand, the +search+ subcommand can use a code block to - filter or transform the information returned from the search: + Just as the +all+ subcommand, the +search+ subcommand can use a code block to + filter or transform the information returned from the search: - clients.search("KEY:VALUE") { |c| c.name } + clients.search("KEY:VALUE") { |c| c.name } - You can also use a Hash based syntax, multiple search conditions will be - joined with AND. + You can also use a Hash based syntax, multiple search conditions will be + joined with AND. - clients.find :KEY => :VALUE, :KEY2 => :VALUE2, ... + clients.find :KEY => :VALUE, :KEY2 => :VALUE2, ... -## BULK-EDIT CLIENTS ## - **BE CAREFUL, THIS IS DESTRUCTIVE** - You can bulk edit API Clients using the +transform+ subcommand, which requires - a code block. Each client will be saved after the code block is run. If the - code block returns +nil+ or +false+, that client will be skipped: + ## BULK-EDIT CLIENTS ## + **BE CAREFUL, THIS IS DESTRUCTIVE** + You can bulk edit API Clients using the +transform+ subcommand, which requires + a code block. Each client will be saved after the code block is run. If the + code block returns +nil+ or +false+, that client will be skipped: - clients.transform("*:*") do |client| - if client.name =~ /borat/i - client.admin(false) - true - else - nil - end - end + clients.transform("*:*") do |client| + if client.name =~ /borat/i + client.admin(false) + true + else + nil + end + end - This will strip the admin privileges from any client named after borat. + This will strip the admin privileges from any client named after borat. E - subcommands :all => "list all api clients", - :show => "load an api client by name", - :search => "search for API clients", - :transform => "edit all api clients via a code block and save them" + subcommands all: "list all api clients", + show: "load an api client by name", + search: "search for API clients", + transform: "edit all api clients via a code block and save them" def clients @clients ||= Shell::ModelWrapper.new(Chef::ApiClient, :client) end desc "Find and edit cookbooks" - subcommands :all => "list all cookbooks", - :show => "load a cookbook by name", - :transform => "edit all cookbooks via a code block and save them" + subcommands all: "list all cookbooks", + show: "load a cookbook by name", + transform: "edit all cookbooks via a code block and save them" def cookbooks @cookbooks ||= Shell::ModelWrapper.new(Chef::CookbookVersion) end desc "Find and edit nodes via the API" - explain(<<-E) -## SUMMARY ## - +nodes+ Allows you to query your chef server for information about your nodes. + explain(<<~E) + ## SUMMARY ## + +nodes+ Allows you to query your chef server for information about your nodes. -## LIST ALL NODES ## - You can list all nodes using +all+ or +list+ + ## LIST ALL NODES ## + You can list all nodes using +all+ or +list+ - nodes.all #=> [<Chef::Node...>, <Chef::Node...>, ...] + nodes.all #=> [<Chef::Node...>, <Chef::Node...>, ...] - To limit the information returned for each node, pass a code block to the +all+ - subcommand: + To limit the information returned for each node, pass a code block to the +all+ + subcommand: - nodes.all { |node| node.name } #=> [NODE1_NAME, NODE2_NAME, ...] + nodes.all { |node| node.name } #=> [NODE1_NAME, NODE2_NAME, ...] -## SHOW ONE NODE ## - You can show the data for a single node using the +show+ subcommand: + ## SHOW ONE NODE ## + You can show the data for a single node using the +show+ subcommand: - nodes.show("NODE_NAME") => <Chef::Node @name="NODE_NAME" ...> + nodes.show("NODE_NAME") => <Chef::Node @name="NODE_NAME" ...> -## SEARCH FOR NODES ## - You can search for nodes using the +search+ or +find+ subcommands: + ## SEARCH FOR NODES ## + You can search for nodes using the +search+ or +find+ subcommands: - nodes.find(:name => "app*") #=> [<Chef::Node @name="app1.example.com" ...>, ...] + nodes.find(:name => "app*") #=> [<Chef::Node @name="app1.example.com" ...>, ...] - Similarly to +all+, you can pass a code block to limit or transform the - information returned: + Similarly to +all+, you can pass a code block to limit or transform the + information returned: - nodes.find(:name => "app#") { |node| node.ec2 } + nodes.find(:name => "app#") { |node| node.ec2 } -## BULK EDIT NODES ## - **BE CAREFUL, THIS OPERATION IS DESTRUCTIVE** + ## BULK EDIT NODES ## + **BE CAREFUL, THIS OPERATION IS DESTRUCTIVE** - Bulk edit nodes by passing a code block to the +transform+ or +bulk_edit+ - subcommand. The block will be applied to each matching node, and then the node - will be saved. If the block returns +nil+ or +false+, that node will be - skipped. + Bulk edit nodes by passing a code block to the +transform+ or +bulk_edit+ + subcommand. The block will be applied to each matching node, and then the node + will be saved. If the block returns +nil+ or +false+, that node will be + skipped. - nodes.transform do |node| - if node.fqdn =~ /.*\\.preprod\\.example\\.com/ - node.set[:environment] = "preprod" - end - end + nodes.transform do |node| + if node.fqdn =~ /.*\\.preprod\\.example\\.com/ + node.set[:environment] = "preprod" + end + end - This will assign the attribute to every node with a FQDN matching the regex. + This will assign the attribute to every node with a FQDN matching the regex. E - subcommands :all => "list all nodes", - :show => "load a node by name", - :search => "search for nodes", - :transform => "edit all nodes via a code block and save them" + subcommands all: "list all nodes", + show: "load a node by name", + search: "search for nodes", + transform: "edit all nodes via a code block and save them" def nodes @nodes ||= Shell::ModelWrapper.new(Chef::Node) end desc "Find and edit roles via the API" - explain(<<-E) -## SUMMARY ## - +roles+ allows you to query and edit roles on your Chef server. - -## SUBCOMMANDS ## - * all (list) - * show (load) - * search (find) - * transform (bulk_edit) - -## SEE ALSO ## - See the help for +nodes+ for more information about the subcommands. + explain(<<~E) + ## SUMMARY ## + +roles+ allows you to query and edit roles on your Chef server. + + ## SUBCOMMANDS ## + * all (list) + * show (load) + * search (find) + * transform (bulk_edit) + + ## SEE ALSO ## + See the help for +nodes+ for more information about the subcommands. E - subcommands :all => "list all roles", - :show => "load a role by name", - :search => "search for roles", - :transform => "edit all roles via a code block and save them" + subcommands all: "list all roles", + show: "load a role by name", + search: "search for roles", + transform: "edit all roles via a code block and save them" def roles @roles ||= Shell::ModelWrapper.new(Chef::Role) end desc "Find and edit +databag_name+ via the api" - explain(<<-E) -## SUMMARY ## - +databags(DATABAG_NAME)+ allows you to query and edit data bag items on your - Chef server. Unlike other commands for working with data on the server, - +databags+ requires the databag name as an argument, for example: - databags(:users).all - -## SUBCOMMANDS ## - * all (list) - * show (load) - * search (find) - * transform (bulk_edit) - -## SEE ALSO ## - See the help for +nodes+ for more information about the subcommands. + explain(<<~E) + ## SUMMARY ## + +databags(DATABAG_NAME)+ allows you to query and edit data bag items on your + Chef server. Unlike other commands for working with data on the server, + +databags+ requires the databag name as an argument, for example: + databags(:users).all + + ## SUBCOMMANDS ## + * all (list) + * show (load) + * search (find) + * transform (bulk_edit) + + ## SEE ALSO ## + See the help for +nodes+ for more information about the subcommands. E - subcommands :all => "list all items in the data bag", - :show => "load a data bag item by id", - :search => "search for items in the data bag", - :transform => "edit all items via a code block and save them" + subcommands all: "list all items in the data bag", + show: "load a data bag item by id", + search: "search for items in the data bag", + transform: "edit all items via a code block and save them" def databags(databag_name) @named_databags_wrappers ||= {} @named_databags_wrappers[databag_name] ||= Shell::NamedDataBagWrapper.new(databag_name) end desc "Find and edit environments via the API" - explain(<<-E) -## SUMMARY ## - +environments+ allows you to query and edit environments on your Chef server. - -## SUBCOMMANDS ## - * all (list) - * show (load) - * search (find) - * transform (bulk_edit) - -## SEE ALSO ## - See the help for +nodes+ for more information about the subcommands. + explain(<<~E) + ## SUMMARY ## + +environments+ allows you to query and edit environments on your Chef server. + + ## SUBCOMMANDS ## + * all (list) + * show (load) + * search (find) + * transform (bulk_edit) + + ## SEE ALSO ## + See the help for +nodes+ for more information about the subcommands. E - subcommands :all => "list all environments", - :show => "load an environment by name", - :search => "search for environments", - :transform => "edit all environments via a code block and save them" + subcommands all: "list all environments", + show: "load an environment by name", + search: "search for environments", + transform: "edit all environments via a code block and save them" def environments @environments ||= Shell::ModelWrapper.new(Chef::Environment) end diff --git a/lib/chef/shell/shell_session.rb b/lib/chef/shell/shell_session.rb index aec2152063..789a022b56 100644 --- a/lib/chef/shell/shell_session.rb +++ b/lib/chef/shell/shell_session.rb @@ -264,8 +264,8 @@ module Shell end def register - @rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url], :client_name => Chef::Config[:node_name], - :signing_key_filename => Chef::Config[:client_key]) + @rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: Chef::Config[:node_name], + signing_key_filename: Chef::Config[:client_key]) end end diff --git a/lib/chef/user.rb b/lib/chef/user.rb index f52d0e2555..eba55c4186 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -49,32 +49,32 @@ class Chef end def chef_rest_v0 - @chef_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "0" }) + @chef_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "0" }) end def name(arg = nil) set_or_return(:name, arg, - :regex => /^[a-z0-9\-_]+$/) + regex: /^[a-z0-9\-_]+$/) end def admin(arg = nil) set_or_return(:admin, - arg, :kind_of => [TrueClass, FalseClass]) + arg, kind_of: [TrueClass, FalseClass]) end def public_key(arg = nil) set_or_return(:public_key, - arg, :kind_of => String) + arg, kind_of: String) end def private_key(arg = nil) set_or_return(:private_key, - arg, :kind_of => String) + arg, kind_of: String) end def password(arg = nil) set_or_return(:password, - arg, :kind_of => String) + arg, kind_of: String) end def to_hash @@ -97,14 +97,14 @@ class Chef end def create - payload = { :name => name, :admin => admin, :password => password } + payload = { name: name, admin: admin, password: password } payload[:public_key] = public_key if public_key new_user = chef_rest_v0.post("users", payload) Chef::User.from_hash(to_hash.merge(new_user)) end def update(new_key = false) - payload = { :name => name, :admin => admin } + payload = { name: name, admin: admin } payload[:private_key] = new_key if new_key payload[:password] = password if password updated_user = chef_rest_v0.put("users/#{name}", payload) @@ -122,7 +122,7 @@ class Chef end def reregister - reregistered_self = chef_rest_v0.put("users/#{name}", { :name => name, :admin => admin, :private_key => true }) + reregistered_self = chef_rest_v0.put("users/#{name}", { name: name, admin: admin, private_key: true }) private_key(reregistered_self["private_key"]) self end @@ -153,7 +153,7 @@ class Chef end def self.list(inflate = false) - response = Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "0" }).get("users") + response = Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "0" }).get("users") users = if response.is_a?(Array) transform_ohc_list_response(response) # OHC/OPC else @@ -170,7 +170,7 @@ class Chef end def self.load(name) - response = Chef::ServerAPI.new(Chef::Config[:chef_server_url], { :api_version => "0" }).get("users/#{name}") + response = Chef::ServerAPI.new(Chef::Config[:chef_server_url], { api_version: "0" }).get("users/#{name}") Chef::User.from_hash(response) end diff --git a/lib/chef/user_v1.rb b/lib/chef/user_v1.rb index 0ca17c6ed6..8bd92dfab8 100644 --- a/lib/chef/user_v1.rb +++ b/lib/chef/user_v1.rb @@ -55,61 +55,61 @@ class Chef end def chef_root_rest_v0 - @chef_root_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { :api_version => "0" }) + @chef_root_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "0" }) end def chef_root_rest_v1 - @chef_root_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { :api_version => "1" }) + @chef_root_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "1" }) end def username(arg = nil) set_or_return(:username, arg, - :regex => /^[a-z0-9\-_]+$/) + regex: /^[a-z0-9\-_]+$/) end def display_name(arg = nil) set_or_return(:display_name, - arg, :kind_of => String) + arg, kind_of: String) end def first_name(arg = nil) set_or_return(:first_name, - arg, :kind_of => String) + arg, kind_of: String) end def middle_name(arg = nil) set_or_return(:middle_name, - arg, :kind_of => String) + arg, kind_of: String) end def last_name(arg = nil) set_or_return(:last_name, - arg, :kind_of => String) + arg, kind_of: String) end def email(arg = nil) set_or_return(:email, - arg, :kind_of => String) + arg, kind_of: String) end def create_key(arg = nil) set_or_return(:create_key, arg, - :kind_of => [TrueClass, FalseClass]) + kind_of: [TrueClass, FalseClass]) end def public_key(arg = nil) set_or_return(:public_key, - arg, :kind_of => String) + arg, kind_of: String) end def private_key(arg = nil) set_or_return(:private_key, - arg, :kind_of => String) + arg, kind_of: String) end def password(arg = nil) set_or_return(:password, - arg, :kind_of => String) + arg, kind_of: String) end def to_hash @@ -141,12 +141,12 @@ class Chef # try v1, fail back to v0 if v1 not supported begin payload = { - :username => @username, - :display_name => @display_name, - :first_name => @first_name, - :last_name => @last_name, - :email => @email, - :password => @password, + username: @username, + display_name: @display_name, + first_name: @first_name, + last_name: @last_name, + email: @email, + password: @password, } payload[:public_key] = @public_key unless @public_key.nil? payload[:create_key] = @create_key unless @create_key.nil? @@ -167,12 +167,12 @@ class Chef supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS) raise e unless supported_versions && supported_versions.include?(0) payload = { - :username => @username, - :display_name => @display_name, - :first_name => @first_name, - :last_name => @last_name, - :email => @email, - :password => @password, + username: @username, + display_name: @display_name, + first_name: @first_name, + last_name: @last_name, + email: @email, + password: @password, } payload[:middle_name] = @middle_name unless @middle_name.nil? payload[:public_key] = @public_key unless @public_key.nil? @@ -185,7 +185,7 @@ class Chef def update(new_key = false) begin - payload = { :username => username } + payload = { username: username } payload[:display_name] = display_name unless display_name.nil? payload[:first_name] = first_name unless first_name.nil? payload[:middle_name] = middle_name unless middle_name.nil? diff --git a/lib/chef/util/backup.rb b/lib/chef/util/backup.rb index 8bf2b3f25b..5b6bf0b9b8 100644 --- a/lib/chef/util/backup.rb +++ b/lib/chef/util/backup.rb @@ -52,7 +52,7 @@ class Chef nanoseconds = sprintf("%6f", time.to_f).split(".")[1] savetime = time.strftime("%Y%m%d%H%M%S.#{nanoseconds}") backup_filename = "#{path}.chef-#{savetime}" - backup_filename = backup_filename.sub(/^([A-Za-z]:)/, "") #strip drive letter on Windows + backup_filename = backup_filename.sub(/^([A-Za-z]:)/, "") # strip drive letter on Windows end end @@ -69,7 +69,7 @@ class Chef def do_backup FileUtils.mkdir_p(::File.dirname(backup_path)) if Chef::Config[:file_backup_path] - FileUtils.cp(path, backup_path, :preserve => true) + FileUtils.cp(path, backup_path, preserve: true) Chef::Log.info("#{@new_resource} backed up to #{backup_path}") end diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb index b5c85df56d..decff35d85 100644 --- a/lib/chef/util/diff.rb +++ b/lib/chef/util/diff.rb @@ -176,7 +176,7 @@ class Chef end def encode_diff_for_json(diff_str) - diff_str.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?") + diff_str.encode!("UTF-8", invalid: :replace, undef: :replace, replace: "?") end end diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb index 3e9475bac2..409730ce20 100644 --- a/lib/chef/util/dsc/configuration_generator.rb +++ b/lib/chef/util/dsc/configuration_generator.rb @@ -68,7 +68,7 @@ class Chef::Util::DSC end def get_merged_configuration_flags!(configuration_flags, configuration_name) - merged_configuration_flags = { :outputpath => configuration_document_directory(configuration_name) } + merged_configuration_flags = { outputpath: configuration_document_directory(configuration_name) } if configuration_flags configuration_flags.map do |switch, value| if merged_configuration_flags.key?(switch.to_s.downcase.to_sym) @@ -81,16 +81,16 @@ class Chef::Util::DSC end def configuration_code(code, configuration_name, imports) - <<-EOF -$ProgressPreference = 'SilentlyContinue'; -Configuration '#{configuration_name}' -{ - #{generate_import_resource_statements(imports).join(" \n")} - node 'localhost' - { - #{code} - } -} + <<~EOF + $ProgressPreference = 'SilentlyContinue'; + Configuration '#{configuration_name}' + { + #{generate_import_resource_statements(imports).join(" \n")} + node 'localhost' + { + #{code} + } + } EOF end diff --git a/lib/chef/util/dsc/lcm_output_parser.rb b/lib/chef/util/dsc/lcm_output_parser.rb index 658d5c7d8f..b164db6b19 100644 --- a/lib/chef/util/dsc/lcm_output_parser.rb +++ b/lib/chef/util/dsc/lcm_output_parser.rb @@ -128,7 +128,7 @@ class Chef if current_resource[:name] resources.push(current_resource) end - current_resource = { :name => info } + current_resource = { name: info } else Chef::Log.trace("Ignoring op_action #{op_action}: Read line #{line}") end diff --git a/lib/chef/util/file_edit.rb b/lib/chef/util/file_edit.rb index 5aa33fd169..5a01e72e70 100644 --- a/lib/chef/util/file_edit.rb +++ b/lib/chef/util/file_edit.rb @@ -40,38 +40,38 @@ class Chef @file_edited end - #search the file line by line and match each line with the given regex - #if matched, replace the whole line with newline. + # search the file line by line and match each line with the given regex + # if matched, replace the whole line with newline. def search_file_replace_line(regex, newline) @changes = (editor.replace_lines(regex, newline) > 0) || @changes end - #search the file line by line and match each line with the given regex - #if matched, replace the match (all occurrences) with the replace parameter + # search the file line by line and match each line with the given regex + # if matched, replace the match (all occurrences) with the replace parameter def search_file_replace(regex, replace) @changes = (editor.replace(regex, replace) > 0) || @changes end - #search the file line by line and match each line with the given regex - #if matched, delete the line + # search the file line by line and match each line with the given regex + # if matched, delete the line def search_file_delete_line(regex) @changes = (editor.remove_lines(regex) > 0) || @changes end - #search the file line by line and match each line with the given regex - #if matched, delete the match (all occurrences) from the line + # search the file line by line and match each line with the given regex + # if matched, delete the match (all occurrences) from the line def search_file_delete(regex) search_file_replace(regex, "") end - #search the file line by line and match each line with the given regex - #if matched, insert newline after each matching line + # search the file line by line and match each line with the given regex + # if matched, insert newline after each matching line def insert_line_after_match(regex, newline) @changes = (editor.append_line_after(regex, newline) > 0) || @changes end - #search the file line by line and match each line with the given regex - #if not matched, insert newline at the end of the file + # search the file line by line and match each line with the given regex + # if not matched, insert newline at the end of the file def insert_line_if_no_match(regex, newline) @changes = (editor.append_line_if_missing(regex, newline) > 0) || @changes end @@ -80,11 +80,11 @@ class Chef !!@changes end - #Make a copy of old_file and write new file out (only if file changed) + # Make a copy of old_file and write new file out (only if file changed) def write_file if @changes backup_pathname = original_pathname + ".old" - FileUtils.cp(original_pathname, backup_pathname, :preserve => true) + FileUtils.cp(original_pathname, backup_pathname, preserve: true) File.open(original_pathname, "w") do |newfile| editor.lines.each do |line| newfile.puts(line) diff --git a/lib/chef/util/powershell/cmdlet.rb b/lib/chef/util/powershell/cmdlet.rb index e300266b1e..edd3e92da1 100644 --- a/lib/chef/util/powershell/cmdlet.rb +++ b/lib/chef/util/powershell/cmdlet.rb @@ -48,8 +48,8 @@ class Chef attr_reader :output_format def run(switches = {}, execution_options = {}, *arguments) - streams = { :json => CmdletStream.new("json"), - :verbose => CmdletStream.new("verbose"), + streams = { json: CmdletStream.new("json"), + verbose: CmdletStream.new("verbose"), } arguments_string = arguments.join(" ") @@ -74,7 +74,7 @@ class Chef "#{arguments_string} #{redirections}"\ "#{json_command}\";if ( ! $? ) { exit 1 }" - augmented_options = { :returns => [0], :live_stream => false }.merge(execution_options) + augmented_options = { returns: [0], live_stream: false }.merge(execution_options) command = Mixlib::ShellOut.new(command_string, augmented_options) status = nil diff --git a/lib/chef/util/selinux.rb b/lib/chef/util/selinux.rb index fb0c98cff5..a46e486f96 100644 --- a/lib/chef/util/selinux.rb +++ b/lib/chef/util/selinux.rb @@ -72,7 +72,7 @@ class Chef def check_selinux_enabled? if selinuxenabled_path - cmd = shell_out!(selinuxenabled_path, :returns => [0, 1]) + cmd = shell_out!(selinuxenabled_path, returns: [0, 1]) case cmd.exitstatus when 1 return false diff --git a/lib/chef/util/windows/net_group.rb b/lib/chef/util/windows/net_group.rb index 214881df56..efe2561bf2 100644 --- a/lib/chef/util/windows/net_group.rb +++ b/lib/chef/util/windows/net_group.rb @@ -19,7 +19,7 @@ require "chef/util/windows" require "chef/win32/net" -#wrapper around a subset of the NetGroup* APIs. +# wrapper around a subset of the NetGroup* APIs. class Chef::Util::Windows::NetGroup private diff --git a/lib/chef/util/windows/net_use.rb b/lib/chef/util/windows/net_use.rb index 196ce42215..99626371a0 100644 --- a/lib/chef/util/windows/net_use.rb +++ b/lib/chef/util/windows/net_use.rb @@ -16,9 +16,9 @@ # limitations under the License. # -#the Win32 Volume APIs do not support mapping network drives. not supported by WMI either. -#see also: WNetAddConnection2 and WNetAddConnection3 -#see also cmd.exe: net use /? +# the Win32 Volume APIs do not support mapping network drives. not supported by WMI either. +# see also: WNetAddConnection2 and WNetAddConnection3 +# see also cmd.exe: net use /? require "chef/util/windows" require "chef/win32/net" diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb index cf8bf3615a..d282ba9046 100644 --- a/lib/chef/util/windows/net_user.rb +++ b/lib/chef/util/windows/net_user.rb @@ -21,8 +21,8 @@ require "chef/exceptions" require "chef/win32/net" require "chef/win32/security" -#wrapper around a subset of the NetUser* APIs. -#nothing Chef specific, but not complete enough to be its own gem, so util for now. +# wrapper around a subset of the NetUser* APIs. +# nothing Chef specific, but not complete enough to be its own gem, so util for now. class Chef::Util::Windows::NetUser < Chef::Util::Windows private @@ -91,7 +91,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows LOGON32_PROVIDER_DEFAULT = Security::LOGON32_PROVIDER_DEFAULT LOGON32_LOGON_NETWORK = Security::LOGON32_LOGON_NETWORK - #XXX for an extra painful alternative, see: http://support.microsoft.com/kb/180548 + # XXX for an extra painful alternative, see: http://support.microsoft.com/kb/180548 def validate_credentials(passwd) token = Security.logon_user(@username, nil, passwd, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT) @@ -118,8 +118,8 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows # FIXME: yard with @yield def user_modify user = get_info - user[:last_logon] = user[:units_per_week] = 0 #ignored as per USER_INFO_3 doc - user[:logon_hours] = nil #PBYTE field; \0 == no changes + user[:last_logon] = user[:units_per_week] = 0 # ignored as per USER_INFO_3 doc + user[:logon_hours] = nil # PBYTE field; \0 == no changes yield(user) set_info(user) end @@ -141,9 +141,9 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows def disable_account user_modify do |user| user[:flags] |= NetUser::UF_ACCOUNTDISABLE - #This does not set the password to nil. It (for some reason) means to ignore updating the field. - #See similar behavior for the logon_hours field documented at - #http://msdn.microsoft.com/en-us/library/windows/desktop/aa371338%28v=vs.85%29.aspx + # This does not set the password to nil. It (for some reason) means to ignore updating the field. + # See similar behavior for the logon_hours field documented at + # http://msdn.microsoft.com/en-us/library/windows/desktop/aa371338%28v=vs.85%29.aspx user[:password] = nil end end @@ -151,9 +151,9 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows def enable_account user_modify do |user| user[:flags] &= ~NetUser::UF_ACCOUNTDISABLE - #This does not set the password to nil. It (for some reason) means to ignore updating the field. - #See similar behavior for the logon_hours field documented at - #http://msdn.microsoft.com/en-us/library/windows/desktop/aa371338%28v=vs.85%29.aspx + # This does not set the password to nil. It (for some reason) means to ignore updating the field. + # See similar behavior for the logon_hours field documented at + # http://msdn.microsoft.com/en-us/library/windows/desktop/aa371338%28v=vs.85%29.aspx user[:password] = nil end end diff --git a/lib/chef/util/windows/volume.rb b/lib/chef/util/windows/volume.rb index 358a3f4bb8..ff5f46163f 100644 --- a/lib/chef/util/windows/volume.rb +++ b/lib/chef/util/windows/volume.rb @@ -16,7 +16,7 @@ # limitations under the License. # -#simple wrapper around Volume APIs. might be possible with WMI, but possibly more complex. +# simple wrapper around Volume APIs. might be possible with WMI, but possibly more complex. require "chef/win32/api/file" require "chef/util/windows" @@ -25,7 +25,7 @@ class Chef::Util::Windows::Volume < Chef::Util::Windows attr_reader :mount_point def initialize(name) - name += "\\" unless name =~ /\\$/ #trailing slash required + name += "\\" unless name =~ /\\$/ # trailing slash required @mount_point = name end diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 3b76eecae6..4d98c99969 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -13,11 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # NOTE: This file is generated by running `rake version` in the top level of # this repo. Do not edit this manually. Edit the VERSION file and run the rake # task instead. -#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! require "chef/version_string" diff --git a/lib/chef/win32/api.rb b/lib/chef/win32/api.rb index 503920a0ed..fccedd1d54 100644 --- a/lib/chef/win32/api.rb +++ b/lib/chef/win32/api.rb @@ -51,7 +51,7 @@ class Chef host.typedef :bool, :BOOL host.typedef :bool, :BOOLEAN host.typedef :uchar, :BYTE # Byte (8 bits). Declared as unsigned char - #CALLBACK: K, # Win32.API gem-specific ?? MSDN: #define CALLBACK __stdcall + # CALLBACK: K, # Win32.API gem-specific ?? MSDN: #define CALLBACK __stdcall host.typedef :char, :CHAR # 8-bit Windows (ANSI) character. See http://msdn.microsoft.com/en-us/library/dd183415%28VS.85%29.aspx host.typedef :uint32, :COLORREF # Red, green, blue (RGB) color value (32 bits). See COLORREF for more info. host.typedef :uint32, :DWORD # 32-bit unsigned integer. The range is 0 through 4,294,967,295 decimal. @@ -78,7 +78,7 @@ class Chef host.typedef :ulong, :HDESK # (L) Handle to a desktop. http://msdn.microsoft.com/en-us/library/ms682573%28VS.85%29.aspx host.typedef :ulong, :HDROP # (L) Handle to an internal drop structure. host.typedef :ulong, :HDWP # (L) Handle to a deferred window position structure. - host.typedef :ulong, :HENHMETAFILE #(L) Handle to an enhanced metafile. http://msdn.microsoft.com/en-us/library/dd145051%28VS.85%29.aspx + host.typedef :ulong, :HENHMETAFILE # (L) Handle to an enhanced metafile. http://msdn.microsoft.com/en-us/library/dd145051%28VS.85%29.aspx host.typedef :uint, :HFILE # (I) Special file handle to a file opened by OpenFile, not CreateFile. # WinDef.h: #host.typedef int HFILE; host.typedef :ulong, :HFONT # (L) Handle to a font. http://msdn.microsoft.com/en-us/library/dd162470%28VS.85%29.aspx @@ -107,7 +107,7 @@ class Chef host.typedef :int, :INT # 32-bit signed integer. The range is -2147483648 through 2147483647 decimal. host.typedef :int, :INT_PTR # Signed integer type for pointer precision. Use when casting a pointer to an integer # to perform pointer arithmetic. BaseTsd.h: - #if defined(_WIN64) host.typedef __int64 INT_PTR; #else host.typedef int INT_PTR; + # if defined(_WIN64) host.typedef __int64 INT_PTR; #else host.typedef int INT_PTR; host.typedef :int32, :INT32 # 32-bit signed integer. The range is -2,147,483,648 through +...647 decimal. host.typedef :int64, :INT64 # 64-bit signed integer. The range is –9,223,372,036,854,775,808 through +...807 host.typedef :ushort, :LANGID # Language identifier. For more information, see Locales. WinNT.h: #host.typedef WORD LANGID; @@ -122,7 +122,7 @@ class Chef host.typedef :int64, :LONGLONG # 64-bit signed integer. The range is –9,223,372,036,854,775,808 through +...807 host.typedef :long, :LONG_PTR # Signed long type for pointer precision. Use when casting a pointer to a long to # perform pointer arithmetic. BaseTsd.h: - #if defined(_WIN64) host.typedef __int64 LONG_PTR; #else host.typedef long LONG_PTR; + # if defined(_WIN64) host.typedef __int64 LONG_PTR; #else host.typedef long LONG_PTR; host.typedef :long, :LPARAM # Message parameter. WinDef.h as follows: #host.typedef LONG_PTR LPARAM; host.typedef :pointer, :LPBOOL # Pointer to a BOOL. WinDef.h as follows: #host.typedef BOOL far *LPBOOL; host.typedef :pointer, :LPBYTE # Pointer to a BYTE. WinDef.h as follows: #host.typedef BYTE far *LPBYTE; @@ -160,7 +160,7 @@ class Chef host.typedef :pointer, :PDWORD32 # Pointer to a DWORD32. host.typedef :pointer, :PDWORD64 # Pointer to a DWORD64. host.typedef :pointer, :PFLOAT # Pointer to a FLOAT. - host.typedef :pointer, :PGENERICMAPPING #Pointer to GENERIC_MAPPING + host.typedef :pointer, :PGENERICMAPPING # Pointer to GENERIC_MAPPING host.typedef :pointer, :PHALF_PTR # Pointer to a HALF_PTR. host.typedef :pointer, :PHANDLE # Pointer to a HANDLE. host.typedef :pointer, :PHKEY # Pointer to an HKEY. @@ -235,7 +235,7 @@ class Chef host.typedef :ulong_long, :USN # Update sequence number (USN). host.typedef :ushort, :WCHAR # 16-bit Unicode character. For more information, see Character Sets Used By Fonts. # In WinNT.h: host.typedef wchar_t WCHAR; - #WINAPI: K, # Calling convention for system functions. WinDef.h: define WINAPI __stdcall + # WINAPI: K, # Calling convention for system functions. WinDef.h: define WINAPI __stdcall host.typedef :ushort, :WORD # 16-bit unsigned integer. The range is 0 through 65535 decimal. host.typedef :uint, :WPARAM # Message parameter. WinDef.h as follows: host.typedef UINT_PTR WPARAM; end diff --git a/lib/chef/win32/api/error.rb b/lib/chef/win32/api/error.rb index 758eb98874..e37468c609 100644 --- a/lib/chef/win32/api/error.rb +++ b/lib/chef/win32/api/error.rb @@ -211,9 +211,9 @@ class Chef ERROR_META_EXPANSION_TOO_LONG = 208 # if "*a" > 8.3 ERROR_INVALID_SIGNAL_NUMBER = 209 ERROR_THREAD_1_INACTIVE = 210 - ERROR_INFO_NOT_AVAIL = 211 #@@ PTM 5550 + ERROR_INFO_NOT_AVAIL = 211 # @@ PTM 5550 ERROR_LOCKED = 212 - ERROR_BAD_DYNALINK = 213 #@@ PTM 5760 + ERROR_BAD_DYNALINK = 213 # @@ PTM 5760 ERROR_TOO_MANY_MODULES = 214 ERROR_NESTING_NOT_ALLOWED = 215 ERROR_EXE_MACHINE_TYPE_MISMATCH = 216 diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index 6aa2927e1f..a239671557 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -461,22 +461,22 @@ BOOL WINAPI DeviceIoControl( =end safe_attach_function :DeviceIoControl, [:HANDLE, :DWORD, :LPVOID, :DWORD, :LPVOID, :DWORD, :LPDWORD, :pointer], :BOOL -#BOOL WINAPI DeleteVolumeMountPoint( - #_In_ LPCTSTR lpszVolumeMountPoint -#); +# BOOL WINAPI DeleteVolumeMountPoint( + # _In_ LPCTSTR lpszVolumeMountPoint +# ); safe_attach_function :DeleteVolumeMountPointW, [:LPCTSTR], :BOOL -#BOOL WINAPI SetVolumeMountPoint( - #_In_ LPCTSTR lpszVolumeMountPoint, - #_In_ LPCTSTR lpszVolumeName -#); +# BOOL WINAPI SetVolumeMountPoint( + # _In_ LPCTSTR lpszVolumeMountPoint, + # _In_ LPCTSTR lpszVolumeName +# ); safe_attach_function :SetVolumeMountPointW, [:LPCTSTR, :LPCTSTR], :BOOL -#BOOL WINAPI GetVolumeNameForVolumeMountPoint( - #_In_ LPCTSTR lpszVolumeMountPoint, - #_Out_ LPTSTR lpszVolumeName, - #_In_ DWORD cchBufferLength -#); +# BOOL WINAPI GetVolumeNameForVolumeMountPoint( + # _In_ LPCTSTR lpszVolumeMountPoint, + # _Out_ LPTSTR lpszVolumeName, + # _In_ DWORD cchBufferLength +# ); safe_attach_function :GetVolumeNameForVolumeMountPointW, [:LPCTSTR, :LPTSTR, :DWORD], :BOOL =begin diff --git a/lib/chef/win32/api/net.rb b/lib/chef/win32/api/net.rb index 169c68bbdf..e7c191dd9c 100644 --- a/lib/chef/win32/api/net.rb +++ b/lib/chef/win32/api/net.rb @@ -43,7 +43,7 @@ class Chef USE_NOFORCE = 0 USE_FORCE = 1 - USE_LOTS_OF_FORCE = 2 #every windows API should support this flag + USE_LOTS_OF_FORCE = 2 # every windows API should support this flag NERR_Success = 0 # rubocop:disable Naming/ConstantName ERROR_MORE_DATA = 234 @@ -158,32 +158,32 @@ class Chef :ui2_domainname, :LMSTR end - #NET_API_STATUS NetLocalGroupAdd( - #_In_ LPCWSTR servername, - #_In_ DWORD level, - #_In_ LPBYTE buf, - #_Out_ LPDWORD parm_err - #); + # NET_API_STATUS NetLocalGroupAdd( + # _In_ LPCWSTR servername, + # _In_ DWORD level, + # _In_ LPBYTE buf, + # _Out_ LPDWORD parm_err + # ); safe_attach_function :NetLocalGroupAdd, [ :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD ], :DWORD - #NET_API_STATUS NetLocalGroupDel( - #_In_ LPCWSTR servername, - #_In_ LPCWSTR groupname - #); + # NET_API_STATUS NetLocalGroupDel( + # _In_ LPCWSTR servername, + # _In_ LPCWSTR groupname + # ); safe_attach_function :NetLocalGroupDel, [:LPCWSTR, :LPCWSTR], :DWORD - #NET_API_STATUS NetLocalGroupGetMembers( - #_In_ LPCWSTR servername, - #_In_ LPCWSTR localgroupname, - #_In_ DWORD level, - #_Out_ LPBYTE *bufptr, - #_In_ DWORD prefmaxlen, - #_Out_ LPDWORD entriesread, - #_Out_ LPDWORD totalentries, - #_Inout_ PDWORD_PTR resumehandle - #); + # NET_API_STATUS NetLocalGroupGetMembers( + # _In_ LPCWSTR servername, + # _In_ LPCWSTR localgroupname, + # _In_ DWORD level, + # _Out_ LPBYTE *bufptr, + # _In_ DWORD prefmaxlen, + # _Out_ LPDWORD entriesread, + # _Out_ LPDWORD totalentries, + # _Inout_ PDWORD_PTR resumehandle + # ); safe_attach_function :NetLocalGroupGetMembers, [ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD, :LPDWORD, :LPDWORD, :PDWORD_PTR @@ -209,102 +209,102 @@ class Chef # ); safe_attach_function :NetApiBufferFree, [:LPVOID], :DWORD - #NET_API_STATUS NetUserAdd( - #_In_ LMSTR servername, - #_In_ DWORD level, - #_In_ LPBYTE buf, - #_Out_ LPDWORD parm_err - #); + # NET_API_STATUS NetUserAdd( + # _In_ LMSTR servername, + # _In_ DWORD level, + # _In_ LPBYTE buf, + # _Out_ LPDWORD parm_err + # ); safe_attach_function :NetUserAdd, [ :LMSTR, :DWORD, :LPBYTE, :LPDWORD ], :DWORD - #NET_API_STATUS NetLocalGroupAddMembers( + # NET_API_STATUS NetLocalGroupAddMembers( # _In_ LPCWSTR servername, # _In_ LPCWSTR groupname, # _In_ DWORD level, # _In_ LPBYTE buf, # _In_ DWORD totalentries - #); + # ); safe_attach_function :NetLocalGroupAddMembers, [ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD ], :DWORD - #NET_API_STATUS NetLocalGroupSetMembers( + # NET_API_STATUS NetLocalGroupSetMembers( # _In_ LPCWSTR servername, # _In_ LPCWSTR groupname, # _In_ DWORD level, # _In_ LPBYTE buf, # _In_ DWORD totalentries - #); + # ); safe_attach_function :NetLocalGroupSetMembers, [ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD ], :DWORD - #NET_API_STATUS NetLocalGroupDelMembers( + # NET_API_STATUS NetLocalGroupDelMembers( # _In_ LPCWSTR servername, # _In_ LPCWSTR groupname, # _In_ DWORD level, # _In_ LPBYTE buf, # _In_ DWORD totalentries - #); + # ); safe_attach_function :NetLocalGroupDelMembers, [ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD ], :DWORD - #NET_API_STATUS NetUserGetInfo( + # NET_API_STATUS NetUserGetInfo( # _In_ LPCWSTR servername, # _In_ LPCWSTR username, # _In_ DWORD level, # _Out_ LPBYTE *bufptr - #); + # ); safe_attach_function :NetUserGetInfo, [ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE ], :DWORD - #NET_API_STATUS NetApiBufferFree( + # NET_API_STATUS NetApiBufferFree( # _In_ LPVOID Buffer - #); + # ); safe_attach_function :NetApiBufferFree, [:LPVOID], :DWORD - #NET_API_STATUS NetUserSetInfo( + # NET_API_STATUS NetUserSetInfo( # _In_ LPCWSTR servername, # _In_ LPCWSTR username, # _In_ DWORD level, # _In_ LPBYTE buf, # _Out_ LPDWORD parm_err - #); + # ); safe_attach_function :NetUserSetInfo, [ :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD ], :DWORD - #NET_API_STATUS NetUserDel( + # NET_API_STATUS NetUserDel( # _In_ LPCWSTR servername, # _In_ LPCWSTR username - #); + # ); safe_attach_function :NetUserDel, [:LPCWSTR, :LPCWSTR], :DWORD - #NET_API_STATUS NetUseDel( - #_In_ LMSTR UncServerName, - #_In_ LMSTR UseName, - #_In_ DWORD ForceCond - #); + # NET_API_STATUS NetUseDel( + # _In_ LMSTR UncServerName, + # _In_ LMSTR UseName, + # _In_ DWORD ForceCond + # ); safe_attach_function :NetUseDel, [:LMSTR, :LMSTR, :DWORD], :DWORD - #NET_API_STATUS NetUseGetInfo( - #_In_ LMSTR UncServerName, - #_In_ LMSTR UseName, - #_In_ DWORD Level, - #_Out_ LPBYTE *BufPtr - #); + # NET_API_STATUS NetUseGetInfo( + # _In_ LMSTR UncServerName, + # _In_ LMSTR UseName, + # _In_ DWORD Level, + # _Out_ LPBYTE *BufPtr + # ); safe_attach_function :NetUseGetInfo, [:LMSTR, :LMSTR, :DWORD, :pointer], :DWORD - #NET_API_STATUS NetUseAdd( - #_In_ LMSTR UncServerName, - #_In_ DWORD Level, - #_In_ LPBYTE Buf, - #_Out_ LPDWORD ParmError - #); + # NET_API_STATUS NetUseAdd( + # _In_ LMSTR UncServerName, + # _In_ DWORD Level, + # _In_ LPBYTE Buf, + # _Out_ LPDWORD ParmError + # ); safe_attach_function :NetUseAdd, [:LMSTR, :DWORD, :LPBYTE, :LPDWORD], :DWORD end end diff --git a/lib/chef/win32/registry.rb b/lib/chef/win32/registry.rb index 1193911b00..b1365fd61b 100644 --- a/lib/chef/win32/registry.rb +++ b/lib/chef/win32/registry.rb @@ -56,7 +56,7 @@ class Chef hive, key = get_hive_and_key(key_path) key_exists!(key_path) values = hive.open(key, ::Win32::Registry::KEY_READ | registry_system_architecture) do |reg| - reg.map { |name, type, data| { :name => name, :type => get_name_from_type(type), :data => data } } + reg.map { |name, type, data| { name: name, type: get_name_from_type(type), data: data } } end end @@ -321,13 +321,13 @@ class Chef def _type_name_map { - :binary => ::Win32::Registry::REG_BINARY, - :string => ::Win32::Registry::REG_SZ, - :multi_string => ::Win32::Registry::REG_MULTI_SZ, - :expand_string => ::Win32::Registry::REG_EXPAND_SZ, - :dword => ::Win32::Registry::REG_DWORD, - :dword_big_endian => ::Win32::Registry::REG_DWORD_BIG_ENDIAN, - :qword => ::Win32::Registry::REG_QWORD, + binary: ::Win32::Registry::REG_BINARY, + string: ::Win32::Registry::REG_SZ, + multi_string: ::Win32::Registry::REG_MULTI_SZ, + expand_string: ::Win32::Registry::REG_EXPAND_SZ, + dword: ::Win32::Registry::REG_DWORD, + dword_big_endian: ::Win32::Registry::REG_DWORD_BIG_ENDIAN, + qword: ::Win32::Registry::REG_QWORD, } end diff --git a/lib/chef/win32/security/securable_object.rb b/lib/chef/win32/security/securable_object.rb index aef1a72c8c..f0bbfc7354 100644 --- a/lib/chef/win32/security/securable_object.rb +++ b/lib/chef/win32/security/securable_object.rb @@ -42,10 +42,10 @@ class Chef # compare an existing ACE with one you want to create. def predict_rights_mask(generic_mask) mask = generic_mask - #mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_READ if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_READ) != 0 - #mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_WRITE if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_WRITE) != 0 - #mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_EXECUTE if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE) != 0 - #mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_ALL if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_ALL) != 0 + # mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_READ if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_READ) != 0 + # mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_WRITE if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_WRITE) != 0 + # mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_EXECUTE if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE) != 0 + # mask |= Chef::ReservedNames::Win32::API::Security::STANDARD_RIGHTS_ALL if (mask | Chef::ReservedNames::Win32::API::Security::GENERIC_ALL) != 0 if type == :SE_FILE_OBJECT mask |= Chef::ReservedNames::Win32::API::Security::FILE_GENERIC_READ if (mask & Chef::ReservedNames::Win32::API::Security::GENERIC_READ) != 0 mask |= Chef::ReservedNames::Win32::API::Security::FILE_GENERIC_WRITE if (mask & Chef::ReservedNames::Win32::API::Security::GENERIC_WRITE) != 0 @@ -71,36 +71,36 @@ class Chef end def dacl=(val) - Security.set_named_security_info(path, type, :dacl => val) + Security.set_named_security_info(path, type, dacl: val) end # You don't set dacl_inherits without also setting dacl, # because Windows gets angry and denies you access. So # if you want to do that, you may as well do both at once. def set_dacl(dacl, dacl_inherits) - Security.set_named_security_info(path, type, :dacl => dacl, :dacl_inherits => dacl_inherits) + Security.set_named_security_info(path, type, dacl: dacl, dacl_inherits: dacl_inherits) end def group=(val) - Security.set_named_security_info(path, type, :group => val) + Security.set_named_security_info(path, type, group: val) end def owner=(val) # TODO to fix serious permissions problems, we may need to enable SeBackupPrivilege. But we might need it (almost) everywhere else, too. Security.with_privileges("SeTakeOwnershipPrivilege", "SeRestorePrivilege") do - Security.set_named_security_info(path, type, :owner => val) + Security.set_named_security_info(path, type, owner: val) end end def sacl=(val) Security.with_privileges("SeSecurityPrivilege") do - Security.set_named_security_info(path, type, :sacl => val) + Security.set_named_security_info(path, type, sacl: val) end end def set_sacl(sacl, sacl_inherits) Security.with_privileges("SeSecurityPrivilege") do - Security.set_named_security_info(path, type, :sacl => sacl, :sacl_inherits => sacl_inherits) + Security.set_named_security_info(path, type, sacl: sacl, sacl_inherits: sacl_inherits) end end end diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index 944cb207f5..f96fd18316 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -50,21 +50,21 @@ class Chef private_class_method :method_name_from_marketing_name WIN_VERSIONS = { - "Windows 10" => { :major => 10, :minor => 0, :callable => lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, - "Windows Server 2016" => { :major => 10, :minor => 0, :callable => lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, - "Windows 8.1" => { :major => 6, :minor => 3, :callable => lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, - "Windows Server 2012 R2" => { :major => 6, :minor => 3, :callable => lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, - "Windows 8" => { :major => 6, :minor => 2, :callable => lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, - "Windows Server 2012" => { :major => 6, :minor => 2, :callable => lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, - "Windows 7" => { :major => 6, :minor => 1, :callable => lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, - "Windows Server 2008 R2" => { :major => 6, :minor => 1, :callable => lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, - "Windows Server 2008" => { :major => 6, :minor => 0, :callable => lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, - "Windows Vista" => { :major => 6, :minor => 0, :callable => lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, - "Windows Server 2003 R2" => { :major => 5, :minor => 2, :callable => lambda { |product_type, suite_mask| get_system_metrics(SM_SERVERR2) != 0 } }, - "Windows Home Server" => { :major => 5, :minor => 2, :callable => lambda { |product_type, suite_mask| (suite_mask & VER_SUITE_WH_SERVER) == VER_SUITE_WH_SERVER } }, - "Windows Server 2003" => { :major => 5, :minor => 2, :callable => lambda { |product_type, suite_mask| get_system_metrics(SM_SERVERR2) == 0 } }, - "Windows XP" => { :major => 5, :minor => 1 }, - "Windows 2000" => { :major => 5, :minor => 0 }, + "Windows 10" => { major: 10, minor: 0, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, + "Windows Server 2016" => { major: 10, minor: 0, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, + "Windows 8.1" => { major: 6, minor: 3, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, + "Windows Server 2012 R2" => { major: 6, minor: 3, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, + "Windows 8" => { major: 6, minor: 2, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, + "Windows Server 2012" => { major: 6, minor: 2, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, + "Windows 7" => { major: 6, minor: 1, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, + "Windows Server 2008 R2" => { major: 6, minor: 1, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, + "Windows Server 2008" => { major: 6, minor: 0, callable: lambda { |product_type, suite_mask| product_type != VER_NT_WORKSTATION } }, + "Windows Vista" => { major: 6, minor: 0, callable: lambda { |product_type, suite_mask| product_type == VER_NT_WORKSTATION } }, + "Windows Server 2003 R2" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask| get_system_metrics(SM_SERVERR2) != 0 } }, + "Windows Home Server" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask| (suite_mask & VER_SUITE_WH_SERVER) == VER_SUITE_WH_SERVER } }, + "Windows Server 2003" => { major: 5, minor: 2, callable: lambda { |product_type, suite_mask| get_system_metrics(SM_SERVERR2) == 0 } }, + "Windows XP" => { major: 5, minor: 1 }, + "Windows 2000" => { major: 5, minor: 0 }, } def initialize |