-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathconnection_pause.go
More file actions
67 lines (51 loc) · 1.46 KB
/
connection_pause.go
File metadata and controls
67 lines (51 loc) · 1.46 KB
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
package cmd
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/hookdeck/hookdeck-cli/pkg/validators"
)
type connectionPauseCmd struct {
cmd *cobra.Command
}
func newConnectionPauseCmd() *connectionPauseCmd {
cc := &connectionPauseCmd{}
cc.cmd = &cobra.Command{
Use: "pause <connection-id-or-name>",
Args: validators.ExactArgs(1),
Short: "Pause a connection temporarily",
Long: `Pause a connection temporarily.
The connection will queue incoming events until unpaused.
Examples:
# Pause by connection ID
hookdeck gateway connection pause web_abc123
# Pause by connection name
hookdeck gateway connection pause my-connection`,
RunE: cc.runConnectionPauseCmd,
}
cc.cmd.Annotations = map[string]string{
"cli.arguments": `[{"name":"connection-id-or-name","type":"string","description":"Connection ID or name","required":true}]`,
}
return cc
}
func (cc *connectionPauseCmd) runConnectionPauseCmd(cmd *cobra.Command, args []string) error {
if err := Config.Profile.ValidateAPIKey(); err != nil {
return err
}
client := Config.GetAPIClient()
ctx := context.Background()
id, err := resolveConnectionID(ctx, client, args[0])
if err != nil {
return err
}
conn, err := client.PauseConnection(ctx, id)
if err != nil {
return fmt.Errorf("failed to pause connection: %w", err)
}
name := "unnamed"
if conn.Name != nil {
name = *conn.Name
}
fmt.Printf(SuccessCheck+" Connection paused: %s (%s)\n", name, conn.ID)
return nil
}