forked from cloudfoundry/cli
/
purge_service_offering_command.go
70 lines (58 loc) · 3.48 KB
/
purge_service_offering_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
package v7
import (
"github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccerror"
"github.com/LukasHeimann/cloudfoundrycli/v8/command/flag"
)
type PurgeServiceOfferingCommand struct {
BaseCommand
RequiredArgs flag.ServiceOffering `positional-args:"yes"`
ServiceBroker string `short:"b" description:"Purge a service offering from a particular service broker. Required when service offering name is ambiguous"`
Force bool `short:"f" description:"Force deletion without confirmation"`
usage interface{} `usage:"CF_NAME purge-service-offering SERVICE_OFFERING [-b BROKER] [-f]\n\nWARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database. All knowledge of the service offering will be removed from Cloud Foundry, including service instances and service bindings. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup."`
relatedCommands interface{} `related_commands:"marketplace, purge-service-instance, service-brokers"`
}
func (cmd PurgeServiceOfferingCommand) Execute(args []string) error {
if err := cmd.SharedActor.CheckTarget(false, false); err != nil {
return err
}
if !cmd.Force {
cmd.UI.DisplayText("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database. All knowledge of the service offering will be removed from Cloud Foundry, including service instances and service bindings. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup.\n")
confirmed, err := cmd.confirmationPrompt()
if err != nil {
return err
}
if !confirmed {
cmd.UI.DisplayText("Purge service offering cancelled.\n")
return nil
}
}
cmd.UI.DisplayText("Purging service offering {{.ServiceOffering}}...", map[string]interface{}{
"ServiceOffering": cmd.RequiredArgs.ServiceOffering,
})
warnings, err := cmd.Actor.PurgeServiceOfferingByNameAndBroker(cmd.RequiredArgs.ServiceOffering, cmd.ServiceBroker)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
switch err.(type) {
case ccerror.ServiceOfferingNotFoundError:
cmd.UI.DisplayText("Service offering '{{.ServiceOffering}}' not found.", map[string]interface{}{
"ServiceOffering": cmd.RequiredArgs.ServiceOffering,
})
default:
return err
}
}
cmd.UI.DisplayOK()
return nil
}
func (cmd PurgeServiceOfferingCommand) confirmationPrompt() (bool, error) {
var promptMessage string
if cmd.ServiceBroker != "" {
promptMessage = "Really purge service offering {{.ServiceOffering}} from broker {{.ServiceBroker}} from Cloud Foundry?"
} else {
promptMessage = "Really purge service offering {{.ServiceOffering}} from Cloud Foundry?"
}
return cmd.UI.DisplayBoolPrompt(false, promptMessage, map[string]interface{}{
"ServiceOffering": cmd.RequiredArgs.ServiceOffering,
"ServiceBroker": cmd.ServiceBroker,
})
}