mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 15:22:47 +01:00
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/arangodb/go-driver"
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/SecurityBrewery/catalyst/database"
|
|
"github.com/SecurityBrewery/catalyst/generated/model"
|
|
)
|
|
|
|
func jobResponseID(job *model.JobResponse) []driver.DocumentID {
|
|
if job == nil {
|
|
return nil
|
|
}
|
|
return jobID(job.ID)
|
|
}
|
|
|
|
func jobID(id string) []driver.DocumentID {
|
|
return []driver.DocumentID{driver.DocumentID(fmt.Sprintf("%s/%s", database.JobCollectionName, id))}
|
|
}
|
|
|
|
func (s *Service) ListJobs(ctx context.Context) ([]*model.JobResponse, error) {
|
|
return s.database.JobList(ctx)
|
|
}
|
|
|
|
func (s *Service) RunJob(ctx context.Context, form *model.JobForm) (err error) {
|
|
msgContext := &model.Context{}
|
|
newJobID := uuid.NewString()
|
|
|
|
defer s.publishRequest(ctx, err, "RunJob", jobID(newJobID))
|
|
return s.bus.PublishJob(newJobID, form.Automation, form.Payload, msgContext, form.Origin)
|
|
}
|
|
|
|
func (s *Service) GetJob(ctx context.Context, id string) (*model.JobResponse, error) {
|
|
return s.database.JobGet(ctx, id)
|
|
}
|
|
|
|
func (s *Service) UpdateJob(ctx context.Context, id string, job *model.Job) (doc *model.JobResponse, err error) {
|
|
defer s.publishRequest(ctx, err, "UpdateJob", jobResponseID(doc))
|
|
return s.database.JobUpdate(ctx, id, job)
|
|
}
|