knife-ec-backup 2.0.6 → 2.0.7

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
2
  SHA1:
3
- metadata.gz: 8a281b55227d745f186c3c9a9a471d274e078585
4
- data.tar.gz: cc3f0d8ed0a83f0e4b00eab7713c51f670fec1a7
3
+ metadata.gz: b97714005f59fe60b36667b628c58f9de216f1e2
4
+ data.tar.gz: 8ba4fc5291580630844c140dea952c78d4a69db2
5
5
  SHA512:
6
- metadata.gz: 0b58a4651be0b287f89ac2e2ec362db20f0193f17ce15dd6749591e26e71683b311933cf2a8ece1c1ba65be30398db844094dc6659344a570b0c60437b888133
7
- data.tar.gz: 046df1b5018e9ff98cd44b47d7768df28de07562f166ab0d7c2962a6847f21b579c35189b1de777b9bb2277aa696673d1918cb466e59c26e201132f1d860e42f
6
+ metadata.gz: 49ea3afa7fa7ed54a318c828b235703fda5b38d28a171124ee4837efc43867ffecb4ff46b157c82aee9c7d93da65d39041f6aeb2f50f5792903e22d536e82f2c
7
+ data.tar.gz: 3443451e72baa28454cf805cfc8c20a241cc21bcf14ff286beb3d80e5caab8bc33d6c658f3191562d2ee0a59c5b8f482835be1b3028d15b272d7e2d433048af7
@@ -144,21 +144,23 @@ class Chef
144
144
 
145
145
  ensure_dir(Chef::Config.chef_repo_path)
146
146
 
147
- # Download the billing-admins ACL and group as pivotal
147
+ # Download the billing-admins, public_key_read_access ACL and group as pivotal
148
148
  chef_fs_config = Chef::ChefFS::Config.new
149
149
  chef_fs_copy_pattern('/acls/groups/billing-admins.json', chef_fs_config)
150
150
  chef_fs_copy_pattern('/groups/billing-admins.json', chef_fs_config)
151
+ chef_fs_copy_pattern('/acls/groups/public_key_read_access.json', chef_fs_config)
152
+ chef_fs_copy_pattern('/groups/public_key_read_access.json', chef_fs_config)
151
153
  chef_fs_copy_pattern('/groups/admins.json', chef_fs_config)
152
154
 
153
155
  # Set Chef::Config to use an organization administrator
154
156
  Chef::Config.node_name = org_admin
155
157
 
156
- # Download the entire org skipping the billing admins group ACL and the group itself
158
+ # Download the entire org skipping the billing-admins, public_key_read_access group ACLs and the groups themselves
157
159
  chef_fs_config = Chef::ChefFS::Config.new
158
160
  top_level_paths = chef_fs_config.chef_fs.children.select { |entry| entry.name != 'acls' && entry.name != 'groups' }.map { |entry| entry.path }
159
- acl_paths = chef_fs_paths('/acls/*', chef_fs_config, 'groups')
160
- group_acl_paths = chef_fs_paths('/acls/groups/*', chef_fs_config, 'billing-admins.json')
161
- group_paths = chef_fs_paths('/groups/*', chef_fs_config, 'billing-admins.json')
161
+ acl_paths = chef_fs_paths('/acls/*', chef_fs_config, ['groups'])
162
+ group_acl_paths = chef_fs_paths('/acls/groups/*', chef_fs_config, ['billing-admins','public_key_read_access'])
163
+ group_paths = chef_fs_paths('/groups/*', chef_fs_config, ['billing-admins','public_key_read_access'])
162
164
  (top_level_paths + group_acl_paths + acl_paths + group_paths).each do |path|
163
165
  chef_fs_copy_pattern(path, chef_fs_config)
164
166
  end
@@ -167,14 +169,19 @@ class Chef
167
169
  end
168
170
  end
169
171
 
170
- def chef_fs_paths(pattern_str, chef_fs_config, exclude=nil)
172
+ def normalize_path_name(path)
173
+ path=~/\.json\z/ ? path : path<<'.json'
174
+ end
175
+
176
+ def chef_fs_paths(pattern_str, chef_fs_config, exclude=[])
171
177
  pattern = Chef::ChefFS::FilePattern.new(pattern_str)
172
178
  list = Chef::ChefFS::FileSystem.list(chef_fs_config.chef_fs, pattern)
173
- list = list.select { |entry| entry.name != exclude } if ! exclude.nil?
174
- list.map {|entry| entry.path }
179
+ list = list.select { |entry| ! exclude.include?(entry.name) } if ! exclude.empty?
180
+ list.map { |entry| normalize_path_name(entry.path) }
175
181
  end
176
182
 
177
183
  def chef_fs_copy_pattern(pattern_str, chef_fs_config)
184
+ ui.msg "Copying #{pattern_str}"
178
185
  pattern = Chef::ChefFS::FilePattern.new(pattern_str)
179
186
  Chef::ChefFS::FileSystem.copy_to(pattern, chef_fs_config.chef_fs,
180
187
  chef_fs_config.local_fs, nil,
@@ -193,11 +193,11 @@ class Chef
193
193
  Chef::Config.versioned_cookbooks = true
194
194
  Chef::Config.chef_server_url = "#{server.root_url}/organizations/#{name}"
195
195
 
196
- # Upload the admins group and billing-admins acls
196
+ # Upload the admins, public_key_read_access and billing-admins groups and acls
197
197
  ui.msg "Restoring org admin data"
198
198
  chef_fs_config = Chef::ChefFS::Config.new
199
199
 
200
- # Handle Admins and Billing Admins seperately
200
+ # Handle Admins, Billing Admins and Public Key Read Access seperately
201
201
  #
202
202
  # admins: We need to upload admins first so that we
203
203
  # can upload all of the other objects as a user in the org
@@ -213,14 +213,21 @@ class Chef
213
213
  # and then update it again once all of the clients and
214
214
  # groups are uploaded.
215
215
  #
216
- ['admins', 'billing-admins'].each do |group|
216
+ # public_key_read_access: Similarly for public_key_read_access,
217
+ # the default permissions only give read/update to
218
+ # pivotal and members of the admins group. Use the same strategy
219
+ # above here.
220
+ #
221
+ ['admins', 'billing-admins', 'public_key_read_access'].each do |group|
217
222
  restore_group(chef_fs_config, group, :clients => false)
218
223
  end
219
224
 
220
- pattern = Chef::ChefFS::FilePattern.new('/acls/groups/billing-admins.json')
221
- Chef::ChefFS::FileSystem.copy_to(pattern, chef_fs_config.local_fs,
225
+ ['/acls/groups/billing-admins.json', '/acls/groups/public_key_read_access.json'].each do |acl|
226
+ pattern = Chef::ChefFS::FilePattern.new(acl)
227
+ Chef::ChefFS::FileSystem.copy_to(pattern, chef_fs_config.local_fs,
222
228
  chef_fs_config.chef_fs, nil, config, ui,
223
229
  proc { |entry| chef_fs_config.format_path(entry)})
230
+ end
224
231
 
225
232
  Chef::Config.node_name = org_admin
226
233
 
@@ -231,10 +238,10 @@ class Chef
231
238
  top_level_paths = chef_fs_config.local_fs.children.select { |entry| entry.name != 'acls' && entry.name != 'groups' }.map { |entry| entry.path }
232
239
 
233
240
  # Topologically sort groups for upload
234
- unsorted_groups = Chef::ChefFS::FileSystem.list(chef_fs_config.local_fs, Chef::ChefFS::FilePattern.new('/groups/*')).select { |entry| entry.name != 'billing-admins.json' }.map { |entry| JSON.parse(entry.read) }
241
+ unsorted_groups = Chef::ChefFS::FileSystem.list(chef_fs_config.local_fs, Chef::ChefFS::FilePattern.new('/groups/*')).select { |entry| ! ['billing-admins.json', 'public_key_read_access.json'].include?(entry.name) }.map { |entry| JSON.parse(entry.read) }
235
242
  group_paths = sort_groups_for_upload(unsorted_groups).map { |group_name| "/groups/#{group_name}.json" }
236
243
 
237
- group_acl_paths = Chef::ChefFS::FileSystem.list(chef_fs_config.local_fs, Chef::ChefFS::FilePattern.new('/acls/groups/*')).select { |entry| entry.name != 'billing-admins.json' }.map { |entry| entry.path }
244
+ group_acl_paths = Chef::ChefFS::FileSystem.list(chef_fs_config.local_fs, Chef::ChefFS::FilePattern.new('/acls/groups/*')).select { |entry| ! ['billing-admins.json', 'public_key_read_access.json'].include?(entry.name) }.map { |entry| entry.path }
238
245
  acl_paths = Chef::ChefFS::FileSystem.list(chef_fs_config.local_fs, Chef::ChefFS::FilePattern.new('/acls/*')).select { |entry| entry.name != 'groups' }.map { |entry| entry.path }
239
246
 
240
247
 
@@ -249,7 +256,7 @@ class Chef
249
256
 
250
257
  # restore clients to groups, using the pivotal user again
251
258
  Chef::Config[:node_name] = 'pivotal'
252
- ['admins', 'billing-admins'].each do |group|
259
+ ['admins', 'billing-admins', 'public_key_read_access'].each do |group|
253
260
  restore_group(Chef::ChefFS::Config.new, group)
254
261
  end
255
262
  ensure
@@ -285,6 +292,7 @@ class Chef
285
292
  "/groups/#{group_name}.json"
286
293
  )
287
294
 
295
+ # Will throw NotFoundError if JSON file does not exist on disk. See below.
288
296
  members_json = Chef::ChefFS::FileSystem.resolve_path(
289
297
  chef_fs_config.local_fs,
290
298
  "/groups/#{group_name}.json"
@@ -301,6 +309,8 @@ class Chef
301
309
  end
302
310
 
303
311
  group.write(members.to_json)
312
+ rescue Chef::ChefFS::FileSystem::NotFoundError
313
+ Chef::Log.warn "Could not find #{group.display_path} on disk. Will not restore."
304
314
  end
305
315
 
306
316
  def put_acl(rest, url, acls)
@@ -1,3 +1,3 @@
1
1
  module KnifeECBackup
2
- VERSION = '2.0.6'
2
+ VERSION = '2.0.7'
3
3
  end
@@ -135,4 +135,15 @@ describe Chef::Knife::EcRestore do
135
135
  @knife.restore_users
136
136
  end
137
137
  end
138
+
139
+ describe "#restore_group" do
140
+ context "when group is not present in backup" do
141
+ let(:chef_fs_config) { Chef::ChefFS::Config.new }
142
+ let(:group_name) { "bad_group" }
143
+
144
+ it "does not raise error" do
145
+ expect { @knife.restore_group(chef_fs_config, group_name) }.not_to raise_error
146
+ end
147
+ end
148
+ end
138
149
  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.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.4.5
105
+ rubygems_version: 2.6.10
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Backup and Restore of Enterprise Chef