Class: A2::Subcommand::Reporting::ListReports

Inherits:
Paginated show all
Defined in:
lib/a2/subcommands/reporting.rb

Instance Attribute Summary

Attributes inherited from Filtered

#filter_key, #query_filter

Instance Method Summary collapse

Methods inherited from Paginated

#generate_paginated_query_string, #with_paginated_filter_json, #with_paginated_filter_query

Methods inherited from Filtered

#generate_json_filters, #generate_query_filters, #parse_filters, #set_custom_opts!, #set_filter_optparse_options!, #with_filter_query

Constructor Details

#initializeListReports

Returns a new instance of ListReports.



29
30
31
32
33
34
# File 'lib/a2/subcommands/reporting.rb', line 29

def initialize
  super('list-reports', takes_commands: false, filter_key: 'type')
  options.on('-i', '--skip-impact IMPACT', 'Only show reports with an impact score greater than the provided value.') do |impact|
    @opt[:impact] = impact
  end
end

Instance Method Details

#executeObject



36
37
38
39
40
41
42
43
44
# File 'lib/a2/subcommands/reporting.rb', line 36

def execute
  impact = @opt.delete(:impact)
  with_paginated_filter_json do |json|
    reports_json = A2::Client.new(command_parser.data).list_reports(json)
    reports_json = filter_by_min_impact(reports_json, impact) unless impact.nil?

    puts JSON.pretty_generate(reports_json)
  end
end

#filter_by_min_impact(report_json, impact) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/a2/subcommands/reporting.rb', line 46

def filter_by_min_impact(report_json, impact)
  report_json['reports'].delete_if do |report|
    if impact == 'minor'
      if report['controls']['failed']['major'].eql?(0) && report['controls']['failed']['critical'].eql?(0)
        true
      end
    elsif impact == 'major'
      true if report['controls']['failed']['critical'].eql?(0)
    end
  end
  report_json
end