diff options
author | sanga17 <sausekar@msystechnologies.com> | 2021-07-02 19:50:00 +0530 |
---|---|---|
committer | sanga17 <sausekar@msystechnologies.com> | 2021-07-02 19:50:00 +0530 |
commit | c654e7691cb8fd2878050b94f20ae7a27003e69c (patch) | |
tree | e28f7c4b3f0afa2828095277fd5a1c38e7bbff8a | |
parent | 658d85bee57829a2957eccdc919db397e867c5d2 (diff) | |
download | chef-c654e7691cb8fd2878050b94f20ae7a27003e69c.tar.gz |
Reverted some changes as per review comments and updated method as opts_in missing user and port variables
Signed-off-by: sanga17 <sausekar@msystechnologies.com>
-rw-r--r-- | knife/lib/chef/knife/bootstrap.rb | 8 | ||||
-rw-r--r-- | knife/lib/chef/knife/bootstrap/train_connector.rb | 13 | ||||
-rw-r--r-- | knife/spec/unit/knife/bootstrap_spec.rb | 6 |
3 files changed, 10 insertions, 17 deletions
diff --git a/knife/lib/chef/knife/bootstrap.rb b/knife/lib/chef/knife/bootstrap.rb index 756b73ec43..d57614cb3d 100644 --- a/knife/lib/chef/knife/bootstrap.rb +++ b/knife/lib/chef/knife/bootstrap.rb @@ -974,17 +974,13 @@ class Chef # Reference: https://github.com/chef/chef/blob/master/lib/chef/knife/ssh.rb#L272 opts[:keys_only] = config.key?(:connection_password) == false else - opts[:key_files] = nil + opts[:key_files] = [] opts[:keys_only] = false end gateway_identity_file = config[:ssh_gateway] ? config[:ssh_gateway_identity] : nil unless gateway_identity_file.nil? - if opts[:key_files].nil? - opts[:key_files] = [gateway_identity_file] - else - opts[:key_files] << gateway_identity_file - end + opts[:key_files] << gateway_identity_file end opts diff --git a/knife/lib/chef/knife/bootstrap/train_connector.rb b/knife/lib/chef/knife/bootstrap/train_connector.rb index d369cf3dcc..1faae2eeff 100644 --- a/knife/lib/chef/knife/bootstrap/train_connector.rb +++ b/knife/lib/chef/knife/bootstrap/train_connector.rb @@ -127,11 +127,8 @@ class Chef # running with sudo right now - so this directory would be owned by root. # File upload is performed over SCP as the current logged-in user, # so we'll set ownership to ensure that works. - if config[:sudo] - # While using ssh config file user might present in ssh file - user = config[:user] || ssh_config_for_host(config[:host])[:user] - run_command!("chown #{user} '#{dir}'") - end + run_command!("chown #{config[:user]} '#{dir}'") if config[:sudo] + dir end end @@ -243,7 +240,7 @@ class Chef # Now that everything is populated, fill in anything missing # that may be found in user ssh config - opts.merge!(missing_opts_from_ssh_config(opts, opts_in)) + opts.merge!(missing_opts_from_ssh_config(opts)) Train.target_config(opts) end @@ -300,12 +297,12 @@ class Chef # in the configuration passed in. # This is necessary because train will default these values # itself - causing SSH config data to be ignored - def missing_opts_from_ssh_config(config, opts_in) + def missing_opts_from_ssh_config(config) return {} unless config[:backend] == "ssh" host_cfg = ssh_config_for_host(config[:host]) opts_out = {} - opts_in.each do |key, _value| + host_cfg.each do |key, _value| if SSH_CONFIG_OVERRIDE_KEYS.include?(key) && !config.key?(key) opts_out[key] = host_cfg[key] end diff --git a/knife/spec/unit/knife/bootstrap_spec.rb b/knife/spec/unit/knife/bootstrap_spec.rb index 0ccbf8b01e..2db2a959e4 100644 --- a/knife/spec/unit/knife/bootstrap_spec.rb +++ b/knife/spec/unit/knife/bootstrap_spec.rb @@ -1,4 +1,4 @@ -# + # # Author:: Ian Meyer (<ianmmeyer@gmail.com>) # Copyright:: Copyright 2010-2016, Ian Meyer # Copyright:: Copyright (c) Chef Software Inc. @@ -1127,7 +1127,7 @@ describe Chef::Knife::Bootstrap do let(:expected_result) do { forward_agent: false, - key_files: nil, + key_files: [], logger: Chef::Log, keys_only: false, sudo: false, @@ -1307,7 +1307,7 @@ describe Chef::Knife::Bootstrap do context "when no identity file is specified" do it "generates the expected configuration (no keys, keys_only false)" do expect(knife.ssh_identity_opts).to eq( { - key_files: nil, + key_files: [], keys_only: false, }) end |