forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth_token_command.go
53 lines (42 loc) · 1.26 KB
/
oauth_token_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
package v2
import (
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/actor/v2action"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/v2/shared"
)
//go:generate counterfeiter . OauthTokenActor
type OauthTokenActor interface {
RefreshAccessToken(refreshToken string) (string, error)
}
type OauthTokenCommand struct {
usage interface{} `usage:"CF_NAME oauth-token"`
relatedCommands interface{} `related_commands:"curl"`
UI command.UI
Config command.Config
SharedActor command.SharedActor
Actor OauthTokenActor
}
func (cmd *OauthTokenCommand) Setup(config command.Config, ui command.UI) error {
cmd.UI = ui
cmd.Config = config
cmd.SharedActor = sharedaction.NewActor()
ccClient, uaaClient, err := shared.NewClients(config, ui, true)
if err != nil {
return err
}
cmd.Actor = v2action.NewActor(ccClient, uaaClient, config)
return nil
}
func (cmd OauthTokenCommand) Execute(_ []string) error {
err := cmd.SharedActor.CheckTarget(cmd.Config, false, false)
if err != nil {
return shared.HandleError(err)
}
accessToken, err := cmd.Actor.RefreshAccessToken(cmd.Config.RefreshToken())
if err != nil {
return shared.HandleError(err)
}
cmd.UI.DisplayText(accessToken)
return nil
}