-
Notifications
You must be signed in to change notification settings - Fork 218
/
root.go
170 lines (156 loc) · 4.41 KB
/
root.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package wireguard
import (
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/spf13/cobra"
)
func New() *cobra.Command {
const (
short = "Commands that manage WireGuard peer connections"
long = `Commands that manage WireGuard peer connections`
)
cmd := command.New("wireguard", short, long, nil)
cmd.Aliases = []string{"wg"}
cmd.AddCommand(
newWireguardList(),
newWireguardCreate(),
newWireguardRemove(),
newWireguardReset(),
newWireguardWebsockets(),
newWireguardToken(),
)
return cmd
}
func newWireguardList() *cobra.Command {
const (
short = "List all WireGuard peer connections"
long = `List all WireGuard peer connections`
)
cmd := command.New("list [org]", short, long, runWireguardList,
command.RequireSession,
)
flag.Add(cmd,
flag.JSONOutput(),
)
cmd.Args = cobra.MaximumNArgs(1)
return cmd
}
func newWireguardCreate() *cobra.Command {
const (
short = "Add a WireGuard peer connection"
long = `Add a WireGuard peer connection to an organization`
)
cmd := command.New("create [org] [region] [name] [file]", short, long, runWireguardCreate,
command.RequireSession,
)
cmd.Args = cobra.MaximumNArgs(4)
return cmd
}
func newWireguardRemove() *cobra.Command {
const (
short = "Remove a WireGuard peer connection"
long = `Remove a WireGuard peer connection from an organization`
)
cmd := command.New("remove [org] [name]", short, long, runWireguardRemove,
command.RequireSession,
)
cmd.Args = cobra.MaximumNArgs(2)
return cmd
}
func newWireguardReset() *cobra.Command {
const (
short = "Reset WireGuard peer connection for an organization"
long = `Reset WireGuard peer connection for an organization`
)
cmd := command.New("reset [org]", short, long, runWireguardReset,
command.RequireSession,
)
cmd.Args = cobra.MaximumNArgs(1)
return cmd
}
func newWireguardWebsockets() *cobra.Command {
const (
short = "Enable or disable WireGuard tunneling over WebSockets"
long = `Enable or disable WireGuard tunneling over WebSockets`
)
cmd := command.New("websockets [enable|disable]", short, long, runWireguardWebsockets,
command.RequireSession,
)
cmd.Args = cobra.ExactArgs(1)
return cmd
}
func newWireguardToken() *cobra.Command {
const (
short = "Commands that managed WireGuard delegated access tokens"
long = `Commands that managed WireGuard delegated access tokens`
)
cmd := command.New("token", short, long, nil,
command.RequireSession,
)
cmd.AddCommand(
newWireguardTokenCreate(),
newWireguardTokenDelete(),
newWireguardTokenList(),
newWireguardTokenStart(),
newWireguardTokenUpdate(),
)
return cmd
}
func newWireguardTokenList() *cobra.Command {
const (
short = "List all WireGuard tokens"
long = `List all WireGuard tokens`
)
cmd := command.New("list [org]", short, long, runWireguardTokenList,
command.RequireSession,
)
flag.Add(cmd,
flag.JSONOutput(),
)
cmd.Args = cobra.MaximumNArgs(1)
return cmd
}
func newWireguardTokenCreate() *cobra.Command {
const (
short = "Create a new WireGuard token"
long = `Create a new WireGuard token`
)
cmd := command.New("create [org] [name]", short, long, runWireguardTokenCreate,
command.RequireSession,
)
cmd.Args = cobra.MaximumNArgs(2)
return cmd
}
func newWireguardTokenDelete() *cobra.Command {
const (
short = "Delete a WireGuard token; token is name:<name> or token:<token>"
long = `Delete a WireGuard token; token is name:<name> or token:<token>`
)
cmd := command.New("delete [org] [token]", short, long, runWireguardTokenDelete,
command.RequireSession,
)
cmd.Args = cobra.MaximumNArgs(2)
return cmd
}
func newWireguardTokenStart() *cobra.Command {
const (
short = "Start a new WireGuard peer connection associated with a token (set FLY_WIREGUARD_TOKEN)"
long = `Start a new WireGuard peer connection associated with a token (set FLY_WIREGUARD_TOKEN)`
)
cmd := command.New("start [name] [group] [region] [file]", short, long, runWireguardTokenStart,
command.RequireSession,
)
cmd.Args = cobra.MaximumNArgs(4)
return cmd
}
func newWireguardTokenUpdate() *cobra.Command {
const (
short = "Rekey a WireGuard peer connection associated with a token (set FLY_WIREGUARD_TOKEN)"
long = `Rekey a WireGuard peer connection associated with a token (set FLY_WIREGUARD_TOKEN)`
)
cmd := command.New("update [name] [file]", short, long, runWireguardTokenUpdate,
command.RequireSession,
)
cmd.Args = cobra.MaximumNArgs(2)
return cmd
}