github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/broker/server.go (about) 1 package broker 2 3 import ( 4 "context" 5 "net/http" 6 7 "code.cloudfoundry.org/lager" 8 "github.com/gorilla/mux" 9 "github.com/pivotal-cf/brokerapi/v8/domain" 10 "github.com/pivotal-cf/brokerapi/v8/handlers" 11 "github.com/pivotal-cf/brokerapi/v8/middlewares" 12 ) 13 14 // copied from github.com/pivotal-cf/brokerapi/api.go 15 func AttachRoutes(router *mux.Router, serviceBroker domain.ServiceBroker, logger lager.Logger) *mux.Router { 16 apiHandler := handlers.NewApiHandler(serviceBroker, logger) 17 deprovision := func(w http.ResponseWriter, req *http.Request) { 18 req2 := req.WithContext(context.WithValue(req.Context(), "User-Agent", req.Header.Get("User-Agent"))) 19 apiHandler.Deprovision(w, req2) 20 } 21 router.HandleFunc("/v2/catalog", apiHandler.Catalog).Methods("GET") 22 23 router.HandleFunc("/v2/service_instances/{instance_id}", apiHandler.GetInstance).Methods("GET") 24 router.HandleFunc("/v2/service_instances/{instance_id}", apiHandler.Provision).Methods("PUT") 25 router.HandleFunc("/v2/service_instances/{instance_id}", deprovision).Methods("DELETE") 26 router.HandleFunc("/v2/service_instances/{instance_id}/last_operation", apiHandler.LastOperation).Methods("GET") 27 router.HandleFunc("/v2/service_instances/{instance_id}", apiHandler.Update).Methods("PATCH") 28 29 router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}", apiHandler.GetBinding).Methods("GET") 30 router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}", apiHandler.Bind).Methods("PUT") 31 router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}", apiHandler.Unbind).Methods("DELETE") 32 33 router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}/last_operation", apiHandler.LastBindingOperation).Methods("GET") 34 35 router.Use(middlewares.AddCorrelationIDToContext) 36 apiVersionMiddleware := middlewares.APIVersionMiddleware{LoggerFactory: logger} 37 38 router.Use(middlewares.AddOriginatingIdentityToContext) 39 router.Use(apiVersionMiddleware.ValidateAPIVersionHdr) 40 router.Use(middlewares.AddInfoLocationToContext) 41 42 return router 43 }