From b84ef033a0dac6d6be73df9d82a4284521f90aaa Mon Sep 17 00:00:00 2001 From: lucamrgs <39555424+lucamrgs@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:52:08 +0100 Subject: [PATCH] modify API calls as I think they're better now --- .../en/docs/core-components/api-manual.md | 8 +++++--- pkg/api/api.go | 4 ++-- pkg/api/manual/manual_api.go | 18 ++++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/content/en/docs/core-components/api-manual.md b/docs/content/en/docs/core-components/api-manual.md index 6800056b..7dcba4f2 100644 --- a/docs/content/en/docs/core-components/api-manual.md +++ b/docs/content/en/docs/core-components/api-manual.md @@ -17,7 +17,8 @@ We will use HTTP status codes https://en.wikipedia.org/wiki/List_of_HTTP_status_ @startuml protocol Manual { GET /manual - POST /manual/continue + GET /manual/{execution-id}/{step-id} + PATCH /manual/{execution-id}/{step-id} } @enduml ``` @@ -153,7 +154,7 @@ None 404/Not found with payload: General error -#### POST `/manual/continue` +#### PATCH `/manual//` Respond to manual command pending in SOARCA, if out_args are defined they must be filled in and returned in the payload body. Only value is required in the response of the variable. You can however return the entire object. If the object does not match the original out_arg, the call we be considered as failed. ##### Call payload @@ -192,7 +193,8 @@ Respond to manual command pending in SOARCA, if out_args are defined they must b ``` ##### Response -200/OK with payload: +200/OK with payload: +Generic execution information ##### Error 400/BAD REQUEST with payload: diff --git a/pkg/api/api.go b/pkg/api/api.go index ac948f26..0a98bfcf 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -142,7 +142,7 @@ func ManualRoutes(route *gin.Engine, manualHandler *manual_handler.ManualHandler manualRoutes := route.Group("/manual") { manualRoutes.GET("./", manualHandler.GetPendingCommands) - manualRoutes.GET(":execution_id/:step_id", manualHandler.GetPendingCommand) - manualRoutes.POST("/continue", manualHandler.PostContinue) + manualRoutes.GET(":exec_id/:step_id", manualHandler.GetPendingCommand) + manualRoutes.PATCH(":exec_id/:step_id", manualHandler.PatchContinue) } } diff --git a/pkg/api/manual/manual_api.go b/pkg/api/manual/manual_api.go index c787bd5f..7e6c1fdd 100644 --- a/pkg/api/manual/manual_api.go +++ b/pkg/api/manual/manual_api.go @@ -88,11 +88,11 @@ func (manualHandler *ManualHandler) GetPendingCommands(g *gin.Context) { // @Tags manual // @Accept json // @Produce json -// @Param execution_id path string true "execution ID" -// @Param step_id path string true "step ID" +// @Param exec_id path string true "execution ID" +// @Param step_id path string true "step ID" // @Success 200 {object} manual.InteractionCommandData // @failure 400 {object} api.Error -// @Router /manual/{execution_id}/{step_id} [GET] +// @Router /manual/{exec_id}/{step_id} [GET] func (manualHandler *ManualHandler) GetPendingCommand(g *gin.Context) { execution_id := g.Param("execution_id") step_id := g.Param("step_id") @@ -126,6 +126,8 @@ func (manualHandler *ManualHandler) GetPendingCommand(g *gin.Context) { // @Tags manual // @Accept json // @Produce json +// @Param exec_id path string true "execution ID" +// @Param step_id path string true "step ID" // @Param type body string true "type" // @Param outArgs body string true "execution ID" // @Param execution_id body string true "playbook ID" @@ -135,10 +137,10 @@ func (manualHandler *ManualHandler) GetPendingCommand(g *gin.Context) { // @Param response_out_args body manual.ManualOutArgs true "out args" // @Success 200 {object} api.Execution // @failure 400 {object} api.Error -// @Router /manual/continue/{execution_id}/{step_id} [POST] -func (manualHandler *ManualHandler) PostContinue(g *gin.Context) { +// @Router /manual/{exec_id}/{step_id} [PATCH] +func (manualHandler *ManualHandler) PatchContinue(g *gin.Context) { - paramExecutionId := g.Param("execution_id") + paramExecutionId := g.Param("exec_id") paramStepId := g.Param("step_id") jsonData, err := io.ReadAll(g.Request.Body) @@ -146,7 +148,7 @@ func (manualHandler *ManualHandler) PostContinue(g *gin.Context) { log.Error("failed") apiError.SendErrorResponse(g, http.StatusBadRequest, "Failed to read json", - "POST /manual/continue/{execution_id}/{step_id}", "") + "POST /manual/continue/{exec_id}/{step_id}", "") return } @@ -156,7 +158,7 @@ func (manualHandler *ManualHandler) PostContinue(g *gin.Context) { log.Error("failed to unmarshal JSON") apiError.SendErrorResponse(g, http.StatusBadRequest, "Failed to unmarshal JSON", - "POST /manual/continue/{execution_id}/{step_id}", "") + "POST /manual/continue/{exec_id}/{step_id}", "") return }