Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions backend/modules/soar/connectors/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,33 @@ type AgentRepository interface {
}

type VariableRepository interface {
Save(v *domain.UtmIncidentVariable) error
FindByID(id int64) (*domain.UtmIncidentVariable, error)
FindAll(f dto.VariableFilter) ([]domain.UtmIncidentVariable, int64, error)
FindAllPlain() ([]domain.UtmIncidentVariable, error)
FindByName(name string) (*domain.UtmIncidentVariable, error)
FindByNames(names []string) ([]domain.UtmIncidentVariable, error)
Delete(id int64) error
Save(ctx context.Context, v *domain.UtmIncidentVariable) error
FindByID(ctx context.Context, id int64) (*domain.UtmIncidentVariable, error)
FindAll(ctx context.Context, f dto.VariableFilter) ([]domain.UtmIncidentVariable, int64, error)
FindAllPlain(ctx context.Context) ([]domain.UtmIncidentVariable, error)
FindByName(ctx context.Context, name string) (*domain.UtmIncidentVariable, error)
FindByNames(ctx context.Context, names []string) ([]domain.UtmIncidentVariable, error)
Delete(ctx context.Context, id int64) error
}

type ActionRepository interface {
Save(action *domain.UtmIncidentAction) error
FindByID(id int64) (*domain.UtmIncidentAction, error)
FindAll(f dto.ActionFilter) ([]domain.UtmIncidentAction, int64, error)
Delete(id int64) error
Save(ctx context.Context, action *domain.UtmIncidentAction) error
FindByID(ctx context.Context, id int64) (*domain.UtmIncidentAction, error)
FindAll(ctx context.Context, f dto.ActionFilter) ([]domain.UtmIncidentAction, int64, error)
Delete(ctx context.Context, id int64) error
}

type ActionCommandRepository interface {
Save(cmd *domain.UtmIncidentActionCommand) error
FindByID(id int64) (*domain.UtmIncidentActionCommand, error)
FindAll(f dto.ActionCommandFilter) ([]domain.UtmIncidentActionCommand, int64, error)
Delete(id int64) error
Save(ctx context.Context, cmd *domain.UtmIncidentActionCommand) error
FindByID(ctx context.Context, id int64) (*domain.UtmIncidentActionCommand, error)
FindAll(ctx context.Context, f dto.ActionCommandFilter) ([]domain.UtmIncidentActionCommand, int64, error)
Delete(ctx context.Context, id int64) error
}

type JobRepository interface {
Save(job *domain.UtmIncidentJob) error
FindByID(id int64) (*domain.UtmIncidentJob, error)
FindAll(f dto.JobFilter) ([]domain.UtmIncidentJob, int64, error)
Count(f dto.JobFilter) (int64, error)
Delete(id int64) error
Save(ctx context.Context, job *domain.UtmIncidentJob) error
FindByID(ctx context.Context, id int64) (*domain.UtmIncidentJob, error)
FindAll(ctx context.Context, f dto.JobFilter) ([]domain.UtmIncidentJob, int64, error)
Count(ctx context.Context, f dto.JobFilter) (int64, error)
Delete(ctx context.Context, id int64) error
}
44 changes: 22 additions & 22 deletions backend/modules/soar/connectors/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,40 @@ type ExecutionUsecase interface {
}

type VariableUsecase interface {
Create(req dto.CreateVariableRequest, user string) (*dto.VariableResponse, error)
Update(req dto.UpdateVariableRequest, user string) (*dto.VariableResponse, error)
FindByID(id int64) (*dto.VariableResponse, error)
FindAll(f dto.VariableFilter) ([]dto.VariableResponse, int64, error)
Delete(id int64) error
Create(ctx context.Context, req dto.CreateVariableRequest, user string) (*dto.VariableResponse, error)
Update(ctx context.Context, req dto.UpdateVariableRequest, user string) (*dto.VariableResponse, error)
FindByID(ctx context.Context, id int64) (*dto.VariableResponse, error)
FindAll(ctx context.Context, f dto.VariableFilter) ([]dto.VariableResponse, int64, error)
Delete(ctx context.Context, id int64) error

InterpolateCommand(cmd string) (string, error)
MaskSecrets(output string) (string, error)
InterpolateCommand(ctx context.Context, cmd string) (string, error)
MaskSecrets(ctx context.Context, output string) (string, error)
}

type ActionUsecase interface {
Create(req dto.CreateActionRequest, user string) (*domain.UtmIncidentAction, error)
Update(req dto.UpdateActionRequest, user string) (*domain.UtmIncidentAction, error)
FindByID(id int64) (*domain.UtmIncidentAction, error)
FindAll(f dto.ActionFilter) ([]domain.UtmIncidentAction, int64, error)
Delete(id int64) error
Create(ctx context.Context, req dto.CreateActionRequest, user string) (*domain.UtmIncidentAction, error)
Update(ctx context.Context, req dto.UpdateActionRequest, user string) (*domain.UtmIncidentAction, error)
FindByID(ctx context.Context, id int64) (*domain.UtmIncidentAction, error)
FindAll(ctx context.Context, f dto.ActionFilter) ([]domain.UtmIncidentAction, int64, error)
Delete(ctx context.Context, id int64) error
}

type ActionCommandUsecase interface {
Create(req dto.CreateActionCommandRequest) (*domain.UtmIncidentActionCommand, error)
Update(req dto.UpdateActionCommandRequest) (*domain.UtmIncidentActionCommand, error)
FindByID(id int64) (*domain.UtmIncidentActionCommand, error)
FindAll(f dto.ActionCommandFilter) ([]domain.UtmIncidentActionCommand, int64, error)
Delete(id int64) error
Create(ctx context.Context, req dto.CreateActionCommandRequest) (*domain.UtmIncidentActionCommand, error)
Update(ctx context.Context, req dto.UpdateActionCommandRequest) (*domain.UtmIncidentActionCommand, error)
FindByID(ctx context.Context, id int64) (*domain.UtmIncidentActionCommand, error)
FindAll(ctx context.Context, f dto.ActionCommandFilter) ([]domain.UtmIncidentActionCommand, int64, error)
Delete(ctx context.Context, id int64) error
}

type AgentUsecase interface {
ListByPlatform(ctx context.Context, platform string) ([]string, error)
}

type JobUsecase interface {
Create(req dto.CreateJobRequest, user string) (*domain.UtmIncidentJob, error)
FindByID(id int64) (*domain.UtmIncidentJob, error)
FindAll(f dto.JobFilter) ([]domain.UtmIncidentJob, int64, error)
Count(f dto.JobFilter) (int64, error)
Delete(id int64) error
Create(ctx context.Context, req dto.CreateJobRequest, user string) (*domain.UtmIncidentJob, error)
FindByID(ctx context.Context, id int64) (*domain.UtmIncidentJob, error)
FindAll(ctx context.Context, f dto.JobFilter) ([]domain.UtmIncidentJob, int64, error)
Count(ctx context.Context, f dto.JobFilter) (int64, error)
Delete(ctx context.Context, id int64) error
}
12 changes: 6 additions & 6 deletions backend/modules/soar/handler/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *ActionHandler) Create(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.uc.Create(req, loginFromCtx(c))
result, err := h.uc.Create(c.Request.Context(), req, loginFromCtx(c))
if err != nil {
writeARRError(c, err)
return
Expand All @@ -63,7 +63,7 @@ func (h *ActionHandler) Update(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.uc.Update(req, loginFromCtx(c))
result, err := h.uc.Update(c.Request.Context(), req, loginFromCtx(c))
if err != nil {
writeARRError(c, err)
return
Expand Down Expand Up @@ -94,7 +94,7 @@ func (h *ActionHandler) List(c *gin.Context) {
ActionType: queryIntPtr(c, "actionType"),
ActionEditable: queryBoolPtr(c, "actionEditable"),
}
items, total, err := h.uc.FindAll(f)
items, total, err := h.uc.FindAll(c.Request.Context(), f)
if err != nil {
writeARRError(c, err)
return
Expand Down Expand Up @@ -135,7 +135,7 @@ func (h *ActionHandler) Count(c *gin.Context) {
ActionType: queryIntPtr(c, "actionType"),
ActionEditable: queryBoolPtr(c, "actionEditable"),
}
_, total, err := h.uc.FindAll(f)
_, total, err := h.uc.FindAll(c.Request.Context(), f)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -160,7 +160,7 @@ func (h *ActionHandler) GetByID(c *gin.Context) {
if !ok {
return
}
result, err := h.uc.FindByID(id)
result, err := h.uc.FindByID(c.Request.Context(), id)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -184,7 +184,7 @@ func (h *ActionHandler) Delete(c *gin.Context) {
if !ok {
return
}
if err := h.uc.Delete(id); err != nil {
if err := h.uc.Delete(c.Request.Context(), id); err != nil {
writeARRError(c, err)
return
}
Expand Down
10 changes: 5 additions & 5 deletions backend/modules/soar/handler/action_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *ActionCommandHandler) Create(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.uc.Create(req)
result, err := h.uc.Create(c.Request.Context(), req)
if err != nil {
writeARRError(c, err)
return
Expand Down Expand Up @@ -64,7 +64,7 @@ func (h *ActionCommandHandler) Update(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.uc.Update(req)
result, err := h.uc.Update(c.Request.Context(), req)
if err != nil {
writeARRError(c, err)
return
Expand Down Expand Up @@ -95,7 +95,7 @@ func (h *ActionCommandHandler) List(c *gin.Context) {
OsPlatform: queryString(c, "osPlatform"),
Command: queryString(c, "command"),
}
items, total, err := h.uc.FindAll(f)
items, total, err := h.uc.FindAll(c.Request.Context(), f)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -120,7 +120,7 @@ func (h *ActionCommandHandler) GetByID(c *gin.Context) {
if !ok {
return
}
result, err := h.uc.FindByID(id)
result, err := h.uc.FindByID(c.Request.Context(), id)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -144,7 +144,7 @@ func (h *ActionCommandHandler) Delete(c *gin.Context) {
if !ok {
return
}
if err := h.uc.Delete(id); err != nil {
if err := h.uc.Delete(c.Request.Context(), id); err != nil {
writeARRError(c, err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions backend/modules/soar/handler/command_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (h *CommandWSHandler) CommandStream(c *gin.Context) {
}
command := req.Command
if h.variableUC != nil {
if interpolated, vErr := h.variableUC.InterpolateCommand(command); vErr != nil {
if interpolated, vErr := h.variableUC.InterpolateCommand(ctx, command); vErr != nil {
_ = catcher.Error("CommandStream: variable interpolation", vErr, nil)
} else {
command = interpolated
Expand Down Expand Up @@ -182,7 +182,7 @@ func (h *CommandWSHandler) CommandStream(c *gin.Context) {
}
output := result.GetResult()
if h.variableUC != nil {
if masked, mErr := h.variableUC.MaskSecrets(output); mErr != nil {
if masked, mErr := h.variableUC.MaskSecrets(ctx, output); mErr != nil {
_ = catcher.Error("CommandStream: mask secrets", mErr, nil)
} else {
output = masked
Expand Down
10 changes: 5 additions & 5 deletions backend/modules/soar/handler/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *JobHandler) Create(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.uc.Create(req, loginFromCtx(c))
result, err := h.uc.Create(c.Request.Context(), req, loginFromCtx(c))
if err != nil {
writeARRError(c, err)
return
Expand Down Expand Up @@ -71,7 +71,7 @@ func (h *JobHandler) List(c *gin.Context) {
OriginID: queryIntPtr(c, "originId"),
OriginType: queryString(c, "originType"),
}
items, total, err := h.uc.FindAll(f)
items, total, err := h.uc.FindAll(c.Request.Context(), f)
if err != nil {
writeARRError(c, err)
return
Expand Down Expand Up @@ -102,7 +102,7 @@ func (h *JobHandler) Count(c *gin.Context) {
OriginID: queryIntPtr(c, "originId"),
OriginType: queryString(c, "originType"),
}
total, err := h.uc.Count(f)
total, err := h.uc.Count(c.Request.Context(), f)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -127,7 +127,7 @@ func (h *JobHandler) GetByID(c *gin.Context) {
if !ok {
return
}
result, err := h.uc.FindByID(id)
result, err := h.uc.FindByID(c.Request.Context(), id)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -151,7 +151,7 @@ func (h *JobHandler) Delete(c *gin.Context) {
if !ok {
return
}
if err := h.uc.Delete(id); err != nil {
if err := h.uc.Delete(c.Request.Context(), id); err != nil {
writeARRError(c, err)
return
}
Expand Down
10 changes: 5 additions & 5 deletions backend/modules/soar/handler/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *VariableHandler) Create(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.uc.Create(req, loginFromCtx(c))
result, err := h.uc.Create(c.Request.Context(), req, loginFromCtx(c))
if err != nil {
writeARRError(c, err)
return
Expand Down Expand Up @@ -64,7 +64,7 @@ func (h *VariableHandler) Update(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.uc.Update(req, loginFromCtx(c))
result, err := h.uc.Update(c.Request.Context(), req, loginFromCtx(c))
if err != nil {
writeARRError(c, err)
return
Expand All @@ -91,7 +91,7 @@ func (h *VariableHandler) List(c *gin.Context) {
Params: database.Params{Page: queryInt(c, "page", 0), Size: queryInt(c, "size", 20)},
VariableName: queryString(c, "variableName"),
}
items, total, err := h.uc.FindAll(f)
items, total, err := h.uc.FindAll(c.Request.Context(), f)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -116,7 +116,7 @@ func (h *VariableHandler) GetByID(c *gin.Context) {
if !ok {
return
}
result, err := h.uc.FindByID(id)
result, err := h.uc.FindByID(c.Request.Context(), id)
if err != nil {
writeARRError(c, err)
return
Expand All @@ -140,7 +140,7 @@ func (h *VariableHandler) Delete(c *gin.Context) {
if !ok {
return
}
if err := h.uc.Delete(id); err != nil {
if err := h.uc.Delete(c.Request.Context(), id); err != nil {
writeARRError(c, err)
return
}
Expand Down
18 changes: 11 additions & 7 deletions backend/modules/soar/repository/action_command_pg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package repository

import (
"context"
"errors"
"fmt"

Expand All @@ -20,16 +21,19 @@ func NewActionCommandRepository(db *gorm.DB) *actionCommandRepository {
return &actionCommandRepository{db: db}
}

func (r *actionCommandRepository) Save(cmd *domain.UtmIncidentActionCommand) error {
func (r *actionCommandRepository) Save(ctx context.Context, cmd *domain.UtmIncidentActionCommand) error {
if cmd.TenantID == "" {
cmd.TenantID = tenantFromCtx(ctx)
}
if err := r.db.Save(cmd).Error; err != nil {
return fmt.Errorf("actionCommandRepository.Save: %w", err)
}
return nil
}

func (r *actionCommandRepository) FindByID(id int64) (*domain.UtmIncidentActionCommand, error) {
func (r *actionCommandRepository) FindByID(ctx context.Context, id int64) (*domain.UtmIncidentActionCommand, error) {
var c domain.UtmIncidentActionCommand
err := r.db.First(&c, id).Error
err := scopeTenant(ctx, r.db).First(&c, id).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, domain.ErrIncidentRecordNotFound
}
Expand All @@ -39,8 +43,8 @@ func (r *actionCommandRepository) FindByID(id int64) (*domain.UtmIncidentActionC
return &c, nil
}

func (r *actionCommandRepository) FindAll(f dto.ActionCommandFilter) ([]domain.UtmIncidentActionCommand, int64, error) {
q := r.db.Model(&domain.UtmIncidentActionCommand{})
func (r *actionCommandRepository) FindAll(ctx context.Context, f dto.ActionCommandFilter) ([]domain.UtmIncidentActionCommand, int64, error) {
q := scopeTenant(ctx, r.db.Model(&domain.UtmIncidentActionCommand{}))
if f.ActionID != nil {
q = q.Where("action_id = ?", *f.ActionID)
}
Expand All @@ -63,8 +67,8 @@ func (r *actionCommandRepository) FindAll(f dto.ActionCommandFilter) ([]domain.U
return items, total, nil
}

func (r *actionCommandRepository) Delete(id int64) error {
if err := r.db.Delete(&domain.UtmIncidentActionCommand{}, id).Error; err != nil {
func (r *actionCommandRepository) Delete(ctx context.Context, id int64) error {
if err := scopeTenant(ctx, r.db).Delete(&domain.UtmIncidentActionCommand{}, id).Error; err != nil {
return fmt.Errorf("actionCommandRepository.Delete: %w", err)
}
return nil
Expand Down
Loading
Loading