knife-ec-backup 2.2.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 49eae40bfe9da28186050773eef46ac2cd63a1f4
4
- data.tar.gz: 1669ea6a6b98ec0154889832a2ed382d21376d7f
2
+ SHA256:
3
+ metadata.gz: 6e94dbbeb73cf96ad811e14f7f28c23122179345a8e892c56ca1a1b562f727e2
4
+ data.tar.gz: 2bf04cbef9be2ec11aaccc083ee4b01d8647e7b3b3da6a9aec3f95ada34e1f59
5
5
  SHA512:
6
- metadata.gz: 27c51b93ff94f47c7386421aa926c1ea6442fd746077936601eb7623d8732fe8e4a521dd191146250880eeafe925fc69cc5f8c62346a7b13cda5725dfd1b9947
7
- data.tar.gz: 0ecb787dfe351a7094fb81643d4de7eae4d8f00238208678e0e1e6a79be07c4cd6f7d6c61b21189a327cabb0fabdb7c4abf93948c3fcbff8ca5edc09bc54ed09
6
+ metadata.gz: 101b9da212a5407d68829335e264b919760aca883cd9d9aec04a7165a4fb38b0daf86d04126324c681ee59965b80b3b34f8241f0d11eb351af771cf3612e087f
7
+ data.tar.gz: 5b44c656dc7ed08f8965c0a6492ecdcf76fec04fa81631bd16d4c92dc4061accdbbe3c89b5805514832c88ef4b9c6df1dc5875389d5ca24af3273a349f994615
@@ -50,6 +50,8 @@ class Chef
50
50
  download_org_invitations(name)
51
51
  end
52
52
 
53
+ warn_on_incorrect_clients_group(dest_dir, "backup")
54
+
53
55
  completion_banner
54
56
  end
55
57
 
@@ -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
- users_to_update.update(d)
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
@@ -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
- ver_string = ver_line.split(' ').last
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
 
@@ -1,3 +1,3 @@
1
1
  module KnifeECBackup
2
- VERSION = '2.2.3'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -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 server version" do
14
- s = Chef::Server.new("http://api.example.com")
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("1.8.1")
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 ngingx" do
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.2.3
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: 2017-08-30 00:00:00.000000000 Z
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.11
121
+ rubygems_version: 2.7.6
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Backup and Restore of Enterprise Chef