2018-04-26 22:42:03 +00:00
|
|
|
require 'swagger/blocks'
|
|
|
|
|
|
|
|
module NoteApiDoc
|
|
|
|
include Swagger::Blocks
|
|
|
|
|
2018-05-22 19:57:21 +00:00
|
|
|
NTYPE_DESC = 'The type of note this is.'
|
|
|
|
NTYPE_EXAMPLE = "'host.info', 'host.os.session_fingerprint', 'smb_peer_os', etc."
|
|
|
|
HOST_ID_DESC = 'The ID of the host record this note is associated with.'
|
|
|
|
HOST_DESC = 'The IP address of the host this note is associated with.'
|
|
|
|
SERVICE_ID_DESC = 'The ID of the host record this service is associated with.'
|
|
|
|
VULN_ID_DESC = 'The ID of the host record this note is associated with.'
|
2018-05-08 21:15:40 +00:00
|
|
|
CRITICAL_DESC = 'Boolean regarding the criticality of this note\'s contents.'
|
|
|
|
SEEN_DESC = 'Boolean regarding if this note has been acknowledged.'
|
|
|
|
DATA_DESC = 'The contents of the note.'
|
|
|
|
|
2018-04-26 22:42:03 +00:00
|
|
|
# Swagger documentation for notes model
|
|
|
|
swagger_schema :Note do
|
2018-05-22 19:57:21 +00:00
|
|
|
key :required, [:ntype]
|
|
|
|
property :id, type: :integer, format: :int32, description: RootApiDoc::ID_DESC
|
|
|
|
property :ntype, type: :string, description: NTYPE_DESC, example: NTYPE_EXAMPLE
|
|
|
|
property :workspace_id, type: :integer, format: :int32, description: RootApiDoc::WORKSPACE_ID_DESC
|
|
|
|
property :host_id, type: :integer, format: :int32, description: HOST_ID_DESC
|
|
|
|
property :service_id, type: :integer, format: :int32, description: SERVICE_ID_DESC
|
|
|
|
property :vuln_id, type: :integer, format: :int32, description: VULN_ID_DESC
|
2018-05-08 21:15:40 +00:00
|
|
|
property :critical, type: :boolean, description: CRITICAL_DESC
|
|
|
|
property :seen, type: :boolean, description: SEEN_DESC
|
|
|
|
property :data, type: :string, description: DATA_DESC
|
2018-05-22 19:57:21 +00: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-04-26 22:42:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
swagger_path '/api/v1/notes' do
|
2018-05-02 19:47:17 +00:00
|
|
|
# Swagger documentation for /api/v1/notes GET
|
2018-04-26 22:42:03 +00:00
|
|
|
operation :get do
|
|
|
|
key :description, 'Return notes that are stored in the database.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'note' ]
|
2018-04-26 22:42:03 +00:00
|
|
|
|
|
|
|
parameter :workspace
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Returns note data.'
|
2018-04-26 22:42:03 +00:00
|
|
|
schema do
|
|
|
|
key :type, :array
|
|
|
|
items do
|
|
|
|
key :'$ref', :Note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Swagger documentation for /api/v1/notes POST
|
|
|
|
operation :post do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Create a note entry.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'note' ]
|
2018-04-26 22:42:03 +00:00
|
|
|
|
|
|
|
parameter do
|
|
|
|
key :in, :body
|
|
|
|
key :name, :body
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'The attributes to assign to the note.'
|
2018-04-26 22:42:03 +00:00
|
|
|
key :required, true
|
|
|
|
schema do
|
2018-05-22 19:57:21 +00:00
|
|
|
property :ntype, type: :string, description: NTYPE_DESC, example: NTYPE_EXAMPLE, required: true
|
|
|
|
property :workspace, type: :string, required: true, description: RootApiDoc::WORKSPACE_POST_DESC, example: RootApiDoc::WORKSPACE_POST_EXAMPLE
|
|
|
|
property :host, type: :integer, format: :ipv4, description: HOST_DESC, example: RootApiDoc::HOST_EXAMPLE
|
2018-05-08 21:15:40 +00:00
|
|
|
property :critical, type: :boolean, description: CRITICAL_DESC
|
|
|
|
property :seen, type: :boolean, description: SEEN_DESC
|
|
|
|
property :data, type: :string, description: DATA_DESC
|
2018-04-26 22:42:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Successful operation.'
|
2018-04-26 22:42:03 +00:00
|
|
|
schema do
|
|
|
|
key :type, :object
|
|
|
|
key :'$ref', :Note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Swagger documentation for /api/v1/notes/ DELETE
|
|
|
|
operation :delete do
|
|
|
|
key :description, 'Delete the specified notes.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'note' ]
|
2018-04-26 22:42:03 +00:00
|
|
|
|
|
|
|
parameter :delete_opts
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Successful operation.'
|
2018-04-26 22:42:03 +00:00
|
|
|
schema do
|
|
|
|
key :type, :array
|
|
|
|
items do
|
|
|
|
key :'$ref', :Note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-08 21:15:40 +00:00
|
|
|
swagger_path '/api/v1/notes/{id}' do
|
2018-05-02 19:47:17 +00:00
|
|
|
# Swagger documentation for api/v1/notes/:id GET
|
2018-04-26 22:42:03 +00:00
|
|
|
operation :get do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Return specific note that is stored in the database.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'note' ]
|
2018-04-26 22:42:03 +00:00
|
|
|
|
|
|
|
parameter :workspace
|
|
|
|
|
|
|
|
parameter do
|
|
|
|
key :name, :id
|
|
|
|
key :in, :path
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'ID of note to retrieve.'
|
2018-04-26 22:42:03 +00:00
|
|
|
key :required, true
|
|
|
|
key :type, :integer
|
|
|
|
key :format, :int32
|
|
|
|
end
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Returns notes data.'
|
2018-04-26 22:42:03 +00:00
|
|
|
schema do
|
|
|
|
key :type, :array
|
|
|
|
items do
|
|
|
|
key :'$ref', :Note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Swagger documentation for /api/v1/notes/:id PUT
|
|
|
|
operation :put do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Update the attributes an existing note.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'note' ]
|
2018-04-26 22:42:03 +00:00
|
|
|
|
|
|
|
parameter :update_id
|
|
|
|
|
|
|
|
parameter do
|
|
|
|
key :in, :body
|
|
|
|
key :name, :body
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'The updated attributes to overwrite to the note.'
|
2018-04-26 22:42:03 +00:00
|
|
|
key :required, true
|
|
|
|
schema do
|
|
|
|
key :'$ref', :Note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Successful operation.'
|
2018-04-26 22:42:03 +00:00
|
|
|
schema do
|
|
|
|
key :type, :object
|
|
|
|
key :'$ref', :Note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|