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

Method GetInstance

handlers/get_instance.go:18–67  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

16const getInstanceLogKey = "getInstance"
17
18func (h APIHandler) GetInstance(w http.ResponseWriter, req *http.Request) {
19 instanceID := req.PathValue("instance_id")
20
21 logger := h.logger.Session(req.Context(), getInstanceLogKey, blog.InstanceID(instanceID))
22
23 requestId := fmt.Sprintf("%v", req.Context().Value(middlewares.RequestIdentityKey))
24
25 version := getAPIVersion(req)
26 if version.Minor < 14 {
27 err := errors.New("get instance endpoint only supported starting with OSB version 2.14")
28 h.respond(w, http.StatusPreconditionFailed, requestId, apiresponses.ErrorResponse{
29 Description: err.Error(),
30 })
31 logger.Error(middlewares.ApiVersionInvalidKey, err)
32 return
33 }
34
35 details := domain.FetchInstanceDetails{
36 ServiceID: req.URL.Query().Get("service_id"),
37 PlanID: req.URL.Query().Get("plan_id"),
38 }
39
40 instanceDetails, err := h.serviceBroker.GetInstance(req.Context(), instanceID, details)
41 if err != nil {
42 switch err := err.(type) {
43 case *apiresponses.FailureResponse:
44 logger.Error(err.LoggerAction(), err)
45 h.respond(w, err.ValidatedStatusCode(slog.New(logger)), requestId, err.ErrorResponse())
46 default:
47 logger.Error(unknownErrorKey, err)
48 h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{
49 Description: err.Error(),
50 })
51 }
52 return
53 }
54
55 var metadata any
56 if !instanceDetails.Metadata.IsEmpty() {
57 metadata = instanceDetails.Metadata
58 }
59
60 h.respond(w, http.StatusOK, requestId, apiresponses.GetInstanceResponse{
61 ServiceID: instanceDetails.ServiceID,
62 PlanID: instanceDetails.PlanID,
63 DashboardURL: instanceDetails.DashboardURL,
64 Parameters: instanceDetails.Parameters,
65 Metadata: metadata,
66 })
67}

Callers

nothing calls this directly

Calls 10

respondMethod · 0.95
InstanceIDFunction · 0.92
getAPIVersionFunction · 0.85
SessionMethod · 0.80
ErrorMethod · 0.80
LoggerActionMethod · 0.80
ValidatedStatusCodeMethod · 0.80
ErrorResponseMethod · 0.80
GetInstanceMethod · 0.65
IsEmptyMethod · 0.45

Tested by

no test coverage detected