From 31cf27dac3181ea3cc706f90f6641f5466a6c6a4 Mon Sep 17 00:00:00 2001 From: taylor_socfortress <111797488+taylorwalton@users.noreply.github.com> Date: Wed, 12 Jul 2023 14:08:31 -0600 Subject: [PATCH] swagger config for sublime endpoint (#13) --- backend/app/routes/sublime.py | 6 +- backend/app/static/swagger.json | 197 ++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+), 3 deletions(-) diff --git a/backend/app/routes/sublime.py b/backend/app/routes/sublime.py index 76c1336d..44d32c6a 100644 --- a/backend/app/routes/sublime.py +++ b/backend/app/routes/sublime.py @@ -28,10 +28,10 @@ def put_alert() -> jsonify: try: message_id = service.validate_payload(data=data) service.store_alert(message_id=message_id) - return jsonify({"message": "Successfully stored payload.", "success": True}), 200 + return jsonify({"message": "Successfully stored message ID.", "success": True}), 200 except InvalidPayloadError: - logger.error("Received invalid payload.") - return jsonify({"message": "Invalid payload.", "success": False}), 400 + logger.error("Received invalid payload. No message ID found.") + return jsonify({"message": "Invalid payload. No message ID found", "success": False}), 400 @bp.route("/sublime/alerts", methods=["GET"]) diff --git a/backend/app/static/swagger.json b/backend/app/static/swagger.json index 71af1b30..7e8fc315 100644 --- a/backend/app/static/swagger.json +++ b/backend/app/static/swagger.json @@ -73,6 +73,14 @@ "description": "Find out more", "url": "http://swagger.io" } + }, + { + "name": "Sublime", + "description": "Everything about Sublime", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } } ], "paths": { @@ -1821,6 +1829,195 @@ "operationId": "getAllAlerts", "tags": ["DFIR Iris"] } + }, + "/sublime/alerts": { + "get": { + "summary": "Get all alerts", + "description": "Endpoint to get all alerts.", + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "alerts": { + "type": "array", + "items": { + "type": "object", + "description": "Alert details" + } + } + } + } + } + } + }, + "default": { + "description": "Unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "operationId": "getAllAlerts", + "tags": ["Sublime"] + } + }, + "/sublime/alert": { + "post": { + "summary": "Create an alert", + "description": "Endpoint to create an alert.", + "requestBody": { + "description": "Alert details", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "api_version": { + "type": "string", + "example": "1" + }, + "created_at": { + "type": "string", + "format": "date-time", + "example": "2023-06-28T20:45:01.619833409Z" + }, + "data": { + "type": "object", + "properties": { + "flagged_rules": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "example": "1845f3e6-e446-4f1a-b256-83539f850ed3" + }, + "name": { + "type": "string", + "example": "Test rule" + }, + "severity": { + "type": "string", + "nullable": true + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "message": { + "type": "object", + "properties": { + "canonical_id": { + "type": "string", + "example": "c6a577585601e9ac17c949a33f73956ec7ee9f2ad1c4209d7e69dda819a62969" + }, + "external_id": { + "type": "string", + "example": "29082" + }, + "id": { + "type": "string", + "example": "4a29ffda-3efe-4418-b9a0-c4e40878b7c5" + }, + "mailbox": { + "type": "object", + "properties": { + "external_id": { + "type": "string", + "nullable": true + }, + "id": { + "type": "string", + "example": "e921c909-e72a-4c9c-b56c-0dd59c7f49c3" + } + } + }, + "message_source_id": { + "type": "string", + "example": "d4bc5aef-ee26-4c54-a43e-de5faa794575" + } + } + }, + "triggered_actions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "example": "2c16da90-6f79-496b-886a-bf382423762a" + }, + "name": { + "type": "string", + "example": "Shuffle" + }, + "type": { + "type": "string", + "example": "webhook" + } + } + } + } + } + }, + "id": { + "type": "string", + "example": "30aae129-ec7a-4797-bcd4-a1e6e924e5db" + }, + "type": { + "type": "string", + "example": "message.flagged" + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "alert": { + "type": "object", + "description": "Alert details" + } + } + } + } + } + }, + "default": { + "description": "Unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "operationId": "createAlert", + "tags": ["Sublime"] + } } }, "components": {