knife 18.3.0 → 18.4.2

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: eee4d86bce76117b7bc25593ac766eea25bb2f3a6d46c861b578f04595c23e71
4
- data.tar.gz: 92f611bca1afb09fffe920d91120c00ccb7e6bc5bca12af188ceecc1378bb216
3
+ metadata.gz: fdf20084b258549d98683a30f13e82c8c05ef96454c04108db37f1a2a5a71182
4
+ data.tar.gz: 0cae6131e1d8c5b05547b1f221942e84f501b0ce9685f162e308af8b868c16df
5
5
  SHA512:
6
- metadata.gz: 597d3b7e1ff3d0743318324185b920318c36c56d247d0a32a212b23f565c0bfc26812932db787129e401614d2e518e5a5e7fb19c1aa3f5138cc0f05890ccab55
7
- data.tar.gz: c918ef6cdb6999f1b2eb943fb1b0003a1b5c71acf2b2ef5206b40035fdd06558678a77b84f82815415e4c3695ceae4861ad1646663b853fbc6c6c2bff72b4354
6
+ metadata.gz: 5c1ff58d3324c77d44cd1168bad50e7fa94abf3be2eda9bdd8a39708b41e89f054a3b1113889c38f118adf8d85c75289f9443d3dba0675e2121ff530a645ba84
7
+ data.tar.gz: e3d0a3749aa738b7e1cb69793af8bff04a3d209442f58d0f4bdbacbcd4484b1222ce240eae440f45dbd537c73768d86bdcc0d22e4a4e0c36824382ee0b00000b
@@ -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.untaint }
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].map(&:untaint)
117
+ Dir[glob]
118
118
  end
119
119
 
120
120
  def from_different_chef_version?(path)
@@ -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
@@ -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" ]
@@ -17,7 +17,7 @@
17
17
  class Chef
18
18
  class Knife
19
19
  KNIFE_ROOT = File.expand_path("../..", __dir__)
20
- VERSION = "18.3.0".freeze
20
+ VERSION = "18.4.2".freeze
21
21
  end
22
22
  end
23
23
 
@@ -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
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.3.0
4
+ version: 18.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2024-01-30 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.7
1148
+ rubygems_version: 3.2.33
1148
1149
  signing_key:
1149
1150
  specification_version: 4
1150
1151
  summary: The knife CLI for Chef Infra.