2018-04-30 13:41:31 -05:00
require 'swagger/blocks'
module VulnApiDoc
include Swagger :: Blocks
2018-05-22 14:57:21 -05:00
HOST_ID_DESC = 'The ID of host record associated with this vuln.'
2018-05-16 15:26:44 -05:00
HOST_DESC = 'The host where this vuln was discovered.'
NAME_DESC = 'The friendly name/title for this vulnerability.'
NAME_EXAMPLE = 'Docker Daemon Privilege Escalation'
INFO_DESC = 'Information about how this vuln was discovered.'
INFO_EXAMPLE = 'Exploited by exploit/linux/local/docker_daemon_privilege_escalation to create session.'
2018-05-22 14:57:21 -05:00
EXPLOITED_AT_DESC = 'The date and time this vuln was successfully exploited.'
VULN_DETAIL_COUNT = 'Cached count of the number of associated vuln detail objects.'
VULN_ATTEMPT_COUNT = 'Cached count of the number of associated vuln attempt object.'
ORIGIN_ID_DESC = 'ID of the associated origin record.'
ORIGIN_TYPE_DESC = 'The origin type of this vuln.'
2018-05-16 15:26:44 -05:00
REFS_DESC = 'An array of public reference IDs for this vuln.'
2018-12-12 16:01:05 -06:00
REF_ID_DESC = 'The ID of the related Mdm::Ref associated with this vuln.'
2018-05-22 14:57:21 -05:00
REF_NAME_DESC = 'Designation for external reference. May include a prefix for the authority, such as \'CVE-\', in which case the rest of the name is the designation assigned by that authority.'
2018-05-16 15:37:33 -05:00
REFS_EXAMPLE = [ 'CVE-2008-4250' , 'OSVDB-49243' , 'MSB-MS08-067' ]
2018-05-16 15:26:44 -05:00
2018-04-30 13:41:31 -05:00
# Swagger documentation for vulns model
swagger_schema :Vuln do
2018-05-16 15:26:44 -05:00
key :required , [ :host_id , :name ]
2018-05-22 14:57:21 -05:00
property :id , type : :integer , format : :int32 , description : RootApiDoc :: ID_DESC
property :host_id , type : :integer , format : :int32 , description : HOST_ID_DESC
2018-05-16 15:26:44 -05:00
property :name , type : :string , description : NAME_DESC , example : NAME_EXAMPLE
property :info , type : :string , description : INFO_DESC , example : INFO_EXAMPLE
2018-05-22 14:57:21 -05:00
property :exploited_at , type : :string , format : :date_time , description : EXPLOITED_AT_DESC
property :vuln_detail_count , type : :integer , format : :int32 , description : VULN_DETAIL_COUNT
property :vuln_attempt_count , type : :integer , format : :int32 , description : VULN_ATTEMPT_COUNT
property :origin_id , type : :integer , format : :int32 , description : ORIGIN_ID_DESC
property :origin_type , type : :string , description : ORIGIN_TYPE_DESC
2018-05-16 15:26:44 -05:00
property :refs do
key :type , :array
items do
key :'$ref' , :Ref
end
end
2018-05-22 14:57:21 -05:00
property :created_at , type : :string , format : :date_time , description : RootApiDoc :: CREATED_AT_DESC
property :updated_at , type : :string , format : :date_time , description : RootApiDoc :: UPDATED_AT_DESC
2018-05-16 15:26:44 -05:00
end
swagger_schema :Ref do
key :required , [ :name ]
2018-05-22 14:57:21 -05:00
property :id , type : :integer , format : :int32 , description : RootApiDoc :: ID_DESC
property :ref_id , type : :integer , format : :int32 , description : REF_ID_DESC
property :name , type : :string , required : true , description : REF_NAME_DESC
property :created_at , type : :string , format : :date_time , description : RootApiDoc :: CREATED_AT_DESC
property :updated_at , type : :string , format : :date_time , description : RootApiDoc :: UPDATED_AT_DESC
2018-05-16 15:26:44 -05:00
end
2018-04-30 13:41:31 -05:00
swagger_path '/api/v1/vulns' do
2018-05-02 14:47:17 -05:00
# Swagger documentation for /api/v1/vulns GET
2018-04-30 13:41:31 -05:00
operation :get do
key :description , 'Return vulns that are stored in the database.'
2018-04-30 16:40:07 -05:00
key :tags , [ 'vuln' ]
2018-04-30 13:41:31 -05:00
parameter :workspace
response 200 do
2018-05-16 15:26:44 -05:00
key :description , 'Returns vuln data.'
2018-04-30 13:41:31 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :type , :array
items do
key :'$ref' , :Vuln
end
2018-04-30 13:41:31 -05:00
end
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-30 13:41:31 -05:00
end
# Swagger documentation for /api/v1/vulns POST
operation :post do
2018-05-16 15:26:44 -05:00
key :description , 'Create a vuln entry.'
2018-04-30 16:40:07 -05:00
key :tags , [ 'vuln' ]
2018-04-30 13:41:31 -05:00
parameter do
key :in , :body
key :name , :body
2018-05-16 15:26:44 -05:00
key :description , 'The attributes to assign to the vuln.'
2018-04-30 13:41:31 -05:00
key :required , true
schema do
2018-05-22 14:57:21 -05:00
property :workspace , type : :string , required : true , description : RootApiDoc :: WORKSPACE_POST_DESC , example : RootApiDoc :: WORKSPACE_POST_EXAMPLE
property :host , type : :string , format : :ipv4 , required : true , description : HOST_DESC , example : RootApiDoc :: HOST_EXAMPLE
2018-05-16 15:26:44 -05:00
property :name , type : :string , description : NAME_DESC , example : NAME_EXAMPLE
property :info , type : :string , description : INFO_DESC , example : INFO_EXAMPLE
property :refs do
key :type , :array
key :description , REFS_DESC
key :example , REFS_EXAMPLE
items do
key :type , :string
end
end
2018-04-30 13:41:31 -05:00
end
end
response 200 do
2018-07-25 18:01:05 -05:00
key :description , 'Returns vuln data.'
2018-04-30 13:41:31 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :'$ref' , :Vuln
end
2018-04-30 13:41:31 -05:00
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-30 13:41:31 -05:00
end
# Swagger documentation for /api/v1/vulns/ DELETE
operation :delete do
key :description , 'Delete the specified vulns.'
2018-04-30 16:40:07 -05:00
key :tags , [ 'vuln' ]
2018-04-30 13:41:31 -05:00
parameter :delete_opts
response 200 do
2018-07-26 08:43:05 -05:00
key :description , 'Returns an array containing the successfully deleted vulns.'
2018-04-30 13:41:31 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :type , :array
items do
key :'$ref' , :Vuln
end
2018-04-30 13:41:31 -05:00
end
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-30 13:41:31 -05:00
end
end
2018-05-16 15:26:44 -05:00
swagger_path '/api/v1/vulns/{id}' do
2018-05-02 14:47:17 -05:00
# Swagger documentation for api/v1/vulns/:id GET
2018-04-30 13:41:31 -05:00
operation :get do
2018-05-17 16:56:22 -05:00
key :description , 'Return specific vuln that is stored in the database.'
2018-04-30 16:40:07 -05:00
key :tags , [ 'vuln' ]
2018-04-30 13:41:31 -05:00
parameter do
key :name , :id
key :in , :path
2018-05-16 15:26:44 -05:00
key :description , 'ID of vuln to retrieve.'
2018-04-30 13:41:31 -05:00
key :required , true
key :type , :integer
key :format , :int32
end
response 200 do
2018-05-16 15:26:44 -05:00
key :description , 'Returns vuln data.'
2018-04-30 13:41:31 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
2018-07-31 15:43:57 -05:00
key :'$ref' , :Vuln
2018-04-30 13:41:31 -05:00
end
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-30 13:41:31 -05:00
end
# Swagger documentation for /api/v1/vulns/:id PUT
operation :put do
2019-01-11 13:20:32 -05:00
key :description , 'Update the attributes on an existing vuln.'
2018-04-30 16:40:07 -05:00
key :tags , [ 'vuln' ]
2018-04-30 13:41:31 -05:00
parameter :update_id
parameter do
key :in , :body
key :name , :body
2018-05-16 15:26:44 -05:00
key :description , 'The updated attributes to overwrite to the vuln.'
2018-04-30 13:41:31 -05:00
key :required , true
schema do
key :'$ref' , :Vuln
end
end
response 200 do
2018-07-25 18:01:05 -05:00
key :description , 'Returns vuln data.'
2018-04-30 13:41:31 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :'$ref' , :Vuln
end
2018-04-30 13:41:31 -05:00
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-30 13:41:31 -05:00
end
end
2018-08-14 13:35:59 -05:00
end