knife-tidy 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +33 -20
- data/lib/chef/knife/tidy_backup_clean.rb +36 -9
- data/lib/chef/tidy_common.rb +1 -1
- data/lib/chef/tidy_substitutions.rb +3 -1
- data/lib/knife-tidy/version.rb +1 -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: 430581b6c4b852bc0b345ce4159519c325be6841
|
4
|
+
data.tar.gz: 4a4578f085705c816c1d5c011fc7772e37779401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc2cb8e6fd15cfe1ffe174b6416e2c886f79ee79399547bd9bad27e91c6a53dabe2f3328dd47c6f69f91689d1626429e54e50c62aebdf2605669688d023b67d2
|
7
|
+
data.tar.gz: 5bff332dbfc245637da73d60a022ebabbd1e25ec2042e184d1b1db7e21f98b67621a6dbd81c69e1a6d754af9546b964bf5c21c76b6cc064fda38ce7bb610c52b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.3.3](https://github.com/chef-customers/knife-tidy/tree/0.3.3) (2017-09-15)
|
4
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.3.2...0.3.3)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- boiler plate gsub file now works [\#25](https://github.com/chef-customers/knife-tidy/pull/25) ([jeremymv2](https://github.com/jeremymv2))
|
9
|
+
- fixing null values and emtpy arrays in metadata.json [\#24](https://github.com/chef-customers/knife-tidy/pull/24) ([jeremymv2](https://github.com/jeremymv2))
|
10
|
+
- Jeremyv2/action needed notification [\#23](https://github.com/chef-customers/knife-tidy/pull/23) ([jeremymv2](https://github.com/jeremymv2))
|
11
|
+
|
3
12
|
## [0.3.2](https://github.com/chef-customers/knife-tidy/tree/0.3.2) (2017-09-14)
|
4
13
|
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.3.1...0.3.2)
|
5
14
|
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
This Chef Knife plugin has two primary purposes:
|
6
6
|
* Report on the state of Chef Server objects that can be tidied up (Future: clean up objects)
|
7
|
-
*
|
7
|
+
* A companion tool to [knife-ec-backup](https://github.com/chef/knife-ec-backup) that will clean up data integrity issues in an object backup
|
8
8
|
|
9
9
|
# Requirements
|
10
10
|
|
@@ -12,7 +12,7 @@ A current Chef Client. Can easily be installed via [Chef DK](https://github.com/
|
|
12
12
|
|
13
13
|
# Installation
|
14
14
|
|
15
|
-
Via
|
15
|
+
Via Rubygems
|
16
16
|
```bash
|
17
17
|
gem install knife-tidy
|
18
18
|
```
|
@@ -31,19 +31,24 @@ The following options are supported across all subcommands:
|
|
31
31
|
* `--orgs ORG1,ORG2`:
|
32
32
|
Only apply to objects in the named organizations (default: all orgs)
|
33
33
|
|
34
|
-
## $ knife tidy server report
|
34
|
+
## $ knife tidy server report --help
|
35
35
|
|
36
36
|
Cookbooks and nodes account for the largest objects in your Chef Server.
|
37
37
|
If you want to keep it lean and mean and easy to port the object data, you must
|
38
|
-
|
38
|
+
tidy these unused objects up!
|
39
39
|
|
40
40
|
## Options
|
41
41
|
|
42
42
|
* `--node-threshold NUM_DAYS`
|
43
43
|
Maximum number of days since last checkin before node is considered stale (default: 30)
|
44
44
|
|
45
|
+
Example:
|
46
|
+
```bash
|
47
|
+
knife tidy server report --orgs brewinc,acmeinc --node-threshold 50
|
48
|
+
```
|
49
|
+
|
45
50
|
## Notes
|
46
|
-
|
51
|
+
`server report` generates json reports as such:
|
47
52
|
|
48
53
|
File Name | Contents
|
49
54
|
--- | ---
|
@@ -51,7 +56,7 @@ org_threshold_numdays_stale_nodes.json | Nodes in that org that have not checked
|
|
51
56
|
org_cookbook_count.json | Number of cookbook versions for each cookbook that that org.
|
52
57
|
org_unused_cookbooks.json | List of cookbooks and versions that do not appear to be in-use for that org. This is determined by checking the versioned run list of each of the nodes in the org.
|
53
58
|
|
54
|
-
## $ knife tidy backup clean
|
59
|
+
## $ knife tidy backup clean --help
|
55
60
|
|
56
61
|
## Options
|
57
62
|
|
@@ -61,39 +66,47 @@ org_unused_cookbooks.json | List of cookbooks and versions that do not appear to
|
|
61
66
|
* `--gsub-file /path/to/gsub/file`:
|
62
67
|
The path to the file used for substitutions. If non-existant, a boiler plate one will be created.
|
63
68
|
|
69
|
+
Run the following example before attempting the `knife ec backup restore` operation:
|
70
|
+
```bash
|
71
|
+
knife tidy backup clean --gen-gsub
|
72
|
+
NFO: Creating boiler plate gsub file: 'substitutions.json'
|
73
|
+
knife tidy backup clean --backup-path backups/ --gsub-file substitutions.json
|
74
|
+
```
|
75
|
+
|
64
76
|
## Notes
|
65
77
|
|
66
78
|
Global file substitutions can be performed when `--gsub-file` option is used. Several known issues are corrected
|
67
|
-
and others can be added with search/replace pairings:
|
68
|
-
|
69
|
-
* DONE: global glob'd file gsub definitions
|
79
|
+
and others can be added with search/replace pairings. The following boiler plate file is created for you when `--gen-gsub` is used:
|
70
80
|
|
71
81
|
```json
|
72
82
|
{
|
73
83
|
"chef-sugar":{
|
74
84
|
"organizations/*/cookbooks/chef-sugar*/metadata.rb":[
|
75
85
|
{
|
76
|
-
"pattern":"require
|
77
|
-
"replace":"# require File.expand_path('../lib/chef/sugar/version', __FILE__)"
|
86
|
+
"pattern":"^require .*/lib/chef/sugar/version",
|
87
|
+
"replace":"# require File.expand_path('../lib/chef/sugar/version', *__FILE__)"
|
78
88
|
},
|
79
89
|
{
|
80
90
|
"pattern":"version *Chef::Sugar::VERSION",
|
81
91
|
"replace":"version !COOKBOOK_VERSION!"
|
82
92
|
}
|
83
93
|
]
|
94
|
+
},
|
95
|
+
"io-read-version-and-readme.md":{
|
96
|
+
"organizations/*/cookbooks/*/metadata.rb":[
|
97
|
+
{
|
98
|
+
"pattern":"^version +IO.read.* 'VERSION'.*",
|
99
|
+
"replace":"version !COOKBOOK_VERSION!"
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"pattern":"^long_description +IO.read.* 'README.md'.*",
|
103
|
+
"replace":"#long_description \"A Long Description..\""
|
104
|
+
}
|
105
|
+
]
|
84
106
|
}
|
85
107
|
}
|
86
108
|
```
|
87
109
|
|
88
|
-
* DONE: metadata validation with `Chef::CookbookLoader`
|
89
|
-
* DONE: metadata.rb and metadata.json inconsistencies correction
|
90
|
-
* DONE: metadata self-dependency correction
|
91
|
-
* DONE: user email validation
|
92
|
-
* DONE: ensure user emails do not cause primary key violation
|
93
|
-
* DONE: ambiguous actors (acl actor exists as client and user)
|
94
|
-
* DONE: users/clients referenced as actors in acls that do not exist in users/clients
|
95
|
-
* DONE: nonexistent groups referenced in acls
|
96
|
-
|
97
110
|
## Summary and Credits
|
98
111
|
|
99
112
|
* Server Report was ported from Nolan Davidson's [chef-cleanup](https://github.com/nsdavidson/chef-cleanup)
|
@@ -25,23 +25,26 @@ class Chef
|
|
25
25
|
:long => '--gsub-file path/to/gsub/file',
|
26
26
|
:description => 'The path to the file used for substitutions. If non-existant, a boiler plate one will be created.'
|
27
27
|
|
28
|
+
option :gen_gsub,
|
29
|
+
:long => '--gen-gsub',
|
30
|
+
:description => 'Generate a new boiler plate global substitutions file: \'substitutions.json\'.'
|
31
|
+
|
28
32
|
def run
|
33
|
+
FileUtils.rm_f(action_needed_file_path)
|
34
|
+
|
35
|
+
if config[:gen_gsub]
|
36
|
+
Chef::TidySubstitutions.new().boiler_plate
|
37
|
+
exit
|
38
|
+
end
|
29
39
|
|
30
40
|
unless config[:backup_path] && ::File.directory?(config[:backup_path])
|
31
41
|
ui.error 'Must specify valid --backup-path'
|
32
42
|
exit 1
|
33
43
|
end
|
34
44
|
|
35
|
-
|
45
|
+
Chef::TidySubstitutions.new(substitutions_file, tidy).run_substitutions if config[:gsub_file]
|
36
46
|
|
37
|
-
|
38
|
-
unless ::File.exist?(config[:gsub_file])
|
39
|
-
Chef::TidySubstitutions.new(substitutions_file).boiler_plate
|
40
|
-
exit
|
41
|
-
else
|
42
|
-
Chef::TidySubstitutions.new(substitutions_file, tidy).run_substitutions
|
43
|
-
end
|
44
|
-
end
|
47
|
+
validate_user_emails
|
45
48
|
|
46
49
|
orgs.each do |org|
|
47
50
|
org_acls = Chef::TidyOrgAcls.new(tidy, org)
|
@@ -54,6 +57,8 @@ class Chef
|
|
54
57
|
end
|
55
58
|
|
56
59
|
completion_message
|
60
|
+
|
61
|
+
puts "\nWARNING: ** Unrepairable Items **\nPlease see #{action_needed_file_path}\n" if ::File.exist?(action_needed_file_path)
|
57
62
|
end
|
58
63
|
|
59
64
|
def validate_user_emails
|
@@ -142,6 +147,7 @@ class Chef
|
|
142
147
|
def generate_new_metadata(org)
|
143
148
|
for_each_cookbook_path(org) do |cookbook_path|
|
144
149
|
generate_metadata_from_file(tidy.cookbook_name_from_path(cookbook_path), cookbook_path)
|
150
|
+
fix_metadata_fields(cookbook_path)
|
145
151
|
end
|
146
152
|
end
|
147
153
|
|
@@ -160,6 +166,27 @@ class Chef
|
|
160
166
|
end
|
161
167
|
end
|
162
168
|
|
169
|
+
def fix_metadata_fields(cookbook_path)
|
170
|
+
json_path = ::File.join(cookbook_path, 'metadata.json')
|
171
|
+
metadata = FFI_Yajl::Parser.parse(::File.read(json_path), symbolize_names: false)
|
172
|
+
md = metadata.dup
|
173
|
+
metadata.each_pair do |key, value|
|
174
|
+
if value.nil?
|
175
|
+
puts "REPAIRING: Fixing null value for key #{key} in #{json_path}"
|
176
|
+
md[key] = 'default value'
|
177
|
+
end
|
178
|
+
end
|
179
|
+
metadata['platforms'].each_pair do |key, value|
|
180
|
+
if value.kind_of?(Array) && value.empty?
|
181
|
+
puts "REPAIRING: Fixing empty platform key for for key #{key} in #{json_path}"
|
182
|
+
md['platforms'][key] = '>= 0.0.0'
|
183
|
+
end
|
184
|
+
end
|
185
|
+
::File.open(json_path, 'w') do |f|
|
186
|
+
f.write(Chef::JSONCompat.to_json_pretty(md))
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
163
190
|
def generate_metadata_from_file(cookbook, path)
|
164
191
|
md_path = ::File.join(path, 'metadata.rb')
|
165
192
|
json_path = ::File.join(path, 'metadata.json')
|
data/lib/chef/tidy_common.rb
CHANGED
@@ -22,7 +22,9 @@ class Chef
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def boiler_plate
|
25
|
-
|
25
|
+
bp = ::File.join(File.dirname(__FILE__), '../../conf/substitutions.json.example')
|
26
|
+
puts "INFO: Creating boiler plate gsub file: 'substitutions.json'"
|
27
|
+
FileUtils.cp(bp, ::File.join(Dir.pwd, 'substitutions.json'))
|
26
28
|
end
|
27
29
|
|
28
30
|
def cookbook_version_from_path(path)
|
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.3.
|
4
|
+
version: 0.3.3
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|