github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/v6/purge_service_offering_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/actor/sharedaction" 6 "code.cloudfoundry.org/cli/actor/v2action" 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/flag" 9 "code.cloudfoundry.org/cli/command/translatableerror" 10 "code.cloudfoundry.org/cli/command/v6/shared" 11 ) 12 13 //go:generate counterfeiter . PurgeServiceOfferingActor 14 15 type PurgeServiceOfferingActor interface { 16 PurgeServiceOffering(service v2action.Service) (v2action.Warnings, error) 17 GetServiceByNameAndBrokerName(serviceName, brokerName string) (v2action.Service, v2action.Warnings, error) 18 } 19 20 type PurgeServiceOfferingCommand struct { 21 RequiredArgs flag.Service `positional-args:"yes"` 22 Force bool `short:"f" description:"Force deletion without confirmation"` 23 Provider string `short:"p" description:"Provider"` 24 usage interface{} `usage:"CF_NAME purge-service-offering SERVICE [-p PROVIDER] [-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 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."` 25 relatedCommands interface{} `related_commands:"marketplace, purge-service-instance, service-brokers"` 26 27 UI command.UI 28 SharedActor command.SharedActor 29 Actor PurgeServiceOfferingActor 30 Config command.Config 31 } 32 33 func (cmd *PurgeServiceOfferingCommand) Setup(config command.Config, ui command.UI) error { 34 cmd.Config = config 35 cmd.UI = ui 36 cmd.SharedActor = sharedaction.NewActor(config) 37 38 ccClient, uaaClient, err := shared.NewClients(config, ui, true) 39 if err != nil { 40 return err 41 } 42 43 cmd.Actor = v2action.NewActor(ccClient, uaaClient, config) 44 45 return nil 46 } 47 48 func (cmd *PurgeServiceOfferingCommand) Execute(args []string) error { 49 if !cmd.Config.Experimental() { 50 return translatableerror.UnrefactoredCommandError{} 51 } 52 53 if len(args) > 0 { 54 return translatableerror.TooManyArgumentsError{ 55 ExtraArgument: args[0], 56 } 57 } 58 59 if err := cmd.SharedActor.CheckTarget(false, false); err != nil { 60 return err 61 } 62 63 if cmd.Provider != "" { 64 return translatableerror.FlagNoLongerSupportedError{Flag: "-p"} 65 } 66 67 service, warnings, err := cmd.Actor.GetServiceByNameAndBrokerName(cmd.RequiredArgs.Service, "") 68 if err != nil { 69 cmd.UI.DisplayWarnings(warnings) 70 71 switch err.(type) { 72 case actionerror.ServiceNotFoundError: 73 cmd.UI.DisplayText("Service offering '{{.ServiceOffering}}' not found", map[string]interface{}{ 74 "ServiceOffering": cmd.RequiredArgs.Service, 75 }) 76 cmd.UI.DisplayOK() 77 return nil 78 default: 79 return err 80 } 81 } 82 83 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 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") 84 85 if !cmd.Force { 86 promptMessage := "Really purge service offering {{.ServiceOffering}} from Cloud Foundry?" 87 purgeServiceOffering, promptErr := cmd.UI.DisplayBoolPrompt(false, promptMessage, map[string]interface{}{"ServiceOffering": cmd.RequiredArgs.Service}) 88 89 if promptErr != nil { 90 return promptErr 91 } 92 93 if !purgeServiceOffering { 94 cmd.UI.DisplayText("Purge service offering cancelled") 95 return nil 96 } 97 } 98 99 cmd.UI.DisplayText("Purging service {{.ServiceOffering}}...", map[string]interface{}{ 100 "ServiceOffering": cmd.RequiredArgs.Service, 101 }) 102 103 purgeWarnings, err := cmd.Actor.PurgeServiceOffering(service) 104 allWarnings := append(warnings, purgeWarnings...) 105 cmd.UI.DisplayWarnings(allWarnings) 106 107 if err != nil { 108 return err 109 } 110 111 cmd.UI.DisplayOK() 112 113 return nil 114 }