-
Notifications
You must be signed in to change notification settings - Fork 71
/
deprovision.go
68 lines (57 loc) · 1.92 KB
/
deprovision.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
package handlers
import (
"net/http"
"code.cloudfoundry.org/lager"
"github.com/gorilla/mux"
"github.com/pivotal-cf/brokerapi/v7/domain"
"github.com/pivotal-cf/brokerapi/v7/domain/apiresponses"
"github.com/pivotal-cf/brokerapi/v7/middlewares"
"github.com/pivotal-cf/brokerapi/v7/utils"
)
const deprovisionLogKey = "deprovision"
func (h APIHandler) Deprovision(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
instanceID := vars["instance_id"]
logger := h.logger.Session(deprovisionLogKey, lager.Data{
instanceIDLogKey: instanceID,
}, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey))
details := domain.DeprovisionDetails{
PlanID: req.FormValue("plan_id"),
ServiceID: req.FormValue("service_id"),
Force: req.FormValue("force") == "true",
}
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
}
asyncAllowed := req.FormValue("accepts_incomplete") == "true"
deprovisionSpec, err := h.serviceBroker.Deprovision(req.Context(), instanceID, 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 deprovisionSpec.IsAsync {
h.respond(w, http.StatusAccepted, apiresponses.DeprovisionResponse{OperationData: deprovisionSpec.OperationData})
} else {
h.respond(w, http.StatusOK, apiresponses.EmptyResponse{})
}
}