/
last_binding_operation.go
66 lines (55 loc) · 1.99 KB
/
last_binding_operation.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
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 lastBindingOperationLogKey = "lastBindingOperation"
func (h APIHandler) LastBindingOperation(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
instanceID := vars["instance_id"]
bindingID := vars["binding_id"]
pollDetails := domain.PollDetails{
PlanID: req.FormValue("plan_id"),
ServiceID: req.FormValue("service_id"),
OperationData: req.FormValue("operation"),
}
logger := h.logger.Session(lastBindingOperationLogKey, lager.Data{
instanceIDLogKey: instanceID,
}, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey))
version := getAPIVersion(req)
if version.Minor < 14 {
err := errors.New("get binding endpoint only supported starting with OSB version 2.14")
h.respond(w, http.StatusPreconditionFailed, apiresponses.ErrorResponse{
Description: err.Error(),
})
logger.Error(middlewares.ApiVersionInvalidKey, err)
return
}
logger.Info("starting-check-for-binding-operation")
lastOperation, err := h.serviceBroker.LastBindingOperation(req.Context(), instanceID, bindingID, pollDetails)
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
}
logger.WithData(lager.Data{"state": lastOperation.State}).Info("done-check-for-binding-operation")
lastOperationResponse := apiresponses.LastOperationResponse{
State: lastOperation.State,
Description: lastOperation.Description,
}
h.respond(w, http.StatusOK, lastOperationResponse)
}