knife 18.3.0 → 18.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/lib/chef/chef_fs/knife.rb +1 -1
- data/lib/chef/knife/core/gem_glob_loader.rb +2 -2
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/core/ui.rb +1 -0
- data/lib/chef/knife/search.rb +3 -3
- data/lib/chef/knife/version.rb +1 -1
- data/lib/chef/knife.rb +14 -10
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +1 -1
- data/spec/unit/knife/search_spec.rb +148 -0
- data/spec/unit/knife_spec.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7dbcf835eedd6dece43282604cd9c7136ba0adf6375c856582860700d65031e
|
4
|
+
data.tar.gz: bc342db29c4bb913525ff031519efaa585a0067e1ae65bb2786403edef3934f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11a5c1d4e9449e7e566ba18ca38efda979c2341ecba1e07b607a90c7c18acc57af69115039757a3cdb48059c08468d38c75c65f5a28953863c5d8228337d3378
|
7
|
+
data.tar.gz: baa24762c6c61cc695ccd0f8fcba24284aab84502dbd2c74f26d436912d66ce7e2119edc401d5071c1577ce77d2b5c08da2eaa145738a4871f18a139d79da609
|
data/Gemfile
CHANGED
@@ -4,7 +4,8 @@ gem "knife", path: "."
|
|
4
4
|
|
5
5
|
group(:development, :test) do
|
6
6
|
gem "cheffish", ">= 14" # testing only , but why didn't this need to explicit in chef?
|
7
|
-
gem "webmock"
|
7
|
+
gem "webmock"
|
8
|
+
gem "crack", "< 0.4.6" # due to https://github.com/jnunemaker/crack/pull/75
|
8
9
|
gem "rake"
|
9
10
|
gem "rspec"
|
10
11
|
gem "chef-bin", path: "../chef-bin"
|
data/lib/chef/chef_fs/knife.rb
CHANGED
@@ -112,7 +112,7 @@ class Chef
|
|
112
112
|
end
|
113
113
|
# Use the original path because we can't be sure.
|
114
114
|
inferred_path = arg
|
115
|
-
elsif arg
|
115
|
+
elsif arg.start_with?("~")
|
116
116
|
# Let's be nice and fix it if possible - but warn the user.
|
117
117
|
ui.warn("A path relative to a user home directory has been provided: #{arg}")
|
118
118
|
ui.warn("Paths provided need to be rooted at the chef-repo being considered or be relative paths.")
|
@@ -78,7 +78,7 @@ class Chef
|
|
78
78
|
if check_load_path
|
79
79
|
files = $LOAD_PATH.map do |load_path|
|
80
80
|
Dir["#{File.expand_path glob, ChefConfig::PathHelper.escape_glob_dir(load_path)}#{Gem.suffix_pattern}"]
|
81
|
-
end.flatten.select { |file| File.file? file
|
81
|
+
end.flatten.select { |file| File.file? file }
|
82
82
|
|
83
83
|
end
|
84
84
|
|
@@ -114,7 +114,7 @@ class Chef
|
|
114
114
|
|
115
115
|
glob = File.join(ChefConfig::PathHelper.escape_glob_dir(spec.full_gem_path, dirs), glob)
|
116
116
|
|
117
|
-
Dir[glob]
|
117
|
+
Dir[glob]
|
118
118
|
end
|
119
119
|
|
120
120
|
def from_different_chef_version?(path)
|
@@ -160,7 +160,7 @@ class Chef
|
|
160
160
|
|
161
161
|
#
|
162
162
|
# Utility function for finding an element in a hash given an array
|
163
|
-
# of words and a separator. We find the
|
163
|
+
# of words and a separator. We find the longest key in the
|
164
164
|
# hash composed of the given words joined by the separator.
|
165
165
|
#
|
166
166
|
def find_longest_key(hash, words, sep = "_")
|
data/lib/chef/knife/core/ui.rb
CHANGED
@@ -41,6 +41,7 @@ class Chef
|
|
41
41
|
def_delegator :@presenter, :format_list_for_display
|
42
42
|
def_delegator :@presenter, :format_for_display
|
43
43
|
def_delegator :@presenter, :format_cookbook_list_for_display
|
44
|
+
def_delegator :@presenter, :attribute_field_separator
|
44
45
|
|
45
46
|
def initialize(stdout, stderr, stdin, config)
|
46
47
|
@stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config
|
data/lib/chef/knife/search.rb
CHANGED
@@ -90,7 +90,7 @@ class Chef
|
|
90
90
|
if config[:filter_result]
|
91
91
|
search_args[:filter_result] = create_result_filter(config[:filter_result])
|
92
92
|
elsif (not ui.config[:attribute].nil?) && (not ui.config[:attribute].empty?)
|
93
|
-
search_args[:filter_result] = create_result_filter_from_attributes(ui.config[:attribute])
|
93
|
+
search_args[:filter_result] = create_result_filter_from_attributes(ui.config[:attribute], ui.attribute_field_separator)
|
94
94
|
elsif config[:id_only]
|
95
95
|
search_args[:filter_result] = create_result_filter_from_attributes([])
|
96
96
|
end
|
@@ -179,10 +179,10 @@ class Chef
|
|
179
179
|
final_filter
|
180
180
|
end
|
181
181
|
|
182
|
-
def create_result_filter_from_attributes(filter_array)
|
182
|
+
def create_result_filter_from_attributes(filter_array, separator = ".")
|
183
183
|
final_filter = {}
|
184
184
|
filter_array.each do |f|
|
185
|
-
final_filter[f] = f.split(
|
185
|
+
final_filter[f] = f.split(separator)
|
186
186
|
end
|
187
187
|
# adding magic filter so we can actually pull the name as before
|
188
188
|
final_filter["__display_name"] = [ "name" ]
|
data/lib/chef/knife/version.rb
CHANGED
data/lib/chef/knife.rb
CHANGED
@@ -414,16 +414,20 @@ class Chef
|
|
414
414
|
def apply_computed_config
|
415
415
|
Chef::Config[:color] = config[:color]
|
416
416
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
417
|
+
# If the verbosity is not set, use what is already present on the log_level config.
|
418
|
+
Chef::Config[:log_level] = case Chef::Config[:verbosity]
|
419
|
+
when 0
|
420
|
+
:warn
|
421
|
+
when 1
|
422
|
+
:info
|
423
|
+
when 2
|
424
|
+
:debug
|
425
|
+
when nil
|
426
|
+
# The default log_level is auto and that is not a valid log_level.
|
427
|
+
Chef::Config[:log_level] == :auto ? :warn : Chef::Config[:log_level]
|
428
|
+
else
|
429
|
+
:trace
|
430
|
+
end
|
427
431
|
|
428
432
|
Chef::Config[:log_level] = :trace if ENV["KNIFE_DEBUG"]
|
429
433
|
|
@@ -105,7 +105,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do
|
|
105
105
|
expect(loader.subcommand_for_args(%w{cooler b})).to eq("cooler_b")
|
106
106
|
end
|
107
107
|
|
108
|
-
it "returns nil if the
|
108
|
+
it "returns nil if the subcommand isn't in our manifest" do
|
109
109
|
expect(loader.subcommand_for_args(["cooler c"])).to eq(nil)
|
110
110
|
end
|
111
111
|
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ashique Saidalavi (<ashique.saidalavi@progress.com>)
|
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
|
+
|
19
|
+
require "knife_spec_helper"
|
20
|
+
|
21
|
+
describe Chef::Knife::Search do
|
22
|
+
describe "node" do
|
23
|
+
let(:knife) { Chef::Knife::Search.new }
|
24
|
+
let(:query) { double("Chef::Search::Query") }
|
25
|
+
let(:stdout) { StringIO.new }
|
26
|
+
let(:stderr) { StringIO.new }
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
node = Chef::Node.new.tap do |n|
|
30
|
+
n.automatic_attrs["fqdn"] = "foobar"
|
31
|
+
n.automatic_attrs["ohai_time"] = 1343845969
|
32
|
+
n.automatic_attrs["platform"] = "mac_os_x"
|
33
|
+
n.automatic_attrs["platform_version"] = "10.12.5"
|
34
|
+
end
|
35
|
+
|
36
|
+
allow(query).to receive(:search).and_yield(node)
|
37
|
+
allow(Chef::Search::Query).to receive(:new).and_return(query)
|
38
|
+
|
39
|
+
allow(knife).to receive(:output).and_return(true)
|
40
|
+
allow(knife.ui).to receive(:stdout).and_return(stdout)
|
41
|
+
allow(knife.ui).to receive(:stderr).and_return(stderr)
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "run" do
|
45
|
+
it "should be successful" do
|
46
|
+
knife.name_args = ["node", ":"]
|
47
|
+
expect(query).to receive(:search).with("node", ":", { fuzz: true })
|
48
|
+
knife.run
|
49
|
+
end
|
50
|
+
|
51
|
+
context "read_cli_args" do
|
52
|
+
it "should be invoked" do
|
53
|
+
expect(knife).to receive(:read_cli_args)
|
54
|
+
knife.run
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should raise error if query passed with argument as well as -q option" do
|
58
|
+
knife.name_args = ["node", ":"]
|
59
|
+
knife.config[:query] = ":"
|
60
|
+
|
61
|
+
expect { knife.run }.to raise_error(SystemExit)
|
62
|
+
expect(stderr.string).to match /Please specify query as an argument or an option via -q, not both/im
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should fail if no query passed" do
|
66
|
+
knife.name_args = []
|
67
|
+
|
68
|
+
expect { knife.run }.to raise_error(SystemExit)
|
69
|
+
expect(stderr.string).to match /No query specified/im
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "filters" do
|
74
|
+
before do
|
75
|
+
knife.name_args = ["node", "packages:git"]
|
76
|
+
knife.config[:filter_result] = "env=chef_environment"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should invoke create_result_filter" do
|
80
|
+
expect(knife).to receive(:create_result_filter).with("env=chef_environment")
|
81
|
+
knife.run
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should invoke search object with correct filter" do
|
85
|
+
expect(query).to receive(:search).with("node", "packages:git", { filter_result: { env: ["chef_environment"] }, fuzz: true })
|
86
|
+
knife.run
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "attributes" do
|
91
|
+
before do
|
92
|
+
knife.name_args = ["node", "packages:git"]
|
93
|
+
knife.ui.config[:attribute] = ["packages.git.version"]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should invoke create_result_filter_from_attributes method" do
|
97
|
+
expect(knife).to receive(:create_result_filter_from_attributes).with(["packages.git.version"], knife.ui.attribute_field_separator)
|
98
|
+
knife.run
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should invoke search query with correct filter" do
|
102
|
+
filter_obj = {
|
103
|
+
filter_result: {
|
104
|
+
"__display_name" => ["name"],
|
105
|
+
"packages.git.version" => %w{packages git version} },
|
106
|
+
fuzz: true,
|
107
|
+
}
|
108
|
+
expect(query).to receive(:search).with("node", "packages:git", filter_obj)
|
109
|
+
knife.run
|
110
|
+
end
|
111
|
+
|
112
|
+
context "field_separator" do
|
113
|
+
it "should have dot as the default field_separator" do
|
114
|
+
expect(knife.ui.attribute_field_separator).to eq(".")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "has the correct field_separator" do
|
118
|
+
knife.config[:field_separator] = ":"
|
119
|
+
|
120
|
+
expect(knife.ui.attribute_field_separator).to eq(":")
|
121
|
+
end
|
122
|
+
|
123
|
+
context "parsing" do
|
124
|
+
before do
|
125
|
+
knife.name_args = %w{node packages:git}
|
126
|
+
end
|
127
|
+
|
128
|
+
it "parses the attributes correctly for dot field_separator" do
|
129
|
+
knife.config[:field_separator] = "."
|
130
|
+
knife.ui.config[:attribute] = ["packages.git.version"]
|
131
|
+
|
132
|
+
filter_output = { "__display_name" => ["name"], "packages.git.version" => %w{packages git version} }
|
133
|
+
expect(knife.create_result_filter_from_attributes(["packages.git.version"], ".")).to eq(filter_output)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "parses it for different field_separator" do
|
137
|
+
knife.config[:field_separator] = ":"
|
138
|
+
knife.ui.config[:attribute] = ["packages:git:version"]
|
139
|
+
|
140
|
+
filter_output = { "__display_name" => ["name"], "packages:git:version" => %w{packages git version} }
|
141
|
+
expect(knife.create_result_filter_from_attributes(["packages:git:version"], ":")).to eq(filter_output)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/spec/unit/knife_spec.rb
CHANGED
@@ -320,6 +320,9 @@ describe Chef::Knife do
|
|
320
320
|
end
|
321
321
|
|
322
322
|
it "sets the default log_level to warn so we can issue Chef::Log.warn" do
|
323
|
+
# Reset the log level to the default value
|
324
|
+
Chef::Config[:log_level] = :auto
|
325
|
+
|
323
326
|
knife_command = KnifeSpecs::TestYourself.new([])
|
324
327
|
knife_command.configure_chef
|
325
328
|
expect(Chef::Config[:log_level]).to eql(:warn)
|
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: 18.
|
4
|
+
version: 18.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-config
|
@@ -1098,6 +1098,7 @@ files:
|
|
1098
1098
|
- spec/unit/knife/role_run_list_replace_spec.rb
|
1099
1099
|
- spec/unit/knife/role_run_list_set_spec.rb
|
1100
1100
|
- spec/unit/knife/role_show_spec.rb
|
1101
|
+
- spec/unit/knife/search_spec.rb
|
1101
1102
|
- spec/unit/knife/ssh_spec.rb
|
1102
1103
|
- spec/unit/knife/ssl_check_spec.rb
|
1103
1104
|
- spec/unit/knife/ssl_fetch_spec.rb
|
@@ -1144,7 +1145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1144
1145
|
- !ruby/object:Gem::Version
|
1145
1146
|
version: '0'
|
1146
1147
|
requirements: []
|
1147
|
-
rubygems_version: 3.3.
|
1148
|
+
rubygems_version: 3.3.26
|
1148
1149
|
signing_key:
|
1149
1150
|
specification_version: 4
|
1150
1151
|
summary: The knife CLI for Chef Infra.
|