mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-08 00:02:49 +01:00
@@ -8,32 +8,37 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/database"
|
||||
"github.com/SecurityBrewery/catalyst/generated/models"
|
||||
"github.com/SecurityBrewery/catalyst/generated/restapi/api"
|
||||
"github.com/SecurityBrewery/catalyst/generated/restapi/operations/jobs"
|
||||
"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) RunJob(ctx context.Context, params *jobs.RunJobParams) *api.Response {
|
||||
msgContext := &models.Context{}
|
||||
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()
|
||||
return s.response(ctx, "RunJob", jobID(newJobID), nil, s.bus.PublishJob(newJobID, params.Job.Automation, params.Job.Payload, msgContext, params.Job.Origin))
|
||||
|
||||
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, params *jobs.GetJobParams) *api.Response {
|
||||
i, err := s.database.JobGet(ctx, params.ID)
|
||||
return s.response(ctx, "GetJob", nil, i, err)
|
||||
func (s *Service) GetJob(ctx context.Context, id string) (*model.JobResponse, error) {
|
||||
return s.database.JobGet(ctx, id)
|
||||
}
|
||||
|
||||
func (s *Service) ListJobs(ctx context.Context) *api.Response {
|
||||
i, err := s.database.JobList(ctx)
|
||||
return s.response(ctx, "ListJobs", nil, i, err)
|
||||
}
|
||||
|
||||
func (s *Service) UpdateJob(ctx context.Context, params *jobs.UpdateJobParams) *api.Response {
|
||||
i, err := s.database.JobUpdate(ctx, params.ID, params.Job)
|
||||
return s.response(ctx, "UpdateJob", jobID(i.ID), i, err)
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user