-
Notifications
You must be signed in to change notification settings - Fork 927
/
delete_service_broker_command.go
101 lines (83 loc) · 2.99 KB
/
delete_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package v7
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"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/clock"
)
//go:generate counterfeiter . UpdateServiceBrokerActor
type DeleteServiceBrokerActor interface {
GetServiceBrokerByName(serviceBrokerName string) (v7action.ServiceBroker, v7action.Warnings, error)
DeleteServiceBroker(serviceBrokerGUID string) (v7action.Warnings, error)
}
type DeleteServiceBrokerCommand struct {
RequiredArgs flag.ServiceBroker `positional-args:"yes"`
usage interface{} `usage:"CF_NAME delete-service-broker SERVICE_BROKER [-f]\n\n"`
Force bool `short:"f" description:"Force deletion without confirmation"`
relatedCommands interface{} `related_commands:"delete-service, purge-service-offering, service-brokers"`
UI command.UI
Config command.Config
Actor DeleteServiceBrokerActor
SharedActor command.SharedActor
}
func (cmd *DeleteServiceBrokerCommand) Setup(config command.Config, ui command.UI) error {
cmd.UI = ui
cmd.Config = config
sharedActor := sharedaction.NewActor(config)
cmd.SharedActor = sharedActor
ccClient, uaaClient, err := shared.GetNewClientsAndConnectToCF(config, ui, "")
if err != nil {
return err
}
cmd.Actor = v7action.NewActor(ccClient, config, sharedActor, uaaClient, clock.NewClock())
return nil
}
func (cmd DeleteServiceBrokerCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
serviceBrokerName := cmd.RequiredArgs.ServiceBroker
if !cmd.Force {
confirmed, promptErr := cmd.UI.DisplayBoolPrompt(false, "Really delete the service-broker {{.ServiceBroker}}?", map[string]interface{}{
"ServiceBroker": serviceBrokerName,
})
if promptErr != nil {
return promptErr
}
if !confirmed {
cmd.UI.DisplayText("'{{.ServiceBroker}}' has not been deleted.", map[string]interface{}{
"ServiceBroker": serviceBrokerName,
})
return nil
}
}
cmd.UI.DisplayTextWithFlavor("Deleting service-broker {{.ServiceBroker}}...",
map[string]interface{}{
"ServiceBroker": serviceBrokerName,
})
serviceBroker, warnings, err := cmd.Actor.GetServiceBrokerByName(serviceBrokerName)
cmd.UI.DisplayWarningsV7(warnings)
if err != nil {
if _, ok := err.(actionerror.ServiceBrokerNotFoundError); ok {
// TODO: Verify the correct error message to display for idempotent case
//cmd.UI.DisplayText(`Unable to delete. ` + err.Error())
cmd.UI.DisplayText("Service broker '{{.ServiceBroker}}' does not exist.", map[string]interface{}{
"ServiceBroker": serviceBrokerName,
})
cmd.UI.DisplayOK()
return nil
}
return err
}
warnings, err = cmd.Actor.DeleteServiceBroker(serviceBroker.GUID)
cmd.UI.DisplayWarningsV7(warnings)
if err != nil {
return err
}
cmd.UI.DisplayOK()
return nil
}