-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(APIv2): RHINENG-2149 implement reports endpoint
- Loading branch information
1 parent
18e2ffa
commit c61b791
Showing
19 changed files
with
4,968 additions
and
3,554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module V2 | ||
# API for Reports (rule results) | ||
class ReportsController < ApplicationController | ||
def index | ||
render_json reports | ||
end | ||
permission_for_action :index, Rbac::REPORT_READ | ||
|
||
def show | ||
render_json report | ||
end | ||
permission_for_action :show, Rbac::REPORT_READ | ||
|
||
private | ||
|
||
def reports | ||
@reports ||= authorize(fetch_collection) | ||
end | ||
|
||
def report | ||
@report ||= authorize(expand_resource.find(permitted_params[:id])) | ||
end | ||
|
||
def resource | ||
V2::Report | ||
end | ||
|
||
def serializer | ||
V2::ReportSerializer | ||
end | ||
|
||
def extra_fields | ||
%i[account_id] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module V2 | ||
# Policies for accessing Reports | ||
class ReportPolicy < V2::ApplicationPolicy | ||
def index? | ||
true # FIXME: this is handled in scoping | ||
end | ||
|
||
def show? | ||
match_account? | ||
end | ||
|
||
# Only show Reports in our user account | ||
class Scope < V2::ApplicationPolicy::Scope | ||
def resolve | ||
return scope.where('1=0') if user&.account_id.blank? | ||
|
||
scope.where(account_id: user.account_id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module V2 | ||
# JSON serialization for Reports | ||
class ReportSerializer < V2::ApplicationSerializer | ||
attributes :title, :description, :business_objective, :compliance_threshold | ||
|
||
derived_attribute :os_major_version, security_guide: [:os_major_version] | ||
derived_attribute :profile_title, profile: [:title] | ||
derived_attribute :ref_id, profile: [:ref_id] | ||
derived_attribute :all_systems_exposed, :total_system_count | ||
|
||
aggregated_attribute :assigned_system_count, :assigned_systems, V2::Report::SYSTEM_COUNT | ||
aggregated_attribute :compliant_system_count, :systems, V2::Report::COMPLIANT_SYSTEM_COUNT | ||
aggregated_attribute :unsupported_system_count, :systems, V2::Report::UNSUPPORTED_SYSTEM_COUNT | ||
aggregated_attribute :result_system_count, :systems, V2::Report::SYSTEM_COUNT | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# frozen_string_literal: true | ||
|
||
require './spec/api/v2/schemas/util' | ||
|
||
module Api | ||
module V2 | ||
module Schemas | ||
# :nodoc: | ||
module Report | ||
extend Api::V2::Schemas::Util | ||
|
||
REPORT = { | ||
type: :object, | ||
properties: { | ||
id: ref_schema('id'), | ||
type: { | ||
type: :string, | ||
enum: ['report'], | ||
readOnly: true | ||
}, | ||
title: { | ||
type: :string, | ||
examples: ['CIS Red Hat Enterprise Linux 7 Benchmark'], | ||
description: 'Short title of the Report', | ||
readOnly: true | ||
}, | ||
business_objective: { | ||
type: :string, | ||
examples: ['Guide to the Secure Configuration of Red Hat Enterprise Linux 7'], | ||
description: 'The Business Objective associated to the Policy', | ||
readOnly: true | ||
}, | ||
compliance_threshold: { | ||
type: :number, | ||
examples: [90], | ||
maximum: 100, | ||
minimum: 0, | ||
description: 'The percentage above which the Policy meets compliance requirements', | ||
readOnly: true | ||
}, | ||
os_major_version: { | ||
type: :number, | ||
minimum: 6, | ||
examples: [7], | ||
description: 'Major version of the Operating System that the Report covers', | ||
readOnly: true | ||
}, | ||
ref_id: { | ||
type: :string, | ||
examples: ['xccdf_org.ssgproject.content_profile_pci-dss'], | ||
description: 'Identificator of the Profile', | ||
readOnly: true | ||
}, | ||
profile_title: { | ||
type: :string, | ||
examples: ['CIS Red Hat Enterprise Linux 7 Benchmark'], | ||
description: 'Title of the associated Profile', | ||
readOnly: true | ||
}, | ||
assigned_system_count: { | ||
type: :number, | ||
minium: 1, | ||
examples: [42], | ||
description: 'The number of Systems assigned to this Report', | ||
readOnly: true | ||
}, | ||
compliant_system_count: { | ||
type: :number, | ||
minium: 0, | ||
examples: [21], | ||
description: 'The number of compliant Systems assigned to this Report', | ||
readOnly: true | ||
}, | ||
all_systems_exposed: { | ||
type: :boolean, | ||
description: 'Informs if the user has access to all the account\'s systems', | ||
examples: [false], | ||
readOnly: true | ||
}, | ||
unsupported_system_count: { | ||
type: :number, | ||
minium: 0, | ||
examples: [3], | ||
description: 'The number of unsupported Systems assigned to this Report', | ||
readOnly: true | ||
} | ||
} | ||
}.freeze | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.