-
Notifications
You must be signed in to change notification settings - Fork 1
/
multilogin.go
76 lines (71 loc) · 1.83 KB
/
multilogin.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
package main
import (
"bytes"
"github.com/orange-cloudfoundry/cfm/messages"
)
type MultiLoginCmd struct {
Apis []string `short:"a" description:"api"`
Username string `short:"u" description:"username"`
Password string `short:"p" description:"password"`
Org string `short:"o" description:"org"`
Space string `short:"s" description:"s"`
SkipSslValidation bool `long:"skip-ssl-validation" description:"skip-ssl-validation"`
}
var multiLoginCmd MultiLoginCmd
func (c *MultiLoginCmd) Execute(_ []string) error {
if len(c.Apis) > 0 {
err := storeTargetsStr(c.Apis)
if err != nil {
return err
}
}
targets := findTargets()
if len(targets) == 0 {
messages.Fatal("please set targets with command set-targets: cfm set-targets https://my.cf.1.com https://my.cf.2.com")
}
targetSet := false
if c.Org != "" || c.Space != "" {
targetSet = true
}
for _, target := range targets {
var args []string
if targetSet {
args = []string{
"login",
"-a", target.Api,
"-u", c.Username,
"-p", c.Password,
}
if c.Org != "" {
args = append(args, "-o", c.Org)
}
if c.Space != "" {
args = append(args, "-s", c.Space)
}
if c.SkipSslValidation {
args = append(args, "--skip-ssl-validation")
}
runCfCommand(args, convertToFolder(target), &bytes.Buffer{})
continue
}
args = []string{"api", target.Api}
if c.SkipSslValidation {
args = append(args, "--skip-ssl-validation")
}
runCfCommand(args, convertToFolder(target), &bytes.Buffer{})
args = []string{"auth", c.Username, c.Password}
runCfCommand(args, convertToFolder(target), &bytes.Buffer{})
}
return nil
}
func init() {
desc := `perform login on all targets`
_, err := parser.AddCommand(
"multi-login",
desc,
desc,
&multiLoginCmd)
if err != nil {
panic(err)
}
}