Skip to content

Commit

Permalink
modify API calls as I think they're better now
Browse files Browse the repository at this point in the history
  • Loading branch information
lucamrgs authored and MaartendeKruijf committed Dec 20, 2024
1 parent f3cb35a commit b84ef03
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 5 additions & 3 deletions docs/content/en/docs/core-components/api-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -153,7 +154,7 @@ None
404/Not found with payload:
General error

#### POST `/manual/continue`
#### PATCH `/manual/<execution-id>/<step-id>`
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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
18 changes: 10 additions & 8 deletions pkg/api/manual/manual_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand All @@ -135,18 +137,18 @@ 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)
if err != nil {
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
}

Expand All @@ -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
}

Expand Down

0 comments on commit b84ef03

Please sign in to comment.