-
Notifications
You must be signed in to change notification settings - Fork 14
/
handle.go
63 lines (54 loc) · 1.99 KB
/
handle.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package actioners
import (
"github.com/jenkins-x/jx-logging/v3/pkg/log"
"github.com/jenkins-x/octant-jx/pkg/common/actions"
"github.com/jenkins-x/octant-jx/pkg/common/pluginctx"
"github.com/vmware-tanzu/octant/pkg/action"
"github.com/vmware-tanzu/octant/pkg/plugin/service"
)
// CreateHandler creates a handler from the given context
func CreateHandler(c *pluginctx.Context) service.HandlerActionFunc {
return func(request *service.ActionRequest) error {
return HandleAction(request, c)
}
}
// HandleAction handles the action to update the namespace
func HandleAction(request *service.ActionRequest, c *pluginctx.Context) error {
switch request.ActionName {
case action.RequestSetNamespace:
namespace, err := request.Payload.String("namespace")
if err != nil {
log.Logger().Infof("failed to handle %s for payload %#v with error: %s", action.RequestSetNamespace, request.Payload, err.Error())
} else {
c.Namespace = namespace
log.Logger().Infof("set the namespace to %s", namespace)
log.Logger().Infof("payload is %#v", request.Payload)
}
case actions.PerformAction:
action, err := request.Payload.String("action")
if err != nil {
namespace, err2 := request.Payload.String("namespace")
if err2 == nil && namespace != "" {
c.Namespace = namespace
log.Logger().Infof("set the namespace to %s", namespace)
} else {
log.Logger().Infof("failed to handle %s for payload %#v with error: %s", actions.PerformAction, request.Payload, err.Error())
}
} else {
switch action {
case actions.TriggerBootJob:
log.Logger().Infof("Trigger BOOT Job with payload %#v", request.Payload)
// TODO how to get an alerter?
return HandleTriggerBootJob(request)
case actions.TriggerJob:
log.Logger().Infof("Trigger Job with payload %#v", request.Payload)
// TODO how to get an alerter?
default:
log.Logger().Infof("unknown PerformAction %#v", request.Payload)
}
}
default:
log.Logger().Infof("unknown action %s", request.ActionName)
}
return nil
}