knife-tidy 0.3.6 → 0.4.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/CHANGELOG.md +11 -0
- data/Rakefile +0 -23
- data/lib/chef/knife/tidy_backup_clean.rb +90 -1
- data/lib/chef/tidy_common.rb +4 -0
- data/lib/knife-tidy/version.rb +1 -1
- data/spec/chef/knife/tidy_backup_clean_spec.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c88d6c7424cf8313b281efc0f68e2d635df4fae
|
4
|
+
data.tar.gz: 2fb450888ca5ca8d612b73efcb810806314246b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c63e4dd5f37b8a9cf028430455727243d944e01b13bca25b4562d00ea16b8fed5a86d47adcc727935197e95dfd60792d5cbcda7f6ca4f85a6ea580acdffefcd1
|
7
|
+
data.tar.gz: cbdeb1bca74cee204b16ec6bb89c6bab18263d73f98268a58197a2bd8b8d9107cfeac88298c522d543cadc63854ba1f1a4f08647bf2a735ae12332143e9a8804
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.4.0](https://github.com/chef-customers/knife-tidy/tree/0.4.0) (2017-09-26)
|
4
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.3.6...0.4.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- fix NilClass on env\_run\_lists [\#35](https://github.com/chef-customers/knife-tidy/pull/35) ([jeremymv2](https://github.com/jeremymv2))
|
9
|
+
- fix merge conflict from rebase [\#34](https://github.com/chef-customers/knife-tidy/pull/34) ([jeremymv2](https://github.com/jeremymv2))
|
10
|
+
- Simple feature to clean up EC11 org objects which don't load into CS12 [\#33](https://github.com/chef-customers/knife-tidy/pull/33) ([irvingpop](https://github.com/irvingpop))
|
11
|
+
- role run\_list clean up and metadata name regex simplification [\#32](https://github.com/chef-customers/knife-tidy/pull/32) ([jeremymv2](https://github.com/jeremymv2))
|
12
|
+
- bump to 0.3.6 [\#30](https://github.com/chef-customers/knife-tidy/pull/30) ([jeremymv2](https://github.com/jeremymv2))
|
13
|
+
|
3
14
|
## [0.3.6](https://github.com/chef-customers/knife-tidy/tree/0.3.6) (2017-09-25)
|
4
15
|
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.3.5...0.3.6)
|
5
16
|
|
data/Rakefile
CHANGED
@@ -42,29 +42,6 @@ rescue LoadError => e
|
|
42
42
|
puts ">>> Gem load error: #{e}, omitting spec" unless ENV['CI']
|
43
43
|
end
|
44
44
|
|
45
|
-
# Integration tests. Kitchen.ci
|
46
|
-
namespace :integration do
|
47
|
-
begin
|
48
|
-
require 'kitchen/rake_tasks'
|
49
|
-
|
50
|
-
desc 'Run kitchen integration tests'
|
51
|
-
Kitchen::RakeTasks.new
|
52
|
-
rescue StandardError => e
|
53
|
-
puts ">>> Kitchen error: #{e}, omitting #{task.name}" unless ENV['CI']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
namespace :supermarket do
|
58
|
-
begin
|
59
|
-
require 'stove/rake_task'
|
60
|
-
|
61
|
-
desc 'Publish cookbook to Supermarket with Stove'
|
62
|
-
Stove::RakeTask.new
|
63
|
-
rescue LoadError => e
|
64
|
-
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
45
|
# Changelog
|
69
46
|
namespace :changelog do
|
70
47
|
begin
|
@@ -7,10 +7,13 @@ class Chef
|
|
7
7
|
deps do
|
8
8
|
require 'chef/cookbook_loader'
|
9
9
|
require 'chef/cookbook/metadata'
|
10
|
+
require 'chef/role'
|
11
|
+
require 'chef/run_list'
|
10
12
|
require 'chef/tidy_substitutions'
|
11
13
|
require 'chef/tidy_acls'
|
12
14
|
require 'ffi_yajl'
|
13
15
|
require 'fileutils'
|
16
|
+
require 'securerandom'
|
14
17
|
end
|
15
18
|
|
16
19
|
banner "knife tidy backup clean (options)"
|
@@ -47,6 +50,8 @@ class Chef
|
|
47
50
|
validate_user_emails
|
48
51
|
|
49
52
|
orgs.each do |org|
|
53
|
+
fix_org_object(org)
|
54
|
+
validate_roles(org)
|
50
55
|
org_acls = Chef::TidyOrgAcls.new(tidy, org)
|
51
56
|
org_acls.validate_acls
|
52
57
|
org_acls.validate_user_acls
|
@@ -89,10 +94,40 @@ class Chef
|
|
89
94
|
end
|
90
95
|
end
|
91
96
|
|
97
|
+
# In Chef Server 12 an org object should have exactly 3 keys: name, full_name and guid
|
98
|
+
# The existence of anything else will cause a restore to fail
|
99
|
+
# EC11 backups will contain org objects with 6 extra fields including org_type, billing_plan, assigned_at, etc
|
100
|
+
def fix_org_object(org)
|
101
|
+
puts "INFO: Validating org object for #{org}"
|
102
|
+
org_object = load_org_object(org)
|
103
|
+
|
104
|
+
unless org_object.keys.count == 3 # cheapo, maybe expect the exact names?
|
105
|
+
puts "REPAIRING: org object for #{org} contains extra/missing fields. Fixing that for you"
|
106
|
+
# quick/dirty attempt at fixing any of the required fields in case they're nil
|
107
|
+
good_name = org_object['name'] || org
|
108
|
+
good_full_name = org_object['full_name'] || org
|
109
|
+
good_guid = org_object['guid'] || SecureRandom.uuid.gsub('-','')
|
110
|
+
fixed_org_object = { name: good_name, full_name: good_full_name, guid: good_guid }
|
111
|
+
|
112
|
+
write_org_object(org, fixed_org_object)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def load_org_object(org)
|
117
|
+
JSON.parse(File.read(File.join(tidy.org_path(org), 'org.json')))
|
118
|
+
rescue Errno::ENOENT, JSON::ParserError
|
119
|
+
puts "REPAIRING: org object for organization #{org} is missing or corrupt. Generating a new one"
|
120
|
+
return { name: org, full_name: org, guid: SecureRandom.uuid.gsub('-','') }
|
121
|
+
end
|
122
|
+
|
123
|
+
def write_org_object(org, org_object)
|
124
|
+
File.write(File.join(tidy.org_path(org), 'org.json') , JSON.pretty_generate(org_object))
|
125
|
+
end
|
126
|
+
|
92
127
|
def add_cookbook_name_to_metadata(cookbook_name, rb_path)
|
93
128
|
puts "REPAIRING: Correcting `name` in #{rb_path}"
|
94
129
|
content = IO.readlines(rb_path)
|
95
|
-
new_content = content.
|
130
|
+
new_content = content.reject { |line| line =~ /^name .*/ }
|
96
131
|
name_field = "name '#{cookbook_name}'\n"
|
97
132
|
IO.write rb_path, name_field + new_content.join('')
|
98
133
|
end
|
@@ -276,6 +311,60 @@ class Chef
|
|
276
311
|
f.write(msg + "\n")
|
277
312
|
end
|
278
313
|
end
|
314
|
+
|
315
|
+
def write_role(path, role)
|
316
|
+
::File.open(path, 'w') do |f|
|
317
|
+
f.write(Chef::JSONCompat.to_json_pretty(role))
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def for_each_role(org)
|
322
|
+
Dir[::File.join(tidy.roles_path(org), '*.json')].each do |role|
|
323
|
+
yield role
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def repair_role_run_lists(role_path)
|
328
|
+
# rubocop:disable MethodLength
|
329
|
+
the_role = FFI_Yajl::Parser.parse(::File.read(role_path), symbolize_names: false)
|
330
|
+
new_role = the_role.clone
|
331
|
+
rl = Chef::RunList.new
|
332
|
+
new_role['run_list'] = []
|
333
|
+
the_role['run_list'].each do |item|
|
334
|
+
begin
|
335
|
+
rl << item
|
336
|
+
new_role['run_list'].push(item)
|
337
|
+
rescue ArgumentError
|
338
|
+
puts "REPAIRING: Invalid Recipe Item: #{item} in run_list from #{role_path}"
|
339
|
+
end
|
340
|
+
end
|
341
|
+
if the_role.has_key?('env_run_lists')
|
342
|
+
the_role['env_run_lists'].each_pair do |key, value|
|
343
|
+
new_role['env_run_lists'][key] = []
|
344
|
+
value.each do |item|
|
345
|
+
begin
|
346
|
+
rl << item
|
347
|
+
new_role['env_run_lists'][key].push(item)
|
348
|
+
rescue ArgumentError
|
349
|
+
puts "REPAIRING: Invalid Recipe Item: #{item} in env_run_lists #{key} from #{role_path}"
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
write_role(role_path, new_role)
|
355
|
+
# rubocop:enable MethodLength
|
356
|
+
end
|
357
|
+
|
358
|
+
def validate_roles(org)
|
359
|
+
for_each_role(org) do |role_path|
|
360
|
+
puts "INFO: Validating Role at #{role_path}"
|
361
|
+
begin
|
362
|
+
Chef::Role.from_hash(FFI_Yajl::Parser.parse(::File.read(role_path), symbolize_names: false))
|
363
|
+
rescue ArgumentError
|
364
|
+
repair_role_run_lists(role_path)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
279
368
|
end
|
280
369
|
end
|
281
370
|
end
|
data/lib/chef/tidy_common.rb
CHANGED
@@ -37,6 +37,10 @@ class Chef
|
|
37
37
|
::File.expand_path(::File.join(@backup_path, 'organizations', org, 'cookbooks'))
|
38
38
|
end
|
39
39
|
|
40
|
+
def roles_path(org)
|
41
|
+
::File.expand_path(::File.join(@backup_path, 'organizations', org, 'roles'))
|
42
|
+
end
|
43
|
+
|
40
44
|
def org_path(org)
|
41
45
|
::File.expand_path(::File.join(@backup_path, 'organizations', org))
|
42
46
|
end
|
data/lib/knife-tidy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-tidy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|