MCPcopy Create free account
hub / github.com/cloudfoundry/brokerapi / Unbind

Method Unbind

handlers/unbind.go:16–68  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

14const unbindLogKey = "unbind"
15
16func (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}

Callers

nothing calls this directly

Calls 9

respondMethod · 0.95
InstanceIDFunction · 0.92
BindingIDFunction · 0.92
SessionMethod · 0.80
ErrorMethod · 0.80
LoggerActionMethod · 0.80
ValidatedStatusCodeMethod · 0.80
ErrorResponseMethod · 0.80
UnbindMethod · 0.65

Tested by

no test coverage detected