-
Notifications
You must be signed in to change notification settings - Fork 244
/
event_orchestration_update.go
83 lines (68 loc) · 1.66 KB
/
event_orchestration_update.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
)
type EventOrchestrationUpdate struct {
Meta
}
func EventOrchestrationUpdateCommand() (cli.Command, error) {
return &EventOrchestrationUpdate{}, nil
}
func (c *EventOrchestrationUpdate) Help() string {
helpText := `
pd event-orchestration update <FILE> Update an event orchestration from json file
Options:
-id
` + c.Meta.Help()
return strings.TrimSpace(helpText)
}
func (c *EventOrchestrationUpdate) Synopsis() string {
return "Update an existing event orchestration"
}
func (c *EventOrchestrationUpdate) Run(args []string) int {
var eoID string
flags := c.Meta.FlagSet("event-orchestration update")
flags.Usage = func() { fmt.Println(c.Help()) }
flags.StringVar(&eoID, "id", "", "Event orchestration id")
if err := flags.Parse(args); err != nil {
log.Error(err)
return -1
}
if err := c.Meta.Setup(); err != nil {
log.Error(err)
return -1
}
if eoID == "" {
log.Error("You must provide event orchestration id")
return -1
}
client := c.Meta.Client()
var eo pagerduty.Orchestration
if len(flags.Args()) != 1 {
log.Error("Please specify input json file")
return -1
}
log.Info("Input file is:", flags.Arg(0))
f, err := os.ReadFile(flags.Arg(0))
if err != nil {
log.Error(err)
return -1
}
if err := json.Unmarshal(f, &eo); err != nil {
log.Errorln("Failed to decode json. Error:", err)
return -1
}
log.Debugf("%#v", eo)
if _, err := client.UpdateOrchestrationWithContext(context.Background(), eoID, eo); err != nil {
log.Error(err)
return -1
}
return 0
}