shiftzilla 0.2.17 → 0.2.18

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
  SHA256:
3
- metadata.gz: 7760e6a4a4ceeef4415f2f9cd59ecf541c90a090e603770b79565dac73e72dfc
4
- data.tar.gz: a26c1233b6139e559168f238a0321722a338215e179ef394a217178d938148f2
3
+ metadata.gz: 04b96fe5e59a6af07ab19279d5c88d5f77404b9ebaf7ad16c7ca7036dfbe9030
4
+ data.tar.gz: e748c09421a5cae2ee28188f63d8e92cbc3f8910fcb852afca4b27c2a8e7df88
5
5
  SHA512:
6
- metadata.gz: d0cc58b437e36ca624e9ce644ba927c62a6040a364e227b1311b4501af780adbfcac9b12c193ce8408cc4137ce6b6fd93e131141c45ef7eec5913f6318b64683
7
- data.tar.gz: ce6dc18cffc21d09be327ffdd14d1fea430fc5875c12fdd48ad6b081722cf7c0f500cc0098e20e15e1def98329c4f200bfe14ddd5271ada36f568dc231b9af96
6
+ metadata.gz: 89952488ce6929e7bdad90fa7c020efcea98c37abc1c11dce547df73abc62e2c6bc5727e11fcef44129f9c2a393a2f4b3a0ab036f3b593445feb53489413fe46
7
+ data.tar.gz: bfe2ab32dab27b347b09d388eef5b7f2f6b8f3aec3f7cb33d3194d8368356deb35e14504f9cc110d71377320ede0b4ad7b0433482efd8ec3816f453459c8a4cb
@@ -43,7 +43,7 @@ module Shiftzilla
43
43
  end
44
44
 
45
45
  def cfg_file
46
- @cfg_file ||= YAML.load_file(CFG_FILE)
46
+ @cfg_file ||= validated_config_file(YAML.load_file(CFG_FILE))
47
47
  end
48
48
 
49
49
  def dbh
@@ -170,5 +170,217 @@ module Shiftzilla
170
170
  def db_backed_up
171
171
  @db_backed_up ||= false
172
172
  end
173
+
174
+ def valid_config_string?(value)
175
+ return false if value.class == NilClass
176
+ return false if value.class == String and value.length == 0
177
+ return true
178
+ end
179
+
180
+ def validated_config_file(raw_cfg)
181
+ unless raw_cfg.class == Hash
182
+ puts "#{CFG_FILE} did not get parsed as a hash."
183
+ exit
184
+ end
185
+ missing_keys = ['Groups','Teams','Sources','Releases','SSH'].select{ |k| not raw_cfg.has_key?(k) }
186
+ if missing_keys.length > 0
187
+ if missing_keys.length > 1
188
+ puts "#{CFG_FILE} is missing the following keys: #{missing_keys.join(', ')}"
189
+ else
190
+ puts "#{CFG_FILE} is missing the '#{missing_keys[0]}' key."
191
+ end
192
+ exit
193
+ end
194
+ zero_length_lists = ['Groups','Teams','Releases'].select{ |k| not raw_cfg[k].class == Array or raw_cfg[k].length == 0 }
195
+ if zero_length_lists.length > 0
196
+ if zero_length_lists.length > 1
197
+ puts "#{CFG_FILE} contains some zero-length lists: #{zero_length_lists.join(', ')}"
198
+ else
199
+ puts "#{CFG_FILE} contains a zero-length list for #{zero_length_lists[0]}"
200
+ end
201
+ exit
202
+ end
203
+
204
+ errors = []
205
+
206
+ # Group checks
207
+ list_idx = 0
208
+ seen_gids = {}
209
+ raw_cfg['Groups'].each do |group|
210
+ if not group.has_key?('id')
211
+ errors << "Group at index #{list_idx} is missing the 'id' key."
212
+ elsif not valid_config_string?(group['id'])
213
+ errors << "Group at index #{list_idx} has a nil or zero-length 'id'."
214
+ else
215
+ gid = group['id']
216
+ if seen_gids.has_key?(gid)
217
+ errors << "Group at index #{list_idx} has same id ('#{gid}') as group at index #{seen_gids[gid]}"
218
+ else
219
+ seen_gids[gid] = list_idx
220
+ end
221
+ end
222
+ if not group.has_key?('lead')
223
+ errors << "Group at index #{list_idx} is missing the 'lead' key."
224
+ elsif not valid_config_string?(group['lead'])
225
+ errors << "Group at index #{list_idx} has a nil or zero-length 'lead'."
226
+ end
227
+ list_idx += 1
228
+ end
229
+
230
+ # Team checks
231
+ list_idx = 0
232
+ seen_tnms = {}
233
+ raw_cfg['Teams'].each do |team|
234
+ if not team.has_key?('name')
235
+ errors << "Team at index #{list_idx} is missing the 'name' key."
236
+ elsif not valid_config_string?(team['name'])
237
+ errors << "Team at index #{list_idx} has a nil or zero-length 'name'."
238
+ else
239
+ tnm = team['name']
240
+ if seen_tnms.has_key?(tnm)
241
+ errors << "Team at index #{list_idx} has same name ('#{tnm}') as team at index #{seen_tnms[tnm]}"
242
+ else
243
+ seen_tnms[tnm] = list_idx
244
+ end
245
+ end
246
+ if not team.has_key?('lead')
247
+ errors << "Team at index #{list_idx} is missing the 'lead' key."
248
+ elsif not valid_config_string?(team['lead'])
249
+ errors << "Team at index #{list_idx} has a nil or zero-length 'lead'."
250
+ end
251
+ if not team.has_key?('group')
252
+ errors << "Team at index #{list_idx} is missing the 'group' key."
253
+ elsif not valid_config_string?(team['group'])
254
+ errors << "Team at index #{list_idx} has a nil or zero-length 'group'."
255
+ elsif not seen_gids.has_key?(team['group'])
256
+ errors << "Team at index #{list_idx} has a group id ('#{team['group']}') that doesn't map to any Group."
257
+ end
258
+ if team.has_key?('components')
259
+ comps = team['components']
260
+ if not comps.class == Array
261
+ errors << "Team at index #{list_idx} has a 'components' key that didn't parse as a list"
262
+ else
263
+ comp_idx = 0
264
+ comps.each do |comp|
265
+ if not valid_config_string?(comp)
266
+ errors << "Team at index #{list_idx} has a nil or zero-length BZ component at index #{comp_idx}"
267
+ end
268
+ comp_idx += 1
269
+ end
270
+ end
271
+ end
272
+ list_idx += 1
273
+ end
274
+
275
+ # Release checks
276
+ list_idx = 0
277
+ seen_rnms = {}
278
+ raw_cfg['Releases'].each do |release|
279
+ if not release.has_key?('name')
280
+ errors << "Release at index #{list_idx} is missing the 'name' key."
281
+ elsif not valid_config_string?(release['name'])
282
+ errors << "Release at index #{list_idx} has a nil or zero-length 'name'."
283
+ else
284
+ rnm = release['name']
285
+ if seen_rnms.has_key?(rnm)
286
+ errors << "Release at index #{list_idx} has same name ('#{rnm}') as release at index #{seen_rnms[rnm]}"
287
+ else
288
+ seen_rnms[rnm] = list_idx
289
+ end
290
+ end
291
+ if not release.has_key?('targets')
292
+ errors << "Release at index #{list_idx} is missing the 'targets' key."
293
+ else
294
+ targets = release['targets']
295
+ if not targets.class == Array
296
+ errors << "Release at index #{list_idx} has a 'targets' key that didn't parse as a list"
297
+ else
298
+ tgt_idx = 0
299
+ targets.each do |tgt|
300
+ if not valid_config_string?(tgt)
301
+ errors << "Release at index #{list_idx} has a nil or zero-length target at index #{tgt_idx}"
302
+ end
303
+ tgt_idx += 1
304
+ end
305
+ end
306
+ end
307
+ if not release.has_key?('milestones')
308
+ errors << "Release at index #{list_idx} is missing the 'milestones' key."
309
+ else
310
+ milestones = release['milestones']
311
+ if not milestones.class == Hash
312
+ errors << "Release at index #{list_idx} has a 'milestones' key that didn't parse as a hash"
313
+ else
314
+ ['start','feature_complete','code_freeze','ga'].each do |ms|
315
+ if not milestones.has_key?(ms)
316
+ errors << "Release at index #{list_idx} is missing the '#{ms}' milestone."
317
+ else
318
+ ms_date = milestones[ms].split('-')
319
+ if ms_date.length == 3 and ms_date[0].length == 4 and ms_date[1].length == 2 and ms_date[2].length == 2
320
+ else
321
+ errors << "Release at index #{list_idx}: milestone '#{ms}' is not formatted correctly (YYYY-MM-DD)."
322
+ end
323
+ end
324
+ end
325
+ end
326
+ end
327
+ list_idx += 1
328
+ end
329
+
330
+ # Source checks
331
+ if not raw_cfg['Sources'].class == Hash
332
+ errors << "The Sources portion of the config file didn't parse as a hash."
333
+ else
334
+ seen_srcs = {}
335
+ raw_cfg['Sources'].each do |src_id,src_info|
336
+ ['search','sharer','table','external_sub','fields'].each do |key|
337
+ if not src_info.has_key?(key)
338
+ errors << "Source '#{src_id}' is missing the '#{key}' key."
339
+ else
340
+ if key == 'fields'
341
+ if not src_info['fields'].class == Array
342
+ errors << "Source '#{src_id}': the 'fields' value didn't parse as a list."
343
+ else
344
+ fld_idx = 0
345
+ src_info['fields'].each do |fld|
346
+ if not valid_config_string?(fld)
347
+ errors << "Source '#{src_id}': the field value at index #{fld_idx} is nil or zero-length."
348
+ end
349
+ fld_idx += 1
350
+ end
351
+ end
352
+ elsif not valid_config_string?(src_info[key])
353
+ errors << "Source '#{src_id}' has nil or zero-length value for '#{key}'"
354
+ end
355
+ end
356
+ end
357
+ end
358
+ end
359
+
360
+ # SSH checks
361
+ if not raw_cfg['SSH'].class == Hash
362
+ errors << "The SSH portion of the config file didn't parse as a hash."
363
+ else
364
+ ssh = raw_cfg['SSH']
365
+ ['host','path','url'].each do |key|
366
+ if not ssh.has_key?(key)
367
+ errors << "SSH config is missing the '#{key}' key."
368
+ elsif not valid_config_string?(ssh[key])
369
+ errors << "SSH config: '#{key}' value is nil or zero-length"
370
+ end
371
+ end
372
+ end
373
+
374
+ # Report errors
375
+ if errors.length > 0
376
+ puts "Config file at '#{CFG_FILE}' has the following errors:"
377
+ errors.each do |error|
378
+ puts "- #{error}"
379
+ end
380
+ exit
381
+ end
382
+
383
+ return raw_cfg
384
+ end
173
385
  end
174
386
  end
@@ -1,3 +1,3 @@
1
1
  module Shiftzilla
2
- VERSION = "0.2.17"
2
+ VERSION = "0.2.18"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiftzilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - N. Harrison Ripps
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler