Module: Pipeline
- Defined in:
- lib/pipeline.rb,
lib/pipeline/version.rb
Defined Under Namespace
Modules: Options, Util Classes: AV, BaseFilter, BaseMounter, BaseReporter, BaseTask, Brakeman, BundleAudit, CSVReporter, Checkmarx, DawnScanner, DepCheckListener, DependencyError, DockerMounter, ESLint, Event, FIM, FileSystemMounter, Filters, FindSecurityBugs, Finding, GitMounter, ISOMounter, JSONReporter, JiraConfigError, JiraOneTimeFilter, JiraReporter, Mounters, NoPipelineError, NoTargetError, NodeSecurityProject, Npm, OWASPDependencyCheck, PMD, RemoveAllFilter, Reporters, RetireJS, SFL, ScanJS, Scanner, Snyk, Tasks, Test, TextReporter, Tracker, URLMounter, ZAPCondensingFilter, Zap
Constant Summary collapse
- Warnings_Found_Exit_Code =
This exit code is used when warnings are found and the –exit-on-warn option is set
3
- CONFIG_FILES =
[ File.("./config/pipeline.yml"), File.("~/.pipeline/config.yml"), File.("/etc/pipeline/config.yml") ]
- Version =
"0.8.7"
Class Method Summary collapse
- .add_external_tasks(options) ⇒ Object
- .config_file(custom_location = nil) ⇒ Object
- .debug(message) ⇒ Object
-
.default_options ⇒ Object
Default set of options.
-
.dump_config(options) ⇒ Object
Output configuration to YAML.
- .error(message) ⇒ Object
- .get_output_format(options) ⇒ Object
-
.list_checks(options) ⇒ Object
Output list of tasks (for ‘-k` option).
-
.load_options(custom_location, quiet) ⇒ Object
Load options from YAML file.
- .load_pipeline_dependency(name) ⇒ Object
- .notify(message) ⇒ Object
-
.run(options) ⇒ Object
Run Pipeline.
-
.scan(options) ⇒ Object
Run a scan.
-
.set_options(options) ⇒ Object
Sets up options for run, checks given application path.
- .warn(message) ⇒ Object
Class Method Details
.add_external_tasks(options) ⇒ Object
307 308 309 310 311 |
# File 'lib/pipeline.rb', line 307 def self.add_external_tasks [:additional_tasks_path].each do |path| Pipeline::Tasks.initialize_tasks path end if [:additional_tasks_path] end |
.config_file(custom_location = nil) ⇒ Object
105 106 107 108 |
# File 'lib/pipeline.rb', line 105 def self.config_file custom_location = nil supported_locations = [File.(custom_location || "")] + CONFIG_FILES supported_locations.detect {|f| File.file?(f) } end |
.debug(message) ⇒ Object
290 291 292 293 |
# File 'lib/pipeline.rb', line 290 def self.debug $stderr.puts if @debug $logfile.puts "[#{Time.now}] #{}" if $logfile end |
.default_options ⇒ Object
Default set of options
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/pipeline.rb', line 111 def self. { :parallel_tasks => true, :skip_tasks => Set.new(), :exit_on_warn => true, :output_format => :text, :working_dir => "~/line/tmp/", :zap_host => "http://localhost", :zap_port => "9999", :labels => Set.new() << "filesystem" << "code" # Defaults to run. } end |
.dump_config(options) ⇒ Object
Output configuration to YAML
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/pipeline.rb', line 206 def self.dump_config if [:create_config].is_a? String file = [:create_config] else file = nil end .delete :create_config .each do |k,v| if v.is_a? Set [k] = v.to_a end end if file File.open file, "w" do |f| YAML.dump , f end puts "Output configuration to #{file}" else puts YAML.dump() end exit end |
.error(message) ⇒ Object
275 276 277 278 |
# File 'lib/pipeline.rb', line 275 def self.error $stderr.puts $logfile.puts "[#{Time.now}] #{}" if $logfile end |
.get_output_format(options) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/pipeline.rb', line 126 def self.get_output_format if [:output_file] get_format_from_output_file [:output_file] elsif [:output_format] get_format_from_output_format [:output_format] else begin require 'terminal-table' return [:to_s] rescue LoadError return [:to_json] end end end |
.list_checks(options) ⇒ Object
Output list of tasks (for ‘-k` option)
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/pipeline.rb', line 184 def self.list_checks require 'pipeline/scanner' add_external_tasks if [:list_optional_tasks] $stderr.puts "Optional Tasks:" tasks = Tasks.optional_tasks else $stderr.puts "Available tasks:" tasks = Tasks.tasks end format_length = 30 $stderr.puts "-" * format_length tasks.each do |task| $stderr.printf("%-#{format_length}s\n", task.name) end end |
.load_options(custom_location, quiet) ⇒ Object
Load options from YAML file
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/pipeline.rb', line 85 def self. custom_location, quiet #Load configuration file if config = config_file(custom_location) = YAML.load_file config if .each { |k, v| [k] = Set.new v if v.is_a? Array } # notify if options[:quiet] and quiet is nil||false notify "[Notice] Using configuration in #{config}" unless ([:quiet] || quiet) else notify "[Notice] Empty configuration file: #{config}" unless quiet {} end else {} end end |
.load_pipeline_dependency(name) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/pipeline.rb', line 295 def self.load_pipeline_dependency name return if @loaded_dependencies.include? name begin require name rescue LoadError => e $stderr.puts e. $stderr.puts "Please install the appropriate dependency." exit! -1 end end |
.notify(message) ⇒ Object
285 286 287 288 |
# File 'lib/pipeline.rb', line 285 def self.notify $stderr.puts #unless @debug $logfile.puts "[#{Time.now}] #{}" if $logfile end |
.run(options) ⇒ Object
Run Pipeline.
Options:
* :config_file - configuration file
* :exit_on_warn - return false if warnings found, true otherwise. Not recommended for library use (default: false)
* :output_files - files for output
* :output_formats - formats for output (:to_s, :to_tabs, :to_csv, :to_html)
* :parallel_checks - run checks in parallel (default: true)
* :print_report - if no output file specified, print to stdout (default: false)
* :quiet - suppress most messages (default: true)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pipeline.rb', line 27 def self.run = @quiet = !![:quiet] @debug = !![:debug] if @quiet [:report_progress] = false end unless [:logfile].nil? if [:logfile].is_a? File $logfile = [:logfile] else $logfile = File.open([:logfile], 'a') end begin scan ensure $logfile.close unless [:logfile].is_a? File end end end |
.scan(options) ⇒ Object
Run a scan. Generally called from Pipeline.run instead of directly.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/pipeline.rb', line 233 def self.scan #Load scanner notify "Loading scanner..." begin require 'pipeline/scanner' require 'pipeline/tracker' require 'pipeline/mounters' require 'pipeline/filters' require 'pipeline/reporters' rescue LoadError => e $stderr.puts e. raise NoPipelineError, "Cannot find lib/ directory or load the key pipeline." end # debug "API: #{options[:jira_api_url.to_s]}" # debug "Project: #{options[:jira_project.to_s]}" # debug "Cookie: #{options[:jira_cookie.to_s]}" add_external_tasks tracker = Tracker.new debug "Mounting ... #{[:target]}" # Make the target accessible. target = Pipeline::Mounters.mount tracker #Start scanning scanner = Scanner.new notify "Processing target...#{[:target]}" scanner.process target, tracker # Filter the results (Don't report anything that has been reported before) Pipeline::Filters.filter tracker # Generate Report notify "Generating report...#{[:output_format]}" Pipeline::Reporters.run_report tracker tracker end |
.set_options(options) ⇒ Object
Sets up options for run, checks given application path
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pipeline.rb', line 53 def self. if .is_a? String = { :target => } end if [:quiet] == :command_line command_line = true .delete :quiet end = .merge(([:config_file], [:quiet])).merge() if [:quiet].nil? and not command_line [:quiet] = true end [:output_format] = get_output_format if [:appname].nil? path = [:target] [:appname] = File.split(path).last end end |
.warn(message) ⇒ Object
280 281 282 283 |
# File 'lib/pipeline.rb', line 280 def self.warn $stderr.puts unless @quiet $logfile.puts "[#{Time.now}] #{}" if $logfile end |