Class: Scanny::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/scanny/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :scanny) {|_self| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

  • (_self)

Yield Parameters:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/scanny/rake_task.rb', line 23

def initialize(name=:scanny)
  @name           = name
  @include        = []
  @disable        = []
  @format         = nil
  @strict         = nil
  @path           = nil
  @fail_on_error  = nil
  @ruby_mode      = nil

  yield self if block_given?
  define
end

Instance Attribute Details

#disableObject

list of disabled checks



11
12
13
# File 'lib/scanny/rake_task.rb', line 11

def disable
  @disable
end

#fail_on_errorObject

raise exception on error



19
20
21
# File 'lib/scanny/rake_task.rb', line 19

def fail_on_error
  @fail_on_error
end

#formatObject

output format



13
14
15
# File 'lib/scanny/rake_task.rb', line 13

def format
  @format
end

#includeObject

paths to custom checks



9
10
11
# File 'lib/scanny/rake_task.rb', line 9

def include
  @include
end

#nameObject

name of rake task



7
8
9
# File 'lib/scanny/rake_task.rb', line 7

def name
  @name
end

#pathObject

custom path to scan



17
18
19
# File 'lib/scanny/rake_task.rb', line 17

def path
  @path
end

#ruby_modeObject

ruby mode



21
22
23
# File 'lib/scanny/rake_task.rb', line 21

def ruby_mode
  @ruby_mode
end

#strictObject

strict mode



15
16
17
# File 'lib/scanny/rake_task.rb', line 15

def strict
  @strict
end

Instance Method Details

#defineObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/scanny/rake_task.rb', line 37

def define
  desc("Run scanny security scanner")

  task name do
    cmd =   ["scanny"]
    cmd <<  ["-i"] + [@include]   unless @include.empty?
    cmd <<  ["-d"] + [@disable]   unless @disable.empty?
    cmd <<  ["-f #{@format}"]     if @format
    cmd <<  ["-s"]                if @strict
    cmd <<  ["-m #{@ruby_mode}"]  if @ruby_mode
    cmd <<  [@path]               if @path
    cmd = cmd.flatten.join(" ")

    unless system(cmd)
      raise("Command #{cmd} failed") if fail_on_error
    end
  end
end