-
Notifications
You must be signed in to change notification settings - Fork 927
/
create_service_broker_command.go
86 lines (71 loc) · 2.56 KB
/
create_service_broker_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package v7
import (
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/v7/shared"
"code.cloudfoundry.org/cli/util/configv3"
)
//go:generate counterfeiter . CreateServiceBrokerActor
type CreateServiceBrokerActor interface {
CreateServiceBroker(name, user, password, url, spaceGUID string) (v7action.Warnings, error)
}
type CreateServiceBrokerCommand struct {
RequiredArgs flag.ServiceBrokerArgs `positional-args:"yes"`
SpaceScoped bool `long:"space-scoped" description:"Make the broker's service plans only visible within the targeted space"`
usage interface{} `usage:"CF_NAME create-service-broker SERVICE_BROKER USERNAME PASSWORD URL [--space-scoped]"`
relatedCommands interface{} `related_commands:"enable-service-access, service-brokers, target"`
SharedActor command.SharedActor
Config command.Config
UI command.UI
Actor CreateServiceBrokerActor
}
func (cmd *CreateServiceBrokerCommand) Setup(config command.Config, ui command.UI) error {
cmd.Config = config
cmd.UI = ui
cmd.SharedActor = sharedaction.NewActor(config)
ccClient, _, err := shared.NewClients(config, ui, true, "")
if err != nil {
return err
}
cmd.Actor = v7action.NewActor(ccClient, config, nil, nil)
return nil
}
func (cmd *CreateServiceBrokerCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(cmd.SpaceScoped, cmd.SpaceScoped)
if err != nil {
return err
}
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
var space configv3.Space
if cmd.SpaceScoped {
space = cmd.Config.TargetedSpace()
cmd.UI.DisplayTextWithFlavor(
"Creating service broker {{.ServiceBroker}} in org {{.Org}} / space {{.Space}} as {{.Username}}...",
map[string]interface{}{
"Username": user.Name,
"ServiceBroker": cmd.RequiredArgs.ServiceBroker,
"Org": cmd.Config.TargetedOrganizationName(),
"Space": space.Name,
},
)
} else {
cmd.UI.DisplayTextWithFlavor(
"Creating service broker {{.ServiceBroker}} as {{.Username}}...",
map[string]interface{}{
"Username": user.Name,
"ServiceBroker": cmd.RequiredArgs.ServiceBroker,
},
)
}
warnings, err := cmd.Actor.CreateServiceBroker(cmd.RequiredArgs.ServiceBroker, cmd.RequiredArgs.Username, cmd.RequiredArgs.Password, cmd.RequiredArgs.URL, space.GUID)
cmd.UI.DisplayWarnings(warnings)
if err == nil {
cmd.UI.DisplayOK()
}
return err
}