-
Notifications
You must be signed in to change notification settings - Fork 926
/
auth_command.go
67 lines (53 loc) · 1.96 KB
/
auth_command.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
package v2
import (
"fmt"
"code.cloudfoundry.org/cli/actor/v2action"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/v2/shared"
)
//go:generate counterfeiter . AuthActor
type AuthActor interface {
Authenticate(config v2action.Config, username string, password string) error
}
type AuthCommand struct {
RequiredArgs flag.Authentication `positional-args:"yes"`
usage interface{} `usage:"CF_NAME auth USERNAME PASSWORD\n\nWARNING:\n Providing your password as a command line option is highly discouraged\n Your password may be visible to others and may be recorded in your shell history\n\nEXAMPLES:\n CF_NAME auth name@example.com \"my password\" (use quotes for passwords with a space)\n CF_NAME auth name@example.com \"\\\"password\\\"\" (escape quotes if used in password)"`
relatedCommands interface{} `related_commands:"api, login, target"`
UI command.UI
Config command.Config
Actor AuthActor
}
func (cmd *AuthCommand) Setup(config command.Config, ui command.UI) error {
cmd.UI = ui
cmd.Config = config
ccClient, uaaClient, err := shared.NewClients(config, ui, true)
if err != nil {
return err
}
cmd.Actor = v2action.NewActor(ccClient, uaaClient, config)
return nil
}
func (cmd AuthCommand) Execute(args []string) error {
err := command.WarnAPIVersionCheck(cmd.Config, cmd.UI)
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor(
"API endpoint: {{.Endpoint}}",
map[string]interface{}{
"Endpoint": cmd.Config.Target(),
})
cmd.UI.DisplayText("Authenticating...")
err = cmd.Actor.Authenticate(cmd.Config, cmd.RequiredArgs.Username, cmd.RequiredArgs.Password)
if err != nil {
return shared.HandleError(err)
}
cmd.UI.DisplayOK()
cmd.UI.DisplayTextWithFlavor(
"Use '{{.Command}}' to view or set your target org and space.",
map[string]interface{}{
"Command": fmt.Sprintf("%s target", cmd.Config.BinaryName()),
})
return nil
}