(w http.ResponseWriter, req *http.Request)
| 14 | const unbindLogKey = "unbind" |
| 15 | |
| 16 | func (h APIHandler) Unbind(w http.ResponseWriter, req *http.Request) { |
| 17 | instanceID := req.PathValue("instance_id") |
| 18 | bindingID := req.PathValue("binding_id") |
| 19 | |
| 20 | logger := h.logger.Session(req.Context(), unbindLogKey, blog.InstanceID(instanceID), blog.BindingID(bindingID)) |
| 21 | |
| 22 | requestId := fmt.Sprintf("%v", req.Context().Value(middlewares.RequestIdentityKey)) |
| 23 | |
| 24 | details := domain.UnbindDetails{ |
| 25 | PlanID: req.FormValue("plan_id"), |
| 26 | ServiceID: req.FormValue("service_id"), |
| 27 | } |
| 28 | |
| 29 | if details.ServiceID == "" { |
| 30 | h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ |
| 31 | Description: serviceIdError.Error(), |
| 32 | }) |
| 33 | logger.Error(serviceIdMissingKey, serviceIdError) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | if details.PlanID == "" { |
| 38 | h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ |
| 39 | Description: planIdError.Error(), |
| 40 | }) |
| 41 | logger.Error(planIdMissingKey, planIdError) |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | asyncAllowed := req.FormValue("accepts_incomplete") == "true" |
| 46 | unbindResponse, err := h.serviceBroker.Unbind(req.Context(), instanceID, bindingID, details, asyncAllowed) |
| 47 | if err != nil { |
| 48 | switch err := err.(type) { |
| 49 | case *apiresponses.FailureResponse: |
| 50 | logger.Error(err.LoggerAction(), err) |
| 51 | h.respond(w, err.ValidatedStatusCode(slog.New(logger)), requestId, err.ErrorResponse()) |
| 52 | default: |
| 53 | logger.Error(unknownErrorKey, err) |
| 54 | h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ |
| 55 | Description: err.Error(), |
| 56 | }) |
| 57 | } |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | if unbindResponse.IsAsync { |
| 62 | h.respond(w, http.StatusAccepted, requestId, apiresponses.UnbindResponse{ |
| 63 | OperationData: unbindResponse.OperationData, |
| 64 | }) |
| 65 | } else { |
| 66 | h.respond(w, http.StatusOK, requestId, apiresponses.EmptyResponse{}) |
| 67 | } |
| 68 | } |
nothing calls this directly
no test coverage detected