Class: Pipeline::SFL
Instance Attribute Summary
Attributes inherited from BaseTask
#appname, #description, #findings, #labels, #name, #stage, #trigger, #warnings
Instance Method Summary
collapse
Methods included from Util
#fingerprint, #relative_path, #runsystem, #strip_archive_path
Methods inherited from BaseTask
#directories_with?, #report, #severity, #warn
Constructor Details
#initialize(trigger, tracker) ⇒ SFL
Returns a new instance of SFL.
11
12
13
14
15
16
17
18
19
|
# File 'lib/pipeline/tasks/sfl.rb', line 11
def initialize(trigger, tracker)
super(trigger,tracker)
@name = "SFL"
@description = "Sentive Files Lookup"
@stage = :code
@labels << "code"
@patterns = read_patterns_file!
end
|
Instance Method Details
#analyze ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pipeline/tasks/sfl.rb', line 27
def analyze
begin
@files.each do |file|
@patterns.each do |pattern|
case pattern['part']
when 'filename'
if pattern_matched?(File.basename(file), pattern)
report pattern['caption'], pattern['description'], @name + ":" + file, 'unknown', 'TBD'
end
when 'extension'
if pattern_matched?(File.extname(file), pattern)
report pattern['caption'], pattern['description'], @name + ":" + file, 'unknown', 'TBD'
end
end
end
end
rescue Exception => e
Pipeline.warn e.message
end
end
|
#pattern_matched?(txt, pattrn) ⇒ Boolean
52
53
54
55
56
57
58
59
60
|
# File 'lib/pipeline/tasks/sfl.rb', line 52
def pattern_matched?(txt, pattrn)
case pattrn['type']
when 'match'
return txt == pattrn['pattern']
when 'regex'
regex = Regexp.new(pattrn['pattern'], Regexp::IGNORECASE)
return !regex.match(txt).nil?
end
end
|
#read_patterns_file! ⇒ Object
62
63
64
65
66
|
# File 'lib/pipeline/tasks/sfl.rb', line 62
def read_patterns_file!
JSON.parse(File.read("#{File.dirname(__FILE__)}/patterns.json"))
rescue JSON::ParserError => e
Pipeline.warn "Cannot parse pattern file: #{e.message}"
end
|
#run ⇒ Object
21
22
23
24
25
|
# File 'lib/pipeline/tasks/sfl.rb', line 21
def run
@files = Find.find(@trigger.path)
Pipeline.debug "Found #{@files.count} files"
end
|
#supported? ⇒ Boolean
48
49
50
|
# File 'lib/pipeline/tasks/sfl.rb', line 48
def supported?
true
end
|