knife-tidy 2.1.2 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebbadbfe49e6402c189f63e8e0290eeb93d409f89f4220ef9ad6bdc96b0b455f
4
- data.tar.gz: ee7f3392eac804aeec3490c33c1e02d9d22d1bd038f3a1eb8222fd9d9c660dd9
3
+ metadata.gz: 6c2702f9782813c2c218f78232a3d174459c457d55c5384a52b10d23a0ac28bb
4
+ data.tar.gz: d0212907d1f8d6b8287e76f12ecac60bcecfb7dd9ca614a48a06b6d3322f0dca
5
5
  SHA512:
6
- metadata.gz: e78b266e0482121cd3d551a9d683cd79b85aae16bb31d53260c2c73a7ceae1080052cd582957b55a23099c7799ed8312e0a5fcde1b920640497af04872894ab7
7
- data.tar.gz: b1e97749b9ed73fe512b76a45291541b070eb730ded2f86dc4de1f355258e319017338e183c53a0dd2b4671f98a513ba4a5ca69053e6dc834359f396e15257ee
6
+ metadata.gz: 5f31036894ee89b00964d0a6c94297935f6c8824414c90e09005d8ac9ab45399d56b430ca4f1b941cbeadd9b1b177d76963e2f85c81d2a288e3d611301479fb9
7
+ data.tar.gz: 7e93f0b7404db7453bac17ebd260a6e31e9ff72a1425353ad6331dc3bcbc3728226bc4ad9587d6c346b0036d36e416dc1f147105fa5e5dbf60eb1bd7b9a9ebed
@@ -130,10 +130,10 @@ class Chef
130
130
 
131
131
  def add_cookbook_name_to_metadata(cookbook_name, rb_path)
132
132
  ui.stdout.puts "REPAIRING: Correcting `name` in #{rb_path}"
133
- content = IO.readlines(rb_path)
133
+ content = File.readlines(rb_path)
134
134
  new_content = content.reject { |line| line =~ /^name\s+/ }
135
135
  name_field = "name '#{cookbook_name}'\n"
136
- IO.write rb_path, name_field + new_content.join("")
136
+ File.write(rb_path, name_field + new_content.join(""))
137
137
  end
138
138
 
139
139
  def fix_cookbook_names(org)
@@ -354,23 +354,19 @@ class Chef
354
354
  rl = Chef::RunList.new
355
355
  new_role["run_list"] = []
356
356
  the_role["run_list"].each do |item|
357
- begin
358
- rl << item
359
- new_role["run_list"].push(item)
360
- rescue ArgumentError
361
- ui.stdout.puts "REPAIRING: Invalid Recipe Item: #{item} in run_list from #{role_path}"
362
- end
357
+ rl << item
358
+ new_role["run_list"].push(item)
359
+ rescue ArgumentError
360
+ ui.stdout.puts "REPAIRING: Invalid Recipe Item: #{item} in run_list from #{role_path}"
363
361
  end
364
362
  if the_role.key?("env_run_lists")
365
363
  the_role["env_run_lists"].each_pair do |key, value|
366
364
  new_role["env_run_lists"][key] = []
367
365
  value.each do |item|
368
- begin
369
- rl << item
370
- new_role["env_run_lists"][key].push(item)
371
- rescue ArgumentError
372
- ui.stdout.puts "REPAIRING: Invalid Recipe Item: #{item} in env_run_lists #{key} from #{role_path}"
373
- end
366
+ rl << item
367
+ new_role["env_run_lists"][key].push(item)
368
+ rescue ArgumentError
369
+ ui.stdout.puts "REPAIRING: Invalid Recipe Item: #{item} in env_run_lists #{key} from #{role_path}"
374
370
  end
375
371
  end
376
372
  end
@@ -84,15 +84,13 @@ class Chef
84
84
  ui.info("Fetching report data for organization #{org}")
85
85
  reports[org] = {}
86
86
  report_file_suffixes.each do |report|
87
- begin
88
- file_name = "#{reports_dir}/#{org}#{report}"
89
- ui.info(" Parsing file #{file_name}")
90
- json_string = File.read(file_name)
91
- reports[org][report] = tidy.json_file_to_hash(json_string, symbolize_names: false)
92
- rescue Errno::ENOENT
93
- ui.info(" Skipping file #{file_name} - not found for organization #{org}")
94
- reports[org][report] = {}
95
- end
87
+ file_name = "#{reports_dir}/#{org}#{report}"
88
+ ui.info(" Parsing file #{file_name}")
89
+ json_string = File.read(file_name)
90
+ reports[org][report] = tidy.json_file_to_hash(json_string, symbolize_names: false)
91
+ rescue Errno::ENOENT
92
+ ui.info(" Skipping file #{file_name} - not found for organization #{org}")
93
+ reports[org][report] = {}
96
94
  end
97
95
 
98
96
  # Fetch a list of admin users for the current organization
@@ -19,8 +19,8 @@ class Chef
19
19
 
20
20
  option :keep_versions,
21
21
  long: "--keep-versions MIN",
22
- default: 0,
23
- description: "Keep a minimum of this many versions of each cookbook (default: 0)"
22
+ default: 1,
23
+ description: "Keep a minimum of this many versions of each cookbook (default: 1)"
24
24
 
25
25
  def run
26
26
  ensure_reports_dir!
@@ -82,8 +82,6 @@ class Chef
82
82
  end
83
83
  end
84
84
 
85
- used_cookbooks = keep_cookbook_versions(cb_list, keep_versions)
86
-
87
85
  Chef::Log.debug("Used cookbook list before checking environments: #{used_cookbooks}")
88
86
  pins = environment_constraints(org)
89
87
  used_cookbooks = check_environment_pins(used_cookbooks, pins, cb_list)
@@ -98,7 +96,7 @@ class Chef
98
96
  stale_nodes_hash = { 'threshold_days': node_threshold, 'org_total_node_count': nodes.count, 'count': stale_nodes.count, 'list': stale_nodes }
99
97
  stale_orgs.push(org) if stale_nodes.count == nodes.count
100
98
 
101
- tidy.write_new_file(unused_cookbooks(used_cookbooks, cb_list), ::File.join(tidy.reports_dir, "#{org}_unused_cookbooks.json"), backup = false)
99
+ tidy.write_new_file(unused_cookbooks(used_cookbooks, cb_list, keep_versions), ::File.join(tidy.reports_dir, "#{org}_unused_cookbooks.json"), backup = false)
102
100
  tidy.write_new_file(version_count, ::File.join(tidy.reports_dir, "#{org}_cookbook_count.json"), backup = false)
103
101
  tidy.write_new_file(stale_nodes_hash, ::File.join(tidy.reports_dir, "#{org}_stale_nodes.json"), backup = false)
104
102
 
@@ -162,15 +160,6 @@ class Chef
162
160
  cb_list
163
161
  end
164
162
 
165
- def keep_cookbook_versions(cb_list, min)
166
- retain = {}
167
- cb_list.each do |name, versions|
168
- keep = versions.sort { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last(min)
169
- retain[name] = keep
170
- end
171
- retain
172
- end
173
-
174
163
  def cookbook_count(cb_list)
175
164
  cb_count_list = {}
176
165
  cb_list.each do |name, versions|
@@ -179,14 +168,14 @@ class Chef
179
168
  cb_count_list
180
169
  end
181
170
 
182
- def unused_cookbooks(used_list, cb_list)
171
+ def unused_cookbooks(used_list, cb_list, keep_versions)
183
172
  unused_list = {}
184
173
  cb_list.each do |name, versions|
185
174
  versions.sort! { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
186
175
  if used_list[name].nil? # Not in the used list at all (Remove all versions)
187
176
  unused_list[name] = versions
188
177
  elsif used_list[name].sort != versions # Is in the used cookbook list, but version arrays do not match (Find unused versions)
189
- unused = versions - used_list[name] - [versions.last] # Don't delete the most recent version as it might not be in a run_list yet.
178
+ unused = versions - used_list[name] - versions.last(keep_versions) # Don't delete the X most recent version as it might not be in a run_list yet.
190
179
  unused_list[name] = unused unless unused.empty?
191
180
  end
192
181
  end
@@ -196,9 +196,9 @@ class Chef
196
196
  dirs = path.split(File::SEPARATOR)
197
197
 
198
198
  until dirs.empty?
199
- version_match = dirs[-1].match(/\d+\.\d+\.\d+/)
200
- if dirs[-2] == "cookbooks" && version_match # we found the cookbook version not something that looks like one inside a cookbook path
201
- return version_match.to_s
199
+ version_match = dirs[-1][/\b\d{1,3}\.\d{1,3}\.\d{1,3}\b/]
200
+ if dirs.length >= 2 && dirs[-2] == "cookbooks" && version_match
201
+ return version_match
202
202
  else
203
203
  dirs.pop
204
204
  end
@@ -1,4 +1,4 @@
1
1
  module KnifeTidy
2
- VERSION = "2.1.2".freeze
2
+ VERSION = "2.3.0".freeze
3
3
  MAJOR, MINOR, TINY = VERSION.split(".")
4
4
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-tidy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Jeremy Miller
7
+ - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-21 00:00:00.000000000 Z
11
+ date: 2025-08-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Report on stale Chef Server nodes and cookbooks and clean up data integrity
14
- issues in a knife-ec-backup object based backup
13
+ description: Report on stale Chef Infra Server nodes and cookbooks and clean up data
14
+ integrity issues in a knife-ec-backup object based backup
15
15
  email:
16
- - jmiller@chef.io
16
+ - oss@chef.io
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
@@ -30,7 +30,7 @@ files:
30
30
  - lib/chef/tidy_server.rb
31
31
  - lib/chef/tidy_substitutions.rb
32
32
  - lib/knife-tidy/version.rb
33
- homepage: https://github.com/chef-customers/knife-tidy
33
+ homepage: https://github.com/chef/knife-tidy
34
34
  licenses:
35
35
  - Apache-2.0
36
36
  metadata: {}
@@ -42,16 +42,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 2.3.0
45
+ version: 2.7.0
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubygems_version: 3.0.3
52
+ rubygems_version: 3.3.27
53
53
  signing_key:
54
54
  specification_version: 4
55
- summary: Report on stale Chef Server nodes and cookbooks and clean up data integrity
55
+ summary: Report on stale Chef Infra Server nodes and cookbooks and clean up data integrity
56
56
  issues in a knife-ec-backup object based backup
57
57
  test_files: []