-
Notifications
You must be signed in to change notification settings - Fork 69
/
unbind.go
81 lines (70 loc) · 2.24 KB
/
unbind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package handlers
import (
"errors"
"net/http"
"code.cloudfoundry.org/lager"
"github.com/gorilla/mux"
"github.com/pivotal-cf/brokerapi/domain"
"github.com/pivotal-cf/brokerapi/domain/apiresponses"
"github.com/pivotal-cf/brokerapi/middlewares"
"github.com/pivotal-cf/brokerapi/utils"
)
const unbindLogKey = "unbind"
func (h APIHandler) Unbind(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
instanceID := vars["instance_id"]
bindingID := vars["binding_id"]
logger := h.logger.Session(unbindLogKey, lager.Data{
instanceIDLogKey: instanceID,
bindingIDLogKey: bindingID,
}, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey))
version := getAPIVersion(req)
asyncAllowed := req.FormValue("accepts_incomplete") == "true"
if asyncAllowed && version.Minor < 14 {
err := errors.New("async unbinding only supported from OSB version 2.14 and up")
h.respond(w, http.StatusUnprocessableEntity, apiresponses.ErrorResponse{
Description: err.Error(),
})
logger.Error(middlewares.ApiVersionInvalidKey, err)
return
}
details := domain.UnbindDetails{
PlanID: req.FormValue("plan_id"),
ServiceID: req.FormValue("service_id"),
}
if details.ServiceID == "" {
h.respond(w, http.StatusBadRequest, apiresponses.ErrorResponse{
Description: serviceIdError.Error(),
})
logger.Error(serviceIdMissingKey, serviceIdError)
return
}
if details.PlanID == "" {
h.respond(w, http.StatusBadRequest, apiresponses.ErrorResponse{
Description: planIdError.Error(),
})
logger.Error(planIdMissingKey, planIdError)
return
}
unbindResponse, err := h.serviceBroker.Unbind(req.Context(), instanceID, bindingID, details, asyncAllowed)
if err != nil {
switch err := err.(type) {
case *apiresponses.FailureResponse:
logger.Error(err.LoggerAction(), err)
h.respond(w, err.ValidatedStatusCode(logger), err.ErrorResponse())
default:
logger.Error(unknownErrorKey, err)
h.respond(w, http.StatusInternalServerError, apiresponses.ErrorResponse{
Description: err.Error(),
})
}
return
}
if unbindResponse.IsAsync {
h.respond(w, http.StatusAccepted, apiresponses.UnbindResponse{
OperationData: unbindResponse.OperationData,
})
} else {
h.respond(w, http.StatusOK, apiresponses.EmptyResponse{})
}
}