Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

note_api_doc.rb 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. require 'swagger/blocks'
  2. module NoteApiDoc
  3. include Swagger::Blocks
  4. NTYPE_DESC = 'The type of note this is.'
  5. NTYPE_EXAMPLE = "'host.info', 'host.os.session_fingerprint', 'smb_peer_os', etc."
  6. HOST_ID_DESC = 'The ID of the host record this note is associated with.'
  7. HOST_DESC = 'The IP address of the host this note is associated with.'
  8. SERVICE_ID_DESC = 'The ID of the host record this service is associated with.'
  9. VULN_ID_DESC = 'The ID of the host record this note is associated with.'
  10. CRITICAL_DESC = 'Boolean regarding the criticality of this note\'s contents.'
  11. SEEN_DESC = 'Boolean regarding if this note has been acknowledged.'
  12. DATA_DESC = 'The contents of the note.'
  13. # Swagger documentation for notes model
  14. swagger_schema :Note do
  15. key :required, [:ntype]
  16. property :id, type: :integer, format: :int32, description: RootApiDoc::ID_DESC
  17. property :ntype, type: :string, description: NTYPE_DESC, example: NTYPE_EXAMPLE
  18. property :workspace_id, type: :integer, format: :int32, description: RootApiDoc::WORKSPACE_ID_DESC
  19. property :host_id, type: :integer, format: :int32, description: HOST_ID_DESC
  20. property :service_id, type: :integer, format: :int32, description: SERVICE_ID_DESC
  21. property :vuln_id, type: :integer, format: :int32, description: VULN_ID_DESC
  22. property :critical, type: :boolean, description: CRITICAL_DESC
  23. property :seen, type: :boolean, description: SEEN_DESC
  24. property :data, type: :string, description: DATA_DESC
  25. property :created_at, type: :string, format: :date_time, description: RootApiDoc::CREATED_AT_DESC
  26. property :updated_at, type: :string, format: :date_time, description: RootApiDoc::UPDATED_AT_DESC
  27. end
  28. swagger_path '/api/v1/notes' do
  29. # Swagger documentation for /api/v1/notes GET
  30. operation :get do
  31. key :description, 'Return notes that are stored in the database.'
  32. key :tags, [ 'note' ]
  33. parameter :workspace
  34. response 200 do
  35. key :description, 'Returns note data.'
  36. schema do
  37. property :data do
  38. key :type, :array
  39. items do
  40. key :'$ref', :Note
  41. end
  42. end
  43. end
  44. end
  45. response 401 do
  46. key :description, RootApiDoc::DEFAULT_RESPONSE_401
  47. schema do
  48. key :'$ref', :AuthErrorModel
  49. end
  50. end
  51. response 500 do
  52. key :description, RootApiDoc::DEFAULT_RESPONSE_500
  53. schema do
  54. key :'$ref', :ErrorModel
  55. end
  56. end
  57. end
  58. # Swagger documentation for /api/v1/notes POST
  59. operation :post do
  60. key :description, 'Create a note entry.'
  61. key :tags, [ 'note' ]
  62. parameter do
  63. key :in, :body
  64. key :name, :body
  65. key :description, 'The attributes to assign to the note.'
  66. key :required, true
  67. schema do
  68. property :ntype, type: :string, description: NTYPE_DESC, example: NTYPE_EXAMPLE, required: true
  69. property :workspace, type: :string, required: true, description: RootApiDoc::WORKSPACE_POST_DESC, example: RootApiDoc::WORKSPACE_POST_EXAMPLE
  70. property :host, type: :integer, format: :ipv4, description: HOST_DESC, example: RootApiDoc::HOST_EXAMPLE
  71. property :critical, type: :boolean, description: CRITICAL_DESC
  72. property :seen, type: :boolean, description: SEEN_DESC
  73. property :data, type: :string, description: DATA_DESC
  74. end
  75. end
  76. response 200 do
  77. key :description, RootApiDoc::DEFAULT_RESPONSE_200
  78. schema do
  79. property :data do
  80. key :'$ref', :Note
  81. end
  82. end
  83. end
  84. response 401 do
  85. key :description, RootApiDoc::DEFAULT_RESPONSE_401
  86. schema do
  87. key :'$ref', :AuthErrorModel
  88. end
  89. end
  90. response 500 do
  91. key :description, RootApiDoc::DEFAULT_RESPONSE_500
  92. schema do
  93. key :'$ref', :ErrorModel
  94. end
  95. end
  96. end
  97. # Swagger documentation for /api/v1/notes/ DELETE
  98. operation :delete do
  99. key :description, 'Delete the specified notes.'
  100. key :tags, [ 'note' ]
  101. parameter :delete_opts
  102. response 200 do
  103. key :description, 'Returns an array containing the successfully deleted notes.'
  104. schema do
  105. property :data do
  106. key :type, :array
  107. items do
  108. key :'$ref', :Note
  109. end
  110. end
  111. end
  112. end
  113. response 401 do
  114. key :description, RootApiDoc::DEFAULT_RESPONSE_401
  115. schema do
  116. key :'$ref', :AuthErrorModel
  117. end
  118. end
  119. response 500 do
  120. key :description, RootApiDoc::DEFAULT_RESPONSE_500
  121. schema do
  122. key :'$ref', :ErrorModel
  123. end
  124. end
  125. end
  126. end
  127. swagger_path '/api/v1/notes/{id}' do
  128. # Swagger documentation for api/v1/notes/:id GET
  129. operation :get do
  130. key :description, 'Return specific note that is stored in the database.'
  131. key :tags, [ 'note' ]
  132. parameter do
  133. key :name, :id
  134. key :in, :path
  135. key :description, 'ID of note to retrieve.'
  136. key :required, true
  137. key :type, :integer
  138. key :format, :int32
  139. end
  140. response 200 do
  141. key :description, 'Returns note data.'
  142. schema do
  143. property :data do
  144. key :'$ref', :Note
  145. end
  146. end
  147. end
  148. response 401 do
  149. key :description, RootApiDoc::DEFAULT_RESPONSE_401
  150. schema do
  151. key :'$ref', :AuthErrorModel
  152. end
  153. end
  154. response 500 do
  155. key :description, RootApiDoc::DEFAULT_RESPONSE_500
  156. schema do
  157. key :'$ref', :ErrorModel
  158. end
  159. end
  160. end
  161. # Swagger documentation for /api/v1/notes/:id PUT
  162. operation :put do
  163. key :description, 'Update the attributes on an existing note.'
  164. key :tags, [ 'note' ]
  165. parameter :update_id
  166. parameter do
  167. key :in, :body
  168. key :name, :body
  169. key :description, 'The updated attributes to overwrite to the note.'
  170. key :required, true
  171. schema do
  172. key :'$ref', :Note
  173. end
  174. end
  175. response 200 do
  176. key :description, RootApiDoc::DEFAULT_RESPONSE_200
  177. schema do
  178. property :data do
  179. key :'$ref', :Note
  180. end
  181. end
  182. end
  183. response 401 do
  184. key :description, RootApiDoc::DEFAULT_RESPONSE_401
  185. schema do
  186. key :'$ref', :AuthErrorModel
  187. end
  188. end
  189. response 500 do
  190. key :description, RootApiDoc::DEFAULT_RESPONSE_500
  191. schema do
  192. key :'$ref', :ErrorModel
  193. end
  194. end
  195. end
  196. end
  197. end