diff --git a/docs/static/openapi/swagger.json b/docs/static/openapi/swagger.json index 07f24987..00e53fcc 100644 --- a/docs/static/openapi/swagger.json +++ b/docs/static/openapi/swagger.json @@ -4,61 +4,30 @@ "contact": {} }, "paths": { - "/trigger/workflow": { - "post": { - "description": "trigger workflow", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "trigger" - ], - "summary": "trigger a workflow with via cacao payload", - "parameters": [ - { - "description": "execute playbook by payload", - "name": "playbook", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - ], - "responses": { - "200": { - "description": "{\"execution_id\":\"uuid\",\"payload\":\"playbook--uuid\"}" - } - } - } - }, - "/workflow/": { + "/playbook/": { "get": { - "description": "get UUIDs for workflow", + "description": "return all stored playbooks default limit:100", "produces": [ "application/json" ], "tags": [ - "workflow" + "playbook" ], - "summary": "gets all the UUIDs for the stored workflows", + "summary": "gets all the UUIDs for the stored playbooks", "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/cacao.Playbook" } } } } }, "post": { - "description": "submit a new workflow api", + "description": "submit a new playbook api", "consumes": [ "application/json" ], @@ -66,12 +35,12 @@ "application/json" ], "tags": [ - "workflow" + "playbook" ], - "summary": "submit workflow via the api", + "summary": "submit playbook via the api", "parameters": [ { - "description": "workflow", + "description": "playbook", "name": "data", "in": "body", "required": true, @@ -90,9 +59,32 @@ } } }, - "/workflow/{id}": { + "/playbook/meta": { "get": { - "description": "get workflow by ID", + "description": "get playbook meta information for playbook", + "produces": [ + "application/json" + ], + "tags": [ + "playbook" + ], + "summary": "gets all the meta information for the stored playbooks", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/api.PlaybookMeta" + } + } + } + } + } + }, + "/playbook/{id}": { + "get": { + "description": "get playbook by ID", "consumes": [ "application/json" ], @@ -100,13 +92,13 @@ "application/json" ], "tags": [ - "workflow" + "playbook" ], - "summary": "get CACAO playbook workflow by its ID", + "summary": "get CACAO playbook by its ID", "parameters": [ { "type": "string", - "description": "workflow ID", + "description": "playbook ID", "name": "id", "in": "path", "required": true @@ -122,7 +114,7 @@ } }, "put": { - "description": "update workflow by ID", + "description": "update playbook by Id", "consumes": [ "application/json" ], @@ -130,19 +122,19 @@ "application/json" ], "tags": [ - "workflow" + "playbook" ], - "summary": "update workflow", + "summary": "update playbook", "parameters": [ { "type": "string", - "description": "workflow ID", + "description": "playbook Id", "name": "id", "in": "path", "required": true }, { - "description": "workflow", + "description": "playbook", "name": "data", "in": "body", "required": true, @@ -161,7 +153,7 @@ } }, "delete": { - "description": "delete workflow by ID", + "description": "delete playbook by Id", "consumes": [ "application/json" ], @@ -169,13 +161,13 @@ "application/json" ], "tags": [ - "workflow" + "playbook" ], - "summary": "delete worflow", + "summary": "delete playbook by Id", "parameters": [ { "type": "string", - "description": "workflow ID", + "description": "playbook ID", "name": "id", "in": "path", "required": true @@ -187,13 +179,69 @@ } } } + }, + "/trigger/playbook": { + "post": { + "description": "trigger playbook", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "trigger" + ], + "summary": "trigger a playbook by supplying a cacao playbook payload", + "parameters": [ + { + "description": "execute playbook by payload", + "name": "playbook", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/cacao.Playbook" + } + } + ], + "responses": { + "200": { + "description": "{\"execution_id\":\"uuid\",\"payload\":\"playbook--uuid\"}" + } + } + } } }, "definitions": { + "api.PlaybookMeta": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "labels": { + "type": "array", + "items": { + "type": "string" + } + }, + "name": { + "type": "string" + }, + "valid_from": { + "type": "string" + }, + "valid_until": { + "type": "string" + } + } + }, "cacao.AgentTarget": { "type": "object", "required": [ - "id", "name", "type" ], @@ -208,10 +256,7 @@ } }, "agent_target_extensions": { - "type": "array", - "items": { - "type": "string" - } + "$ref": "#/definitions/cacao.Extensions" }, "authentication_info": { "type": "string" @@ -228,9 +273,6 @@ "description": { "type": "string" }, - "http_url": { - "type": "string" - }, "id": { "type": "string" }, @@ -260,7 +302,6 @@ "cacao.AuthenticationInformation": { "type": "object", "required": [ - "id", "type" ], "properties": { @@ -371,7 +412,10 @@ "headers": { "type": "object", "additionalProperties": { - "type": "string" + "type": "array", + "items": { + "type": "string" + } } }, "playbook_activity": { @@ -386,10 +430,33 @@ } }, "cacao.Contact": { - "type": "object" + "type": "object", + "properties": { + "contact_details": { + "type": "string" + }, + "email": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "phone": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } }, "cacao.DataMarking": { "type": "object", + "required": [ + "created", + "created_by", + "id", + "type" + ], "properties": { "affected_party_notifications": { "type": "string" @@ -430,6 +497,9 @@ "type": "string" } }, + "marking_extensions": { + "$ref": "#/definitions/cacao.Extensions" + }, "name": { "type": "string" }, @@ -465,21 +535,63 @@ } } }, + "cacao.ExtensionDefinition": { + "type": "object", + "required": [ + "created_by", + "schema", + "type", + "version" + ], + "properties": { + "created_by": { + "type": "string" + }, + "description": { + "type": "string" + }, + "external_references": { + "type": "array", + "items": { + "$ref": "#/definitions/cacao.ExternalReferences" + } + }, + "name": { + "type": "string" + }, + "schema": { + "type": "string" + }, + "type": { + "type": "string" + }, + "version": { + "type": "string" + } + } + }, + "cacao.Extensions": { + "type": "object", + "additionalProperties": true + }, "cacao.ExternalReferences": { "type": "object", "required": [ - "description", - "name", - "source", - "url" + "name" ], "properties": { "description": { "type": "string" }, + "external_id": { + "type": "string" + }, "name": { "type": "string" }, + "reference_id": { + "type": "string" + }, "source": { "type": "string" }, @@ -493,22 +605,12 @@ "required": [ "created", "created_by", - "description", - "external_references", "id", - "impact", - "labels", "modified", "name", - "playbook_types", - "priority", - "severity", "spec_version", "type", - "valid_from", - "valid_until", "workflow", - "workflow_exception", "workflow_start" ], "properties": { @@ -525,14 +627,16 @@ } }, "created": { - "description": "date time is already validate by the field type!", "type": "string" }, "created_by": { "type": "string" }, "data_marking_definitions": { - "$ref": "#/definitions/cacao.DataMarking" + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/cacao.DataMarking" + } }, "derived_from": { "type": "array", @@ -543,6 +647,12 @@ "description": { "type": "string" }, + "extension_definitions": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/cacao.ExtensionDefinition" + } + }, "external_references": { "type": "array", "items": { @@ -568,18 +678,23 @@ } }, "modified": { - "description": ",datetime=2006-01-02T15:04:05Z07:00\"`", "type": "string" }, "name": { "type": "string" }, + "playbook_extensions": { + "$ref": "#/definitions/cacao.Extensions" + }, "playbook_types": { "type": "array", "items": { "type": "string" } }, + "playbook_variables": { + "$ref": "#/definitions/cacao.Variables" + }, "priority": { "type": "integer" }, @@ -617,6 +732,9 @@ }, "cacao.Step": { "type": "object", + "required": [ + "type" + ], "properties": { "agent": { "type": "string" @@ -696,15 +814,15 @@ "playbook_id": { "type": "string" }, - "playbook_variables": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.Variables" - } - }, "playbook_version": { "type": "string" }, + "step_extensions": { + "$ref": "#/definitions/cacao.Extensions" + }, + "step_variables": { + "$ref": "#/definitions/cacao.Variables" + }, "switch": { "type": "string" }, @@ -722,8 +840,11 @@ } } }, - "cacao.Variables": { + "cacao.Variable": { "type": "object", + "required": [ + "type" + ], "properties": { "constant": { "type": "boolean" @@ -745,6 +866,12 @@ } } }, + "cacao.Variables": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/cacao.Variable" + } + }, "cacao.Workflow": { "type": "object", "additionalProperties": { diff --git a/docs/static/openapi/swagger.yaml b/docs/static/openapi/swagger.yaml index cba7aa4f..9c3c952a 100644 --- a/docs/static/openapi/swagger.yaml +++ b/docs/static/openapi/swagger.yaml @@ -1,4 +1,21 @@ definitions: + api.PlaybookMeta: + properties: + description: + type: string + id: + type: string + labels: + items: + type: string + type: array + name: + type: string + valid_from: + type: string + valid_until: + type: string + type: object cacao.AgentTarget: properties: address: @@ -8,9 +25,7 @@ definitions: type: array type: object agent_target_extensions: - items: - type: string - type: array + $ref: '#/definitions/cacao.Extensions' authentication_info: type: string category: @@ -21,8 +36,6 @@ definitions: $ref: '#/definitions/cacao.Contact' description: type: string - http_url: - type: string id: type: string location: @@ -40,7 +53,6 @@ definitions: type: type: string required: - - id - name - type type: object @@ -71,7 +83,6 @@ definitions: username: type: string required: - - id - type type: object cacao.CivicLocation: @@ -117,7 +128,9 @@ definitions: type: string headers: additionalProperties: - type: string + items: + type: string + type: array type: object playbook_activity: type: string @@ -130,6 +143,17 @@ definitions: - type type: object cacao.Contact: + properties: + contact_details: + type: string + email: + additionalProperties: + type: string + type: object + phone: + additionalProperties: + type: string + type: object type: object cacao.DataMarking: properties: @@ -159,6 +183,8 @@ definitions: items: type: string type: array + marking_extensions: + $ref: '#/definitions/cacao.Extensions' name: type: string permitted_actions: @@ -181,22 +207,55 @@ definitions: type: string valid_until: type: string + required: + - created + - created_by + - id + - type + type: object + cacao.ExtensionDefinition: + properties: + created_by: + type: string + description: + type: string + external_references: + items: + $ref: '#/definitions/cacao.ExternalReferences' + type: array + name: + type: string + schema: + type: string + type: + type: string + version: + type: string + required: + - created_by + - schema + - type + - version + type: object + cacao.Extensions: + additionalProperties: true type: object cacao.ExternalReferences: properties: description: type: string + external_id: + type: string name: type: string + reference_id: + type: string source: type: string url: type: string required: - - description - name - - source - - url type: object cacao.Playbook: properties: @@ -209,18 +268,23 @@ definitions: $ref: '#/definitions/cacao.AuthenticationInformation' type: object created: - description: date time is already validate by the field type! type: string created_by: type: string data_marking_definitions: - $ref: '#/definitions/cacao.DataMarking' + additionalProperties: + $ref: '#/definitions/cacao.DataMarking' + type: object derived_from: items: type: string type: array description: type: string + extension_definitions: + additionalProperties: + $ref: '#/definitions/cacao.ExtensionDefinition' + type: object external_references: items: $ref: '#/definitions/cacao.ExternalReferences' @@ -238,14 +302,17 @@ definitions: type: string type: array modified: - description: ',datetime=2006-01-02T15:04:05Z07:00"`' type: string name: type: string + playbook_extensions: + $ref: '#/definitions/cacao.Extensions' playbook_types: items: type: string type: array + playbook_variables: + $ref: '#/definitions/cacao.Variables' priority: type: integer severity: @@ -271,22 +338,12 @@ definitions: required: - created - created_by - - description - - external_references - id - - impact - - labels - modified - name - - playbook_types - - priority - - severity - spec_version - type - - valid_from - - valid_until - workflow - - workflow_exception - workflow_start type: object cacao.Step: @@ -343,12 +400,12 @@ definitions: type: string playbook_id: type: string - playbook_variables: - additionalProperties: - $ref: '#/definitions/cacao.Variables' - type: object playbook_version: type: string + step_extensions: + $ref: '#/definitions/cacao.Extensions' + step_variables: + $ref: '#/definitions/cacao.Variables' switch: type: string targets: @@ -359,8 +416,10 @@ definitions: type: integer type: type: string + required: + - type type: object - cacao.Variables: + cacao.Variable: properties: constant: type: boolean @@ -374,6 +433,12 @@ definitions: type: string value: type: string + required: + - type + type: object + cacao.Variables: + additionalProperties: + $ref: '#/definitions/cacao.Variable' type: object cacao.Workflow: additionalProperties: @@ -382,29 +447,9 @@ definitions: info: contact: {} paths: - /trigger/workflow: - post: - consumes: - - application/json - description: trigger workflow - parameters: - - description: execute playbook by payload - in: body - name: playbook - required: true - schema: - $ref: '#/definitions/cacao.Playbook' - produces: - - application/json - responses: - "200": - description: '{"execution_id":"uuid","payload":"playbook--uuid"}' - summary: trigger a workflow with via cacao payload - tags: - - trigger - /workflow/: + /playbook/: get: - description: get UUIDs for workflow + description: return all stored playbooks default limit:100 produces: - application/json responses: @@ -412,17 +457,17 @@ paths: description: OK schema: items: - type: string + $ref: '#/definitions/cacao.Playbook' type: array - summary: gets all the UUIDs for the stored workflows + summary: gets all the UUIDs for the stored playbooks tags: - - workflow + - playbook post: consumes: - application/json - description: submit a new workflow api + description: submit a new playbook api parameters: - - description: workflow + - description: playbook in: body name: data required: true @@ -435,16 +480,16 @@ paths: description: OK schema: $ref: '#/definitions/cacao.Playbook' - summary: submit workflow via the api + summary: submit playbook via the api tags: - - workflow - /workflow/{id}: + - playbook + /playbook/{id}: delete: consumes: - application/json - description: delete workflow by ID + description: delete playbook by Id parameters: - - description: workflow ID + - description: playbook ID in: path name: id required: true @@ -454,15 +499,15 @@ paths: responses: "200": description: OK - summary: delete worflow + summary: delete playbook by Id tags: - - workflow + - playbook get: consumes: - application/json - description: get workflow by ID + description: get playbook by ID parameters: - - description: workflow ID + - description: playbook ID in: path name: id required: true @@ -474,20 +519,20 @@ paths: description: OK schema: $ref: '#/definitions/cacao.Playbook' - summary: get CACAO playbook workflow by its ID + summary: get CACAO playbook by its ID tags: - - workflow + - playbook put: consumes: - application/json - description: update workflow by ID + description: update playbook by Id parameters: - - description: workflow ID + - description: playbook Id in: path name: id required: true type: string - - description: workflow + - description: playbook in: body name: data required: true @@ -500,7 +545,42 @@ paths: description: OK schema: $ref: '#/definitions/cacao.Playbook' - summary: update workflow + summary: update playbook + tags: + - playbook + /playbook/meta: + get: + description: get playbook meta information for playbook + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/api.PlaybookMeta' + type: array + summary: gets all the meta information for the stored playbooks + tags: + - playbook + /trigger/playbook: + post: + consumes: + - application/json + description: trigger playbook + parameters: + - description: execute playbook by payload + in: body + name: playbook + required: true + schema: + $ref: '#/definitions/cacao.Playbook' + produces: + - application/json + responses: + "200": + description: '{"execution_id":"uuid","payload":"playbook--uuid"}' + summary: trigger a playbook by supplying a cacao playbook payload tags: - - workflow + - trigger swagger: "2.0" diff --git a/routes/playbook/playbook_api.go b/routes/playbook/playbook_api.go index 3dae458b..9ee794b7 100644 --- a/routes/playbook/playbook_api.go +++ b/routes/playbook/playbook_api.go @@ -22,14 +22,14 @@ func NewPlaybookController(controller database.IController) *playbookController } // getAllPlaybooks GET handler for obtaining all the playbooks in the database and return this to the gin context in json format -// @Summary gets all the UUIDs for the stored playbooks -// @Schemes -// @Description return all stored playbooks default limit:100 -// @Tags playbook -// @Produce json -// @success 200 {array} cacao.Playbook -// @error 400 -// @Router /playbook/ [GET] +// @Summary gets all the UUIDs for the stored playbooks +// @Schemes +// @Description return all stored playbooks default limit:100 +// @Tags playbook +// @Produce json +// @success 200 {array} cacao.Playbook +// @error 400 +// @Router /playbook/ [GET] func (plabookCtrl *playbookController) getAllPlaybooks(g *gin.Context) { log.Trace("Trying to obtain all playbook IDs") @@ -45,14 +45,14 @@ func (plabookCtrl *playbookController) getAllPlaybooks(g *gin.Context) { // getAllPlaybookMetas GET handler for obtaining all the meta data of all the stored playbooks // in the database and return this to the gin context in json format -// @Summary gets all the meta information for the stored playbooks -// @Schemes -// @Description get playbook meta information for playbook -// @Tags playbook -// @Produce json -// @success 200 {array} api.PlaybookMeta -// @error 400 -// @Router /playbook/meta [GET] +// @Summary gets all the meta information for the stored playbooks +// @Schemes +// @Description get playbook meta information for playbook +// @Tags playbook +// @Produce json +// @success 200 {array} api.PlaybookMeta +// @error 400 +// @Router /playbook/meta [GET] func (plabookCtrl *playbookController) getAllPlaybookMetas(g *gin.Context) { log.Trace("Trying to obtain all playbook IDs") @@ -67,16 +67,16 @@ func (plabookCtrl *playbookController) getAllPlaybookMetas(g *gin.Context) { } // submitPlaybook POST handler for creating playbooks. -// @Summary submit playbook via the api -// @Schemes -// @Description submit a new playbook api -// @Tags playbook -// @Produce json -// @Accept json -// @Param data body cacao.Playbook true "playbook" -// @Success 200 {object} cacao.Playbook -// @error 400 -// @Router /playbook/ [POST] +// @Summary submit playbook via the api +// @Schemes +// @Description submit a new playbook api +// @Tags playbook +// @Produce json +// @Accept json +// @Param data body cacao.Playbook true "playbook" +// @Success 200 {object} cacao.Playbook +// @error 400 +// @Router /playbook/ [POST] func (plabookCtrl *playbookController) submitPlaybook(g *gin.Context) { jsonData, err := io.ReadAll(g.Request.Body) if err != nil { @@ -98,16 +98,16 @@ func (plabookCtrl *playbookController) submitPlaybook(g *gin.Context) { } // getPlaybookByID GET handler that finds playbook by id -// @Summary get CACAO playbook by its ID -// @Schemes -// @Description get playbook by ID -// @Tags playbook -// @Produce json -// @Accept json -// @Param id path string true "playbook ID" -// @Success 200 {object} cacao.Playbook -// @error 400 -// @Router /playbook/{id} [GET] +// @Summary get CACAO playbook by its ID +// @Schemes +// @Description get playbook by ID +// @Tags playbook +// @Produce json +// @Accept json +// @Param id path string true "playbook ID" +// @Success 200 {object} cacao.Playbook +// @error 400 +// @Router /playbook/{id} [GET] func (plabookCtrl *playbookController) getPlaybookByID(g *gin.Context) { id := g.Param("id") log.Trace("Trying to obtain playbook for id: ", id) @@ -122,17 +122,17 @@ func (plabookCtrl *playbookController) getPlaybookByID(g *gin.Context) { } // updatePlaybookyID PUT handler that allows updating playbook object by ID. -// @Summary update playbook -// @Schemes -// @Description update playbook by Id -// @Tags playbook -// @Produce json -// @Accept json -// @Param id path string true "playbook Id" -// @Param data body cacao.Playbook true "playbook" -// @Success 200 {object} cacao.Playbook -// @error 400 -// @Router /playbook/{id} [PUT] +// @Summary update playbook +// @Schemes +// @Description update playbook by Id +// @Tags playbook +// @Produce json +// @Accept json +// @Param id path string true "playbook Id" +// @Param data body cacao.Playbook true "playbook" +// @Success 200 {object} cacao.Playbook +// @error 400 +// @Router /playbook/{id} [PUT] func (plabookCtrl *playbookController) updatePlaybookByID(g *gin.Context) { id := g.Param("id") log.Trace("Trying to update playbook for id: ", id) @@ -153,16 +153,16 @@ func (plabookCtrl *playbookController) updatePlaybookByID(g *gin.Context) { } // deleteByPlaybookID DELETE handler for deleting playbook by ID. -// @Summary delete playbook by Id -// @Schemes -// @Description delete playbook by Id -// @Tags playbook -// @Produce json -// @Accept json -// @Param id path string true "playbook ID" -// @Success 200 -// @error 400 -// @Router /playbook/{id} [DELETE] +// @Summary delete playbook by Id +// @Schemes +// @Description delete playbook by Id +// @Tags playbook +// @Produce json +// @Accept json +// @Param id path string true "playbook ID" +// @Success 200 +// @error 400 +// @Router /playbook/{id} [DELETE] func (plabookCtrl *playbookController) deleteByPlaybookID(g *gin.Context) { id := g.Param("id") err := plabookCtrl.playbookRepo.Delete(id) diff --git a/routes/trigger/trigger_endpoints.go b/routes/trigger/trigger_endpoints.go index 77f7262f..a07d28e8 100644 --- a/routes/trigger/trigger_endpoints.go +++ b/routes/trigger/trigger_endpoints.go @@ -5,16 +5,16 @@ import ( ) // trigger -// @Summary trigger a playbook by supplying a cacao playbook payload -// @Schemes -// @Description trigger playbook -// @Tags trigger -// @Accept json -// @Produce json -// @Param playbook body cacao.Playbook true "execute playbook by payload" -// @Success 200 "{"execution_id":"uuid","payload":"playbook--uuid"}" -// @error 400 -// @Router /trigger/playbook [POST] +// @Summary trigger a playbook by supplying a cacao playbook payload +// @Schemes +// @Description trigger playbook +// @Tags trigger +// @Accept json +// @Produce json +// @Param playbook body cacao.Playbook true "execute playbook by payload" +// @Success 200 "{"execution_id":"uuid","payload":"playbook--uuid"}" +// @error 400 +// @Router /trigger/playbook [POST] func Routes(route *gin.Engine, trigger *TriggerApi) { group := route.Group("/trigger") {