/
automation.go
49 lines (41 loc) · 1.27 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 rest
import (
"context"
"github.com/cortezaproject/corteza/server/pkg/api"
"github.com/cortezaproject/corteza/server/compose/rest/request"
"github.com/cortezaproject/corteza/server/compose/service/event"
"github.com/cortezaproject/corteza/server/pkg/corredor"
)
type (
Automation struct{}
)
func (Automation) New() *Automation {
return &Automation{}
}
func (ctrl *Automation) List(ctx context.Context, r *request.AutomationList) (interface{}, error) {
return corredor.GenericListHandler(
ctx,
corredor.Service(),
corredor.Filter{
ResourceTypePrefixes: r.ResourceTypePrefixes,
ExcludeInvalid: r.ExcludeInvalid,
ResourceTypes: r.ResourceTypes,
EventTypes: r.EventTypes,
ExcludeServerScripts: r.ExcludeServerScripts,
ExcludeClientScripts: r.ExcludeClientScripts,
},
"compose",
)
}
func (ctrl *Automation) Bundle(ctx context.Context, r *request.AutomationBundle) (interface{}, error) {
return corredor.GenericBundleHandler(
ctx,
corredor.Service(),
r.Bundle,
r.Type,
r.Ext,
)
}
func (ctrl *Automation) TriggerScript(ctx context.Context, r *request.AutomationTriggerScript) (interface{}, error) {
return api.OK(), corredor.Service().Exec(ctx, r.Script, corredor.ExtendScriptArgs(event.ComposeOnManual(), r.Args))
}