knife-ec-backup 2.0.0.beta.1 → 2.0.0.beta.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24f0f5bf6187090c18829999dd6ae339b8f97f44
4
- data.tar.gz: c90dc04b94f007fb059a03021e2d951411e60d92
3
+ metadata.gz: 6a427844677521bea76fb22774f405ae3ed97af6
4
+ data.tar.gz: ac92e509e8ecee7a4e14852f99c5e43a72305306
5
5
  SHA512:
6
- metadata.gz: d8f804e4a2a9bcc0486c86f618af446f3d8cea3a8ce002a39705db49652d6301ac5d68d65b1224c0f5b2db60a8eca620b50c0012a3fabff08ce40762555f1389
7
- data.tar.gz: 0c5f596befa740f26deb0b7bc4bc50065333904d039ce22ded2e9bf02768e5c0475660c4a2d7723d1359901372a58b50463408b2683b6f6e9cfc56f65e469f69
6
+ metadata.gz: 4f27a84674dc02eaee070700efc7f8bf4e898710342d1059b3881deb6c4bd9b75b4aef109708604364a0188cf65a7c67b665460b08c47e019c3abdf77ca0a8a3
7
+ data.tar.gz: ad983d25da97492db691b431ac6fef6f60f468d314ea2909f74132eec633053a8a26cd88b03890703d6fa86f8bd133b7f9ca77091fccda2fdb603406682ff817
@@ -33,6 +33,25 @@ class Chef
33
33
  :long => '--only-org ORGNAME',
34
34
  :description => "Only back up objects in the named organization (default: all orgs)"
35
35
 
36
+ option :sql_host,
37
+ :long => '--sql-host HOSTNAME',
38
+ :description => 'Postgresql database hostname (default: localhost)',
39
+ :default => "localhost"
40
+
41
+ option :sql_port,
42
+ :long => '--sql-port PORT',
43
+ :description => 'Postgresql database port (default: 5432)',
44
+ :default => 5432
45
+
46
+ option :sql_user,
47
+ :long => "--sql-user USERNAME",
48
+ :description => 'User used to connect to the postgresql database.'
49
+
50
+ option :sql_password,
51
+ :long => "--sql-password PASSWORD",
52
+ :description => 'Password used to connect to the postgresql database'
53
+
54
+
36
55
  deps do
37
56
  require 'chef/chef_fs/config'
38
57
  require 'chef/chef_fs/file_system'
@@ -149,8 +168,10 @@ class Chef
149
168
  Chef::Knife::EcKeyExport.deps
150
169
  k = Chef::Knife::EcKeyExport.new
151
170
  k.name_args = ["#{dest_dir}/key_dump.json"]
152
- k.config[:sql_host] = "localhost"
153
- k.config[:sql_port] = 5432
171
+ k.config[:sql_host] = config[:sql_host]
172
+ k.config[:sql_port] = config[:sql_port]
173
+ k.config[:sql_user] = config[:sql_user]
174
+ k.config[:sql_password] = config[:sql_password]
154
175
  k.run
155
176
  end
156
177
 
@@ -37,7 +37,7 @@ class Chef
37
37
  end
38
38
 
39
39
  def export(path)
40
- users = db.select(:username, :id, :public_key, :pubkey_version, :hashed_password, :salt, :hash_type).from(:users)
40
+ users = db.select.from(:users)
41
41
  File.open(path, 'w') { |file| file.write(users.all.to_json) }
42
42
  end
43
43
  end
@@ -52,32 +52,31 @@ class Chef
52
52
  def import(path)
53
53
  key_data = JSON.parse(File.read(path))
54
54
  key_data.each do |d|
55
- id = d['id']
56
- username = d['username']
57
- key = d['public_key']
58
- version = d['pubkey_version']
59
- hashed_password = d['hashed_password']
60
- hash_type = d['hash_type']
61
- salt = d['salt']
62
-
63
- if username == 'pivotal' && config[:skip_pivotal]
55
+ if d['username'] == 'pivotal' && config[:skip_pivotal]
64
56
  ui.warn "Skipping pivotal user."
65
57
  next
66
58
  end
67
59
 
68
- ui.msg "Updating key for #{username}"
69
- users_to_update = db[:users].where(:username => username)
60
+ ui.msg "Updating key for #{d['username']}"
61
+ users_to_update = db[:users].where(:username => d['username'])
62
+
70
63
  if users_to_update.count != 1
71
- ui.warn "Wrong number of users to update for #{username}. Skipping"
64
+ ui.warn "Wrong number of users to update for #{d['username']}. Skipping"
72
65
  else
73
- data = { :public_key => key,
74
- :pubkey_version => version,
75
- :salt => salt,
76
- :hashed_password => hashed_password,
77
- :hash_type => hash_type
78
- }
79
- data[:id] = id unless config[:skip_ids]
80
- users_to_update.update(data)
66
+ # Remove authz id from import since this will no longer
67
+ # be valid.
68
+ d.delete('authz_id')
69
+ d.delete('id') if config[:skip_ids]
70
+ # If the hash_type in the export,
71
+ # we are dealing with a record where the password is still in the
72
+ # serialized_obejct. Explictly setting these to nil ensures that the
73
+ # password set in the restore is wiped out.
74
+ unless d.has_key?('hash_type')
75
+ d['hash_type'] = nil
76
+ d['hashed_password'] = nil
77
+ d['salt'] = nil
78
+ end
79
+ users_to_update.update(d)
81
80
  end
82
81
  end
83
82
  end
@@ -43,6 +43,24 @@ class Chef
43
43
  :long => "--with-user-sql",
44
44
  :description => "Restore user id's, passwords, and keys from sql export"
45
45
 
46
+ option :sql_host,
47
+ :long => '--sql-host HOSTNAME',
48
+ :description => 'Postgresql database hostname (default: localhost)',
49
+ :default => "localhost"
50
+
51
+ option :sql_port,
52
+ :long => '--sql-port PORT',
53
+ :description => 'Postgresql database port (default: 5432)',
54
+ :default => 5432
55
+
56
+ option :sql_user,
57
+ :long => "--sql-user USERNAME",
58
+ :description => 'User used to connect to the postgresql database.'
59
+
60
+ option :sql_password,
61
+ :long => "--sql-password PASSWORD",
62
+ :description => 'Password used to connect to the postgresql database'
63
+
46
64
  deps do
47
65
  require 'chef/json_compat'
48
66
  require 'chef/chef_fs/config'
@@ -218,7 +236,7 @@ class Chef
218
236
  ui.warn("Skipping pivotal update. To overwrite pivotal, pass --overwrite-pivotal.")
219
237
  next
220
238
  end
221
-
239
+
222
240
  # Update user object
223
241
  user = JSONCompat.from_json(IO.read("#{dest_dir}/users/#{name}.json"))
224
242
  begin
@@ -242,8 +260,10 @@ class Chef
242
260
  k.name_args = ["#{dest_dir}/key_dump.json"]
243
261
  k.config[:skip_pivotal] = true
244
262
  k.config[:skip_ids] = false
245
- k.config[:sql_host] = "localhost"
246
- k.config[:sql_port] = 5432
263
+ k.config[:sql_host] = config[:sql_host]
264
+ k.config[:sql_port] = config[:sql_port]
265
+ k.config[:sql_user] = config[:sql_user]
266
+ k.config[:sql_password] = config[:sql_password]
247
267
  k.run
248
268
  end
249
269
 
@@ -307,8 +327,8 @@ class Chef
307
327
  Chef::ChefFS::FileSystem.copy_to(Chef::ChefFS::FilePattern.new(path), chef_fs_config.local_fs, chef_fs_config.chef_fs, nil, config, ui, proc { |entry| chef_fs_config.format_path(entry) })
308
328
  end
309
329
  # restore clients to groups, using the pivotal key again
310
- Chef::Config[:node_name] = old_config['node_name']
311
- Chef::Config[:client_key] = old_config['client_key']
330
+ Chef::Config[:node_name] = old_config[:node_name]
331
+ Chef::Config[:client_key] = old_config[:client_key]
312
332
  Chef::Config.custom_http_headers = {}
313
333
  ['admins', 'billing-admins'].each do |group|
314
334
  restore_group(Chef::ChefFS::Config.new, group)
@@ -1,3 +1,3 @@
1
1
  module KnifeECBackup
2
- VERSION = '2.0.0.beta.1'
2
+ VERSION = '2.0.0.beta.2'
3
3
  end
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.0.0.beta.1
4
+ version: 2.0.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-07-03 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: 1.3.1
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.2.2
121
+ rubygems_version: 2.2.1
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Backup and Restore of Enterprise Chef