forked from flynn/flynn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
82 lines (65 loc) · 1.78 KB
/
cluster.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
package main
import (
"log"
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-docopt"
cfg "github.com/flynn/flynn/cli/config"
)
func init() {
register("cluster", runCluster, `
usage: flynn cluster
flynn cluster add [-g <githost>] [-p <tlspin>] <cluster-name> <url> <key>
flynn cluster remove <cluster-name>
Manage clusters in the ~/.flynnrc configuration file.
Options:
-g, --git-host <githost> git host (if host differs from api URL host)
-p, --tls-pin <tlspin> SHA256 of the cluster's TLS cert (useful if it is self-signed)
Commands:
With no arguments, shows a list of clusters.
add adds a cluster to the ~/.flynnrc configuration file
remove removes a cluster from the ~/.flynnrc configuration file
`)
}
func runCluster(args *docopt.Args) error {
if err := readConfig(); err != nil {
return err
}
if args.Bool["add"] {
return runClusterAdd(args)
} else if args.Bool["remove"] {
return runClusterRemove(args)
}
w := tabWriter()
defer w.Flush()
listRec(w, "NAME", "URL")
for _, s := range config.Clusters {
listRec(w, s.Name, s.URL)
}
return nil
}
func runClusterAdd(args *docopt.Args) error {
s := &cfg.Cluster{
Name: args.String["<cluster-name>"],
URL: args.String["<url>"],
Key: args.String["<key>"],
GitHost: args.String["--git-host"],
TLSPin: args.String["--tls-pin"],
}
if err := config.Add(s); err != nil {
return err
}
if err := config.SaveTo(configPath()); err != nil {
return err
}
log.Printf("Cluster %q added.", s.Name)
return nil
}
func runClusterRemove(args *docopt.Args) error {
name := args.String["<cluster-name>"]
if config.Remove(name) {
if err := config.SaveTo(configPath()); err != nil {
return err
}
log.Printf("Cluster %q removed.", name)
}
return nil
}