MCPcopy Index your code
hub / github.com/cloudfoundry/cli / Execute

Method Execute

cf/commands/service/unbind_route_service.go:85–136  ·  view source on GitHub ↗
(c flags.FlagContext)

Source from the content-addressed store, hash-verified

83}
84
85func (cmd *UnbindRouteService) Execute(c flags.FlagContext) error {
86 var port int
87
88 host := c.String("hostname")
89 domain := cmd.domainReq.GetDomain()
90 path := c.String("path")
91 if !strings.HasPrefix(path, "/") && len(path) > 0 {
92 path = fmt.Sprintf("/%s", path)
93 }
94
95 route, err := cmd.routeRepo.Find(host, domain, path, port)
96 if err != nil {
97 return err
98 }
99
100 serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
101 confirmed := c.Bool("f")
102 if !confirmed {
103 confirmed = cmd.ui.Confirm(T("Unbinding may leave apps mapped to route {{.URL}} vulnerable; e.g. if service instance {{.ServiceInstanceName}} provides authentication. Do you want to proceed?",
104 map[string]interface{}{
105 "URL": route.URL(),
106 "ServiceInstanceName": serviceInstance.Name,
107 }))
108
109 if !confirmed {
110 cmd.ui.Warn(T("Unbind cancelled"))
111 return nil
112 }
113 }
114
115 cmd.ui.Say(T("Unbinding route {{.URL}} from service instance {{.ServiceInstanceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
116 map[string]interface{}{
117 "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name),
118 "URL": terminal.EntityNameColor(route.URL()),
119 "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
120 "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
121 "CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
122 }))
123
124 err = cmd.UnbindRoute(route, serviceInstance)
125 if err != nil {
126 httpError, ok := err.(errors.HTTPError)
127 if ok && httpError.ErrorCode() == errors.InvalidRelation {
128 cmd.ui.Warn(T("Route {{.Route}} was not bound to service instance {{.ServiceInstance}}.", map[string]interface{}{"Route": route.URL(), "ServiceInstance": serviceInstance.Name}))
129 } else {
130 return err
131 }
132 }
133
134 cmd.ui.Ok()
135 return nil
136}
137
138func (cmd *UnbindRouteService) UnbindRoute(route models.Route, serviceInstance models.ServiceInstance) error {
139 return cmd.routeServiceBindingRepo.Unbind(serviceInstance.GUID, route.GUID, serviceInstance.IsUserProvided())

Callers

nothing calls this directly

Calls 15

UnbindRouteMethod · 0.95
EntityNameColorFunction · 0.92
StringMethod · 0.65
GetDomainMethod · 0.65
FindMethod · 0.65
GetServiceInstanceMethod · 0.65
BoolMethod · 0.65
ConfirmMethod · 0.65
WarnMethod · 0.65
SayMethod · 0.65
OrganizationFieldsMethod · 0.65
SpaceFieldsMethod · 0.65

Tested by

no test coverage detected