From b56ddf803b00d6f98823f1953ad0d6bf0c65336f Mon Sep 17 00:00:00 2001 From: Maarten de Kruijf <16100232+MaartendeKruijf@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:38:32 +0200 Subject: [PATCH] Fixed variable naming style --- routes/trigger/trigger_api.go | 27 +++++++++---------- .../routes/trigger_api/tigger_api_test.go | 6 ++--- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/routes/trigger/trigger_api.go b/routes/trigger/trigger_api.go index f35552d9..087d61c5 100644 --- a/routes/trigger/trigger_api.go +++ b/routes/trigger/trigger_api.go @@ -33,9 +33,9 @@ func init() { } type TriggerApi struct { - controller decomposer_controller.IController - database database.IController - Executionsch chan decomposer.ExecutionDetails + controller decomposer_controller.IController + database database.IController + ExecutionsChannel chan decomposer.ExecutionDetails } func New(controller decomposer_controller.IController, database database.IController) *TriggerApi { @@ -43,7 +43,7 @@ func New(controller decomposer_controller.IController, database database.IContro instance.controller = controller instance.database = database // Channel to get back execution details - instance.Executionsch = make(chan decomposer.ExecutionDetails) + instance.ExecutionsChannel = make(chan decomposer.ExecutionDetails) return &instance } @@ -121,7 +121,6 @@ func (trigger *TriggerApi) ExecuteById(context *gin.Context) { return } } - fmt.Println(playbook) trigger.execute(&playbook, context) } @@ -139,8 +138,8 @@ func (trigger *TriggerApi) ExecuteById(context *gin.Context) { // @Router /trigger/playbook [POST] func (trigger *TriggerApi) Execute(context *gin.Context) { - jsonData, errIo := io.ReadAll(context.Request.Body) - if errIo != nil { + jsonData, err := io.ReadAll(context.Request.Body) + if err != nil { log.Error("failed") soarca_http_error.SendErrorResponse(context, http.StatusBadRequest, "Failed to marshall json on server side", @@ -161,7 +160,7 @@ func (trigger *TriggerApi) Execute(context *gin.Context) { func (trigger *TriggerApi) execute(playbook *cacao.Playbook, context *gin.Context) { decomposer := trigger.controller.NewDecomposer() - go decomposer.ExecuteAsync(*playbook, trigger.Executionsch) + go decomposer.ExecuteAsync(*playbook, trigger.ExecutionsChannel) timer := time.NewTimer(time.Duration(3) * time.Second) for { select { @@ -172,13 +171,13 @@ func (trigger *TriggerApi) execute(playbook *cacao.Playbook, context *gin.Contex } context.JSON(http.StatusRequestTimeout, msg) log.Error("async execution timed out for playbook ", playbook.ID) - case exec_details := <-trigger.Executionsch: - playbook_id := exec_details.PlaybookId - exec_id := exec_details.ExecutionId - if playbook_id == playbook.ID { + case executionsDetail := <-trigger.ExecutionsChannel: + playbookId := executionsDetail.PlaybookId + executionId := executionsDetail.ExecutionId + if playbookId == playbook.ID { msg := gin.H{ - "execution_id": exec_id, - "payload": playbook_id, + "execution_id": executionId, + "payload": playbookId, } context.JSON(http.StatusOK, msg) return diff --git a/test/unittest/routes/trigger_api/tigger_api_test.go b/test/unittest/routes/trigger_api/tigger_api_test.go index 00b5ffe6..1d11aa4c 100644 --- a/test/unittest/routes/trigger_api/tigger_api_test.go +++ b/test/unittest/routes/trigger_api/tigger_api_test.go @@ -45,7 +45,7 @@ func TestTriggerExecutionOfPlaybook(t *testing.T) { trigger.Routes(app, trigger_api) executionId, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8") - mock_decomposer.On("ExecuteAsync", *playbook, trigger_api.Executionsch).Return(&decomposer.ExecutionDetails{}, nil, executionId) + mock_decomposer.On("ExecuteAsync", *playbook, trigger_api.ExecutionsChannel).Return(&decomposer.ExecutionDetails{}, nil, executionId) request, err := http.NewRequest("POST", "/trigger/playbook", bytes.NewBuffer(byteValue)) if err != nil { @@ -83,7 +83,7 @@ func TestExecutionOfPlaybookById(t *testing.T) { recorder := httptest.NewRecorder() trigger_api := trigger.New(mock_controller, mock_database_controller) trigger.Routes(app, trigger_api) - mock_decomposer.On("ExecuteAsync", *playbook, trigger_api.Executionsch).Return(&decomposer.ExecutionDetails{}, nil, executionId) + mock_decomposer.On("ExecuteAsync", *playbook, trigger_api.ExecutionsChannel).Return(&decomposer.ExecutionDetails{}, nil, executionId) request, err := http.NewRequest("POST", "/trigger/playbook/1", nil) if err != nil { @@ -132,7 +132,7 @@ func TestExecutionOfPlaybookByIdWithPayloadValidVariables(t *testing.T) { trigger_api := trigger.New(mock_controller, mock_database_controller) trigger.Routes(app, trigger_api) - mock_decomposer.On("ExecuteAsync", *playbook, trigger_api.Executionsch).Return(&decomposer.ExecutionDetails{}, nil, executionId) + mock_decomposer.On("ExecuteAsync", *playbook, trigger_api.ExecutionsChannel).Return(&decomposer.ExecutionDetails{}, nil, executionId) request, err := http.NewRequest("POST", "/trigger/playbook/1", bytes.NewReader(json)) if err != nil {