@@ -32,13 +32,16 @@ def initialize(paths = ['.'])
32
32
] . each do |dir |
33
33
[ 'yaml' , 'json' ] . each do |type |
34
34
Dir . glob ( "#{ path } /#{ dir } /**/*.#{ type } " ) . each do |file |
35
- @data [ file ] = parse ( file )
35
+ this_file = parse ( file )
36
+ next if this_file . nil?
37
+ @data [ file ] = this_file
36
38
merged_data = merged_data . deep_merge! ( @data [ file ] )
37
39
end
38
40
end
39
41
end
40
42
elsif File . exist? ( path )
41
- @data [ path ] = parse ( path )
43
+ this_file = parse ( path )
44
+ @data [ path ] = this_file unless this_file . nil?
42
45
else
43
46
raise "Can't find path '#{ path } '"
44
47
end
@@ -52,6 +55,8 @@ def initialize(paths = ['.'])
52
55
lint ( file , data )
53
56
end
54
57
58
+ validate
59
+
55
60
@data # rubocop:disable Lint/Void
56
61
end
57
62
@@ -65,7 +70,7 @@ def parse(file)
65
70
'json'
66
71
else
67
72
@errors << "#{ file } : Failed to determine file type"
68
- nil
73
+ return nil
69
74
end
70
75
begin
71
76
return YAML . safe_load ( File . read ( file ) ) if type == 'yaml'
@@ -74,7 +79,7 @@ def parse(file)
74
79
@errors << "#{ file } : Failed to parse file: #{ e . message } "
75
80
end
76
81
77
- { }
82
+ nil
78
83
end
79
84
80
85
def files
@@ -252,7 +257,6 @@ def check_remediation(file, check, remediation_section)
252
257
253
258
if remediation_section . is_a? ( Hash )
254
259
remediation_section . each do |section , value |
255
- # require 'pry-byebug'; binding.pry if section == 'disabled'
256
260
case section
257
261
when 'scan-false-positive' , 'disabled'
258
262
value . each do |reason |
@@ -368,6 +372,36 @@ def check_checks(file, data)
368
372
end
369
373
end
370
374
375
+ def profiles
376
+ return nil unless @data . key? ( 'merged data' )
377
+ return nil unless @data [ 'merged data' ] [ 'profiles' ] . is_a? ( Hash )
378
+ return @data [ 'merged data' ] [ 'profiles' ] . keys
379
+ end
380
+
381
+ def confines
382
+ retval = { }
383
+
384
+ @data . each do |key , value |
385
+ next if key == 'merged data'
386
+ next unless value . is_a? ( Hash )
387
+
388
+ [ 'profiles' , 'ce' , 'checks' ] . each do |type |
389
+ next unless value . key? ( type )
390
+ next unless value [ type ] . is_a? ( Hash )
391
+
392
+ value [ type ] . each do |_k , v |
393
+ next unless v . is_a? ( Hash )
394
+ retval = retval . merge ( v [ 'confine' ] ) if v . key? ( 'confine' )
395
+ end
396
+ end
397
+ end
398
+
399
+ retval
400
+ end
401
+
402
+ def validate
403
+ end
404
+
371
405
def lint ( file , data )
372
406
check_version ( file , data )
373
407
check_keys ( file , data )
@@ -376,6 +410,8 @@ def lint(file, data)
376
410
check_ce ( file , data [ 'ce' ] ) if data [ 'ce' ]
377
411
check_checks ( file , data [ 'checks' ] ) if data [ 'checks' ]
378
412
check_controls ( file , data [ 'controls' ] ) if data [ 'controls' ]
413
+ rescue => e
414
+ @errors << "#{ file } : #{ e . message } (not a hash?)"
379
415
end
380
416
end
381
417
end
0 commit comments