knife 17.2.15 → 17.3.48

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: c302c36fa857871e5f6a8a27f6d138ad86bfeb5ffee1887bd10d7197b7981a73
4
- data.tar.gz: c2d3065ce5c79cd01c6095db943faffd6ec1bf877e4ba4abd5734e626d95daf8
3
+ metadata.gz: 31ea76674fe3c36ffd7530564334f6984f1b95cff36f966eb4aa31a51b8fc4cc
4
+ data.tar.gz: 88a1f4d1335f549e881c9142171f0ee831bb8a6848de85808d136da9d083cc53
5
5
  SHA512:
6
- metadata.gz: 96690db49cec67bcad891d57a204f324564ea779d09ef503c251985e4903fe0bd3e7756caaadec14d908fb50363f09b649be1481422ef989f998b3ab992c41c7
7
- data.tar.gz: c75c3f9a98308ffcc6b8cd99551c1a7d0bc88d73d9fa995b32adf9f9405fb80200e6b517f6dec7872319481e215b14433dbd6931c4cc6eac317985dce00726ab
6
+ metadata.gz: 18745c29c6a2c249d6ed67eef2d961f3175e4f2f124ba368caed230f2df4c037e58ba14666ca1bae726addc10fd14ae5658be654cc2cb506afc9e4cafe5afb9b
7
+ data.tar.gz: 63e4f77b325ba95b279d698885a8b92814938ab2c196b5da79ed36a570dc4f0a8ac26c8c56291686f02530cd8e51fb82f2d58f3cd4da13649c7afe271421728a
data/knife.gemspec CHANGED
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
30
30
  s.add_dependency "net-ssh-multi", "~> 1.2", ">= 1.2.1"
31
31
  s.add_dependency "ed25519", "~> 1.2" # ed25519 ssh key support
32
32
  s.add_dependency "bcrypt_pbkdf", "~> 1.1" # ed25519 ssh key support
33
+ # we can't use this gem until illegal instruction issues are resolved
34
+ # s.add_dependency "x25519" # ed25519 KEX module
33
35
  s.add_dependency "highline", ">= 1.6.9", "< 3" # Used in UI to present a list, no other usage.
34
36
 
35
37
  s.add_dependency "tty-prompt", "~> 0.21" # knife ui.ask prompt
@@ -171,12 +171,12 @@ class Chef
171
171
  client_rb << "fips true\n"
172
172
  end
173
173
 
174
- unless chef_config[:file_cache_path].nil?
175
- client_rb << "file_cache_path \"#{chef_config[:file_cache_path]}\"\n"
174
+ unless chef_config[:unix_bootstrap_file_cache_path].nil?
175
+ client_rb << "file_cache_path \"#{chef_config[:unix_bootstrap_file_cache_path]}\"\n"
176
176
  end
177
177
 
178
- unless chef_config[:file_backup_path].nil?
179
- client_rb << "file_backup_path \"#{chef_config[:file_backup_path]}\"\n"
178
+ unless chef_config[:unix_bootstrap_file_backup_path].nil?
179
+ client_rb << "file_backup_path \"#{chef_config[:unix_bootstrap_file_backup_path]}\"\n"
180
180
  end
181
181
 
182
182
  client_rb
@@ -71,8 +71,8 @@ class Chef
71
71
  client_rb = <<~CONFIG
72
72
  chef_server_url "#{chef_config[:chef_server_url]}"
73
73
  validation_client_name "#{chef_config[:validation_client_name]}"
74
- file_cache_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\cache"
75
- file_backup_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\backup"
74
+ file_cache_path "#{ChefConfig::PathHelper.escapepath(chef_config[:windows_bootstrap_file_cache_path] || "")}"
75
+ file_backup_path "#{ChefConfig::PathHelper.escapepath(chef_config[:windows_bootstrap_file_backup_path] || "")}"
76
76
  cache_options ({:path => "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.etc_chef_dir(windows: true))}\\\\cache\\\\checksums", :skip_expires => true})
77
77
  CONFIG
78
78
 
@@ -29,7 +29,7 @@ class Chef
29
29
  description: "Add user to admin group"
30
30
 
31
31
  deps do
32
- require_relative "../org"
32
+ require "chef/org"
33
33
  end
34
34
 
35
35
  def run
@@ -134,6 +134,18 @@ class Chef
134
134
  boolean: true,
135
135
  default: false
136
136
 
137
+ option :pty,
138
+ long: "--[no-]pty",
139
+ description: "Request a PTY, enabled by default.",
140
+ boolean: true,
141
+ default: true
142
+
143
+ option :require_pty,
144
+ long: "--[no-]require-pty",
145
+ description: "Raise exception if a PTY cannot be acquired, disabled by default.",
146
+ boolean: true,
147
+ default: false
148
+
137
149
  def session
138
150
  ssh_error_handler = Proc.new do |server|
139
151
  if config[:on_error]
@@ -353,26 +365,26 @@ class Chef
353
365
  ui.msg(str)
354
366
  end
355
367
 
356
- def ssh_command(command, subsession = nil)
368
+ # @param command [String] the command to run
369
+ # @param session_list [???] list of sessions, one per node
370
+ #
371
+ def ssh_command(command, session_list = session)
372
+ stderr = ""
357
373
  exit_status = 0
358
- subsession ||= session
359
374
  command = fixup_sudo(command)
360
375
  command.force_encoding("binary") if command.respond_to?(:force_encoding)
361
- begin
362
- open_session(subsession, command)
363
- rescue => e
364
- open_session(subsession, command, true)
365
- end
366
- end
367
-
368
- def open_session(subsession, command, pty = false)
369
- stderr = ""
370
- exit_status = 0
371
- subsession.open_channel do |chan|
376
+ session_list.open_channel do |chan|
372
377
  if config[:on_error] && exit_status != 0
373
378
  chan.close
374
379
  else
375
- chan.request_pty if pty
380
+ if config[:pty]
381
+ chan.request_pty do |ch, success|
382
+ unless success
383
+ ui.warn("Failed to obtain a PTY from #{ch.connection.host}")
384
+ raise ArgumentError, "Request for PTY failed" if config[:require_pty]
385
+ end
386
+ end
387
+ end
376
388
  chan.exec command do |ch, success|
377
389
  raise ArgumentError, "Cannot execute #{command}" unless success
378
390
 
@@ -383,13 +395,11 @@ class Chef
383
395
  ichannel.send_data("#{get_password}\n")
384
396
  end
385
397
  end
386
-
387
398
  ch.on_extended_data do |_, _type, data|
388
- raise ArgumentError if data.eql?("sudo: no tty present and no askpass program specified\n")
399
+ raise ArgumentError, "No PTY present. If a PTY is required use --require-pty" if data.eql?("sudo: no tty present and no askpass program specified\n")
389
400
 
390
401
  stderr += data
391
402
  end
392
-
393
403
  ch.on_request "exit-status" do |ichannel, data|
394
404
  exit_status = [exit_status, data.read_long].max
395
405
  end
@@ -398,6 +408,8 @@ class Chef
398
408
  end
399
409
  session.loop
400
410
  exit_status
411
+ ensure
412
+ session_list.close
401
413
  end
402
414
 
403
415
  def get_password
@@ -50,7 +50,8 @@ class Chef
50
50
  rescue Net::HTTPClientException => e
51
51
  raise e unless /Forbidden/.match?(e.message)
52
52
 
53
- ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it."
53
+ ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it & #{config[:supermarket_site]} must allow maintainers to unshare cookbooks."
54
+ ui.warn "The default supermarket #{default_config[:supermarket_site]} does not allow maintainers to unshare cookbooks."
54
55
  exit 1
55
56
  end
56
57
 
@@ -17,7 +17,7 @@
17
17
  class Chef
18
18
  class Knife
19
19
  KNIFE_ROOT = File.expand_path("../..", __dir__)
20
- VERSION = "17.2.15".freeze
20
+ VERSION = "17.3.48".freeze
21
21
  end
22
22
  end
23
23
 
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Marc Pardise (<marc@chef.io>)
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require "chef/knife"
19
+
20
+ Chef::Knife.subcommand_loader.load_commands
21
+ commands = Chef::Knife::SubcommandLoader.generate_hash["_autogenerated_command_paths"]["plugins_paths"].keys
22
+
23
+ # Directly execute each support knife command
24
+ context "Command Sanity Check: executing ", :workstation do
25
+ describe "bundle exec knife" do
26
+ commands.each do |command|
27
+ command_name = command.gsub("_", " ")
28
+ modified_command, expected_result = case command_name
29
+ when /knife/
30
+ # because rspec is the actual executable running, the option parser error message
31
+ # is invalid from within the test.
32
+ next
33
+ when /config (use|get|list) profile.*/
34
+ # hyphenated special cases
35
+ [command_name, /^USAGE: knife config #{$1}-profile.*/]
36
+ when /(role|node|env) (env )?run list(.*)/
37
+ # underscored special cases...
38
+ env_part = $2.nil? ? "" : "env_"
39
+ ["#{$1} #{$2}run_list#{$3}", /^USAGE: knife #{$1} #{env_part}run_list#{$3}.*/]
40
+ else
41
+ [ command_name, /^USAGE: knife #{command_name}.*/]
42
+ end
43
+
44
+ # By using bundle exec knife instead of directly loading the command class or using the knife() helper,
45
+ # we ensure that this is a valid end-to-end test. This operates on the assumption
46
+ # that we continue to require the command class to be fully loaded so that it can handle the parsing of
47
+ # its own options.
48
+ full_command = "#{modified_command} --invalid-option outputs usage for '#{modified_command}' to stdout"
49
+ it full_command do
50
+ result = `bundle exec knife #{full_command}`
51
+ expect(result).to match(expected_result)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -66,7 +66,7 @@ describe "knife cookbook download", :workstation do
66
66
  Downloading root_files
67
67
  Cookbook downloaded to #{tmpdir}/x-1.0.1
68
68
  EOM
69
- )
69
+ )
70
70
  end
71
71
  end
72
72
  end
@@ -80,16 +80,16 @@ describe Chef::Knife::Core::BootstrapContext do
80
80
  end
81
81
  end
82
82
 
83
- describe "when file_cache_path is set" do
84
- let(:chef_config) { { file_cache_path: "/home/opscode/cache" } }
85
- it "sets file_cache_path in the generated config file" do
83
+ describe "when unix_bootstrap_file_cache_path is set" do
84
+ let(:chef_config) { { unix_bootstrap_file_cache_path: "/home/opscode/cache" } }
85
+ it "sets unix_bootstrap_file_cache_path in the generated config file" do
86
86
  expect(bootstrap_context.config_content).to include("file_cache_path \"/home/opscode/cache\"")
87
87
  end
88
88
  end
89
89
 
90
- describe "when file_backup_path is set" do
91
- let(:chef_config) { { file_backup_path: "/home/opscode/backup" } }
92
- it "sets file_backup_path in the generated config file" do
90
+ describe "when unix_bootstrap_file_backup_path is set" do
91
+ let(:chef_config) { { unix_bootstrap_file_backup_path: "/home/opscode/backup" } }
92
+ it "sets unix_bootstrap_file_backup_path in the generated config file" do
93
93
  expect(bootstrap_context.config_content).to include("file_backup_path \"/home/opscode/backup\"")
94
94
  end
95
95
  end
@@ -154,8 +154,8 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
154
154
  config_log_location: STDOUT,
155
155
  chef_server_url: "http://chef.example.com:4444",
156
156
  validation_client_name: "chef-validator-testing",
157
- file_cache_path: "c:/chef/cache",
158
- file_backup_path: "c:/chef/backup",
157
+ windows_bootstrap_file_cache_path: "c:/chef/cache",
158
+ windows_bootstrap_file_backup_path: "c:/chef/backup",
159
159
  cache_options: ({ path: "c:/chef/cache/checksums", skip_expires: true })
160
160
  )
161
161
  )
@@ -165,8 +165,8 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
165
165
  expected = <<~EXPECTED
166
166
  echo.chef_server_url "http://chef.example.com:4444"
167
167
  echo.validation_client_name "chef-validator-testing"
168
- echo.file_cache_path "C:\\\\chef\\\\cache"
169
- echo.file_backup_path "C:\\\\chef\\\\backup"
168
+ echo.file_cache_path "c:/chef/cache"
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
172
  echo.log_level :auto
@@ -289,7 +289,7 @@ describe Chef::Knife::Ssh do
289
289
  let(:execution_channel2) { double(:execution_channel, on_data: nil, on_extended_data: nil) }
290
290
  let(:session_channel2) { double(:session_channel, request_pty: nil) }
291
291
 
292
- let(:session) { double(:session, loop: nil) }
292
+ let(:session) { double(:session, loop: nil, close: nil) }
293
293
 
294
294
  let(:command) { "false" }
295
295
 
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.2.15
4
+ version: 17.3.48
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-06-01 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -950,6 +950,7 @@ files:
950
950
  - spec/integration/client_key_show_spec.rb
951
951
  - spec/integration/client_list_spec.rb
952
952
  - spec/integration/client_show_spec.rb
953
+ - spec/integration/commands_spec.rb
953
954
  - spec/integration/common_options_spec.rb
954
955
  - spec/integration/config_list_spec.rb
955
956
  - spec/integration/config_show_spec.rb
@@ -1148,7 +1149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1148
1149
  - !ruby/object:Gem::Version
1149
1150
  version: '0'
1150
1151
  requirements: []
1151
- rubygems_version: 3.2.15
1152
+ rubygems_version: 3.2.22
1152
1153
  signing_key:
1153
1154
  specification_version: 4
1154
1155
  summary: The knife CLI for Chef Infra.