knife 17.3.48 → 17.4.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31ea76674fe3c36ffd7530564334f6984f1b95cff36f966eb4aa31a51b8fc4cc
4
- data.tar.gz: 88a1f4d1335f549e881c9142171f0ee831bb8a6848de85808d136da9d083cc53
3
+ metadata.gz: 70c4e18afa9b4762387d8a0a6c9c75bca9e1e42723a041147bea36c2efaae176
4
+ data.tar.gz: '00953cd3c86ab1e11eb9ddb9a8fdf8fffbae40705671090169411877fa72a069'
5
5
  SHA512:
6
- metadata.gz: 18745c29c6a2c249d6ed67eef2d961f3175e4f2f124ba368caed230f2df4c037e58ba14666ca1bae726addc10fd14ae5658be654cc2cb506afc9e4cafe5afb9b
7
- data.tar.gz: 63e4f77b325ba95b279d698885a8b92814938ab2c196b5da79ed36a570dc4f0a8ac26c8c56291686f02530cd8e51fb82f2d58f3cd4da13649c7afe271421728a
6
+ metadata.gz: f2d2130d599b56a3d43bbbbe5f64407dfc19aaec9df4ea87af2b835b950dda18ef1b9eb6cee28fae9ee05bafef8b6fe180219b36f1f7fbe5333b4efcd3236002
7
+ data.tar.gz: 0d500fcfd9e9aa0830d04bae3f9d4e3712ab52bf6fcd9b87c4f0e3bbb2149f8568d179c41656189b7614bdbdd91e8dbd5d14800c38771275466c5e3c9e0c78f0
@@ -20,6 +20,7 @@ require_relative "../knife"
20
20
  require_relative "data_bag_secret_options"
21
21
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
22
22
  require "license_acceptance/cli_flags/mixlib_cli"
23
+
23
24
  module LicenseAcceptance
24
25
  autoload :Acceptor, "license_acceptance/acceptor"
25
26
  end
@@ -705,6 +706,8 @@ class Chef
705
706
  ui.warn("#{e.message} - trying with pty request")
706
707
  conn_options[:pty] = true # ensure we can talk to systems with requiretty set true in sshd config
707
708
  retry
709
+ elsif e.reason == :sudo_missing_terminal
710
+ ui.error "Sudo password is required for this operation. Please enter password using -P or --ssh-password option"
708
711
  elsif config[:use_sudo_password] && (e.reason == :sudo_password_required || e.reason == :bad_sudo_password) && limit < 3
709
712
  ui.warn("Failed to authenticate #{conn_options[:user]} to #{server_name} - #{e.message} \n sudo: #{limit} incorrect password attempt")
710
713
  sudo_password = ui.ask("Enter sudo password for #{conn_options[:user]}@#{server_name}:", echo: false)
@@ -240,7 +240,7 @@ class Chef
240
240
 
241
241
  # Now that everything is populated, fill in anything missing
242
242
  # that may be found in user ssh config
243
- opts.merge!(missing_opts_from_ssh_config(opts, opts_in))
243
+ opts.merge!(missing_opts_from_ssh_config(opts))
244
244
 
245
245
  Train.target_config(opts)
246
246
  end
@@ -297,12 +297,12 @@ class Chef
297
297
  # in the configuration passed in.
298
298
  # This is necessary because train will default these values
299
299
  # itself - causing SSH config data to be ignored
300
- def missing_opts_from_ssh_config(config, opts_in)
300
+ def missing_opts_from_ssh_config(config)
301
301
  return {} unless config[:backend] == "ssh"
302
302
 
303
303
  host_cfg = ssh_config_for_host(config[:host])
304
304
  opts_out = {}
305
- opts_in.each do |key, _value|
305
+ host_cfg.each do |key, _value|
306
306
  if SSH_CONFIG_OVERRIDE_KEYS.include?(key) && !config.key?(key)
307
307
  opts_out[key] = host_cfg[key]
308
308
  end
@@ -81,6 +81,14 @@ class Chef
81
81
  client.public_key File.read(File.expand_path(config[:public_key]))
82
82
  end
83
83
 
84
+ # Check the file before creating the client so the api is more transactional.
85
+ if config[:file]
86
+ file = config[:file]
87
+ dir_name = File.dirname(file)
88
+ check_writable_or_exists(dir_name, "Directory")
89
+ check_writable_or_exists(file, "File")
90
+ end
91
+
84
92
  output = edit_hash(client)
85
93
  final_client = create_client(output)
86
94
  ui.info("Created #{final_client}")
@@ -96,6 +104,19 @@ class Chef
96
104
  end
97
105
  end
98
106
  end
107
+
108
+ # To check if file or directory exists or writable and raise exception accordingly
109
+ def check_writable_or_exists(file, type)
110
+ if File.exist?(file)
111
+ unless File.writable?(file)
112
+ ui.fatal "#{type} #{file} is not writable. Check permissions."
113
+ exit 1
114
+ end
115
+ else
116
+ ui.fatal "#{type} #{file} does not exist."
117
+ exit 1
118
+ end
119
+ end
99
120
  end
100
121
  end
101
122
  end
@@ -86,8 +86,8 @@ class Chef
86
86
  client_rb << "# Using default node name (fqdn)\n"
87
87
  end
88
88
 
89
- if config[:config_log_level]
90
- client_rb << %Q{log_level :#{config[:config_log_level]}\n}
89
+ if chef_config[:config_log_level]
90
+ client_rb << %Q{log_level :#{chef_config[:config_log_level]}\n}
91
91
  else
92
92
  client_rb << "log_level :auto\n"
93
93
  end
@@ -17,7 +17,7 @@
17
17
  class Chef
18
18
  class Knife
19
19
  KNIFE_ROOT = File.expand_path("../..", __dir__)
20
- VERSION = "17.3.48".freeze
20
+ VERSION = "17.4.18".freeze
21
21
  end
22
22
  end
23
23
 
File without changes
@@ -50,6 +50,7 @@ describe "knife client create", :workstation do
50
50
 
51
51
  it "saves the private key to a file" do
52
52
  Dir.mktmpdir do |tgt|
53
+ File.open("#{tgt}/bah.pem", "w") { |pub| pub.write("test key") }
53
54
  knife("client create -f #{tgt}/bah.pem bah").should_succeed stderr: out
54
55
  expect(File).to exist("#{tgt}/bah.pem")
55
56
  end
@@ -1307,7 +1307,7 @@ describe Chef::Knife::Bootstrap do
1307
1307
  context "when no identity file is specified" do
1308
1308
  it "generates the expected configuration (no keys, keys_only false)" do
1309
1309
  expect(knife.ssh_identity_opts).to eq( {
1310
- key_files: [ ],
1310
+ key_files: [],
1311
1311
  keys_only: false,
1312
1312
  })
1313
1313
  end
@@ -2050,6 +2050,19 @@ describe Chef::Knife::Bootstrap do
2050
2050
  expect { knife.do_connect({}) }.to raise_error(expected_error)
2051
2051
  end
2052
2052
  end
2053
+
2054
+ context "when a train sudo error is thrown for missing terminal" do
2055
+ let(:ui_error_msg) { "Sudo password is required for this operation. Please enter password using -P or --ssh-password option" }
2056
+ let(:expected_error) { Train::UserError.new(ui_error_msg, :sudo_missing_terminal) }
2057
+ before do
2058
+ allow(connection).to receive(:connect!).and_raise(expected_error)
2059
+ end
2060
+ it "outputs user friendly error message" do
2061
+ expect { knife.do_connect({}) }.not_to raise_error
2062
+ expect(stderr.string).to include(ui_error_msg)
2063
+ end
2064
+ end
2065
+
2053
2066
  end
2054
2067
 
2055
2068
  describe "validate_winrm_transport_opts!" do
@@ -122,10 +122,12 @@ describe Chef::Knife::ClientCreate do
122
122
  end
123
123
 
124
124
  it "should write the private key to a file" do
125
- knife.config[:file] = "/tmp/monkeypants"
125
+ file = Tempfile.new
126
+ file_path = file.path
127
+ knife.config[:file] = file_path
126
128
  filehandle = double("Filehandle")
127
129
  expect(filehandle).to receive(:print).with("woot")
128
- expect(File).to receive(:open).with("/tmp/monkeypants", "w").and_yield(filehandle)
130
+ expect(File).to receive(:open).with(file_path, "w").and_yield(filehandle)
129
131
  knife.run
130
132
  end
131
133
  end
@@ -164,6 +166,39 @@ describe Chef::Knife::ClientCreate do
164
166
  expect(client.validator).to be_truthy
165
167
  end
166
168
  end
169
+
170
+ describe "with -f or --file when dir or file is not writable or does not exists" do
171
+ let(:dir_path) { File.expand_path(File.join(CHEF_SPEC_DATA, "knife", "temp_dir")) }
172
+ let(:file_path) { File.expand_path(File.join(dir_path, "tmp.pem")) }
173
+
174
+ it "when the directory does not exists" do
175
+ knife.config[:file] = "example/client1.pem"
176
+ expect(knife.ui).to receive(:fatal).with("Directory example does not exist.")
177
+ expect { knife.run }.to raise_error(SystemExit)
178
+ end
179
+
180
+ it "when the directory not writable" do
181
+ knife.config[:file] = file_path
182
+ File.chmod(777, dir_path)
183
+ expect(knife.ui).to receive(:fatal).with("Directory #{dir_path} is not writable. Check permissions.")
184
+ expect { knife.run }.to raise_error(SystemExit)
185
+ end
186
+
187
+ it "when the file does not exists" do
188
+ path = "#{dir_path}/client1.pem"
189
+ knife.config[:file] = path
190
+ File.chmod(0755, dir_path)
191
+ expect(knife.ui).to receive(:fatal).with("File #{path} does not exist.")
192
+ expect { knife.run }.to raise_error(SystemExit)
193
+ end
194
+
195
+ it "when the file is not writable" do
196
+ knife.config[:file] = file_path
197
+ File.chmod(777, file_path)
198
+ expect(knife.ui).to receive(:fatal).with("File #{file_path} is not writable. Check permissions.")
199
+ expect { knife.run }.to raise_error(SystemExit)
200
+ end
201
+ end
167
202
  end
168
203
  end
169
204
  end
@@ -169,7 +169,7 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
169
169
  echo.file_backup_path "c:/chef/backup"
170
170
  echo.cache_options ^({:path =^> "C:\\\\chef\\\\cache\\\\checksums", :skip_expires =^> true}^)
171
171
  echo.# Using default node name ^(fqdn^)
172
- echo.log_level :auto
172
+ echo.log_level :info
173
173
  echo.log_location STDOUT
174
174
  EXPECTED
175
175
  expect(bootstrap_context.config_content).to eq expected
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife
3
3
  version: !ruby/object:Gem::Version
4
- version: 17.3.48
4
+ version: 17.4.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-21 00:00:00.000000000 Z
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -751,6 +751,7 @@ files:
751
751
  - spec/data/kitchen/openldap/recipes/woot.rb
752
752
  - spec/data/knife-home/.chef/plugins/knife/example_home_subcommand.rb
753
753
  - spec/data/knife-site-subcommands/plugins/knife/example_subcommand.rb
754
+ - spec/data/knife/temp_dir/tmp.pem
754
755
  - spec/data/knife_subcommand/test_explicit_category.rb
755
756
  - spec/data/knife_subcommand/test_name_mapping.rb
756
757
  - spec/data/knife_subcommand/test_yourself.rb