-
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(REST): RHICOMPL-3904 generate APIv2 spec
- Loading branch information
1 parent
5f699f6
commit 4c8cc1d
Showing
9 changed files
with
731 additions
and
3 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,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require './spec/api/v2/schemas' | ||
|
||
module Api | ||
module V2 | ||
class Openapi | ||
include Api::V2::Schemas | ||
|
||
def self.doc | ||
new.doc | ||
end | ||
|
||
def doc | ||
{ | ||
openapi: '3.1.0', | ||
info: info, | ||
servers: servers, | ||
paths: {}, | ||
components: { | ||
schemas: SCHEMAS | ||
} | ||
} | ||
end | ||
|
||
def servers | ||
[ | ||
# TODO: when v1 gets deprecated | ||
# { | ||
# url: 'https://{defaultHost}/api/compliance', | ||
# variables: { defaultHost: { default: 'console.redhat.com' } } | ||
# }, | ||
{ | ||
url: 'https://{defaultHost}/api/compliance/v2', | ||
variables: { defaultHost: { default: 'console.redhat.com' } } | ||
} | ||
] | ||
end | ||
|
||
def info | ||
{ | ||
title: 'Cloud Services for RHEL Compliance API v2', | ||
version: 'v2', | ||
description: description | ||
} | ||
end | ||
|
||
def description | ||
'This is the API for Cloud Services for RHEL Compliance. ' \ | ||
'You can find out more about Red Hat Cloud Services for RHEL at ' \ | ||
'[https://console.redhat.com/]' \ | ||
'(https://console.redhat.com/)' | ||
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
Dir['./spec/api/v2/schemas/*.rb'].sort.each { |file| require file } | ||
|
||
module Api | ||
module V2 | ||
module Schemas | ||
include Metadata | ||
include SecurityGuides | ||
|
||
SCHEMAS = { | ||
uuid: UUID, | ||
links: LINKS, | ||
metadata: METADATA, | ||
security_guides: SECURITY_GUIDE | ||
}.freeze | ||
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,79 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
module V2 | ||
module Schemas | ||
module Metadata | ||
UUID = { type: :string, format: :uuid }.freeze | ||
|
||
METADATA = { | ||
type: :object, | ||
properties: { | ||
total: { | ||
type: :number, | ||
examples: [1] | ||
}, | ||
limit: { | ||
type: :number, | ||
maximum: 100, | ||
minimum: 1, | ||
default: 10, | ||
examples: [10, 100] | ||
}, | ||
offset: { | ||
type: :number, | ||
minimum: 0, | ||
default: 0, | ||
examples: [15, 90] | ||
}, | ||
sort_by: { | ||
type: :string, | ||
examples: %w[version:asc] | ||
}, | ||
# FIXME: compatibility with the V1 logic from the common concerns | ||
relationships: { | ||
type: :boolean, | ||
enum: [false], | ||
examples: [false], | ||
description: 'The attribute represents a return value, that can be either false or unset' | ||
}, | ||
filter: { | ||
type: :string, | ||
examples: ["name='Standard System Security Profile for Fedora'"] | ||
} | ||
} | ||
}.freeze | ||
|
||
LINKS = { | ||
type: :object, | ||
properties: { | ||
first: { | ||
type: :string, | ||
format: :uri | ||
}, | ||
last: { | ||
type: :string, | ||
format: :uri | ||
}, | ||
previous: { | ||
type: :string, | ||
format: :uri | ||
}, | ||
next: { | ||
type: :string, | ||
format: :uri | ||
} | ||
} | ||
}.freeze | ||
|
||
TAGS = { | ||
type: :array, | ||
items: { | ||
type: :string, | ||
example: 'insights/environment=production' | ||
} | ||
}.freeze | ||
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require './spec/api/v2/schemas/util' | ||
|
||
module Api | ||
module V2 | ||
module Schemas | ||
module SecurityGuides | ||
extend Api::V2::Schemas::Util | ||
|
||
SECURITY_GUIDE = { | ||
type: :object, | ||
required: %w[ref_id title version os_major_version], | ||
properties: { | ||
ref_id: { | ||
type: :string, | ||
examples: ['xccdf_org.ssgproject.content_benchmark_RHEL-7'] | ||
}, | ||
title: { | ||
type: :string, | ||
examples: ['Guide to the Secure Configuration of Red Hat ' \ | ||
'Enterprise Linux 7'] | ||
}, | ||
version: { | ||
type: :string, | ||
examples: ['0.1.46'] | ||
}, | ||
description: { | ||
type: :string, | ||
examples: ['This guide presents a catalog of security-relevant ' \ | ||
'configuration settings for Red Hat Enterprise Linux 7.'] | ||
}, | ||
os_major_version: { | ||
type: :number, | ||
minimum: 6, | ||
examples: [7] | ||
} | ||
} | ||
}.freeze | ||
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require './spec/api/v1/schemas/util' | ||
|
||
module Api | ||
module V2 | ||
module Schemas | ||
module Types | ||
extend Util | ||
|
||
UUID = { type: :string, format: :uuid }.freeze | ||
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
module V2 | ||
module Schemas | ||
module Util | ||
def ref_schema(label) | ||
{ '$ref' => "#/components/schemas/#{label}" } | ||
end | ||
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,91 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'swagger_helper' | ||
|
||
describe 'Security Guides', swagger_doc: 'v2/openapi.json' do | ||
let(:identity_header) do | ||
OpenStruct.new( | ||
cert_based?: false, | ||
valid?: true, | ||
org_id: '1234', | ||
identity: { org_id: '1234' }, | ||
raw: nil | ||
) | ||
end | ||
|
||
before do | ||
allow(Insights::Api::Common::IdentityHeader).to receive(:new).and_return(identity_header) | ||
|
||
stub_rbac_permissions(Rbac::COMPLIANCE_ADMIN, Rbac::INVENTORY_HOSTS_READ) | ||
end | ||
|
||
path '/security_guides' do | ||
get 'List all Security Guides' do | ||
before do | ||
SupportedSsg.all.map(&:os_major_version).uniq.each do |os_version| | ||
FactoryBot.create( | ||
:v2_security_guide, | ||
title: 'Guide to the Secure Configuration of Red Hat Enterprise ' \ | ||
"Linux #{os_version}", | ||
description: 'This guide presents a catalog of security-relevant ' \ | ||
"configuration settings for Red Hat Enterprise Linux #{os_version}.", | ||
os_major_version: os_version | ||
) | ||
end | ||
end | ||
|
||
tags 'security_guide' | ||
description 'Lists all Security guides' | ||
operationId 'ListSecurityGuides' | ||
content_types | ||
pagination_params | ||
sort_params_v2(V2::SecurityGuide) | ||
search_params_v2(V2::SecurityGuide) | ||
|
||
response '200', 'Lists all Security Guides requested' do | ||
schema type: :object, | ||
properties: { | ||
meta: ref_schema('metadata'), | ||
links: ref_schema('links'), | ||
data: { | ||
type: :array, | ||
items: { | ||
properties: { | ||
type: { type: :string }, | ||
id: ref_schema('uuid'), | ||
attributes: ref_schema('security_guides') | ||
} | ||
} | ||
} | ||
} | ||
|
||
after { |e| autogenerate_examples(e, 'List of Security Guides') } | ||
|
||
run_test! | ||
end | ||
|
||
response '200', 'Lists all Security Guides requested' do | ||
let(:sort_by) { ['os_major_version'] } | ||
schema type: :object, | ||
properties: { | ||
meta: ref_schema('metadata'), | ||
links: ref_schema('links'), | ||
data: { | ||
type: :array, | ||
items: { | ||
properties: { | ||
type: { type: :string }, | ||
id: ref_schema('uuid'), | ||
attributes: ref_schema('security_guides') | ||
} | ||
} | ||
} | ||
} | ||
|
||
after { |e| autogenerate_examples(e, 'List of Security Guides sorted by os_major_verision:asc') } | ||
|
||
run_test! | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.