knife-tidy 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/lib/chef/knife/tidy_backup_clean.rb +28 -9
- data/lib/chef/knife/tidy_server_clean.rb +4 -3
- data/lib/chef/tidy_acls.rb +9 -9
- 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: 13a4147cae7f0309f48d49dfc0e014b0afa8d62b
|
4
|
+
data.tar.gz: '009379a697f1930e43f149ef2c072eb75238afba'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcbb69f54629feffb1d4709445f8dab998826898fbfaa2c6a4bd195deeb2ac39c88d341b49174feea4cb0fd15d394e481d5aa38e5905d3552dab91bfc9d54f3c
|
7
|
+
data.tar.gz: a1edef340c2bd84270101ff2f7359d3ad990ad9ff07142b42085df01fd11ab56d55de80df057f2cc66e6d2d1fea075293e4792dd779042d4ef3699175ed25fc8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.2.4](https://github.com/chef-customers/knife-tidy/tree/0.2.4) (2017-09-12)
|
4
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.2.3...0.2.4)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- disable server clean [\#17](https://github.com/chef-customers/knife-tidy/pull/17) ([jeremymv2](https://github.com/jeremymv2))
|
9
|
+
- bump patch to 0.2.4 [\#16](https://github.com/chef-customers/knife-tidy/pull/16) ([jeremymv2](https://github.com/jeremymv2))
|
10
|
+
- correct any cookbook metadata name issues [\#15](https://github.com/chef-customers/knife-tidy/pull/15) ([jeremymv2](https://github.com/jeremymv2))
|
11
|
+
|
12
|
+
## [0.2.3](https://github.com/chef-customers/knife-tidy/tree/0.2.3) (2017-09-11)
|
13
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.2.2...0.2.3)
|
14
|
+
|
15
|
+
**Merged pull requests:**
|
16
|
+
|
17
|
+
- setting required ruby to \>= 2.0.0 [\#14](https://github.com/chef-customers/knife-tidy/pull/14) ([jeremymv2](https://github.com/jeremymv2))
|
18
|
+
|
3
19
|
## [0.2.2](https://github.com/chef-customers/knife-tidy/tree/0.2.2) (2017-09-11)
|
4
20
|
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.2.1...0.2.2)
|
5
21
|
|
@@ -31,4 +47,4 @@
|
|
31
47
|
|
32
48
|
|
33
49
|
|
34
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
50
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
@@ -46,6 +46,7 @@ class Chef
|
|
46
46
|
org_acls.validate_acls
|
47
47
|
org_acls.validate_user_acls
|
48
48
|
fix_self_dependencies(org)
|
49
|
+
fix_cookbook_names(org)
|
49
50
|
load_cookbooks(org)
|
50
51
|
generate_new_metadata(org)
|
51
52
|
end
|
@@ -57,11 +58,11 @@ class Chef
|
|
57
58
|
emails_seen = []
|
58
59
|
tidy.global_user_names.each do |user|
|
59
60
|
email = ''
|
60
|
-
|
61
|
+
puts "INFO: Validating #{user}"
|
61
62
|
the_user = FFI_Yajl::Parser.parse(::File.read(::File.join(tidy.users_path, "#{user}.json")), symbolize_names: false)
|
62
63
|
if the_user['email'].match(/\A[^@\s]+@[^@\s]+\z/)
|
63
64
|
if emails_seen.include?(the_user['email'])
|
64
|
-
|
65
|
+
puts "REPAIRING: Already saw #{user}'s email, creating a unique one."
|
65
66
|
email = tidy.unique_email
|
66
67
|
new_user = the_user.dup
|
67
68
|
new_user['email'] = email
|
@@ -71,7 +72,7 @@ class Chef
|
|
71
72
|
emails_seen.push(the_user['email'])
|
72
73
|
end
|
73
74
|
else
|
74
|
-
|
75
|
+
puts "REPAIRING: User #{user} does not have a valid email, creating a unique one."
|
75
76
|
email = tidy.unique_email
|
76
77
|
new_user = the_user.dup
|
77
78
|
new_user['email'] = email
|
@@ -81,19 +82,37 @@ class Chef
|
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
85
|
+
def add_cookbook_name_to_metadata(cookbook_name, rb_path)
|
86
|
+
puts "REPAIRING: Correcting `name` in #{rb_path}"
|
87
|
+
content = IO.readlines(rb_path)
|
88
|
+
new_content = content.select { |line| line !~ /^name.*['"]\S+['"]/ }
|
89
|
+
name_field = "name '#{cookbook_name}'\n"
|
90
|
+
IO.write rb_path, name_field + new_content.join('')
|
91
|
+
end
|
92
|
+
|
93
|
+
def fix_cookbook_names(org)
|
94
|
+
for_each_cookbook_path(org) do |cookbook_path|
|
95
|
+
rb_path = ::File.join(cookbook_path, 'metadata.rb')
|
96
|
+
next unless ::File.exist?(rb_path)
|
97
|
+
cookbook_name = tidy.cookbook_name_from_path(cookbook_path)
|
98
|
+
lines = ::File.readlines(rb_path).select { |line| line =~ /^name.*['"]#{cookbook_name}['"]/ }
|
99
|
+
add_cookbook_name_to_metadata(cookbook_name, rb_path) if lines.empty?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
84
103
|
def load_cookbooks(org)
|
85
104
|
cl = Chef::CookbookLoader.new(tidy.cookbooks_path(org))
|
86
105
|
for_each_cookbook_basename(org) do |cookbook|
|
87
|
-
|
106
|
+
puts "INFO: Loading #{cookbook}"
|
88
107
|
ret = cl.load_cookbook(cookbook)
|
89
108
|
if ret.nil?
|
90
|
-
|
109
|
+
puts "ACTION NEEDED: Something's wrong with the #{cookbook} cookbook - cannot load it! Moving to cookbooks.broken folder."
|
91
110
|
broken_cookooks_add(org, cookbook)
|
92
111
|
end
|
93
112
|
end
|
94
113
|
rescue LoadError => e
|
95
114
|
ui.error e
|
96
|
-
|
115
|
+
puts 'ACTION NEEDED: Look at the cookbook above and determine what in the metadata.rb is causing the exception and rectify manually'
|
97
116
|
exit 1
|
98
117
|
end
|
99
118
|
|
@@ -116,7 +135,7 @@ class Chef
|
|
116
135
|
name = tidy.cookbook_name_from_path(cookbook_path)
|
117
136
|
md_path = ::File.join(cookbook_path, 'metadata.rb')
|
118
137
|
unless ::File.exist?(md_path)
|
119
|
-
|
138
|
+
puts "INFO: No metadata.rb in #{cookbook_path} - skipping"
|
120
139
|
next
|
121
140
|
end
|
122
141
|
Chef::TidySubstitutions.new.sub_in_file(
|
@@ -129,10 +148,10 @@ class Chef
|
|
129
148
|
def generate_metadata_from_file(cookbook, path)
|
130
149
|
md_path = ::File.join(path, 'metadata.rb')
|
131
150
|
unless ::File.exist?(md_path)
|
132
|
-
|
151
|
+
puts "INFO: No metadata.rb in #{path} - skipping"
|
133
152
|
return
|
134
153
|
end
|
135
|
-
|
154
|
+
puts "INFO: Generating new metadata.json for #{path}"
|
136
155
|
md = Chef::Cookbook::Metadata.new
|
137
156
|
md.name(cookbook)
|
138
157
|
md.from_file(md_path)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# not enabled
|
2
|
-
return
|
3
|
-
|
4
1
|
require 'chef/knife/tidy_base'
|
5
2
|
|
6
3
|
class Chef
|
@@ -30,6 +27,10 @@ class Chef
|
|
30
27
|
:description => 'Only delete stale nodes from Chef Server.'
|
31
28
|
|
32
29
|
def run
|
30
|
+
# not enabled
|
31
|
+
ui.warn "This feature is not enabled"
|
32
|
+
exit
|
33
|
+
|
33
34
|
STDOUT.sync = true
|
34
35
|
|
35
36
|
ensure_reports_dir
|
data/lib/chef/tidy_acls.rb
CHANGED
@@ -18,26 +18,26 @@ class Chef
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def load_users
|
21
|
-
|
21
|
+
puts "INFO: Loading users"
|
22
22
|
Dir[::File.join(@tidy.users_path, '*.json')].each do |user|
|
23
23
|
@users.push(FFI_Yajl::Parser.parse(::File.read(user), symbolize_names: true))
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def load_members
|
28
|
-
|
28
|
+
puts "INFO: Loading members for #{@org}"
|
29
29
|
@members = FFI_Yajl::Parser.parse(::File.read(@tidy.members_path(@org)), symbolize_names: true)
|
30
30
|
end
|
31
31
|
|
32
32
|
def load_clients
|
33
|
-
|
33
|
+
puts "INFO: Loading clients for #{@org}"
|
34
34
|
Dir[::File.join(@tidy.clients_path(@org), '*.json')].each do |client|
|
35
35
|
@clients.push(FFI_Yajl::Parser.parse(::File.read(client), symbolize_names: true))
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
def load_groups
|
40
|
-
|
40
|
+
puts "INFO: Loading groups for #{@org}"
|
41
41
|
Dir[::File.join(@tidy.groups_path(@org), '*.json')].each do |group|
|
42
42
|
@groups.push(FFI_Yajl::Parser.parse(::File.read(group), symbolize_names: true))
|
43
43
|
end
|
@@ -48,7 +48,7 @@ class Chef
|
|
48
48
|
load_members
|
49
49
|
load_clients
|
50
50
|
load_groups
|
51
|
-
|
51
|
+
puts "INFO: #{@org} Actors loaded!"
|
52
52
|
end
|
53
53
|
|
54
54
|
def acl_ops
|
@@ -105,17 +105,17 @@ class Chef
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def fix_ambiguous_actor(actor)
|
108
|
-
|
108
|
+
puts "REPAIRING: Ambiguous actor! #{actor} removing from #{@tidy.members_path(@org)}"
|
109
109
|
remove_user_from_org(actor)
|
110
110
|
end
|
111
111
|
|
112
112
|
def add_client_to_org(actor)
|
113
113
|
# TODO
|
114
|
-
|
114
|
+
puts "ACTION NEEDED: Client referenced in acl non-existant: #{actor}"
|
115
115
|
end
|
116
116
|
|
117
117
|
def add_actor_to_members(actor)
|
118
|
-
|
118
|
+
puts "REPAIRING: Invalid actor: #{actor} adding to #{@tidy.members_path(@org)}"
|
119
119
|
user = { user: { username: actor } }
|
120
120
|
@members.push(user)
|
121
121
|
write_new_file(@members, @tidy.members_path(@org))
|
@@ -134,7 +134,7 @@ class Chef
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def remove_group_from_acl(group, acl_file)
|
137
|
-
|
137
|
+
puts "REPAIRING: Removing invalid group: #{group} from #{acl_file}"
|
138
138
|
acl = FFI_Yajl::Parser.parse(::File.read(acl_file), symbolize_names: false)
|
139
139
|
acl_ops.each do |op|
|
140
140
|
acl[op]['groups'].reject! { |the_group| the_group == group }
|
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.2.
|
4
|
+
version: 0.2.4
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|