summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2019-04-04 12:40:53 -0400
committerMarc A. Paradise <marc.paradise@gmail.com>2019-04-24 13:25:58 -0400
commitc5e4e79d1415d6521d210088172e8ed9ad2cc066 (patch)
tree2bf0bf645d6a4e70bc991fc96a6b7143942ee79b
parentfed15713b59ddab5185661d83884b27525af546b (diff)
downloadchef-c5e4e79d1415d6521d210088172e8ed9ad2cc066.tar.gz
Rubocop!
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r--lib/chef.rb1
-rw-r--r--lib/chef/knife/bootstrap.rb56
-rw-r--r--lib/chef/knife/bootstrap/options.rb302
-rw-r--r--lib/chef/knife/core/ui.rb2
-rw-r--r--lib/chef/knife/core/windows_bootstrap_context.rb56
-rw-r--r--spec/unit/knife/bootstrap_spec.rb260
6 files changed, 326 insertions, 351 deletions
diff --git a/lib/chef.rb b/lib/chef.rb
index ccfb57764d..b103a097b0 100644
--- a/lib/chef.rb
+++ b/lib/chef.rb
@@ -16,7 +16,6 @@
# limitations under the License.
#
-
require "chef/version"
require "chef_core/text"
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index aa5d1f502a..643e22174c 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -32,7 +32,7 @@ class Chef
# so we'll keep this file a little smaller by splitting them out.
include Bootstrap::Options
- SUPPORTED_CONNECTION_PROTOCOLS = %w{ssh winrm}
+ SUPPORTED_CONNECTION_PROTOCOLS = %w{ssh winrm}.freeze
attr_accessor :client_builder
attr_accessor :chef_vault_handler
@@ -88,7 +88,6 @@ class Chef
end
end
-
# @return [String] The CLI specific bootstrap template or the default
def bootstrap_template
# Allow passing a bootstrap template or use the default
@@ -198,14 +197,13 @@ class Chef
chef_vault_handler.run(client_builder.client)
else
ui.info <<~EOM
- Doing old-style registration with the validation key at #{Chef::Config[:validation_key]}..."
- Delete your validation key in order to use your user credentials instead
- EOM
+ Doing old-style registration with the validation key at #{Chef::Config[:validation_key]}..."
+ Delete your validation key in order to use your user credentials instead
+ EOM
end
end
-
def perform_bootstrap(remote_bootstrap_script_path)
ui.info("Bootstrapping #{ui.color(server_name, :bold)}")
cmd = bootstrap_command(remote_bootstrap_script_path)
@@ -220,7 +218,6 @@ class Chef
end
def connect!
-
ui.info("Connecting to #{ui.color(server_name, :bold)}")
opts = connection_opts.dup
do_connect(opts)
@@ -254,7 +251,7 @@ class Chef
def connection_protocol
return @connection_protocol if @connection_protocol
- from_url = host_descriptor =~ /^(.*):\/\// ? $1 : nil
+ from_url = host_descriptor =~ /^(.*):\/\// ? $1 : nil
from_cli = config[:connection_protocol]
from_knife = Chef::Config[:knife][:connection_protocol]
@connection_protocol = from_url || from_cli || from_knife || "ssh"
@@ -287,18 +284,16 @@ class Chef
def validate_winrm_transport_opts!
return true if connection_protocol != "winrm"
-
- if (Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key])))
- if (config_value(:winrm_auth_method) == "plaintext" &&
- config_value(:winrm_ssl) != true)
+ if Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key]))
+ if config_value(:winrm_auth_method) == "plaintext" &&
+ config_value(:winrm_ssl) != true
ui.error <<~EOM
- Validatorless bootstrap over unsecure winrm channels could expose your
- key to network sniffing.
-
- Please use a 'winrm_auth_method' other than 'plaintext',
- or enable ssl on #{server_name} then use the --ssl flag
- to connect.
- EOM
+ Validatorless bootstrap over unsecure winrm channels could expose your
+ key to network sniffing.
+ Please use a 'winrm_auth_method' other than 'plaintext',
+ or enable ssl on #{server_name} then use the --ssl flag
+ to connect.
+ EOM
exit 1
end
@@ -340,13 +335,13 @@ class Chef
# @return [TrueClass] If options are valid.
def validate_protocol!
from_cli = config[:connection_protocol]
- if (from_cli && connection_protocol != from_cli)
+ if from_cli && connection_protocol != from_cli
# Hanging indent to align with the ERROR: prefix
ui.error <<~EOM
- The URL '#{host_descriptor}' indicates protocol is '#{connection_protocol}'
- while the --protocol flag specifies '#{from_cli}'. Please include
- only one or the other.
- EOM
+ The URL '#{host_descriptor}' indicates protocol is '#{connection_protocol}'
+ while the --protocol flag specifies '#{from_cli}'. Please include
+ only one or the other.
+ EOM
exit 1
end
@@ -502,7 +497,6 @@ class Chef
opts
end
-
# use_sudo - tells bootstrap to use the sudo command to run bootstrap
# use_sudo_password - tells bootstrap to use the sudo command to run bootstrap
# and to use the password specified with --password
@@ -522,7 +516,7 @@ class Chef
opts[:sudo_password] = config[:password]
end
if config[:preserve_home]
- opts[:sudo_options] = "-H"
+ opts[:sudo_options] = "-H"
end
end
opts
@@ -535,7 +529,7 @@ class Chef
winrm_transport: auth_method, # winrm gem and train calls auth method 'transport'
winrm_basic_auth_only: config_value(:winrm_basic_auth_only) || false,
ssl: config_value(:winrm_ssl) === true,
- ssl_peer_fingerprint: config_value(:winrm_ssl_peer_fingerprint)
+ ssl_peer_fingerprint: config_value(:winrm_ssl_peer_fingerprint),
}
if auth_method == "kerberos"
@@ -552,7 +546,6 @@ class Chef
opts
end
-
# Config overrides to force password auth.
def force_ssh_password_opts(password)
{
@@ -560,7 +553,7 @@ class Chef
non_interactive: false,
keys_only: false,
key_files: [],
- auth_methods: [:password, :keyboard_interactive]
+ auth_methods: [:password, :keyboard_interactive],
}
end
@@ -593,7 +586,6 @@ class Chef
:not_found
end
-
def upload_bootstrap(content)
script_name = target_host.base_os == :windows ? "bootstrap.bat" : "bootstrap.sh"
remote_path = target_host.normalize_path(File.join(target_host.temp_dir, script_name))
@@ -601,7 +593,6 @@ class Chef
remote_path
end
-
# build the command string for bootrapping
# @return String
def bootstrap_command(remote_path)
@@ -612,7 +603,6 @@ class Chef
end
end
-
# To avoid cluttering the CLI options, some flags (such as port and user)
# are shared between protocols. However, there is still a need to allow the operator
# to specify defaults separately, since they may not be the same values for different protocols.
@@ -621,7 +611,7 @@ class Chef
# For example, :user CLI option will map to :winrm_user and :ssh_user Chef::Config keys,
# based on the connection protocol in use.
def knife_key_for_protocol(protocol, option)
- "#{connection_protocol}_#{option.to_s}".to_sym
+ "#{connection_protocol}_#{option}".to_sym
end
private
diff --git a/lib/chef/knife/bootstrap/options.rb b/lib/chef/knife/bootstrap/options.rb
index 350aef0959..b735c54c50 100644
--- a/lib/chef/knife/bootstrap/options.rb
+++ b/lib/chef/knife/bootstrap/options.rb
@@ -22,10 +22,10 @@ class Chef
# REVIEWER: let's talk about which protocols we want to support.
# TODO this should be available from train, which we can make our source of truth.
# TODO - we don't actually validate that the protocol is valid...
- WINRM_AUTH_PROTOCOL_LIST = %w{plaintext kerberos ssl negotiate}
+ WINRM_AUTH_PROTOCOL_LIST = %w{plaintext kerberos ssl negotiate}.freeze
- #TODO - missing - authtimeout (minutes)
- #TODO - missing impl - session-timeout minutes
+ # TODO - missing - authtimeout (minutes)
+ # TODO - missing impl - session-timeout minutes
def self.included(includer)
includer.class_eval do
@@ -139,76 +139,76 @@ class Chef
}
# bootstrap_context - client.rb
- 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
+ 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
# runtime - sudo settings (train handles sudo)
- option :use_sudo,
- long: "--sudo",
- description: "Execute the bootstrap via sudo",
- boolean: true
+ option :use_sudo,
+ long: "--sudo",
+ description: "Execute the bootstrap via sudo",
+ boolean: true
# runtime - sudo settings (train handles sudo)
- option :preserve_home,
- long: "--sudo-preserve-home",
- description: "Preserve non-root user HOME environment variable with sudo",
- boolean: true
+ option :preserve_home,
+ long: "--sudo-preserve-home",
+ description: "Preserve non-root user HOME environment variable with sudo",
+ boolean: true
# runtime - sudo settings (train handles sudo)
- option :use_sudo_password,
- long: "--use-sudo-password",
- description: "Execute the bootstrap via sudo with password",
- boolean: false
+ option :use_sudo_password,
+ long: "--use-sudo-password",
+ description: "Execute the bootstrap via sudo with password",
+ boolean: false
# runtime - client_builder
- option :chef_node_name,
- short: "-N NAME",
- long: "--node-name NAME",
- description: "The Chef node name for your new node"
+ option :chef_node_name,
+ short: "-N NAME",
+ long: "--node-name NAME",
+ description: "The Chef node name for your new node"
# runtime - client_builder - set runlist when creating node
- 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: []
+ 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: []
# runtime - client_builder - set policy name when creating node
- option :policy_name,
- long: "--policy-name POLICY_NAME",
- description: "Policyfile name to use (--policy-group must also be given)",
- default: nil
+ option :policy_name,
+ long: "--policy-name POLICY_NAME",
+ description: "Policyfile name to use (--policy-group must also be given)",
+ default: nil
# runtime - client_builder - set policy group when creating node
- option :policy_group,
- long: "--policy-group POLICY_GROUP",
- description: "Policy group name to use (--policy-name 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
# runtime - client_builder - node tags
- option :tags,
- long: "--tags TAGS",
- description: "Comma separated list of tags to apply to the node",
- proc: lambda { |o| o.split(/[\s,]+/) },
- default: []
+ option :tags,
+ long: "--tags TAGS",
+ description: "Comma separated list of tags to apply to the node",
+ proc: lambda { |o| o.split(/[\s,]+/) },
+ default: []
# bootstrap template
- 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
+ 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
# bootstrap template
- 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
+ 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
# Note that several of the below options are used by bootstrap template,
# but only from the passed-in knife config; it does not use the
@@ -217,113 +217,111 @@ class Chef
# bootstrap template
# Create ohai hints in /etc/chef/ohai/hints, fname=hintname, content=value
- 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|
- 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 :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|
+ Chef::Config[:knife][:hints] ||= Hash.new
+ name, path = h.split("=")
+ Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new
+ }
# bootstrap override: url of a an installer shell script touse in place of omnitruck
# Note that the bootstrap template _only_ references this out of Chef::Config, and not from
# the provided options to knife bootstrap, so we set the Chef::Config option here.
- option :bootstrap_url,
- long: "--bootstrap-url URL",
- description: "URL to a custom installation script",
- proc: Proc.new { |u| Chef::Config[:knife][:bootstrap_url] = u }
-
+ option :bootstrap_url,
+ long: "--bootstrap-url URL",
+ description: "URL to a custom installation script",
+ proc: Proc.new { |u| Chef::Config[:knife][:bootstrap_url] = u }
# bootstrap override: Do this instead of our own setup.sh from omnitruck. Causes bootstrap_url to be ignored.
- 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 }
+ 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 }
# bootstrap template: Run this command first in the bootstrap script
- 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 }
+ 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 }
# bootstrap template
- 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 }
+ 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 }
# bootstrap template
- 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 }
+ 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 }
# chef_vault_handler
- 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"
+ 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"
# chef_vault_handler
- option :bootstrap_vault_json,
- long: "--bootstrap-vault-json VAULT_JSON",
- description: "A JSON string with the 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"
# chef_vault_handler
- 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|
- (vault, item) = i.split(/:/)
- Chef::Config[:knife][:bootstrap_vault_item] ||= {}
- Chef::Config[:knife][:bootstrap_vault_item][vault] ||= []
- Chef::Config[:knife][:bootstrap_vault_item][vault].push(item)
- Chef::Config[:knife][:bootstrap_vault_item]
- }
+ 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|
+ (vault, item) = i.split(/:/)
+ Chef::Config[:knife][:bootstrap_vault_item] ||= {}
+ Chef::Config[:knife][:bootstrap_vault_item][vault] ||= []
+ Chef::Config[:knife][:bootstrap_vault_item][vault].push(item)
+ Chef::Config[:knife][:bootstrap_vault_item]
+ }
# Windows only
# bootstrap template
- option :install_as_service,
- :long => "--install-as-service",
- :description => "Install chef-client as a Windows service. (Windows only)",
- :default => false
+ option :install_as_service,
+ long: "--install-as-service",
+ description: "Install chef-client as a Windows service. (Windows only)",
+ default: false
# bootstrap template
- option :msi_url,
- :short => "-m URL",
- :long => "--msi-url URL",
- :description => "Location of the Chef Client MSI. The default templates will prefer to download from this location. The MSI will be downloaded from chef.io if not provided (windows).",
- :default => ''
-
- option :winrm_ssl_peer_fingerprint,
- :long => "--winrm-ssl-peer-fingerprint FINGERPRINT",
- :description => "SSL certificate fingerprint expected from the target."
-
- option :ca_trust_file,
- :short => "-f CA_TRUST_PATH",
- :long => "--ca-trust-file CA_TRUST_PATH",
- :description => "The Certificate Authority (CA) trust file used for SSL transport"
-
- option :winrm_no_verify_cert,
- long: "--winrm-no-verify-cert",
- description: "Do not verify the SSL certificate of the target node for WinRM."
-
-
- option :winrm_ssl,
- long: "--winrm-ssl",
- description: "Connect to WinRM using SSL"
-
- option :winrm_auth_method,
- :short => "-w AUTH-METHOD",
- :long => "--winrm-auth-method AUTH-METHOD",
- :description => "The WinRM authentication method to use. Valid choices are #{WINRM_AUTH_PROTOCOL_LIST}",
- :proc => Proc.new { |protocol| Chef::Config[:knife][:winrm_auth_method] = protocol }
-
- option :winrm_basic_auth_only,
- long: "--winrm-basic-auth-only",
- description: "For WinRM basic authentication when using the 'ssl' auth method",
- boolean: true
+ option :msi_url,
+ short: "-m URL",
+ long: "--msi-url URL",
+ description: "Location of the Chef Client MSI. The default templates will prefer to download from this location. The MSI will be downloaded from chef.io if not provided (windows).",
+ default: ""
+
+ option :winrm_ssl_peer_fingerprint,
+ long: "--winrm-ssl-peer-fingerprint FINGERPRINT",
+ description: "SSL certificate fingerprint expected from the target."
+
+ option :ca_trust_file,
+ short: "-f CA_TRUST_PATH",
+ long: "--ca-trust-file CA_TRUST_PATH",
+ description: "The Certificate Authority (CA) trust file used for SSL transport"
+
+ option :winrm_no_verify_cert,
+ long: "--winrm-no-verify-cert",
+ description: "Do not verify the SSL certificate of the target node for WinRM."
+
+ option :winrm_ssl,
+ long: "--winrm-ssl",
+ description: "Connect to WinRM using SSL"
+
+ option :winrm_auth_method,
+ short: "-w AUTH-METHOD",
+ long: "--winrm-auth-method AUTH-METHOD",
+ description: "The WinRM authentication method to use. Valid choices are #{WINRM_AUTH_PROTOCOL_LIST}",
+ proc: Proc.new { |protocol| Chef::Config[:knife][:winrm_auth_method] = protocol }
+
+ option :winrm_basic_auth_only,
+ long: "--winrm-basic-auth-only",
+ description: "For WinRM basic authentication when using the 'ssl' auth method",
+ boolean: true
# This option was provided in knife bootstrap windows winrm,
# but it is ignored in knife-windows/WinrmSession, and so remains unimplemeneted here.
@@ -333,22 +331,22 @@ class Chef
# :description => "The Kerberos keytab file used for authentication",
# :proc => Proc.new { |keytab| Chef::Config[:knife][:kerberos_keytab_file] = keytab }
- option :kerberos_realm,
- :short => "-R KERBEROS_REALM",
- :long => "--kerberos-realm KERBEROS_REALM",
- :description => "The Kerberos realm used for authentication",
- :proc => Proc.new { |protocol| Chef::Config[:knife][:kerberos_realm] = protocol }
-
- option :kerberos_service,
- :short => "-S KERBEROS_SERVICE",
- :long => "--kerberos-service KERBEROS_SERVICE",
- :description => "The Kerberos service used for authentication",
- :proc => Proc.new { |protocol| Chef::Config[:knife][:kerberos_service] = protocol }
-
- option :winrm_session_timeout,
- :long => "--winrm-session-timeout SECONDS",
- :description => "The number of seconds to wait for each WinRM operation to be acknowledged while running bootstrap",
- :proc => Proc.new { |protocol| Chef::Config[:knife][:winrm_session_timeout] = protocol }
+ option :kerberos_realm,
+ short: "-R KERBEROS_REALM",
+ long: "--kerberos-realm KERBEROS_REALM",
+ description: "The Kerberos realm used for authentication",
+ proc: Proc.new { |protocol| Chef::Config[:knife][:kerberos_realm] = protocol }
+
+ option :kerberos_service,
+ short: "-S KERBEROS_SERVICE",
+ long: "--kerberos-service KERBEROS_SERVICE",
+ description: "The Kerberos service used for authentication",
+ proc: Proc.new { |protocol| Chef::Config[:knife][:kerberos_service] = protocol }
+
+ option :winrm_session_timeout,
+ long: "--winrm-session-timeout SECONDS",
+ description: "The number of seconds to wait for each WinRM operation to be acknowledged while running bootstrap",
+ proc: Proc.new { |protocol| Chef::Config[:knife][:winrm_session_timeout] = protocol }
end
end
diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb
index 517e44f0c3..9801b8d033 100644
--- a/lib/chef/knife/core/ui.rb
+++ b/lib/chef/knife/core/ui.rb
@@ -83,7 +83,7 @@ class Chef
# indent subsequent lines to align with the
# log type prefix ("ERROR: ", etc)
unless lines.empty?
- prefix, _ = first_line.split(":", 2)
+ prefix, = first_line.split(":", 2)
return if prefix.nil?
prefix_len = prefix.length
prefix_len -= 9 if color? # prefix includes 9 bytes of color escape sequences
diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb
index 6db017ca2f..1993a68ea8 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -16,8 +16,8 @@
# limitations under the License.
#
-require 'chef/knife/core/bootstrap_context'
-require 'chef/util/path_helper'
+require "chef/knife/core/bootstrap_context"
+require "chef/util/path_helper"
class Chef
class Knife
@@ -30,7 +30,7 @@ class Chef
#
class WindowsBootstrapContext < BootstrapContext
- def initialize(config, run_list, chef_config, secret=nil)
+ def initialize(config, run_list, chef_config, secret = nil)
@config = config
@run_list = run_list
@chef_config = chef_config
@@ -85,24 +85,24 @@ class Chef
# We configure :verify_api_cert only when it's overridden on the CLI
# or when specified in the knife config.
- if !@config[:node_verify_api_cert].nil? || knife_config.has_key?(:verify_api_cert)
+ if !@config[:node_verify_api_cert].nil? || knife_config.key?(:verify_api_cert)
value = @config[:node_verify_api_cert].nil? ? knife_config[:verify_api_cert] : @config[:node_verify_api_cert]
client_rb << %Q{verify_api_cert #{value}\n}
end
# We configure :ssl_verify_mode only when it's overridden on the CLI
# or when specified in the knife config.
- if @config[:node_ssl_verify_mode] || knife_config.has_key?(:ssl_verify_mode)
+ if @config[:node_ssl_verify_mode] || knife_config.key?(:ssl_verify_mode)
value = case @config[:node_ssl_verify_mode]
- when "peer"
- :verify_peer
- when "none"
- :verify_none
- when nil
- knife_config[:ssl_verify_mode]
- else
- nil
- end
+ when "peer"
+ :verify_peer
+ when "none"
+ :verify_none
+ when nil
+ knife_config[:ssl_verify_mode]
+ else
+ nil
+ end
if value
client_rb << %Q{ssl_verify_mode :#{value}\n}
@@ -150,9 +150,9 @@ class Chef
%Q{:#{@chef_config[:config_log_location]}\n}
elsif @chef_config[:config_log_location].equal?(:syslog)
raise "syslog is not supported for log_location on Windows OS\n"
- elsif (@chef_config[:config_log_location].equal?(STDOUT))
+ elsif @chef_config[:config_log_location].equal?(STDOUT)
"STDOUT\n"
- elsif (@chef_config[:config_log_location].equal?(STDERR))
+ elsif @chef_config[:config_log_location].equal?(STDERR)
"STDERR\n"
elsif @chef_config[:config_log_location].nil? || @chef_config[:config_log_location].empty?
"STDOUT\n"
@@ -164,7 +164,7 @@ class Chef
end
def start_chef
- bootstrap_environment_option = bootstrap_environment.nil? ? '' : " -E #{bootstrap_environment}"
+ bootstrap_environment_option = bootstrap_environment.nil? ? "" : " -E #{bootstrap_environment}"
start_chef = "SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin\"\n"
start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json#{bootstrap_environment_option}\n"
end
@@ -175,10 +175,10 @@ class Chef
installer_version_string = "&prerelease=true"
else
chef_version_string = if knife_config[:bootstrap_version]
- knife_config[:bootstrap_version]
- else
- Chef::VERSION.split(".").first
- end
+ knife_config[:bootstrap_version]
+ else
+ Chef::VERSION.split(".").first
+ end
installer_version_string = "&v=#{chef_version_string}"
@@ -285,18 +285,18 @@ class Chef
def install_chef
# The normal install command uses regular double quotes in
# the install command, so request such a string from install_command
- install_chef = install_command('"') + "\n" + fallback_install_task_command
+ install_command('"') + "\n" + fallback_install_task_command
end
def bootstrap_directory
- bootstrap_directory = "C:\\chef"
+ "C:\\chef"
end
def local_download_path
- local_download_path = "%TEMP%\\chef-client-latest.msi"
+ "%TEMP%\\chef-client-latest.msi"
end
- def msi_url(machine_os=nil, machine_arch=nil, download_context=nil)
+ def msi_url(machine_os = nil, machine_arch = nil, download_context = nil)
# The default msi path has a number of url query parameters - we attempt to substitute
# such parameters in as long as they are provided by the template.
@@ -339,7 +339,7 @@ class Chef
if @chef_config[:trusted_certs_dir]
Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(@chef_config[:trusted_certs_dir]), "*.{crt,pem}")).each do |cert|
content << "> #{bootstrap_directory}/trusted_certs/#{File.basename(cert)} (\n" +
- escape_and_echo(IO.read(File.expand_path(cert))) + "\n)\n"
+ escape_and_echo(IO.read(File.expand_path(cert))) + "\n)\n"
end
end
content
@@ -352,7 +352,7 @@ class Chef
root.find do |f|
relative = f.relative_path_from(root)
if f != root
- file_on_node = "#{bootstrap_directory}/client.d/#{relative}".gsub("/","\\")
+ file_on_node = "#{bootstrap_directory}/client.d/#{relative}".tr("/", "\\")
if f.directory?
content << "mkdir #{file_on_node}\n"
else
@@ -370,7 +370,7 @@ class Chef
# code below. To handle tasks that contain arguments that
# need to be double quoted, schtasks allows the use of single
# quotes that will later be converted to double quotes
- command = install_command('\'')
+ command = install_command("'")
<<~EOH
@set MSIERRORCODE=!ERRORLEVEL!
@if ERRORLEVEL 1 (
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 1c6943f2fe..5be0999e37 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -514,43 +514,41 @@ describe Chef::Knife::Bootstrap do
Chef::Util::PathHelper.cleanpath(
File.join(File.dirname(__FILE__), "../../data/client.d_00")) end
- it "creates /etc/chef/client.d" do
- expect(rendered_template).to match("mkdir -p /etc/chef/client\.d")
- end
+ it "creates /etc/chef/client.d" do
+ expect(rendered_template).to match("mkdir -p /etc/chef/client\.d")
+ end
- context "a flat directory structure" do
- it "escapes single-quotes" do
- expect(rendered_template).to match("cat > /etc/chef/client.d/02-strings.rb <<'EOP'")
- expect(rendered_template).to match("something '\\\\''/foo/bar'\\\\''")
- end
+ context "a flat directory structure" do
+ it "escapes single-quotes" do
+ expect(rendered_template).to match("cat > /etc/chef/client.d/02-strings.rb <<'EOP'")
+ expect(rendered_template).to match("something '\\\\''/foo/bar'\\\\''")
+ end
- it "creates a file 00-foo.rb" do
- expect(rendered_template).to match("cat > /etc/chef/client.d/00-foo.rb <<'EOP'")
- expect(rendered_template).to match("d6f9b976-289c-4149-baf7-81e6ffecf228")
- end
- it "creates a file bar" do
- expect(rendered_template).to match("cat > /etc/chef/client.d/bar <<'EOP'")
- expect(rendered_template).to match("1 / 0")
- end
+ it "creates a file 00-foo.rb" do
+ expect(rendered_template).to match("cat > /etc/chef/client.d/00-foo.rb <<'EOP'")
+ expect(rendered_template).to match("d6f9b976-289c-4149-baf7-81e6ffecf228")
end
+ it "creates a file bar" do
+ expect(rendered_template).to match("cat > /etc/chef/client.d/bar <<'EOP'")
+ expect(rendered_template).to match("1 / 0")
+ end
+ end
- context "a nested directory structure" do
- let(:client_d_dir) do
- Chef::Util::PathHelper.cleanpath(
- File.join(File.dirname(__FILE__), "../../data/client.d_01")) end
- it "creates a file foo/bar.rb" do
- expect(rendered_template).to match("cat > /etc/chef/client.d/foo/bar.rb <<'EOP'")
- expect(rendered_template).to match("1 / 0")
- end
+ context "a nested directory structure" do
+ let(:client_d_dir) do
+ Chef::Util::PathHelper.cleanpath(
+ File.join(File.dirname(__FILE__), "../../data/client.d_01")) end
+ it "creates a file foo/bar.rb" do
+ expect(rendered_template).to match("cat > /etc/chef/client.d/foo/bar.rb <<'EOP'")
+ expect(rendered_template).to match("1 / 0")
end
+ end
end
end
-
-
describe "#connection_protocol" do
let(:host_descriptor) { "example.com" }
- let(:config) { { } }
+ let(:config) { {} }
let(:knife_connection_protocol) { nil }
before do
allow(knife).to receive(:config).and_return config
@@ -574,9 +572,8 @@ describe Chef::Knife::Bootstrap do
expect(knife.connection_protocol).to eq "winrm"
end
-
end
- context "when protocol is provided via the host argument and the CLI flag" do
+ context "when protocol is provided via the host argument and the CLI flag" do
let(:host_descriptor) { "ssh://example.com" }
let(:config) { { connection_protocol: "winrm" } }
@@ -604,7 +601,7 @@ describe Chef::Knife::Bootstrap do
describe "#validate_protocol!" do
let(:host_descriptor) { "example.com" }
- let(:config) { { } }
+ let(:config) { {} }
let(:connection_protocol) { "ssh" }
before do
allow(knife).to receive(:config).and_return config
@@ -619,7 +616,7 @@ describe Chef::Knife::Bootstrap do
let(:config) { { connection_protocol: "winrm" } }
it "outputs an error and exits" do
expect(knife.ui).to receive(:error)
- expect{ knife.validate_protocol! }.to raise_error SystemExit
+ expect { knife.validate_protocol! }.to raise_error SystemExit
end
end
@@ -646,7 +643,7 @@ describe Chef::Knife::Bootstrap do
let(:connection_protocol) { "invalid" }
it "outputs an error and exits" do
expect(knife.ui).to receive(:error).with(/Unsupported protocol '#{connection_protocol}'/)
- expect{ knife.validate_protocol! }.to raise_error SystemExit
+ expect { knife.validate_protocol! }.to raise_error SystemExit
end
end
end
@@ -731,15 +728,13 @@ describe Chef::Knife::Bootstrap do
end
end
-
-
context "#connection_opts" do
let(:connection_protocol) { "ssh" }
before do
allow(knife).to receive(:connection_protocol).and_return connection_protocol
end
context "behavioral test: " do
- let(:expected_connection_opts) {
+ let(:expected_connection_opts) do
{ base_opts: true,
ssh_identity_opts: true,
ssh_opts: true,
@@ -747,7 +742,7 @@ describe Chef::Knife::Bootstrap do
host_verify_opts: true,
sudo_opts: true,
winrm_opts: true }
- }
+ end
it "queries and merges only expected configurations" do
expect(knife).to receive(:base_opts).and_return({ base_opts: true })
@@ -798,7 +793,7 @@ describe Chef::Knife::Bootstrap do
before do
knife.config = {}
end
- let(:expected_result) {
+ let(:expected_result) do
{
logger: Chef::Log, # not configurable
ca_trust_file: "trust.me",
@@ -812,9 +807,9 @@ describe Chef::Knife::Bootstrap do
self_signed: true,
ssl: true,
kerberos_realm: "realm",
- kerberos_service: "service"
+ kerberos_service: "service",
}
- }
+ end
it "generates a config hash using the Chef::Config values" do
expect(knife.connection_opts).to match expected_result
@@ -823,7 +818,7 @@ describe Chef::Knife::Bootstrap do
end
context "and some CLI options have been given" do
- let(:expected_result) {
+ let(:expected_result) do
{
logger: Chef::Log, # not configurable
ca_trust_file: "no trust",
@@ -838,9 +833,9 @@ describe Chef::Knife::Bootstrap do
ssl: true,
kerberos_realm: "realm",
kerberos_service: "service",
- password: "lobster"
+ password: "lobster",
}
- }
+ end
before do
knife.config[:ca_trust_file] = "no trust"
@@ -878,7 +873,7 @@ describe Chef::Knife::Bootstrap do
knife.config[:winrm_ssl] = false
knife.config[:winrm_ssl_peer_fingerprint] = "FEDCBA"
end
- let(:expected_result) {
+ let(:expected_result) do
{
logger: Chef::Log, # not configurable
ca_trust_file: "trust.the.internet",
@@ -893,9 +888,9 @@ describe Chef::Knife::Bootstrap do
ssl: false,
kerberos_realm: "otherrealm",
kerberos_service: "otherservice",
- password: "blue"
+ password: "blue",
}
- }
+ end
it "generates a config hash using the CLI options and pulling nothing from Chef::Config" do
expect(knife.connection_opts).to match expected_result
end
@@ -906,7 +901,7 @@ describe Chef::Knife::Bootstrap do
before do
knife.config = {}
end
- let(:expected_result) {
+ let(:expected_result) do
{
logger: Chef::Log,
operation_timeout: 60,
@@ -914,14 +909,14 @@ describe Chef::Knife::Bootstrap do
ssl: false,
ssl_peer_fingerprint: nil,
winrm_basic_auth_only: false,
- winrm_transport: "negotiate"
+ winrm_transport: "negotiate",
}
- }
+ end
it "populates appropriate defaults" do
expect(knife.connection_opts).to match expected_result
end
end
- end # winrm
+ end # winrm
context "when protocol is ssh" do
let(:connection_protocol) { "ssh" }
@@ -945,7 +940,7 @@ describe Chef::Knife::Bootstrap do
before do
knife.config = {}
end
- let(:expected_result) {
+ let(:expected_result) do
{
logger: Chef::Log, # not configurable
max_wait_until_ready: 9999,
@@ -955,12 +950,12 @@ describe Chef::Knife::Bootstrap do
bastion_user: "admin",
forward_agent: false,
keys_only: true,
- key_files: ['/identity.pem', '/gateway.pem'],
+ key_files: ["/identity.pem", "/gateway.pem"],
sudo: false,
verify_host_key: false,
- port: 9999
+ port: 9999,
}
- }
+ end
it "generates a correct config hash using the Chef::Config values" do
expect(knife.connection_opts).to match expected_result
@@ -995,24 +990,23 @@ describe Chef::Knife::Bootstrap do
knife.config[:ssh_forward_agent] = true
end
- let(:expected_result) {
+ let(:expected_result) do
{
logger: Chef::Log, # not configurable
- max_wait_until_ready: 150, #cli
+ max_wait_until_ready: 150, # cli
user: "sshalice", # cli
password: "feta cheese", # cli
bastion_host: "mygateway.local", # Config
bastion_port: 1234, # Config
bastion_user: "admin", # Config
- forward_agent: true, # cli
+ forward_agent: true, # cli
keys_only: false, # implied false from config password present
- key_files: ['/identity.pem', '/gateway.pem'], # Config
+ key_files: ["/identity.pem", "/gateway.pem"], # Config
sudo: true, # ccli
verify_host_key: false, # Config
- port: 12 # cli
+ port: 12, # cli
}
- }
-
+ end
it "generates a config hash using the CLI options when available and falling back to Chef::Config values" do
expect(knife.connection_opts).to match expected_result
@@ -1042,7 +1036,7 @@ describe Chef::Knife::Bootstrap do
knife.config[:ssh_user] = "do not use"
knife.config[:ssh_port] = 1001
end
- let(:expected_result) {
+ let(:expected_result) do
{
logger: Chef::Log, # not configurable
max_wait_until_ready: 150,
@@ -1054,13 +1048,13 @@ describe Chef::Knife::Bootstrap do
bastion_user: "me",
forward_agent: true,
keys_only: false,
- key_files: ['/my-identity.pem', '/gateway-identity.pem'],
+ key_files: ["/my-identity.pem", "/gateway-identity.pem"],
sudo: true,
sudo_options: "-H",
sudo_password: "blah",
verify_host_key: true,
}
- }
+ end
it "generates a config hash using the CLI options and pulling nothing from Chef::Config" do
expect(knife.connection_opts).to match expected_result
end
@@ -1070,25 +1064,25 @@ describe Chef::Knife::Bootstrap do
before do
knife.config = {}
end
- let(:expected_result) {
+ let(:expected_result) do
{
forward_agent: false,
key_files: [],
logger: Chef::Log,
keys_only: false,
sudo: false,
- verify_host_key: true
+ verify_host_key: true,
}
- }
+ end
it "populates appropriate defaults" do
expect(knife.connection_opts).to match expected_result
end
end
- end #ssh
- end #functional tests
+ end # ssh
+ end # functional tests
- end #connection_opts
+ end # connection_opts
context "#base_opts" do
let(:connection_protocol) { nil }
@@ -1116,14 +1110,14 @@ describe Chef::Knife::Bootstrap do
knife.config[:password] = "opscode"
end
- let(:expected_opts) {
+ let(:expected_opts) do
{
port: 250,
user: "test",
logger: Chef::Log,
- password: "opscode"
+ password: "opscode",
}
- }
+ end
it "generates the correct options" do
expect(knife.base_opts).to eq expected_opts
end
@@ -1136,13 +1130,13 @@ describe Chef::Knife::Bootstrap do
knife.config[:connection_user] = "test"
end
- let(:expected_opts) {
+ let(:expected_opts) do
{
port: 250,
user: "test",
- logger: Chef::Log
+ logger: Chef::Log,
}
- }
+ end
it "generates the correct options" do
expect(knife.base_opts).to eq expected_opts
end
@@ -1202,7 +1196,7 @@ describe Chef::Knife::Bootstrap do
it "generates the expected configuration" do
expect(knife.ssh_identity_opts).to eq({
key_files: [ "/identity.pem" ],
- keys_only: true
+ keys_only: true,
})
end
context "and a password is also specified" do
@@ -1212,7 +1206,7 @@ describe Chef::Knife::Bootstrap do
it "generates the expected configuration (key, keys_only false)" do
expect(knife.ssh_identity_opts).to eq({
key_files: [ "/identity.pem" ],
- keys_only: false
+ keys_only: false,
})
end
end
@@ -1222,7 +1216,7 @@ describe Chef::Knife::Bootstrap do
it "does not include the gateway identity file in keys" do
expect(knife.ssh_identity_opts).to eq({
key_files: ["/identity.pem"],
- keys_only: true
+ keys_only: true,
})
end
@@ -1238,7 +1232,7 @@ describe Chef::Knife::Bootstrap do
it "config includes only identity file and not gateway identity" do
expect(knife.ssh_identity_opts).to eq({
key_files: [ "/identity.pem" ],
- keys_only: true
+ keys_only: true,
})
end
end
@@ -1251,7 +1245,7 @@ describe Chef::Knife::Bootstrap do
it "generates the expected configuration (both keys, keys_only true)" do
expect(knife.ssh_identity_opts).to eq({
key_files: [ "/identity.pem", "/gateway.pem" ],
- keys_only: true
+ keys_only: true,
})
end
end
@@ -1262,7 +1256,7 @@ describe Chef::Knife::Bootstrap do
it "generates the expected configuration (no keys, keys_only false)" do
expect(knife.ssh_identity_opts).to eq( {
key_files: [ ],
- keys_only: false
+ keys_only: false,
})
end
context "and a gateway with gateway identity file is specified" do
@@ -1274,7 +1268,7 @@ describe Chef::Knife::Bootstrap do
it "generates the expected configuration (gateway key, keys_only false)" do
expect(knife.ssh_identity_opts).to eq({
key_files: [ "/gateway.pem" ],
- keys_only: false
+ keys_only: false,
})
end
end
@@ -1305,7 +1299,7 @@ describe Chef::Knife::Bootstrap do
expect(knife.gateway_opts).to eq({
bastion_user: "testuser",
bastion_host: "gateway",
- bastion_port: 9021
+ bastion_port: 9021,
})
end
end
@@ -1317,7 +1311,7 @@ describe Chef::Knife::Bootstrap do
expect(knife.gateway_opts).to eq({
bastion_user: nil,
bastion_host: "gateway",
- bastion_port: nil
+ bastion_port: nil,
})
end
end
@@ -1329,7 +1323,7 @@ describe Chef::Knife::Bootstrap do
expect(knife.gateway_opts).to eq({
bastion_user: "testuser",
bastion_host: "gateway",
- bastion_port: nil
+ bastion_port: nil,
})
end
end
@@ -1342,7 +1336,7 @@ describe Chef::Knife::Bootstrap do
expect(knife.gateway_opts).to eq({
bastion_user: nil,
bastion_host: "gateway",
- bastion_port: 11234
+ bastion_port: 11234,
})
end
end
@@ -1376,7 +1370,7 @@ describe Chef::Knife::Bootstrap do
end
it "returns a config that enables sudo" do
- expect(knife.sudo_opts).to eq( { sudo: true} )
+ expect(knife.sudo_opts).to eq( { sudo: true } )
end
context "when use_sudo_password is also set" do
@@ -1387,7 +1381,7 @@ describe Chef::Knife::Bootstrap do
it "includes :password value in a sudo-enabled configuration" do
expect(knife.sudo_opts).to eq({
sudo: true,
- sudo_password: "opscode"
+ sudo_password: "opscode",
})
end
end
@@ -1399,7 +1393,7 @@ describe Chef::Knife::Bootstrap do
it "enables sudo with sudo_option to preserve home" do
expect(knife.sudo_opts).to eq({
sudo_options: "-H",
- sudo: true
+ sudo: true,
})
end
end
@@ -1411,7 +1405,7 @@ describe Chef::Knife::Bootstrap do
knife.config[:preserve_home] = true
end
it "returns configuration for sudo off, ignoring other related options" do
- expect(knife.sudo_opts).to eq( { sudo: false} )
+ expect(knife.sudo_opts).to eq( { sudo: false } )
end
end
end
@@ -1457,22 +1451,23 @@ describe Chef::Knife::Bootstrap do
context "for winrm" do
let(:connection_protocol) { "winrm" }
- let(:expected) { {
+ let(:expected) do
+ {
winrm_transport: "negotiate",
winrm_basic_auth_only: false,
ssl: false,
ssl_peer_fingerprint: nil,
operation_timeout: 60,
- }}
+ } end
it "generates a correct configuration hash with expected defaults" do
expect(knife.winrm_opts).to eq expected
end
context "with ssl_peer_fingerprint" do
- let(:ssl_peer_fingerprint_expected) {
- expected.merge({ ssl_peer_fingerprint: "ABCD"})
- }
+ let(:ssl_peer_fingerprint_expected) do
+ expected.merge({ ssl_peer_fingerprint: "ABCD" })
+ end
before do
knife.config[:winrm_ssl_peer_fingerprint] = "ABCD"
@@ -1484,9 +1479,9 @@ describe Chef::Knife::Bootstrap do
end
context "with winrm_ssl" do
- let(:ssl_expected) {
+ let(:ssl_expected) do
expected.merge({ ssl: true })
- }
+ end
before do
knife.config[:winrm_ssl] = true
end
@@ -1497,9 +1492,9 @@ describe Chef::Knife::Bootstrap do
end
context "with winrm_auth_method" do
- let(:winrm_auth_method_expected) {
+ let(:winrm_auth_method_expected) do
expected.merge({ winrm_transport: "freeaccess" })
- }
+ end
before do
knife.config[:winrm_auth_method] = "freeaccess"
@@ -1511,9 +1506,9 @@ describe Chef::Knife::Bootstrap do
end
context "with ca_trust_file" do
- let(:ca_trust_expected) {
- expected.merge({ ca_trust_file: "/trust.me"})
- }
+ let(:ca_trust_expected) do
+ expected.merge({ ca_trust_file: "/trust.me" })
+ end
before do
knife.config[:ca_trust_file] = "/trust.me"
end
@@ -1524,13 +1519,13 @@ describe Chef::Knife::Bootstrap do
end
context "with kerberos auth" do
- let(:kerberos_expected) {
+ let(:kerberos_expected) do
expected.merge({
kerberos_service: "testsvc",
kerberos_realm: "TESTREALM",
- winrm_transport: "kerberos"
+ winrm_transport: "kerberos",
})
- }
+ end
before do
knife.config[:winrm_auth_method] = "kerberos"
@@ -1547,9 +1542,9 @@ describe Chef::Knife::Bootstrap do
before do
knife.config[:winrm_basic_auth_only] = true
end
- let(:basic_auth_expected) {
+ let(:basic_auth_expected) do
expected.merge( { winrm_basic_auth_only: true } )
- }
+ end
it "generates a correct options hash containing winrm_basic_auth_only from the config provided" do
expect(knife.winrm_opts).to eq basic_auth_expected
end
@@ -1568,7 +1563,7 @@ describe Chef::Knife::Bootstrap do
allow(knife.client_builder).to receive(:client_path).and_return("/key.pem")
end
- it "performs the steps we expect to run a bootstrap" do
+ it "performs the steps we expect to run a bootstrap" do
expect(knife).to receive(:validate_name_args!).ordered
expect(knife).to receive(:validate_protocol!).ordered
expect(knife).to receive(:validate_first_boot_attributes!).ordered
@@ -1618,7 +1613,7 @@ describe Chef::Knife::Bootstrap do
let(:node_name) { nil }
it "shows an error and exits" do
expect(knife.ui).to receive(:error)
- expect{knife.register_client}.to raise_error(SystemExit)
+ expect { knife.register_client }.to raise_error(SystemExit)
end
end
end
@@ -1662,14 +1657,14 @@ describe Chef::Knife::Bootstrap do
end
it "runs the remote script and logs the output" do
expect(knife.ui).to receive(:info).with(/Bootstrapping.*/)
- expect(knife).to receive(:bootstrap_command).
- with("/path.sh").
- and_return("sh /path.sh")
- expect(target_host).
- to receive(:run_command).
- with("sh /path.sh").
- and_yield("output here").
- and_return result_mock
+ expect(knife).to receive(:bootstrap_command)
+ .with("/path.sh")
+ .and_return("sh /path.sh")
+ expect(target_host)
+ .to receive(:run_command)
+ .with("sh /path.sh")
+ .and_yield("output here")
+ .and_return result_mock
expect(knife.ui).to receive(:msg).with(/testhost/)
knife.perform_bootstrap("/path.sh")
@@ -1678,16 +1673,15 @@ describe Chef::Knife::Bootstrap do
let(:exit_status) { 1 }
it "shows an error and exits" do
expect(knife.ui).to receive(:info).with(/Bootstrapping.*/)
- expect(knife).to receive(:bootstrap_command).
- with("/path.sh").
- and_return("sh /path.sh")
+ expect(knife).to receive(:bootstrap_command)
+ .with("/path.sh")
+ .and_return("sh /path.sh")
expect(target_host).to receive(:run_command).with("sh /path.sh").and_return result_mock
- expect{knife.perform_bootstrap("/path.sh")}.to raise_error(SystemExit)
+ expect { knife.perform_bootstrap("/path.sh") }.to raise_error(SystemExit)
end
end
end
-
describe "#connect!" do
context "in the normal case" do
it "connects using the connection_opts and notifies the operator of progress" do
@@ -1704,12 +1698,12 @@ describe Chef::Knife::Bootstrap do
allow(knife).to receive(:do_connect).and_raise(expected_error)
end
it "re-raises the exception" do
- expect{knife.connect!}.to raise_error(expected_error)
+ expect { knife.connect! }.to raise_error(expected_error)
end
end
context "when an auth failure occurs" do
- let(:expected_error) {
+ let(:expected_error) do
# TODO This is awkward and ugly. Requires some refactor of chef_core/error
# to make it not so. See comment in rescue block of connect! for details.
e = RuntimeError.new
@@ -1718,10 +1712,10 @@ describe Chef::Knife::Bootstrap do
allow(interim).to receive(:cause).and_return(actual)
allow(e).to receive(:cause).and_return(interim)
e
- }
+ end
before do
- require 'net/ssh'
+ require "net/ssh"
end
context "and password auth was used" do
@@ -1731,7 +1725,7 @@ describe Chef::Knife::Bootstrap do
it "re-raises the error so as not to resubmit the same failing password" do
expect(knife).to receive(:do_connect).and_raise(expected_error)
- expect{knife.connect!}.to raise_error(expected_error)
+ expect { knife.connect! }.to raise_error(expected_error)
end
end
@@ -1757,8 +1751,6 @@ describe Chef::Knife::Bootstrap do
end
end
-
-
it "verifies that a server to bootstrap was given as a command line arg" do
knife.name_args = nil
expect { knife.run }.to raise_error(SystemExit)
@@ -1769,7 +1761,7 @@ describe Chef::Knife::Bootstrap do
context "under Windows" do
let(:base_os) { :windows }
it "creates a WindowsBootstrapContext" do
- require 'chef/knife/core/windows_bootstrap_context'
+ require "chef/knife/core/windows_bootstrap_context"
expect(knife.bootstrap_context.class).to eq Chef::Knife::Core::WindowsBootstrapContext
end
end
@@ -1777,13 +1769,12 @@ describe Chef::Knife::Bootstrap do
context "under linux" do
let(:base_os) { :linux }
it "creates a BootstrapContext" do
- require 'chef/knife/core/bootstrap_context'
+ require "chef/knife/core/bootstrap_context"
expect(knife.bootstrap_context.class).to eq Chef::Knife::Core::BootstrapContext
end
end
end
-
describe "#config_value" do
before do
knife.config[:test_key_a] = "a from cli"
@@ -1856,7 +1847,6 @@ describe Chef::Knife::Bootstrap do
end
end
-
describe "#default_bootstrap_template" do
context "under Windows" do
let(:base_os) { :windows }
@@ -1924,7 +1914,7 @@ describe Chef::Knife::Bootstrap do
end
it "will error because we will generate and send a client key over the wire in plaintext" do
- expect{knife.validate_winrm_transport_opts!}.to raise_error(SystemExit)
+ expect { knife.validate_winrm_transport_opts! }.to raise_error(SystemExit)
end
end
@@ -2023,5 +2013,3 @@ describe Chef::Knife::Bootstrap do
end
end
end
-
-