2018-04-26 19:38:16 +00:00
|
|
|
require 'swagger/blocks'
|
|
|
|
|
|
|
|
module ServiceApiDoc
|
|
|
|
include Swagger::Blocks
|
|
|
|
|
2018-05-15 19:34:15 +00:00
|
|
|
HOST_DESC = 'The host where this service is running.'
|
2018-05-22 19:57:21 +00:00
|
|
|
HOST_ID_DESC = 'The ID of the host record this service is associated with.'
|
2018-05-15 19:34:15 +00:00
|
|
|
PORT_DESC = 'The port this service is listening on.'
|
|
|
|
PORT_EXAMPLE = '443'
|
|
|
|
PROTO_DESC = 'The transport layer protocol this service is using.'
|
|
|
|
PROTO_ENUM = ['tcp', 'udp']
|
|
|
|
NAME_DESC = 'The application layer protocol.'
|
|
|
|
NAME_EXAMPLE = "'ssh', 'mssql', 'smb', etc."
|
|
|
|
STATE_DESC = 'The current listening state of the service.'
|
|
|
|
STATE_ENUM = ['open', 'closed', 'filtered', 'unknown']
|
|
|
|
INFO_DESC = 'Detailed information about the service such as name and version information.'
|
|
|
|
INFO_EXAMPLE = "'ProFTPD 1.3.5', 'WEBrick httpd 1.3.1 Ruby 2.3.4', etc."
|
|
|
|
|
2018-04-26 19:38:16 +00:00
|
|
|
# Swagger documentation for Service model
|
|
|
|
swagger_schema :Service do
|
|
|
|
key :required, [:id, :port, :proto]
|
2018-05-22 19:57:21 +00:00
|
|
|
property :id, type: :integer, format: :int32, description: RootApiDoc::ID_DESC
|
|
|
|
property :host_id, type: :integer, format: :int32, description: HOST_ID_DESC
|
2018-05-15 19:34:15 +00:00
|
|
|
property :port, type: :string, description: PORT_DESC, example: PORT_EXAMPLE
|
|
|
|
property :proto, type: :string, description: PROTO_DESC, enum: PROTO_ENUM
|
|
|
|
property :name, type: :string, description: NAME_DESC, example: NAME_EXAMPLE
|
|
|
|
property :info, type: :string, description: INFO_DESC, example: INFO_EXAMPLE
|
|
|
|
property :state, type: :string, description: STATE_DESC, enum: STATE_ENUM
|
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 19:38:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
swagger_path '/api/v1/services' do
|
2018-05-02 19:47:17 +00:00
|
|
|
# Swagger documentation for /api/v1/services GET
|
2018-04-26 19:38:16 +00:00
|
|
|
operation :get do
|
|
|
|
key :description, 'Return services that are stored in the database.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'service' ]
|
2018-04-26 19:38:16 +00:00
|
|
|
|
|
|
|
parameter :workspace
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Returns service data.'
|
2018-04-26 19:38:16 +00:00
|
|
|
schema do
|
2018-07-25 23:01:05 +00:00
|
|
|
property :data do
|
|
|
|
key :type, :array
|
|
|
|
items do
|
|
|
|
key :'$ref', :Service
|
|
|
|
end
|
2018-04-26 19:38:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Swagger documentation for /api/v1/services POST
|
|
|
|
operation :post do
|
|
|
|
key :description, 'Create a Service.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'service' ]
|
2018-04-26 19:38:16 +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 service.'
|
2018-04-26 19:38:16 +00:00
|
|
|
key :required, true
|
|
|
|
schema do
|
2018-05-22 19:57:21 +00: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-15 19:34:15 +00:00
|
|
|
property :port, type: :string, required: true, description: PORT_DESC, example: PORT_EXAMPLE
|
|
|
|
property :proto, type: :string, required: true, description: PROTO_DESC, enum: PROTO_ENUM
|
|
|
|
property :name, type: :string, description: NAME_DESC, example: NAME_EXAMPLE
|
|
|
|
property :info, type: :string, description: INFO_DESC, example: INFO_EXAMPLE
|
|
|
|
property :state, type: :string, description: STATE_DESC, enum: STATE_ENUM
|
2018-04-26 19:38:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Successful operation.'
|
2018-04-26 19:38:16 +00:00
|
|
|
schema do
|
2018-07-25 23:01:05 +00:00
|
|
|
property :data do
|
|
|
|
key :'$ref', :Service
|
|
|
|
end
|
2018-04-26 19:38:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Swagger documentation for /api/v1/services/ DELETE
|
|
|
|
operation :delete do
|
|
|
|
key :description, 'Delete the specified services.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'service' ]
|
2018-04-26 19:38:16 +00:00
|
|
|
|
|
|
|
parameter :delete_opts
|
|
|
|
|
|
|
|
response 200 do
|
2018-07-25 23:01:05 +00:00
|
|
|
key :description, 'Returns an array of containing the successfully deleted services.'
|
2018-04-26 19:38:16 +00:00
|
|
|
schema do
|
2018-07-25 23:01:05 +00:00
|
|
|
property :data do
|
|
|
|
key :type, :array
|
|
|
|
items do
|
|
|
|
key :'$ref', :Service
|
|
|
|
end
|
2018-04-26 19:38:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-15 19:34:15 +00:00
|
|
|
swagger_path '/api/v1/services/{id}' do
|
2018-05-02 19:47:17 +00:00
|
|
|
# Swagger documentation for api/v1/services/:id GET
|
2018-04-26 19:38:16 +00:00
|
|
|
|
2018-07-18 21:01:12 +00:00
|
|
|
operation :get do
|
|
|
|
key :description, 'Return specific service that is stored in the database.'
|
|
|
|
key :tags, [ 'service' ]
|
|
|
|
|
|
|
|
parameter do
|
|
|
|
key :name, :id
|
|
|
|
key :in, :path
|
|
|
|
key :description, 'ID of service to retrieve.'
|
|
|
|
key :required, true
|
|
|
|
key :type, :integer
|
|
|
|
key :format, :int32
|
|
|
|
end
|
|
|
|
|
|
|
|
response 200 do
|
|
|
|
key :description, 'Returns service data.'
|
|
|
|
schema do
|
2018-07-25 23:01:05 +00:00
|
|
|
property :data do
|
|
|
|
key :type, :array
|
|
|
|
items do
|
|
|
|
key :'$ref', :Service
|
|
|
|
end
|
2018-07-18 21:01:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-26 19:38:16 +00:00
|
|
|
|
|
|
|
# Swagger documentation for /api/v1/services/:id PUT
|
|
|
|
operation :put do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Update the attributes an existing service.'
|
2018-04-30 21:40:07 +00:00
|
|
|
key :tags, [ 'service' ]
|
2018-04-26 19:38:16 +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 service.'
|
2018-04-26 19:38:16 +00:00
|
|
|
key :required, true
|
|
|
|
schema do
|
|
|
|
key :'$ref', :Service
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response 200 do
|
2018-05-17 21:56:22 +00:00
|
|
|
key :description, 'Successful operation.'
|
2018-04-26 19:38:16 +00:00
|
|
|
schema do
|
2018-07-25 23:01:05 +00:00
|
|
|
property :data do
|
|
|
|
key :'$ref', :Service
|
|
|
|
end
|
2018-04-26 19:38:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|