Class: Emasser::ScanFindings

Inherits:
SubCommandBase show all
Defined in:
lib/emasser/post.rb

Overview

TThe Static Code Scans endpoint provides the ability to upload application scan findings into a system’s assets module.

Application findings can also be cleared from the system.

Endpoint:

/api/systems/{systemId}/static-code-scans - Upload static code scans

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubCommandBase

banner

Methods included from OutputConverters

#to_output_hash

Methods included from InputConverters

#to_input_hash

Methods included from OptionsParser

#optional_options, #required_options

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


496
497
498
# File 'lib/emasser/post.rb', line 496

def self.exit_on_failure?
  true
end

Instance Method Details

#addObject



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/emasser/post.rb', line 515

def add
  application = EmassClient::StaticCodeRequiredPostApplication.new
  application.application_name = options[:applicationName]
  application.version = options[:version]

  application_findings = EmassClient::StaticCodeApplication.new
  application_findings.code_check_name = options[:codeCheckName]
  application_findings.scan_date = options[:scanDate]
  application_findings.cwe_id = options[:cweId]

  application_findings.raw_severity = options[:rawSeverity] if options[:rawSeverity]
  application_findings.count = options[:count] if options[:count]

  body = EmassClient::StaticCodeRequiredPost.new
  body.application = application
  body.application_findings = application_findings

  body_array = Array.new(1, body)

  begin
    result = EmassClient::StaticCodeScansApi
             .new.add_static_code_scans_by_system_id(body_array, options[:systemId])
    puts to_output_hash(result).green
  rescue EmassClient::ApiError => e
    puts 'Exception when calling StaticCodeScansApi->add_static_code_scans_by_system_id'.red
    puts to_output_hash(e)
  end
end

#clearObject

NOTE: clearFindings is a required parameter to clear an application’s findings, however Thor does not allow a boolean type to be required because it automatically creates a –no-clearFindings option for clearFindings=false



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/emasser/post.rb', line 556

def clear
  unless options[:clearFindings]
    puts 'To clear an application findings, the field clearFindings (--clearFindings) is required'.red
    puts NEW_LINE + 'Invoke "bundle exec exe/emasser post scan_findings help clear" for additional help'.yellow
    exit
  end

  application = EmassClient::StaticCodeRequiredPostApplication.new
  application.application_name = options[:applicationName]
  application.version = options[:version]

  application_findings = EmassClient::StaticCodeApplication.new
  application_findings.clear_findings = options[:clearFindings]

  body = EmassClient::StaticCodeRequiredPost.new
  body.application = application
  body.application_findings = application_findings

  body_array = Array.new(1, body)

  begin
    result = EmassClient::StaticCodeScansApi
             .new.add_static_code_scans_by_system_id(body_array, options[:systemId])
    puts to_output_hash(result).green
  rescue EmassClient::ApiError => e
    puts 'Exception when calling StaticCodeScansApi->add_static_code_scans_by_system_id'.red
    puts to_output_hash(e)
  end
end