/
automation.go
49 lines (35 loc) · 1.5 KB
/
automation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package service
import (
"context"
"fmt"
"github.com/arangodb/go-driver"
"github.com/SecurityBrewery/catalyst/database"
"github.com/SecurityBrewery/catalyst/generated/model"
)
func automationResponseID(automation *model.AutomationResponse) []driver.DocumentID {
if automation == nil {
return nil
}
return automationID(automation.ID)
}
func automationID(id string) []driver.DocumentID {
return []driver.DocumentID{driver.DocumentID(fmt.Sprintf("%s/%s", database.AutomationCollectionName, id))}
}
func (s *Service) ListAutomations(ctx context.Context) ([]*model.AutomationResponse, error) {
return s.database.AutomationList(ctx)
}
func (s *Service) CreateAutomation(ctx context.Context, form *model.AutomationForm) (doc *model.AutomationResponse, err error) {
defer s.publishRequest(ctx, err, "CreateAutomation", automationResponseID(doc))
return s.database.AutomationCreate(ctx, form)
}
func (s *Service) GetAutomation(ctx context.Context, id string) (*model.AutomationResponse, error) {
return s.database.AutomationGet(ctx, id)
}
func (s *Service) UpdateAutomation(ctx context.Context, id string, form *model.AutomationForm) (doc *model.AutomationResponse, err error) {
defer s.publishRequest(ctx, err, "UpdateAutomation", automationResponseID(doc))
return s.database.AutomationUpdate(ctx, id, form)
}
func (s *Service) DeleteAutomation(ctx context.Context, id string) (err error) {
defer s.publishRequest(ctx, err, "DeleteAutomation", automationID(id))
return s.database.AutomationDelete(ctx, id)
}