knife-ec-backup 2.2.3 → 2.3.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 +5 -5
- data/lib/chef/knife/ec_backup.rb +2 -0
- data/lib/chef/knife/ec_base.rb +16 -0
- data/lib/chef/knife/ec_key_import.rb +12 -1
- data/lib/chef/knife/ec_restore.rb +3 -0
- data/lib/chef/server.rb +7 -3
- data/lib/knife_ec_backup/version.rb +1 -1
- data/spec/chef/server_spec.rb +10 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e94dbbeb73cf96ad811e14f7f28c23122179345a8e892c56ca1a1b562f727e2
|
4
|
+
data.tar.gz: 2bf04cbef9be2ec11aaccc083ee4b01d8647e7b3b3da6a9aec3f95ada34e1f59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 101b9da212a5407d68829335e264b919760aca883cd9d9aec04a7165a4fb38b0daf86d04126324c681ee59965b80b3b34f8241f0d11eb351af771cf3612e087f
|
7
|
+
data.tar.gz: 5b44c656dc7ed08f8965c0a6492ecdcf76fec04fa81631bd16d4c92dc4061accdbbe3c89b5805514832c88ef4b9c6df1dc5875389d5ca24af3273a349f994615
|
data/lib/chef/knife/ec_backup.rb
CHANGED
data/lib/chef/knife/ec_base.rb
CHANGED
@@ -20,6 +20,7 @@ require 'chef/knife'
|
|
20
20
|
require 'chef/server_api'
|
21
21
|
require 'veil'
|
22
22
|
require 'chef/knife/ec_error_handler'
|
23
|
+
require 'ffi_yajl'
|
23
24
|
|
24
25
|
class Chef
|
25
26
|
class Knife
|
@@ -224,6 +225,21 @@ class Chef
|
|
224
225
|
end
|
225
226
|
end
|
226
227
|
|
228
|
+
def warn_on_incorrect_clients_group(dir, op)
|
229
|
+
orgs = Dir[::File.join(dir, 'organizations', '*')].map { |d| ::File.basename(d) }
|
230
|
+
orgs.each do |org|
|
231
|
+
clients_path = ::File.expand_path(::File.join(dir, 'organizations', org, 'clients'))
|
232
|
+
clients_in_org = Dir[::File.join(clients_path, '*')].map { |d| ::File.basename(d, '.json') }
|
233
|
+
clients_group_path = ::File.expand_path(::File.join(dir, 'organizations', org, 'groups', 'clients.json'))
|
234
|
+
existing_group_data = FFI_Yajl::Parser.parse(::File.read(clients_group_path), symbolize_names: false)
|
235
|
+
existing_group_data['clients'] = [] unless existing_group_data.key?('clients')
|
236
|
+
if existing_group_data['clients'].length != clients_in_org.length
|
237
|
+
ui.warn "There are #{(existing_group_data['clients'].length - clients_in_org.length).abs} missing clients in #{org}'s client group file #{clients_group_path}. If this is not intentional do NOT proceed with a restore until corrected. `knife tidy backup clean` will auto-correct this. https://github.com/chef-customers/knife-tidy"
|
238
|
+
ui.confirm("\nDo you still wish to continue with the restore?") if op == "restore"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
227
243
|
def completion_banner
|
228
244
|
puts "#{ui.color("** Finished **", :magenta)}"
|
229
245
|
end
|
@@ -165,6 +165,7 @@ class Chef
|
|
165
165
|
|
166
166
|
def import_user_data(path)
|
167
167
|
key_data = JSON.parse(File.read(path))
|
168
|
+
knife_ec_error_handler = config[:knife_ec_error_handler]
|
168
169
|
key_data.each do |d|
|
169
170
|
if d['username'] == 'pivotal' && config[:skip_pivotal]
|
170
171
|
ui.warn "Skipping pivotal user."
|
@@ -190,7 +191,17 @@ class Chef
|
|
190
191
|
d['hashed_password'] = nil
|
191
192
|
d['salt'] = nil
|
192
193
|
end
|
193
|
-
|
194
|
+
begin
|
195
|
+
users_to_update.update(d)
|
196
|
+
rescue => ex
|
197
|
+
ui.warn "Could not restore user #{d['username']}"
|
198
|
+
if ex.class == Sequel::ForeignKeyConstraintViolation
|
199
|
+
message = "This error usually indicates that a user already exists with a different ID and is associated with one or more organizations on the target system. The username is #{d['username']} and the ID in the backup files is #{d['id']}"
|
200
|
+
ui.warn message
|
201
|
+
ex = ex.exception "#{ex.message} #{message}"
|
202
|
+
end
|
203
|
+
knife_ec_error_handler.add(ex) if knife_ec_error_handler
|
204
|
+
end
|
194
205
|
end
|
195
206
|
end
|
196
207
|
end
|
@@ -39,6 +39,8 @@ class Chef
|
|
39
39
|
ensure_webui_key_exists!
|
40
40
|
set_skip_user_acl!
|
41
41
|
|
42
|
+
warn_on_incorrect_clients_group(dest_dir, "restore")
|
43
|
+
|
42
44
|
restore_users unless config[:skip_users]
|
43
45
|
restore_user_sql if config[:with_user_sql]
|
44
46
|
|
@@ -186,6 +188,7 @@ class Chef
|
|
186
188
|
|
187
189
|
def restore_user_sql
|
188
190
|
k = ec_key_import
|
191
|
+
k.config[:knife_ec_error_handler] = knife_ec_error_handler
|
189
192
|
k.config[:skip_users_table] = false
|
190
193
|
k.config[:skip_keys_table] = !config[:with_key_sql]
|
191
194
|
k.config[:users_only] = true
|
data/lib/chef/server.rb
CHANGED
@@ -15,13 +15,17 @@ class Chef
|
|
15
15
|
Chef::Server.new(url)
|
16
16
|
end
|
17
17
|
|
18
|
+
def parse_server_version(line)
|
19
|
+
# first line from the /version endpoint will either be this format "chef-server 12.17.5\n"
|
20
|
+
# or, when habitat, this format "Package: chef-server/chef-server-nginx/12.17.42/20180413212943\n"
|
21
|
+
Gem::Version.new(line.include?('/') ? line.split('/')[2] : line.split(' ').last.gsub(/\+.*$/, ''))
|
22
|
+
end
|
23
|
+
|
18
24
|
def version
|
19
25
|
@version ||= begin
|
20
26
|
uri = URI.parse("#{root_url}/version")
|
21
27
|
ver_line = open(uri, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).each_line.first
|
22
|
-
|
23
|
-
ver_string = ver_string.gsub(/\+.*$/, '')
|
24
|
-
Gem::Version.new(ver_string)
|
28
|
+
parse_server_version(ver_line)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
data/spec/chef/server_spec.rb
CHANGED
@@ -10,10 +10,16 @@ describe Chef::Server do
|
|
10
10
|
expect(s.root_url).to eq("http://api.example.com")
|
11
11
|
end
|
12
12
|
|
13
|
-
it "determines the
|
14
|
-
s = Chef::Server.new(
|
13
|
+
it "determines the running habitat service pkg version" do
|
14
|
+
s = Chef::Server.new('http://api.example.com')
|
15
|
+
allow(s).to receive(:open).and_return(StringIO.new("Package: chef-server/chef-server-nginx/12.17.42/20180413212943\nother stuff\nother stuff"))
|
16
|
+
expect(s.version.to_s).to eq('12.17.42')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "determines the running omnibus server version" do
|
20
|
+
s = Chef::Server.new('http://api.example.com')
|
15
21
|
allow(s).to receive(:open).and_return(StringIO.new("Chef Server 1.8.1\nother stuff\nother stuff"))
|
16
|
-
expect(s.version.to_s).to eq(
|
22
|
+
expect(s.version.to_s).to eq('1.8.1')
|
17
23
|
end
|
18
24
|
|
19
25
|
it "ignores git tags when determining the version" do
|
@@ -22,7 +28,7 @@ describe Chef::Server do
|
|
22
28
|
expect(s.version.to_s).to eq("1.8.1")
|
23
29
|
end
|
24
30
|
|
25
|
-
it "knows whether the server supports user ACLs via
|
31
|
+
it "knows whether the server supports user ACLs via nginx" do
|
26
32
|
s1 = Chef::Server.new("http://api.example.com")
|
27
33
|
s2 = Chef::Server.new("http://api.example.com")
|
28
34
|
allow(s1).to receive(:open).and_return(StringIO.new("Chef Server 11.0.0\nother stuff\nother stuff"))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-ec-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.6
|
121
|
+
rubygems_version: 2.7.6
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Backup and Restore of Enterprise Chef
|