(c flags.FlagContext)
| 83 | } |
| 84 | |
| 85 | func (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 | |
| 138 | func (cmd *UnbindRouteService) UnbindRoute(route models.Route, serviceInstance models.ServiceInstance) error { |
| 139 | return cmd.routeServiceBindingRepo.Unbind(serviceInstance.GUID, route.GUID, serviceInstance.IsUserProvided()) |
nothing calls this directly
no test coverage detected