Skip to content

Commit

Permalink
fix(APIv2): add missing fields to report stats and to OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Sep 3, 2024
1 parent 92248e9 commit a1425e1
Show file tree
Hide file tree
Showing 4 changed files with 4,760 additions and 4,614 deletions.
6 changes: 3 additions & 3 deletions app/models/v2/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ def delete_associated

# rubocop:disable Metrics/AbcSize
def top_failed_rules
rule_fields = %i[title ref_id identifier severity].map { |field| V2::Rule.arel_table[field] }

V2::RuleResult.joins(:test_result, :system, :rule)
.merge_with_alias(Pundit.policy_scope(User.current, V2::System))
.where(result: V2::RuleResult::FAILED)
.group(V2::Rule.arel_table[:ref_id], V2::Rule.arel_table[:severity])
.select(V2::Rule.arel_table[:ref_id], V2::Rule.arel_table[:severity],
V2::RuleResult.arel_table[:result].count.as('count'))
.group(rule_fields).select(rule_fields, V2::RuleResult.arel_table[:result].count.as('count'))
.order(V2::Rule.sorted_severities => :desc, count: :desc).limit(10)
end
# rubocop:enable Metrics/AbcSize
Expand Down
26 changes: 25 additions & 1 deletion spec/api/v2/schemas/report_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,38 @@ module ReportStats
items: {
type: :object,
properties: {
title: {
type: :string,
examples: ['Remove tftp'],
readOnly: true,
description: 'Short title of the Rule'
},
ref_id: {
type: :string,
examples: ['xccdf_org.ssgproject.content_rule_package_tftp_removed'],
readOnly: true,
description: 'Identificator of the Rule'
},
identifier: {
type: :object,
readOnly: true,
description: 'Identifier of the Rule',
properties: {
label: {
type: :string,
readOnly: true,
examples: ['CCE-80798-2']
},
system: {
type: :string,
readOnly: true,
examples: ['https://nvd.nist.gov/cce/index.cfm']
}
},
examples: ['CEE-1234-123']
},
severity: {
type: 'string',
type: :string,
examples: ['low'],
readOnly: true,
description: 'The severity of the Rule'
Expand Down
40 changes: 40 additions & 0 deletions spec/api/v2/schemas/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,46 @@ module Rule
readOnly: true,
description: 'The severity of the Rule'
},
identifier: {
type: :object,
readOnly: true,
description: 'Identifier of the Rule',
properties: {
label: {
type: :string,
readOnly: true,
examples: ['CCE-80798-2']
},
system: {
type: :string,
readOnly: true,
examples: ['https://nvd.nist.gov/cce/index.cfm']
}
},
examples: ['CEE-1234-123']
},
references: {
type: :array,
items: {
type: :object,
readOnly: true,
description: 'List of Tags assigned to the System',
properties: {
label: {
type: :string,
readOnly: true,
examples: ['APO01.06']
},
href: {
type: :string,
readOnly: true,
examples: ['https://www.isaca.org/resources/cobit']
}
}
},
readOnly: true,
description: 'Array of the Rule References'
},
remediation_available: {
type: :boolean,
examples: [true, false],
Expand Down
Loading

0 comments on commit a1425e1

Please sign in to comment.