knife-tidy 2.0.15 → 2.1.6

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: c7aaf34102e27291f03892bfb4eddb450aaed46c5e615818e48a59c174c91e42
4
- data.tar.gz: f482bbfb1182b581532ef643900c6f4814dc800ff42e02ff0a29b8936faed77b
3
+ metadata.gz: 6df7a5c7edcbf10d78ed4f4702b68e231b3f016308280b979bdd84928af0362e
4
+ data.tar.gz: ae670780d34592914ddf4eba0ba67e3a4fd5a54fe49a0d8a4a9425e5c92aa1c0
5
5
  SHA512:
6
- metadata.gz: a5192215cbd8341aef601e71bf6c42bb2eb5d19f652570734ac192151941d7b954da8d0fe5c504ea67b599772d09ea12da77d6d782f54e2c967c6c12fc9cef0d
7
- data.tar.gz: 75b37b5663f0558791ad1a52b5281d84197e1def8ed2c15103896165a781b4a07f1ac4556f5d266e35fb662d76218e6be0ccf413d569e0b7b776075e5a5aca27
6
+ metadata.gz: 41fc026a4bb68574ee10ddceb69414868ae4b031f995b6a0e11b86574f579215576b7763c906739c63132d2bf62f886a645dc0b2791bd71683f3ed441d4f7932
7
+ data.tar.gz: 5e3e481f0e98d4bc141773ef92e6bf0c457678790fac6b7e36acf20e5d2da6365c8d0f8f23ce734fc118b217a73a6b994d7c3bfa79837b4540d8816e02d58227
@@ -10,9 +10,9 @@ class Chef
10
10
  require "chef/run_list"
11
11
  require_relative "../tidy_substitutions"
12
12
  require_relative "../tidy_acls"
13
- require "ffi_yajl"
14
- require "fileutils"
15
- require "securerandom"
13
+ require "ffi_yajl" unless defined?(FFI_Yajl)
14
+ require "fileutils" unless defined?(FileUtils)
15
+ require "securerandom" unless defined?(SecureRandom)
16
16
  end
17
17
 
18
18
  banner "knife tidy backup clean (options)"
@@ -25,7 +25,7 @@ class Chef
25
25
 
26
26
  option :gsub_file,
27
27
  long: "--gsub-file path/to/gsub/file",
28
- description: "The path to the file used for substitutions. If non-existant, a boiler plate one will be created."
28
+ description: "The path to the file used for substitutions. If non-existent, a boiler plate one will be created."
29
29
 
30
30
  option :gen_gsub,
31
31
  long: "--gen-gsub",
@@ -167,7 +167,7 @@ class Chef
167
167
  ret = cl.load!
168
168
  if ret.nil?
169
169
  action_needed("ACTION NEEDED: Something's wrong with the #{cookbook} cookbook in org #{org} - cannot load it! Moving to cookbooks.broken folder.")
170
- broken_cookooks_add(org, cookbook)
170
+ broken_cookbooks_add(org, cookbook)
171
171
  end
172
172
  end
173
173
  rescue LoadError, Exceptions::MetadataNotValid => e
@@ -175,7 +175,7 @@ class Chef
175
175
  exit 1
176
176
  end
177
177
 
178
- def broken_cookooks_add(org, cookbook_path)
178
+ def broken_cookbooks_add(org, cookbook_path)
179
179
  broken_path = ::File.join(tidy.org_path(org), "cookbooks.broken")
180
180
  FileUtils.mkdir(broken_path) unless ::File.directory?(broken_path)
181
181
  FileUtils.mv(cookbook_path, broken_path, verbose: true, force: true)
@@ -297,7 +297,7 @@ class Chef
297
297
 
298
298
  def substitutions_file
299
299
  sub_file_path = ::File.expand_path(config[:gsub_file])
300
- ui.error "Subtitutions file #{sub_file_path} does not exist!" unless ::File.exist?(sub_file_path)
300
+ ui.error "Substitutions file #{sub_file_path} does not exist!" unless ::File.exist?(sub_file_path)
301
301
  @substitutions_file ||= sub_file_path
302
302
  end
303
303
 
@@ -397,9 +397,10 @@ class Chef
397
397
  if existing_group_data["clients"].length != tidy.client_names(org).length
398
398
  ui.stdout.puts "REPAIRING: Adding #{(existing_group_data["clients"].length - tidy.client_names(org).length).abs} missing clients into #{org}'s client group file #{clients_group_path}"
399
399
  existing_group_data["clients"] = (existing_group_data["clients"] + tidy.client_names(org)).uniq
400
- ::File.open(clients_group_path, "w") do |f|
401
- f.write(Chef::JSONCompat.to_json_pretty(existing_group_data))
402
- end
400
+ end
401
+ existing_group_data["clients"] = existing_group_data["clients"].sort
402
+ ::File.open(clients_group_path, "w") do |f|
403
+ f.write(Chef::JSONCompat.to_json_pretty(existing_group_data))
403
404
  end
404
405
  end
405
406
 
@@ -4,7 +4,7 @@ class Chef
4
4
  class Knife
5
5
  class TidyNotify < Knife
6
6
  deps do
7
- require "ffi_yajl"
7
+ require "ffi_yajl" unless defined?(FFI_Yajl)
8
8
  require "net/smtp"
9
9
  end
10
10
 
@@ -14,39 +14,39 @@ class Chef
14
14
  short: "-s SERVER_NAME",
15
15
  long: "--smtp_server SERVER_NAME",
16
16
  default: "localhost",
17
- description: "SMTP Server to be used for emailling reports to organization admins (defaults to localhost)"
17
+ description: "SMTP Server to be used for emailing reports to organization admins (defaults to localhost)"
18
18
 
19
19
  option :smtp_port,
20
20
  short: "-p SMTP_PORT",
21
21
  long: "--smtp_port SMTP_PORT",
22
22
  default: 25,
23
- description: "SMTP port to be used for emailling reports to organization admins (defaults to 25)"
23
+ description: "SMTP port to be used for emailing reports to organization admins (defaults to 25)"
24
24
 
25
25
  option :smtp_helo,
26
26
  short: "-h SMTP_HELO",
27
27
  long: "--smtp_helo SMTP_HELO",
28
28
  default: "localhost",
29
- description: "SMTP HELO to be used for emailling reports to organization admins (defaults to localhost)"
29
+ description: "SMTP HELO to be used for emailing reports to organization admins (defaults to localhost)"
30
30
 
31
31
  option :smtp_username,
32
32
  short: "-u SMTP_USERNAME",
33
33
  long: "--smtp_username SMTP_USERNAME",
34
- description: "SMTP Username to be used for emailling reports to organization admins"
34
+ description: "SMTP Username to be used for emailing reports to organization admins"
35
35
 
36
36
  option :smtp_password,
37
37
  long: "--smtp_password SMTP_PASSWORD",
38
- description: "SMTP Password to be used for emailling reports to organization admins"
38
+ description: "SMTP Password to be used for emailing reports to organization admins"
39
39
 
40
40
  option :smtp_from,
41
41
  long: "--smtp_from SMTP_FROM",
42
- description: "SMTP From address to be used for emailling reports to organization admins"
42
+ description: "SMTP From address to be used for emailing reports to organization admins"
43
43
 
44
44
  option :smtp_use_tls,
45
45
  long: "--smtp_use_tls",
46
46
  short: "-t",
47
47
  default: false,
48
48
  boolean: true | false,
49
- description: "Whether TLS should be used for emailling reports to organization admins (defaults to false if omitted)"
49
+ description: "Whether TLS should be used for emailing reports to organization admins (defaults to false if omitted)"
50
50
 
51
51
  include Knife::TidyBase
52
52
 
@@ -6,7 +6,7 @@ class Chef
6
6
  include Knife::TidyBase
7
7
 
8
8
  deps do
9
- require "ffi_yajl"
9
+ require "ffi_yajl" unless defined?(FFI_Yajl)
10
10
  require "chef/util/threaded_job_queue"
11
11
  end
12
12
 
@@ -7,7 +7,7 @@ class Chef
7
7
  include Knife::TidyBase
8
8
 
9
9
  deps do
10
- require "ffi_yajl"
10
+ require "ffi_yajl" unless defined?(FFI_Yajl)
11
11
  end
12
12
 
13
13
  banner "knife tidy server report (options)"
@@ -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
 
@@ -108,7 +106,7 @@ class Chef
108
106
  action_needed(pre_12_3_message, server_warnings_file_path)
109
107
  end
110
108
  if unconverged_recent_nodes.length > 0
111
- unconverged_recent_message = "#{unconverged_recent_nodes.length} nodes have been created in the last hour that have yet to converge in organization #{org}. These nodes WILL NOT be factored in the stale cookbook verisons report. Continuing with the server cleanup will delete cookbooks in-use by these nodes."
109
+ unconverged_recent_message = "#{unconverged_recent_nodes.length} nodes have been created in the last hour that have yet to converge in organization #{org}. These nodes WILL NOT be factored in the stale cookbook versions report. Continuing with the server cleanup will delete cookbooks in-use by these nodes."
112
110
  ui.warn(unconverged_recent_message)
113
111
  action_needed(unconverged_recent_message, server_warnings_file_path)
114
112
  end
@@ -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
@@ -1,5 +1,5 @@
1
- require "ffi_yajl"
2
- require "fileutils"
1
+ require "ffi_yajl" unless defined?(FFI_Yajl)
2
+ require "fileutils" unless defined?(FileUtils)
3
3
  require "chef/log"
4
4
 
5
5
  class Chef
@@ -111,7 +111,7 @@ class Chef
111
111
 
112
112
  def add_client_to_org(actor)
113
113
  # TODO
114
- @tidy.ui.stdout.puts "ACTION NEEDED: Client referenced in acl non-existant: #{actor}"
114
+ @tidy.ui.stdout.puts "ACTION NEEDED: Client referenced in acl non-existent: #{actor}"
115
115
  end
116
116
 
117
117
  def add_actor_to_members(actor)
@@ -1,5 +1,5 @@
1
- require "ffi_yajl"
2
- require "fileutils"
1
+ require "ffi_yajl" unless defined?(FFI_Yajl)
2
+ require "fileutils" unless defined?(FileUtils)
3
3
  require "chef/knife/core/ui"
4
4
 
5
5
  class Chef
@@ -1,6 +1,6 @@
1
- require "ffi_yajl"
2
- require "tempfile"
3
- require "fileutils"
1
+ require "ffi_yajl" unless defined?(FFI_Yajl)
2
+ require "tempfile" unless defined?(Tempfile)
3
+ require "fileutils" unless defined?(FileUtils)
4
4
  require "chef/log"
5
5
 
6
6
  class Chef
@@ -1,4 +1,4 @@
1
1
  module KnifeTidy
2
- VERSION = "2.0.15".freeze
2
+ VERSION = "2.1.6".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.0.15
4
+ version: 2.1.6
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-06-11 00:00:00.000000000 Z
11
+ date: 2022-03-18 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: {}
@@ -49,9 +49,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubygems_version: 3.0.3
52
+ rubygems_version: 3.1.4
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: []