-
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
963f328
commit fd57718
Showing
10 changed files
with
626 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
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require './spec/api/v2/schemas/security_guides' | ||
require './spec/api/v2/schemas/metadata' | ||
|
||
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,74 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
module V2 | ||
module Schemas | ||
module Metadata | ||
UUID = { type: :string, format: :uuid }.freeze | ||
METADATA = { | ||
type: 'object', | ||
properties: { | ||
total: { | ||
type: 'integer', | ||
examples: [1] | ||
}, | ||
limit: { | ||
type: 'integer', | ||
maximum: 100, | ||
minimum: 1, | ||
default: 10, | ||
examples: [10, 100] | ||
}, | ||
offset: { | ||
type: 'integer', | ||
minimum: 1, | ||
default: 1, | ||
examples: [1, 3] | ||
}, | ||
sort_by: { | ||
type: 'string', | ||
examples: %w[asc desc], | ||
default: '' | ||
}, | ||
relationships: { | ||
type: 'boolean', | ||
examples: [false, true] | ||
}, | ||
filter: { | ||
type: 'string', | ||
examples: ["name='Standard System Security Profile for Fedora'"] | ||
} | ||
}, | ||
required: %w[limit offset] | ||
}.freeze | ||
|
||
LINKS = { | ||
type: 'object', | ||
properties: { | ||
first: { | ||
type: 'string' | ||
}, | ||
last: { | ||
type: 'string' | ||
}, | ||
previous: { | ||
type: 'string' | ||
}, | ||
next: { | ||
type: 'string' | ||
} | ||
}, | ||
required: %w[first last] | ||
}.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,40 @@ | ||
# 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], | ||
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' | ||
}, | ||
os_major_version: { | ||
type: 'number', | ||
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,77 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'swagger_helper' | ||
|
||
describe 'Security Guides', swagger_doc: 'v2/openapi.json' do | ||
before do | ||
stub_rbac_permissions(Rbac::COMPLIANCE_ADMIN, Rbac::INVENTORY_VIEWER) | ||
end | ||
|
||
path '/security_guides' do | ||
get 'List all Security Guides' do | ||
before do | ||
FactoryBot.create( | ||
:v2_security_guide, | ||
title: 'Guide to the Secure Configuration of Red Hat Enterprise '\ | ||
'Linux 6', | ||
description: 'This guide presents a catalog of security-relevant '\ | ||
'configuration settings for Red Hat Enterprise Linux 6.', | ||
os_major_version: 6, | ||
version: '0.1.47' | ||
) | ||
FactoryBot.create( | ||
:v2_security_guide, | ||
title: 'Guide to the Secure Configuration of Red Hat Enterprise '\ | ||
'Linux 6', | ||
description: 'This guide presents a catalog of security-relevant '\ | ||
'configuration settings for Red Hat Enterprise Linux 6.', | ||
os_major_version: 6, | ||
version: '0.1.53' | ||
) | ||
[7, 8, 9].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 requested' | ||
operationId 'ListSecurityGuides' | ||
|
||
auth_header | ||
pagination_params | ||
search_params | ||
sort_params(Xccdf::Benchmark) | ||
content_types | ||
|
||
response '200', 'Lists all Security Guides requested' do | ||
let(:'X-RH-IDENTITY') { encoded_header } | ||
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 | ||
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
Oops, something went wrong.