knife-tidy 0.1.0 → 0.1.1
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 +12 -0
- data/README.md +42 -8
- data/Rakefile +13 -1
- data/lib/chef/knife/tidy_backup_clean.rb +45 -6
- data/lib/chef/knife/tidy_base.rb +4 -0
- data/lib/knife-tidy/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d41634bad35e623a19ebe00e33d890aa31c6e4e9
|
4
|
+
data.tar.gz: dc4576d52dc94ea7c5dce5e72d6045dc4ddbb634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 309ce63b1bd9eb385a901efdc4cc185cc04a2953bf88064a5aad88a28d7beb7109eee64956f0e7f3956eac9a549e954e2b957753d0059f3f55893d48f0feca0d
|
7
|
+
data.tar.gz: c7d6e786d7f4ece31e628d3dd3976cf0f723e4bb2db0815851fa68ecf448f5976461897fac525702761997d1f8b380d4e0a99d88eb490656e40d7198685063fe
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [0.1.1](https://github.com/jeremymv2/knife-tidy/tree/0.1.1) (2017-08-11)
|
4
|
+
[Full Changelog](https://github.com/jeremymv2/knife-tidy/compare/0.1.1...0.1.1)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- bump version to 0.1.1 [\#2](https://github.com/jeremymv2/knife-tidy/pull/2) ([jeremymv2](https://github.com/jeremymv2))
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -33,6 +33,10 @@ The following options are supported across all subcommands:
|
|
33
33
|
|
34
34
|
# knife tidy server report (options)
|
35
35
|
|
36
|
+
Cookbooks and nodes account for the largest objects in your Chef Server.
|
37
|
+
If you want to keep it lean and mean and easy to port the object data, you must
|
38
|
+
clean any of these unused objects up!
|
39
|
+
|
36
40
|
## Options
|
37
41
|
|
38
42
|
* `--node-threshold NUM_DAYS`
|
@@ -43,23 +47,53 @@ The following options are supported across all subcommands:
|
|
43
47
|
|
44
48
|
File Name | Contents
|
45
49
|
--- | ---
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
org_threshold_numdays_stale_nodes.json | Nodes in that org that have not checked in for the number of days specified.
|
51
|
+
org_cookbook_count.json | Number of cookbook versions for each cookbook that that org.
|
52
|
+
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.
|
49
53
|
|
50
54
|
# knife tidy backup clean (options)
|
51
55
|
|
52
56
|
## Options
|
53
57
|
|
54
58
|
* `--repo-path /path/to/chef-repo`:
|
55
|
-
The Chef Repo to
|
56
|
-
|
59
|
+
The Chef Repo to tidy up (such as one created from a [knife-ec-backup](https://github.com/chef/knife-ec-backup)
|
60
|
+
|
61
|
+
* `--gsub-file path/to/gsub/file`:
|
62
|
+
The path to the file used for substitutions. If non-existant, a boiler plate one will be created.
|
57
63
|
|
58
64
|
## Notes
|
59
65
|
|
60
|
-
|
61
|
-
|
66
|
+
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
|
70
|
+
|
71
|
+
```json
|
72
|
+
{
|
73
|
+
"chef-sugar":{
|
74
|
+
"organizations/*/cookbooks/chef-sugar*/metadata.rb":[
|
75
|
+
{
|
76
|
+
"pattern":"require +File.expand_path('../lib/chef/sugar/version', __FILE__)",
|
77
|
+
"replace":"# require File.expand_path('../lib/chef/sugar/version', __FILE__)"
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"pattern":"version *Chef::Sugar::VERSION",
|
81
|
+
"replace":"# version !COOKBOOK_VERSION!"
|
82
|
+
}
|
83
|
+
]
|
84
|
+
}
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
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
|
+
* TODO: ambiguous actors (acl actor exists as client and user)
|
94
|
+
* TODO: users/clients referenced as actors in acls that do not exist in users/clients
|
95
|
+
* TODO: nonexistent groups referenced in acls
|
62
96
|
|
63
|
-
|
97
|
+
## Summary and Credits
|
64
98
|
|
65
99
|
* Server Report was ported from Nolan Davidson's [chef-cleanup](https://github.com/nsdavidson/chef-cleanup)
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
|
3
|
-
require_relative 'tasks/maintainers'
|
3
|
+
# require_relative 'tasks/maintainers'
|
4
4
|
|
5
5
|
# Style tests. cookstyle (rubocop) and Foodcritic
|
6
6
|
namespace :style do
|
@@ -65,5 +65,17 @@ namespace :supermarket do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
# Changelog
|
69
|
+
namespace :changelog do
|
70
|
+
begin
|
71
|
+
require 'github_changelog_generator/task'
|
72
|
+
|
73
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
74
|
+
config.since_tag = '0.1.1'
|
75
|
+
config.future_release = '0.1.1'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
68
80
|
# Default
|
69
81
|
task default: %w(style spec)
|
@@ -10,6 +10,7 @@ class Chef
|
|
10
10
|
require 'chef/cookbook_loader'
|
11
11
|
require 'chef/cookbook/metadata'
|
12
12
|
require 'chef/tidy_substitutions'
|
13
|
+
require 'ffi_yajl'
|
13
14
|
end
|
14
15
|
|
15
16
|
option :backup_path,
|
@@ -18,7 +19,7 @@ class Chef
|
|
18
19
|
|
19
20
|
option :gsub_file,
|
20
21
|
:long => '--gsub-file path/to/gsub/file',
|
21
|
-
:description => 'The path to the file used for substitutions'
|
22
|
+
:description => 'The path to the file used for substitutions. If non-existant, a boiler plate one will be created.'
|
22
23
|
|
23
24
|
def run
|
24
25
|
unless config[:backup_path]
|
@@ -26,13 +27,12 @@ class Chef
|
|
26
27
|
exit 1
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
validate_user(user)
|
31
|
-
end
|
30
|
+
validate_user_emails!
|
32
31
|
|
33
32
|
if config[:gsub_file]
|
34
|
-
|
33
|
+
unless ::File.exist?(config[:gsub_file])
|
35
34
|
Chef::TidySubstitutions.new(substitutions_file).boiler_plate
|
35
|
+
exit
|
36
36
|
else
|
37
37
|
Chef::TidySubstitutions.new(substitutions_file, backup_path_expanded).run_substitutions
|
38
38
|
end
|
@@ -45,6 +45,45 @@ class Chef
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def validate_user_emails!
|
49
|
+
emails_seen = []
|
50
|
+
global_users.each do |user|
|
51
|
+
email = ''
|
52
|
+
ui.info "Validating #{user}"
|
53
|
+
the_user = FFI_Yajl::Parser.parse(::File.read(::File.join(global_users_path_expanded, "#{user}.json")), symbolize_names: false)
|
54
|
+
if the_user['email'].match(/\A[^@\s]+@[^@\s]+\z/)
|
55
|
+
if emails_seen.include?(the_user['email'])
|
56
|
+
ui.info "Already saw #{user}'s email, creating a unique one."
|
57
|
+
email = unique_email
|
58
|
+
new_user = the_user.dup
|
59
|
+
new_user['email'] = email
|
60
|
+
save_user(new_user)
|
61
|
+
emails_seen.push(email)
|
62
|
+
else
|
63
|
+
emails_seen.push(the_user['email'])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
ui.info "User #{user} does not have a valid email, creating a unique one."
|
67
|
+
email = unique_email
|
68
|
+
new_user = the_user.dup
|
69
|
+
new_user['email'] = email
|
70
|
+
save_user(new_user)
|
71
|
+
emails_seen.push(email)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def unique_email
|
77
|
+
(0...8).map { (65 + rand(26)).chr }.join.downcase +
|
78
|
+
'@' + (0...8).map { (65 + rand(26)).chr }.join.downcase + '.com'
|
79
|
+
end
|
80
|
+
|
81
|
+
def save_user(user)
|
82
|
+
::File.open(::File.join(global_users_path_expanded, "#{user['username']}.json"), 'w+') do |f|
|
83
|
+
f.write(FFI_Yajl::Encoder.encode(user, pretty: true))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
48
87
|
def load_cookbooks(org)
|
49
88
|
cl = Chef::CookbookLoader.new(cookbooks_path_expanded(org))
|
50
89
|
for_each_cookbook_basename(org) do |cookbook|
|
@@ -87,7 +126,7 @@ class Chef
|
|
87
126
|
ui.warn "No metadata.rb in #{path} - skipping"
|
88
127
|
return
|
89
128
|
end
|
90
|
-
ui.info "
|
129
|
+
ui.info "Generating new metadata.json for #{path}"
|
91
130
|
md = Chef::Cookbook::Metadata.new
|
92
131
|
md.name(cookbook)
|
93
132
|
md.from_file(md_path)
|
data/lib/chef/knife/tidy_base.rb
CHANGED
@@ -60,6 +60,10 @@ class Chef
|
|
60
60
|
::File.expand_path(::File.join(backup_path_expanded, 'organizations', org, 'cookbooks'))
|
61
61
|
end
|
62
62
|
|
63
|
+
def global_users_path_expanded
|
64
|
+
::File.expand_path(::File.join(backup_path_expanded, 'users'))
|
65
|
+
end
|
66
|
+
|
63
67
|
def substitutions_file
|
64
68
|
::File.expand_path(config[:gsub_file])
|
65
69
|
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.1.
|
4
|
+
version: 0.1.1
|
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-08-
|
11
|
+
date: 2017-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -103,6 +103,7 @@ extensions: []
|
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
105
|
- ".gitignore"
|
106
|
+
- CHANGELOG.md
|
106
107
|
- Gemfile
|
107
108
|
- LICENSE
|
108
109
|
- README.md
|