From 8a4cf3618c9162f2857919534e0f75e4b5cb799f Mon Sep 17 00:00:00 2001 From: Felisia Martini Date: Thu, 1 Apr 2021 12:00:12 +0100 Subject: [PATCH] Update to v8 (#150) --- api.go | 6 +- api_test.go | 6 +- auth/auth_test.go | 2 +- catalog.go | 2 +- catalog_test.go | 2 +- context_utils.go | 2 +- context_utils_test.go | 2 +- domain/apiresponses/failure_responses_test.go | 2 +- domain/apiresponses/responses.go | 2 +- domain/apiresponses/responses_test.go | 4 +- domain/maintenance_info_test.go | 2 +- domain/service_catalog_test.go | 2 +- domain/service_metadata_test.go | 2 +- domain/service_plan_metadata_test.go | 4 +- failure_response.go | 2 +- failure_response_test.go | 2 +- fakes/auto_fake_service_broker.go | 2 +- fakes/fake_service_broker.go | 6 +- go.mod | 2 +- handlers/api_handler.go | 2 +- handlers/bind.go | 8 +- handlers/catalog.go | 2 +- handlers/deprovision.go | 8 +- handlers/get_binding.go | 8 +- handlers/get_instance.go | 8 +- handlers/last_binding_operation.go | 8 +- handlers/last_binding_operation_test.go | 12 +- handlers/last_operation.go | 8 +- handlers/provision.go | 8 +- handlers/unbind.go | 8 +- handlers/update.go | 8 +- maintenance_info.go | 2 +- maintenance_info_test.go | 2 +- response.go | 4 +- response_test.go | 2 +- service_broker.go | 4 +- utils/context.go | 2 +- utils/context_test.go | 4 +- v7/api.go | 66 ----- v7/auth/auth.go | 88 ------- v7/catalog.go | 77 ------ v7/context_utils.go | 23 -- v7/domain/apiresponses/errors.go | 94 ------- v7/domain/apiresponses/failure_responses.go | 117 --------- v7/domain/apiresponses/responses.go | 85 ------ v7/domain/experimental_volume_mount.go | 13 - v7/domain/maintenance_info.go | 16 -- v7/domain/service_broker.go | 242 ------------------ v7/domain/service_catalog.go | 76 ------ v7/domain/service_metadata.go | 62 ----- v7/domain/service_plan_metadata.go | 83 ------ v7/failure_response.go | 37 --- v7/handlers/api_handler.go | 66 ----- v7/handlers/bind.go | 146 ----------- v7/handlers/catalog.go | 26 -- v7/handlers/deprovision.go | 71 ----- v7/handlers/get_binding.go | 69 ----- v7/handlers/get_instance.go | 64 ----- v7/handlers/last_binding_operation.go | 68 ----- v7/handlers/last_operation.go | 57 ----- v7/handlers/provision.go | 139 ---------- v7/handlers/unbind.go | 74 ------ v7/handlers/update.go | 71 ----- v7/maintenance_info.go | 8 - v7/middlewares/api_version_header.go | 89 ------- v7/middlewares/correlation_id_header.go | 35 --- v7/middlewares/info_location_header.go | 33 --- v7/middlewares/originating_identity_header.go | 33 --- v7/middlewares/request_identity_header.go | 16 -- v7/response.go | 66 ----- v7/service_broker.go | 140 ---------- v7/utils/context.go | 54 ---- 72 files changed, 81 insertions(+), 2485 deletions(-) delete mode 100644 v7/api.go delete mode 100644 v7/auth/auth.go delete mode 100644 v7/catalog.go delete mode 100644 v7/context_utils.go delete mode 100644 v7/domain/apiresponses/errors.go delete mode 100644 v7/domain/apiresponses/failure_responses.go delete mode 100644 v7/domain/apiresponses/responses.go delete mode 100644 v7/domain/experimental_volume_mount.go delete mode 100644 v7/domain/maintenance_info.go delete mode 100644 v7/domain/service_broker.go delete mode 100644 v7/domain/service_catalog.go delete mode 100644 v7/domain/service_metadata.go delete mode 100644 v7/domain/service_plan_metadata.go delete mode 100644 v7/failure_response.go delete mode 100644 v7/handlers/api_handler.go delete mode 100644 v7/handlers/bind.go delete mode 100644 v7/handlers/catalog.go delete mode 100644 v7/handlers/deprovision.go delete mode 100644 v7/handlers/get_binding.go delete mode 100644 v7/handlers/get_instance.go delete mode 100644 v7/handlers/last_binding_operation.go delete mode 100644 v7/handlers/last_operation.go delete mode 100644 v7/handlers/provision.go delete mode 100644 v7/handlers/unbind.go delete mode 100644 v7/handlers/update.go delete mode 100644 v7/maintenance_info.go delete mode 100644 v7/middlewares/api_version_header.go delete mode 100644 v7/middlewares/correlation_id_header.go delete mode 100644 v7/middlewares/info_location_header.go delete mode 100644 v7/middlewares/originating_identity_header.go delete mode 100644 v7/middlewares/request_identity_header.go delete mode 100644 v7/response.go delete mode 100644 v7/service_broker.go delete mode 100644 v7/utils/context.go diff --git a/api.go b/api.go index c4d19d4d..965e3291 100644 --- a/api.go +++ b/api.go @@ -20,9 +20,9 @@ import ( "code.cloudfoundry.org/lager" "github.com/gorilla/mux" - "github.com/pivotal-cf/brokerapi/v7/auth" - "github.com/pivotal-cf/brokerapi/v7/handlers" - "github.com/pivotal-cf/brokerapi/v7/middlewares" + "github.com/pivotal-cf/brokerapi/v8/auth" + "github.com/pivotal-cf/brokerapi/v8/handlers" + "github.com/pivotal-cf/brokerapi/v8/middlewares" ) type BrokerCredentials struct { diff --git a/api_test.go b/api_test.go index 77352f65..573084ac 100644 --- a/api_test.go +++ b/api_test.go @@ -28,15 +28,15 @@ import ( "github.com/onsi/ginkgo/extensions/table" - "github.com/pivotal-cf/brokerapi/v7/middlewares" + "github.com/pivotal-cf/brokerapi/v8/middlewares" "code.cloudfoundry.org/lager" "code.cloudfoundry.org/lager/lagertest" "github.com/drewolson/testflight" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7" - "github.com/pivotal-cf/brokerapi/v7/fakes" + "github.com/pivotal-cf/brokerapi/v8" + "github.com/pivotal-cf/brokerapi/v8/fakes" ) var _ = Describe("Service Broker API", func() { diff --git a/auth/auth_test.go b/auth/auth_test.go index 812be5ab..56ccbf9f 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/auth" + "github.com/pivotal-cf/brokerapi/v8/auth" ) var _ = Describe("Auth Wrapper", func() { diff --git a/catalog.go b/catalog.go index 41cf543c..4c6a2a26 100644 --- a/catalog.go +++ b/catalog.go @@ -18,7 +18,7 @@ package brokerapi import ( "reflect" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) //Deprecated: Use github.com/pivotal-cf/brokerapi/domain diff --git a/catalog_test.go b/catalog_test.go index a9b1db25..f5d4ecbf 100644 --- a/catalog_test.go +++ b/catalog_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7" + "github.com/pivotal-cf/brokerapi/v8" ) var _ = Describe("Catalog", func() { diff --git a/context_utils.go b/context_utils.go index 1a4d1f62..fa5774fc 100644 --- a/context_utils.go +++ b/context_utils.go @@ -3,7 +3,7 @@ package brokerapi import ( "context" - "github.com/pivotal-cf/brokerapi/v7/utils" + "github.com/pivotal-cf/brokerapi/v8/utils" ) func AddServiceToContext(ctx context.Context, service *Service) context.Context { diff --git a/context_utils_test.go b/context_utils_test.go index d514e006..88e99506 100644 --- a/context_utils_test.go +++ b/context_utils_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7" + "github.com/pivotal-cf/brokerapi/v8" ) var _ = Describe("Context Utilities", func() { diff --git a/domain/apiresponses/failure_responses_test.go b/domain/apiresponses/failure_responses_test.go index ee1d7be5..6d8f1874 100644 --- a/domain/apiresponses/failure_responses_test.go +++ b/domain/apiresponses/failure_responses_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" "code.cloudfoundry.org/lager" "github.com/onsi/gomega/gbytes" diff --git a/domain/apiresponses/responses.go b/domain/apiresponses/responses.go index 2c8c6c81..b51cfdc6 100644 --- a/domain/apiresponses/responses.go +++ b/domain/apiresponses/responses.go @@ -15,7 +15,7 @@ package apiresponses -import "github.com/pivotal-cf/brokerapi/v7/domain" +import "github.com/pivotal-cf/brokerapi/v8/domain" type EmptyResponse struct{} diff --git a/domain/apiresponses/responses_test.go b/domain/apiresponses/responses_test.go index 5a63ee05..214f640b 100644 --- a/domain/apiresponses/responses_test.go +++ b/domain/apiresponses/responses_test.go @@ -5,8 +5,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" ) var _ = Describe("Catalog Response", func() { diff --git a/domain/maintenance_info_test.go b/domain/maintenance_info_test.go index 0d9c0061..0b6b0db9 100644 --- a/domain/maintenance_info_test.go +++ b/domain/maintenance_info_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) var _ = Describe("MaintenanceInfo", func() { diff --git a/domain/service_catalog_test.go b/domain/service_catalog_test.go index c75d615e..ff10e7ab 100644 --- a/domain/service_catalog_test.go +++ b/domain/service_catalog_test.go @@ -5,7 +5,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) var maximumPollingDuration = 3600 diff --git a/domain/service_metadata_test.go b/domain/service_metadata_test.go index 61f86b66..9c277f01 100644 --- a/domain/service_metadata_test.go +++ b/domain/service_metadata_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) var _ = Describe("ServiceMetadata", func() { diff --git a/domain/service_plan_metadata_test.go b/domain/service_plan_metadata_test.go index 9876a90c..3832c9ff 100644 --- a/domain/service_plan_metadata_test.go +++ b/domain/service_plan_metadata_test.go @@ -7,8 +7,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8" + "github.com/pivotal-cf/brokerapi/v8/domain" ) var _ = Describe("ServicePlanMetadata", func() { diff --git a/failure_response.go b/failure_response.go index ab7c85fc..c5aa0eac 100644 --- a/failure_response.go +++ b/failure_response.go @@ -7,7 +7,7 @@ package brokerapi import ( - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" ) //Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses diff --git a/failure_response_test.go b/failure_response_test.go index 3910e3cd..82694d11 100644 --- a/failure_response_test.go +++ b/failure_response_test.go @@ -16,7 +16,7 @@ package brokerapi_test import ( - "github.com/pivotal-cf/brokerapi/v7" + "github.com/pivotal-cf/brokerapi/v8" "errors" diff --git a/fakes/auto_fake_service_broker.go b/fakes/auto_fake_service_broker.go index 1e8f8c01..fbea611f 100644 --- a/fakes/auto_fake_service_broker.go +++ b/fakes/auto_fake_service_broker.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) type AutoFakeServiceBroker struct { diff --git a/fakes/fake_service_broker.go b/fakes/fake_service_broker.go index 2cff5263..827944c9 100644 --- a/fakes/fake_service_broker.go +++ b/fakes/fake_service_broker.go @@ -5,9 +5,9 @@ import ( "errors" "reflect" - "github.com/pivotal-cf/brokerapi/v7" - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" ) type FakeServiceBroker struct { diff --git a/go.mod b/go.mod index 4d9e0b03..a986e9b8 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/pivotal-cf/brokerapi/v7 +module github.com/pivotal-cf/brokerapi/v8 go 1.15 diff --git a/handlers/api_handler.go b/handlers/api_handler.go index 8a9828b1..a5c4735c 100644 --- a/handlers/api_handler.go +++ b/handlers/api_handler.go @@ -7,7 +7,7 @@ import ( "net/http" "code.cloudfoundry.org/lager" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) const ( diff --git a/handlers/bind.go b/handlers/bind.go index eb4fb08c..4529dd2e 100644 --- a/handlers/bind.go +++ b/handlers/bind.go @@ -7,10 +7,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const ( diff --git a/handlers/catalog.go b/handlers/catalog.go index bc436ff8..40e25cab 100644 --- a/handlers/catalog.go +++ b/handlers/catalog.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" ) func (h *APIHandler) Catalog(w http.ResponseWriter, req *http.Request) { diff --git a/handlers/deprovision.go b/handlers/deprovision.go index a4906e07..4f599581 100644 --- a/handlers/deprovision.go +++ b/handlers/deprovision.go @@ -6,10 +6,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const deprovisionLogKey = "deprovision" diff --git a/handlers/get_binding.go b/handlers/get_binding.go index 90048c6a..6d833c1f 100644 --- a/handlers/get_binding.go +++ b/handlers/get_binding.go @@ -7,10 +7,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const getBindLogKey = "getBinding" diff --git a/handlers/get_instance.go b/handlers/get_instance.go index 2466cadc..d2a362aa 100644 --- a/handlers/get_instance.go +++ b/handlers/get_instance.go @@ -5,13 +5,13 @@ import ( "fmt" "net/http" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" "code.cloudfoundry.org/lager" "github.com/gorilla/mux" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" - "github.com/pivotal-cf/brokerapi/v7/middlewares" - "github.com/pivotal-cf/brokerapi/v7/utils" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const getInstanceLogKey = "getInstance" diff --git a/handlers/last_binding_operation.go b/handlers/last_binding_operation.go index 27ed7d99..d37e1d3d 100644 --- a/handlers/last_binding_operation.go +++ b/handlers/last_binding_operation.go @@ -7,10 +7,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const lastBindingOperationLogKey = "lastBindingOperation" diff --git a/handlers/last_binding_operation_test.go b/handlers/last_binding_operation_test.go index b608bccc..3f34c242 100644 --- a/handlers/last_binding_operation_test.go +++ b/handlers/last_binding_operation_test.go @@ -7,17 +7,17 @@ import ( "net/http" "net/url" - "github.com/pivotal-cf/brokerapi/v7/middlewares" + "github.com/pivotal-cf/brokerapi/v8/middlewares" "code.cloudfoundry.org/lager" "github.com/gorilla/mux" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" - brokerFakes "github.com/pivotal-cf/brokerapi/v7/fakes" - "github.com/pivotal-cf/brokerapi/v7/handlers" - "github.com/pivotal-cf/brokerapi/v7/handlers/fakes" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + brokerFakes "github.com/pivotal-cf/brokerapi/v8/fakes" + "github.com/pivotal-cf/brokerapi/v8/handlers" + "github.com/pivotal-cf/brokerapi/v8/handlers/fakes" "github.com/pkg/errors" ) diff --git a/handlers/last_operation.go b/handlers/last_operation.go index 6a8b1af7..b9607e18 100644 --- a/handlers/last_operation.go +++ b/handlers/last_operation.go @@ -6,10 +6,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const lastOperationLogKey = "lastOperation" diff --git a/handlers/provision.go b/handlers/provision.go index e4916eea..991d9e22 100644 --- a/handlers/provision.go +++ b/handlers/provision.go @@ -7,10 +7,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const ( diff --git a/handlers/unbind.go b/handlers/unbind.go index 74d9da09..c16c1b82 100644 --- a/handlers/unbind.go +++ b/handlers/unbind.go @@ -6,10 +6,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const unbindLogKey = "unbind" diff --git a/handlers/update.go b/handlers/update.go index c64236bf..aab37188 100644 --- a/handlers/update.go +++ b/handlers/update.go @@ -8,10 +8,10 @@ import ( "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" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/middlewares" + "github.com/pivotal-cf/brokerapi/v8/utils" ) const updateLogKey = "update" diff --git a/maintenance_info.go b/maintenance_info.go index 3abe4d4d..fe37df7e 100644 --- a/maintenance_info.go +++ b/maintenance_info.go @@ -1,7 +1,7 @@ package brokerapi import ( - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) //Deprecated: Use github.com/pivotal-cf/brokerapi/domain diff --git a/maintenance_info_test.go b/maintenance_info_test.go index 8c0b6431..16b493ba 100644 --- a/maintenance_info_test.go +++ b/maintenance_info_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7" + "github.com/pivotal-cf/brokerapi/v8" ) var _ = Describe("MaintenanceInfo", func() { diff --git a/response.go b/response.go index 4313dae8..2f8b3ebd 100644 --- a/response.go +++ b/response.go @@ -16,8 +16,8 @@ package brokerapi import ( - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" ) //Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses diff --git a/response_test.go b/response_test.go index b13856f3..ff39e372 100644 --- a/response_test.go +++ b/response_test.go @@ -20,7 +20,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7" + "github.com/pivotal-cf/brokerapi/v8" ) var _ = Describe("Catalog Response", func() { diff --git a/service_broker.go b/service_broker.go index 34de1e50..330a4f27 100644 --- a/service_broker.go +++ b/service_broker.go @@ -16,8 +16,8 @@ package brokerapi import ( - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o fakes/auto_fake_service_broker.go -fake-name AutoFakeServiceBroker . ServiceBroker diff --git a/utils/context.go b/utils/context.go index 34e4ce88..39997106 100644 --- a/utils/context.go +++ b/utils/context.go @@ -4,7 +4,7 @@ import ( "context" "code.cloudfoundry.org/lager" - "github.com/pivotal-cf/brokerapi/v7/domain" + "github.com/pivotal-cf/brokerapi/v8/domain" ) type contextKey string diff --git a/utils/context_test.go b/utils/context_test.go index 1f95756d..ca63263c 100644 --- a/utils/context_test.go +++ b/utils/context_test.go @@ -5,8 +5,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/utils" + "github.com/pivotal-cf/brokerapi/v8/domain" + "github.com/pivotal-cf/brokerapi/v8/utils" ) var _ = Describe("Context", func() { diff --git a/v7/api.go b/v7/api.go deleted file mode 100644 index c4d19d4d..00000000 --- a/v7/api.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package brokerapi - -import ( - "net/http" - - "code.cloudfoundry.org/lager" - "github.com/gorilla/mux" - "github.com/pivotal-cf/brokerapi/v7/auth" - "github.com/pivotal-cf/brokerapi/v7/handlers" - "github.com/pivotal-cf/brokerapi/v7/middlewares" -) - -type BrokerCredentials struct { - Username string - Password string -} - -func New(serviceBroker ServiceBroker, logger lager.Logger, brokerCredentials BrokerCredentials) http.Handler { - router := mux.NewRouter() - - AttachRoutes(router, serviceBroker, logger) - - authMiddleware := auth.NewWrapper(brokerCredentials.Username, brokerCredentials.Password).Wrap - apiVersionMiddleware := middlewares.APIVersionMiddleware{LoggerFactory: logger} - - router.Use(middlewares.AddCorrelationIDToContext) - router.Use(authMiddleware) - router.Use(middlewares.AddOriginatingIdentityToContext) - router.Use(apiVersionMiddleware.ValidateAPIVersionHdr) - router.Use(middlewares.AddInfoLocationToContext) - router.Use(middlewares.AddRequestIdentityToContext) - - return router -} - -func AttachRoutes(router *mux.Router, serviceBroker ServiceBroker, logger lager.Logger) { - apiHandler := handlers.NewApiHandler(serviceBroker, logger) - router.HandleFunc("/v2/catalog", apiHandler.Catalog).Methods("GET") - - router.HandleFunc("/v2/service_instances/{instance_id}", apiHandler.GetInstance).Methods("GET") - router.HandleFunc("/v2/service_instances/{instance_id}", apiHandler.Provision).Methods("PUT") - router.HandleFunc("/v2/service_instances/{instance_id}", apiHandler.Deprovision).Methods("DELETE") - router.HandleFunc("/v2/service_instances/{instance_id}/last_operation", apiHandler.LastOperation).Methods("GET") - router.HandleFunc("/v2/service_instances/{instance_id}", apiHandler.Update).Methods("PATCH") - - router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}", apiHandler.GetBinding).Methods("GET") - router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}", apiHandler.Bind).Methods("PUT") - router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}", apiHandler.Unbind).Methods("DELETE") - - router.HandleFunc("/v2/service_instances/{instance_id}/service_bindings/{binding_id}/last_operation", apiHandler.LastBindingOperation).Methods("GET") -} diff --git a/v7/auth/auth.go b/v7/auth/auth.go deleted file mode 100644 index 25229ec2..00000000 --- a/v7/auth/auth.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "crypto/sha256" - "crypto/subtle" - "net/http" -) - -type Wrapper struct { - credentials []Credential -} - -type Credential struct { - username []byte - password []byte -} - -func NewWrapperMultiple(users map[string]string) *Wrapper { - var cs []Credential - for k, v := range users { - u := sha256.Sum256([]byte(k)) - p := sha256.Sum256([]byte(v)) - cs = append(cs, Credential{username: u[:], password: p[:]}) - } - return &Wrapper{credentials: cs} -} - -func NewWrapper(username, password string) *Wrapper { - return NewWrapperMultiple(map[string]string{username: password}) -} - -const notAuthorized = "Not Authorized" - -func (wrapper *Wrapper) Wrap(handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !authorized(wrapper, r) { - http.Error(w, notAuthorized, http.StatusUnauthorized) - return - } - - handler.ServeHTTP(w, r) - }) -} - -func (wrapper *Wrapper) WrapFunc(handlerFunc http.HandlerFunc) http.HandlerFunc { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !authorized(wrapper, r) { - http.Error(w, notAuthorized, http.StatusUnauthorized) - return - } - - handlerFunc(w, r) - }) -} - -func authorized(wrapper *Wrapper, r *http.Request) bool { - username, password, isOk := r.BasicAuth() - if isOk { - u := sha256.Sum256([]byte(username)) - p := sha256.Sum256([]byte(password)) - for _, c := range wrapper.credentials { - if c.isAuthorized(u, p) { - return true - } - } - } - return false -} - -func (c Credential) isAuthorized(uChecksum [32]byte, pChecksum [32]byte) bool { - return subtle.ConstantTimeCompare(c.username, uChecksum[:]) == 1 && - subtle.ConstantTimeCompare(c.password, pChecksum[:]) == 1 -} diff --git a/v7/catalog.go b/v7/catalog.go deleted file mode 100644 index 41cf543c..00000000 --- a/v7/catalog.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package brokerapi - -import ( - "reflect" - - "github.com/pivotal-cf/brokerapi/v7/domain" -) - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type Service = domain.Service - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServiceDashboardClient = domain.ServiceDashboardClient - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServicePlan = domain.ServicePlan - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServiceSchemas = domain.ServiceSchemas - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServiceInstanceSchema = domain.ServiceInstanceSchema - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServiceBindingSchema = domain.ServiceBindingSchema - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type Schema = domain.Schema - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServicePlanMetadata = domain.ServicePlanMetadata - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServicePlanCost = domain.ServicePlanCost - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ServiceMetadata = domain.ServiceMetadata - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -func FreeValue(v bool) *bool { - return domain.FreeValue(v) -} - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -func BindableValue(v bool) *bool { - return domain.BindableValue(v) -} - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type RequiredPermission = domain.RequiredPermission - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -const ( - PermissionRouteForwarding = domain.PermissionRouteForwarding - PermissionSyslogDrain = domain.PermissionSyslogDrain - PermissionVolumeMount = domain.PermissionVolumeMount -) - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -func GetJsonNames(s reflect.Value) (res []string) { - return domain.GetJsonNames(s) -} diff --git a/v7/context_utils.go b/v7/context_utils.go deleted file mode 100644 index 1a4d1f62..00000000 --- a/v7/context_utils.go +++ /dev/null @@ -1,23 +0,0 @@ -package brokerapi - -import ( - "context" - - "github.com/pivotal-cf/brokerapi/v7/utils" -) - -func AddServiceToContext(ctx context.Context, service *Service) context.Context { - return utils.AddServiceToContext(ctx, service) -} - -func RetrieveServiceFromContext(ctx context.Context) *Service { - return utils.RetrieveServiceFromContext(ctx) -} - -func AddServicePlanToContext(ctx context.Context, plan *ServicePlan) context.Context { - return utils.AddServicePlanToContext(ctx, plan) -} - -func RetrieveServicePlanFromContext(ctx context.Context) *ServicePlan { - return utils.RetrieveServicePlanFromContext(ctx) -} diff --git a/v7/domain/apiresponses/errors.go b/v7/domain/apiresponses/errors.go deleted file mode 100644 index 462a1a35..00000000 --- a/v7/domain/apiresponses/errors.go +++ /dev/null @@ -1,94 +0,0 @@ -package apiresponses - -import ( - "errors" - "net/http" -) - -const ( - instanceExistsMsg = "instance already exists" - instanceDoesntExistMsg = "instance does not exist" - serviceLimitReachedMsg = "instance limit for this service has been reached" - servicePlanQuotaExceededMsg = "The quota for this service plan has been exceeded. Please contact your Operator for help." - serviceQuotaExceededMsg = "The quota for this service has been exceeded. Please contact your Operator for help." - bindingExistsMsg = "binding already exists" - bindingDoesntExistMsg = "binding does not exist" - bindingNotFoundMsg = "binding cannot be fetched" - asyncRequiredMsg = "This service plan requires client support for asynchronous service operations." - planChangeUnsupportedMsg = "The requested plan migration cannot be performed" - rawInvalidParamsMsg = "The format of the parameters is not valid JSON" - appGuidMissingMsg = "app_guid is a required field but was not provided" - concurrentInstanceAccessMsg = "instance is being updated and cannot be retrieved" - maintenanceInfoConflictMsg = "passed maintenance_info does not match the catalog maintenance_info" - maintenanceInfoNilConflictMsg = "maintenance_info was passed, but the broker catalog contains no maintenance_info" - - instanceLimitReachedErrorKey = "instance-limit-reached" - instanceAlreadyExistsErrorKey = "instance-already-exists" - bindingAlreadyExistsErrorKey = "binding-already-exists" - instanceMissingErrorKey = "instance-missing" - bindingMissingErrorKey = "binding-missing" - bindingNotFoundErrorKey = "binding-not-found" - asyncRequiredKey = "async-required" - planChangeNotSupportedKey = "plan-change-not-supported" - invalidRawParamsKey = "invalid-raw-params" - appGuidNotProvidedErrorKey = "app-guid-not-provided" - concurrentAccessKey = "get-instance-during-update" - maintenanceInfoConflictKey = "maintenance-info-conflict" -) - -var ( - ErrInstanceAlreadyExists = NewFailureResponseBuilder( - errors.New(instanceExistsMsg), http.StatusConflict, instanceAlreadyExistsErrorKey, - ).WithEmptyResponse().Build() - - ErrInstanceDoesNotExist = NewFailureResponseBuilder( - errors.New(instanceDoesntExistMsg), http.StatusGone, instanceMissingErrorKey, - ).WithEmptyResponse().Build() - - ErrInstanceLimitMet = NewFailureResponse( - errors.New(serviceLimitReachedMsg), http.StatusInternalServerError, instanceLimitReachedErrorKey, - ) - - ErrBindingAlreadyExists = NewFailureResponse( - errors.New(bindingExistsMsg), http.StatusConflict, bindingAlreadyExistsErrorKey, - ) - - ErrBindingDoesNotExist = NewFailureResponseBuilder( - errors.New(bindingDoesntExistMsg), http.StatusGone, bindingMissingErrorKey, - ).WithEmptyResponse().Build() - - ErrBindingNotFound = NewFailureResponseBuilder( - errors.New(bindingNotFoundMsg), http.StatusNotFound, bindingNotFoundErrorKey, - ).WithEmptyResponse().Build() - - ErrAsyncRequired = NewFailureResponseBuilder( - errors.New(asyncRequiredMsg), http.StatusUnprocessableEntity, asyncRequiredKey, - ).WithErrorKey("AsyncRequired").Build() - - ErrPlanChangeNotSupported = NewFailureResponseBuilder( - errors.New(planChangeUnsupportedMsg), http.StatusUnprocessableEntity, planChangeNotSupportedKey, - ).WithErrorKey("PlanChangeNotSupported").Build() - - ErrRawParamsInvalid = NewFailureResponse( - errors.New(rawInvalidParamsMsg), http.StatusUnprocessableEntity, invalidRawParamsKey, - ) - - ErrAppGuidNotProvided = NewFailureResponse( - errors.New(appGuidMissingMsg), http.StatusUnprocessableEntity, appGuidNotProvidedErrorKey, - ) - - ErrPlanQuotaExceeded = errors.New(servicePlanQuotaExceededMsg) - ErrServiceQuotaExceeded = errors.New(serviceQuotaExceededMsg) - - ErrConcurrentInstanceAccess = NewFailureResponseBuilder( - errors.New(concurrentInstanceAccessMsg), http.StatusUnprocessableEntity, concurrentAccessKey, - ).WithErrorKey("ConcurrencyError").Build() - - ErrMaintenanceInfoConflict = NewFailureResponseBuilder( - errors.New(maintenanceInfoConflictMsg), http.StatusUnprocessableEntity, maintenanceInfoConflictKey, - ).WithErrorKey("MaintenanceInfoConflict").Build() - - ErrMaintenanceInfoNilConflict = NewFailureResponseBuilder( - errors.New(maintenanceInfoNilConflictMsg), http.StatusUnprocessableEntity, maintenanceInfoConflictKey, - ).WithErrorKey("MaintenanceInfoConflict").Build() -) diff --git a/v7/domain/apiresponses/failure_responses.go b/v7/domain/apiresponses/failure_responses.go deleted file mode 100644 index d27d2169..00000000 --- a/v7/domain/apiresponses/failure_responses.go +++ /dev/null @@ -1,117 +0,0 @@ -package apiresponses - -import ( - "fmt" - "net/http" - - "code.cloudfoundry.org/lager" -) - -// FailureResponse can be returned from any of the `ServiceBroker` interface methods -// which allow an error to be returned. Doing so will provide greater control over -// the HTTP response. -type FailureResponse struct { - error - statusCode int - loggerAction string - emptyResponse bool - errorKey string -} - -// NewFailureResponse returns a pointer to a new instance of FailureResponse. -// err will by default be used as both a logging message and HTTP response description. -// statusCode is the HTTP status code to be returned, must be 4xx or 5xx -// loggerAction is a short description which will be used as the action if the error is logged. -func NewFailureResponse(err error, statusCode int, loggerAction string) *FailureResponse { - return &FailureResponse{ - error: err, - statusCode: statusCode, - loggerAction: loggerAction, - } -} - -// ErrorResponse returns an interface{} which will be JSON encoded and form the body -// of the HTTP response -func (f *FailureResponse) ErrorResponse() interface{} { - if f.emptyResponse { - return EmptyResponse{} - } - - return ErrorResponse{ - Description: f.error.Error(), - Error: f.errorKey, - } -} - -// ValidatedStatusCode returns the HTTP response status code. If the code is not 4xx -// or 5xx, an InternalServerError will be returned instead. -func (f *FailureResponse) ValidatedStatusCode(logger lager.Logger) int { - if f.statusCode < 400 || 600 <= f.statusCode { - if logger != nil { - logger.Error("validating-status-code", fmt.Errorf("Invalid failure http response code: 600, expected 4xx or 5xx, returning internal server error: 500.")) - } - return http.StatusInternalServerError - } - return f.statusCode -} - -// LoggerAction returns the loggerAction, used as the action when logging -func (f *FailureResponse) LoggerAction() string { - return f.loggerAction -} - -// AppendErrorMessage returns an error with the message updated. All other properties are preserved. -func (f *FailureResponse) AppendErrorMessage(msg string) *FailureResponse { - return &FailureResponse{ - error: fmt.Errorf("%s %s", f.Error(), msg), - statusCode: f.statusCode, - loggerAction: f.loggerAction, - emptyResponse: f.emptyResponse, - errorKey: f.errorKey, - } -} - -// FailureResponseBuilder provides a fluent set of methods to build a *FailureResponse. -type FailureResponseBuilder struct { - error - statusCode int - loggerAction string - emptyResponse bool - errorKey string -} - -// NewFailureResponseBuilder returns a pointer to a newly instantiated FailureResponseBuilder -// Accepts required arguments to create a FailureResponse. -func NewFailureResponseBuilder(err error, statusCode int, loggerAction string) *FailureResponseBuilder { - return &FailureResponseBuilder{ - error: err, - statusCode: statusCode, - loggerAction: loggerAction, - emptyResponse: false, - } -} - -// WithErrorKey adds a custom ErrorKey which will be used in FailureResponse to add an `Error` -// field to the JSON HTTP response body -func (f *FailureResponseBuilder) WithErrorKey(errorKey string) *FailureResponseBuilder { - f.errorKey = errorKey - return f -} - -// WithEmptyResponse will cause the built FailureResponse to return an empty JSON object as the -// HTTP response body -func (f *FailureResponseBuilder) WithEmptyResponse() *FailureResponseBuilder { - f.emptyResponse = true - return f -} - -// Build returns the generated FailureResponse built using previously configured variables. -func (f *FailureResponseBuilder) Build() *FailureResponse { - return &FailureResponse{ - error: f.error, - statusCode: f.statusCode, - loggerAction: f.loggerAction, - emptyResponse: f.emptyResponse, - errorKey: f.errorKey, - } -} diff --git a/v7/domain/apiresponses/responses.go b/v7/domain/apiresponses/responses.go deleted file mode 100644 index 2c8c6c81..00000000 --- a/v7/domain/apiresponses/responses.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package apiresponses - -import "github.com/pivotal-cf/brokerapi/v7/domain" - -type EmptyResponse struct{} - -type ErrorResponse struct { - Error string `json:"error,omitempty"` - Description string `json:"description"` -} - -type CatalogResponse struct { - Services []domain.Service `json:"services"` -} - -type ProvisioningResponse struct { - DashboardURL string `json:"dashboard_url,omitempty"` - OperationData string `json:"operation,omitempty"` - Metadata interface{} `json:"metadata,omitempty"` -} - -type GetInstanceResponse struct { - ServiceID string `json:"service_id"` - PlanID string `json:"plan_id"` - DashboardURL string `json:"dashboard_url,omitempty"` - Parameters interface{} `json:"parameters,omitempty"` -} - -type UpdateResponse struct { - DashboardURL string `json:"dashboard_url,omitempty"` - OperationData string `json:"operation,omitempty"` -} - -type DeprovisionResponse struct { - OperationData string `json:"operation,omitempty"` -} - -type LastOperationResponse struct { - State domain.LastOperationState `json:"state"` - Description string `json:"description,omitempty"` -} - -type AsyncBindResponse struct { - OperationData string `json:"operation,omitempty"` -} - -type BindingResponse struct { - Credentials interface{} `json:"credentials,omitempty"` - SyslogDrainURL string `json:"syslog_drain_url,omitempty"` - RouteServiceURL string `json:"route_service_url,omitempty"` - VolumeMounts []domain.VolumeMount `json:"volume_mounts,omitempty"` - BackupAgentURL string `json:"backup_agent_url,omitempty"` -} - -type GetBindingResponse struct { - BindingResponse - Parameters interface{} `json:"parameters,omitempty"` -} - -type UnbindResponse struct { - OperationData string `json:"operation,omitempty"` -} - -type ExperimentalVolumeMountBindingResponse struct { - Credentials interface{} `json:"credentials,omitempty"` - SyslogDrainURL string `json:"syslog_drain_url,omitempty"` - RouteServiceURL string `json:"route_service_url,omitempty"` - VolumeMounts []domain.ExperimentalVolumeMount `json:"volume_mounts,omitempty"` - BackupAgentURL string `json:"backup_agent_url,omitempty"` -} diff --git a/v7/domain/experimental_volume_mount.go b/v7/domain/experimental_volume_mount.go deleted file mode 100644 index 66993a4f..00000000 --- a/v7/domain/experimental_volume_mount.go +++ /dev/null @@ -1,13 +0,0 @@ -package domain - -type ExperimentalVolumeMount struct { - ContainerPath string `json:"container_path"` - Mode string `json:"mode"` - Private ExperimentalVolumeMountPrivate `json:"private"` -} - -type ExperimentalVolumeMountPrivate struct { - Driver string `json:"driver"` - GroupID string `json:"group_id"` - Config string `json:"config"` -} diff --git a/v7/domain/maintenance_info.go b/v7/domain/maintenance_info.go deleted file mode 100644 index 8399b51c..00000000 --- a/v7/domain/maintenance_info.go +++ /dev/null @@ -1,16 +0,0 @@ -package domain - -import "reflect" - -type MaintenanceInfo struct { - Public map[string]string `json:"public,omitempty"` - Private string `json:"private,omitempty"` - Version string `json:"version,omitempty"` - Description string `json:"description,omitempty"` -} - -func (m *MaintenanceInfo) Equals(input MaintenanceInfo) bool { - return m.Version == input.Version && - m.Private == input.Private && - reflect.DeepEqual(m.Public, input.Public) -} diff --git a/v7/domain/service_broker.go b/v7/domain/service_broker.go deleted file mode 100644 index 6fcee6e5..00000000 --- a/v7/domain/service_broker.go +++ /dev/null @@ -1,242 +0,0 @@ -package domain - -import ( - "context" - "encoding/json" -) - -//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o ../fakes/auto_fake_service_broker.go -fake-name AutoFakeServiceBroker . ServiceBroker - -//Each method of the ServiceBroker interface maps to an individual endpoint of the Open Service Broker API. -//The specification is available here: https://github.com/openservicebrokerapi/servicebroker/blob/v2.14/spec.md -//The OpenAPI documentation is available here: http://petstore.swagger.io/?url=https://raw.githubusercontent.com/openservicebrokerapi/servicebroker/v2.14/openapi.yaml -type ServiceBroker interface { - - // Services gets the catalog of services offered by the service broker - // GET /v2/catalog - Services(ctx context.Context) ([]Service, error) - - // Provision creates a new service instance - // PUT /v2/service_instances/{instance_id} - Provision(ctx context.Context, instanceID string, details ProvisionDetails, asyncAllowed bool) (ProvisionedServiceSpec, error) - - // Deprovision deletes an existing service instance - // DELETE /v2/service_instances/{instance_id} - Deprovision(ctx context.Context, instanceID string, details DeprovisionDetails, asyncAllowed bool) (DeprovisionServiceSpec, error) - - // GetInstance fetches information about a service instance - // GET /v2/service_instances/{instance_id} - GetInstance(ctx context.Context, instanceID string, details FetchInstanceDetails) (GetInstanceDetailsSpec, error) - - // Update modifies an existing service instance - // PATCH /v2/service_instances/{instance_id} - Update(ctx context.Context, instanceID string, details UpdateDetails, asyncAllowed bool) (UpdateServiceSpec, error) - - // LastOperation fetches last operation state for a service instance - // GET /v2/service_instances/{instance_id}/last_operation - LastOperation(ctx context.Context, instanceID string, details PollDetails) (LastOperation, error) - - // Bind creates a new service binding - // PUT /v2/service_instances/{instance_id}/service_bindings/{binding_id} - Bind(ctx context.Context, instanceID, bindingID string, details BindDetails, asyncAllowed bool) (Binding, error) - - // Unbind deletes an existing service binding - // DELETE /v2/service_instances/{instance_id}/service_bindings/{binding_id} - Unbind(ctx context.Context, instanceID, bindingID string, details UnbindDetails, asyncAllowed bool) (UnbindSpec, error) - - // GetBinding fetches an existing service binding - // GET /v2/service_instances/{instance_id}/service_bindings/{binding_id} - GetBinding(ctx context.Context, instanceID, bindingID string, details FetchBindingDetails) (GetBindingSpec, error) - - // LastBindingOperation fetches last operation state for a service binding - // GET /v2/service_instances/{instance_id}/service_bindings/{binding_id}/last_operation - LastBindingOperation(ctx context.Context, instanceID, bindingID string, details PollDetails) (LastOperation, error) -} - -type LastOperation struct { - State LastOperationState `json:"state"` - Description string `json:"description"` -} - -type LastOperationState string - -const ( - InProgress LastOperationState = "in progress" - Succeeded LastOperationState = "succeeded" - Failed LastOperationState = "failed" -) - -type VolumeMount struct { - Driver string `json:"driver"` - ContainerDir string `json:"container_dir"` - Mode string `json:"mode"` - DeviceType string `json:"device_type"` - Device SharedDevice `json:"device"` -} - -type SharedDevice struct { - VolumeId string `json:"volume_id"` - MountConfig map[string]interface{} `json:"mount_config"` -} - -type ProvisionDetails struct { - ServiceID string `json:"service_id"` - PlanID string `json:"plan_id"` - OrganizationGUID string `json:"organization_guid"` - SpaceGUID string `json:"space_guid"` - RawContext json.RawMessage `json:"context,omitempty"` - RawParameters json.RawMessage `json:"parameters,omitempty"` - MaintenanceInfo *MaintenanceInfo `json:"maintenance_info,omitempty"` -} - -type ProvisionedServiceSpec struct { - IsAsync bool - AlreadyExists bool - DashboardURL string - OperationData string - Metadata InstanceMetadata -} - -type InstanceMetadata struct { - Labels map[string]string `json:"labels,omitempty"` - Attributes map[string]string `json:"attributes,omitempty"` -} - -type DeprovisionDetails struct { - PlanID string `json:"plan_id"` - ServiceID string `json:"service_id"` - Force bool `json:"force"` -} - -type DeprovisionServiceSpec struct { - IsAsync bool - OperationData string -} - -type GetInstanceDetailsSpec struct { - ServiceID string `json:"service_id"` - PlanID string `json:"plan_id"` - DashboardURL string `json:"dashboard_url"` - Parameters interface{} `json:"parameters"` -} - -type UpdateDetails struct { - ServiceID string `json:"service_id"` - PlanID string `json:"plan_id"` - RawParameters json.RawMessage `json:"parameters,omitempty"` - PreviousValues PreviousValues `json:"previous_values"` - RawContext json.RawMessage `json:"context,omitempty"` - MaintenanceInfo *MaintenanceInfo `json:"maintenance_info,omitempty"` -} - -type PreviousValues struct { - PlanID string `json:"plan_id"` - ServiceID string `json:"service_id"` - OrgID string `json:"organization_id"` - SpaceID string `json:"space_id"` - MaintenanceInfo *MaintenanceInfo `json:"maintenance_info,omitempty"` -} - -type UpdateServiceSpec struct { - IsAsync bool - DashboardURL string - OperationData string -} - -type FetchInstanceDetails struct { - ServiceID string `json:"service_id"` - PlanID string `json:"plan_id"` -} - -type FetchBindingDetails struct { - ServiceID string `json:"service_id"` - PlanID string `json:"plan_id"` -} - -type PollDetails struct { - ServiceID string `json:"service_id"` - PlanID string `json:"plan_id"` - OperationData string `json:"operation"` -} - -type BindDetails struct { - AppGUID string `json:"app_guid"` - PlanID string `json:"plan_id"` - ServiceID string `json:"service_id"` - BindResource *BindResource `json:"bind_resource,omitempty"` - RawContext json.RawMessage `json:"context,omitempty"` - RawParameters json.RawMessage `json:"parameters,omitempty"` -} - -type BindResource struct { - AppGuid string `json:"app_guid,omitempty"` - SpaceGuid string `json:"space_guid,omitempty"` - Route string `json:"route,omitempty"` - CredentialClientID string `json:"credential_client_id,omitempty"` - BackupAgent bool `json:"backup_agent,omitempty"` -} - -type UnbindDetails struct { - PlanID string `json:"plan_id"` - ServiceID string `json:"service_id"` -} - -type UnbindSpec struct { - IsAsync bool - OperationData string -} - -type Binding struct { - IsAsync bool `json:"is_async"` - AlreadyExists bool `json:"already_exists"` - OperationData string `json:"operation_data"` - Credentials interface{} `json:"credentials"` - SyslogDrainURL string `json:"syslog_drain_url"` - RouteServiceURL string `json:"route_service_url"` - BackupAgentURL string `json:"backup_agent_url,omitempty"` - VolumeMounts []VolumeMount `json:"volume_mounts"` -} - -type GetBindingSpec struct { - Credentials interface{} - SyslogDrainURL string - RouteServiceURL string - VolumeMounts []VolumeMount - Parameters interface{} -} - -func (d ProvisionDetails) GetRawContext() json.RawMessage { - return d.RawContext -} - -func (d ProvisionDetails) GetRawParameters() json.RawMessage { - return d.RawParameters -} - -func (d BindDetails) GetRawContext() json.RawMessage { - return d.RawContext -} - -func (d BindDetails) GetRawParameters() json.RawMessage { - return d.RawParameters -} - -func (m InstanceMetadata) IsEmpty() bool { - return len(m.Attributes) == 0 && len(m.Labels) == 0 -} - -func (d UpdateDetails) GetRawContext() json.RawMessage { - return d.RawContext -} - -func (d UpdateDetails) GetRawParameters() json.RawMessage { - return d.RawParameters -} - -type DetailsWithRawParameters interface { - GetRawParameters() json.RawMessage -} - -type DetailsWithRawContext interface { - GetRawContext() json.RawMessage -} diff --git a/v7/domain/service_catalog.go b/v7/domain/service_catalog.go deleted file mode 100644 index fc02cb22..00000000 --- a/v7/domain/service_catalog.go +++ /dev/null @@ -1,76 +0,0 @@ -package domain - -const ( - PermissionRouteForwarding = RequiredPermission("route_forwarding") - PermissionSyslogDrain = RequiredPermission("syslog_drain") - PermissionVolumeMount = RequiredPermission("volume_mount") - - additionalMetadataName = "AdditionalMetadata" -) - -type Service struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Bindable bool `json:"bindable"` - InstancesRetrievable bool `json:"instances_retrievable,omitempty"` - BindingsRetrievable bool `json:"bindings_retrievable,omitempty"` - Tags []string `json:"tags,omitempty"` - PlanUpdatable bool `json:"plan_updateable"` - Plans []ServicePlan `json:"plans"` - Requires []RequiredPermission `json:"requires,omitempty"` - Metadata *ServiceMetadata `json:"metadata,omitempty"` - DashboardClient *ServiceDashboardClient `json:"dashboard_client,omitempty"` - AllowContextUpdates bool `json:"allow_context_updates,omitempty"` -} - -type ServicePlan struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Free *bool `json:"free,omitempty"` - Bindable *bool `json:"bindable,omitempty"` - Metadata *ServicePlanMetadata `json:"metadata,omitempty"` - Schemas *ServiceSchemas `json:"schemas,omitempty"` - PlanUpdatable *bool `json:"plan_updateable,omitempty"` - MaximumPollingDuration *int `json:"maximum_polling_duration,omitempty"` - MaintenanceInfo *MaintenanceInfo `json:"maintenance_info,omitempty"` -} - -type ServiceSchemas struct { - Instance ServiceInstanceSchema `json:"service_instance,omitempty"` - Binding ServiceBindingSchema `json:"service_binding,omitempty"` -} - -type ServiceInstanceSchema struct { - Create Schema `json:"create,omitempty"` - Update Schema `json:"update,omitempty"` -} - -type ServiceBindingSchema struct { - Create Schema `json:"create,omitempty"` -} - -type Schema struct { - Parameters map[string]interface{} `json:"parameters"` -} - -type RequiredPermission string - -func FreeValue(v bool) *bool { - return &v -} - -func BindableValue(v bool) *bool { - return &v -} - -func PlanUpdatableValue(v bool) *bool { - return &v -} - -type ServiceDashboardClient struct { - ID string `json:"id"` - Secret string `json:"secret"` - RedirectURI string `json:"redirect_uri"` -} diff --git a/v7/domain/service_metadata.go b/v7/domain/service_metadata.go deleted file mode 100644 index 926aae23..00000000 --- a/v7/domain/service_metadata.go +++ /dev/null @@ -1,62 +0,0 @@ -package domain - -import ( - "encoding/json" - "reflect" - - "github.com/pkg/errors" -) - -type ServiceMetadata struct { - DisplayName string `json:"displayName,omitempty"` - ImageUrl string `json:"imageUrl,omitempty"` - LongDescription string `json:"longDescription,omitempty"` - ProviderDisplayName string `json:"providerDisplayName,omitempty"` - DocumentationUrl string `json:"documentationUrl,omitempty"` - SupportUrl string `json:"supportUrl,omitempty"` - Shareable *bool `json:"shareable,omitempty"` - AdditionalMetadata map[string]interface{} -} - -func (sm ServiceMetadata) MarshalJSON() ([]byte, error) { - type Alias ServiceMetadata - - b, err := json.Marshal(Alias(sm)) - if err != nil { - return []byte{}, errors.Wrap(err, "unmarshallable content in AdditionalMetadata") - } - - var m map[string]interface{} - json.Unmarshal(b, &m) - delete(m, additionalMetadataName) - - for k, v := range sm.AdditionalMetadata { - m[k] = v - } - return json.Marshal(m) -} - -func (sm *ServiceMetadata) UnmarshalJSON(data []byte) error { - type Alias ServiceMetadata - - if err := json.Unmarshal(data, (*Alias)(sm)); err != nil { - return err - } - - additionalMetadata := map[string]interface{}{} - if err := json.Unmarshal(data, &additionalMetadata); err != nil { - return err - } - - for _, jsonName := range GetJsonNames(reflect.ValueOf(sm).Elem()) { - if jsonName == additionalMetadataName { - continue - } - delete(additionalMetadata, jsonName) - } - - if len(additionalMetadata) > 0 { - sm.AdditionalMetadata = additionalMetadata - } - return nil -} diff --git a/v7/domain/service_plan_metadata.go b/v7/domain/service_plan_metadata.go deleted file mode 100644 index fbb329d8..00000000 --- a/v7/domain/service_plan_metadata.go +++ /dev/null @@ -1,83 +0,0 @@ -package domain - -import ( - "encoding/json" - "reflect" - "strings" - - "github.com/pkg/errors" -) - -type ServicePlanMetadata struct { - DisplayName string `json:"displayName,omitempty"` - Bullets []string `json:"bullets,omitempty"` - Costs []ServicePlanCost `json:"costs,omitempty"` - AdditionalMetadata map[string]interface{} -} - -type ServicePlanCost struct { - Amount map[string]float64 `json:"amount"` - Unit string `json:"unit"` -} - -func (spm *ServicePlanMetadata) UnmarshalJSON(data []byte) error { - type Alias ServicePlanMetadata - - if err := json.Unmarshal(data, (*Alias)(spm)); err != nil { - return err - } - - additionalMetadata := map[string]interface{}{} - if err := json.Unmarshal(data, &additionalMetadata); err != nil { - return err - } - - s := reflect.ValueOf(spm).Elem() - for _, jsonName := range GetJsonNames(s) { - if jsonName == additionalMetadataName { - continue - } - delete(additionalMetadata, jsonName) - } - - if len(additionalMetadata) > 0 { - spm.AdditionalMetadata = additionalMetadata - } - return nil -} - -func (spm ServicePlanMetadata) MarshalJSON() ([]byte, error) { - type Alias ServicePlanMetadata - - b, err := json.Marshal(Alias(spm)) - if err != nil { - return []byte{}, errors.Wrap(err, "unmarshallable content in AdditionalMetadata") - } - - var m map[string]interface{} - json.Unmarshal(b, &m) - delete(m, additionalMetadataName) - - for k, v := range spm.AdditionalMetadata { - m[k] = v - } - - return json.Marshal(m) -} - -func GetJsonNames(s reflect.Value) (res []string) { - valType := s.Type() - for i := 0; i < s.NumField(); i++ { - field := valType.Field(i) - tag := field.Tag - jsonVal := tag.Get("json") - if jsonVal != "" { - components := strings.Split(jsonVal, ",") - jsonName := components[0] - res = append(res, jsonName) - } else { - res = append(res, field.Name) - } - } - return res -} diff --git a/v7/failure_response.go b/v7/failure_response.go deleted file mode 100644 index ab7c85fc..00000000 --- a/v7/failure_response.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2016-Present Pivotal Software, Inc. All rights reserved. -// This program and the accompanying materials are made available under the terms of the under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - -package brokerapi - -import ( - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" -) - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -// FailureResponse can be returned from any of the `ServiceBroker` interface methods -// which allow an error to be returned. Doing so will provide greater control over -// the HTTP response. -type FailureResponse = apiresponses.FailureResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -// NewFailureResponse returns a pointer to a new instance of FailureResponse. -// err will by default be used as both a logging message and HTTP response description. -// statusCode is the HTTP status code to be returned, must be 4xx or 5xx -// loggerAction is a short description which will be used as the action if the error is logged. -func NewFailureResponse(err error, statusCode int, loggerAction string) *FailureResponse { - return (*FailureResponse)(apiresponses.NewFailureResponse(err, statusCode, loggerAction)) -} - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -// FailureResponseBuilder provides a fluent set of methods to build a *FailureResponse. -type FailureResponseBuilder = apiresponses.FailureResponseBuilder - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -// NewFailureResponseBuilder returns a pointer to a newly instantiated FailureResponseBuilder -// Accepts required arguments to create a FailureResponse. -func NewFailureResponseBuilder(err error, statusCode int, loggerAction string) *FailureResponseBuilder { - return (*FailureResponseBuilder)(apiresponses.NewFailureResponseBuilder(err, statusCode, loggerAction)) -} diff --git a/v7/handlers/api_handler.go b/v7/handlers/api_handler.go deleted file mode 100644 index 8a9828b1..00000000 --- a/v7/handlers/api_handler.go +++ /dev/null @@ -1,66 +0,0 @@ -package handlers - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - - "code.cloudfoundry.org/lager" - "github.com/pivotal-cf/brokerapi/v7/domain" -) - -const ( - invalidServiceDetailsErrorKey = "invalid-service-details" - instanceIDLogKey = "instance-id" - serviceIdMissingKey = "service-id-missing" - planIdMissingKey = "plan-id-missing" - unknownErrorKey = "unknown-error" - - bindingIDLogKey = "binding-id" -) - -var ( - serviceIdError = errors.New("service_id missing") - planIdError = errors.New("plan_id missing") - invalidServiceIDError = errors.New("service-id not in the catalog") - invalidPlanIDError = errors.New("plan-id not in the catalog") -) - -type APIHandler struct { - serviceBroker domain.ServiceBroker - logger lager.Logger -} - -func NewApiHandler(broker domain.ServiceBroker, logger lager.Logger) APIHandler { - return APIHandler{broker, logger} -} - -func (h APIHandler) respond(w http.ResponseWriter, status int, requestIdentity string, response interface{}) { - w.Header().Set("Content-Type", "application/json") - if requestIdentity != "" { - w.Header().Set("X-Broker-API-Request-Identity", requestIdentity) - } - w.WriteHeader(status) - - encoder := json.NewEncoder(w) - encoder.SetEscapeHTML(false) - err := encoder.Encode(response) - if err != nil { - h.logger.Error("encoding response", err, lager.Data{"status": status, "response": response}) - } -} - -type brokerVersion struct { - Major int - Minor int -} - -func getAPIVersion(req *http.Request) brokerVersion { - var version brokerVersion - apiVersion := req.Header.Get("X-Broker-API-Version") - - fmt.Sscanf(apiVersion, "%d.%d", &version.Major, &version.Minor) - - return version -} diff --git a/v7/handlers/bind.go b/v7/handlers/bind.go deleted file mode 100644 index eb4fb08c..00000000 --- a/v7/handlers/bind.go +++ /dev/null @@ -1,146 +0,0 @@ -package handlers - -import ( - "encoding/json" - "fmt" - "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 ( - invalidBindDetailsErrorKey = "invalid-bind-details" - bindLogKey = "bind" -) - -func (h APIHandler) Bind(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) - instanceID := vars["instance_id"] - bindingID := vars["binding_id"] - - logger := h.logger.Session(bindLogKey, lager.Data{ - instanceIDLogKey: instanceID, - bindingIDLogKey: bindingID, - }, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey)) - - version := getAPIVersion(req) - asyncAllowed := false - if version.Minor >= 14 { - asyncAllowed = req.FormValue("accepts_incomplete") == "true" - } - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - var details domain.BindDetails - if err := json.NewDecoder(req.Body).Decode(&details); err != nil { - logger.Error(invalidBindDetailsErrorKey, err) - h.respond(w, http.StatusUnprocessableEntity, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - return - } - - if details.ServiceID == "" { - logger.Error(serviceIdMissingKey, serviceIdError) - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: serviceIdError.Error(), - }) - return - } - - if details.PlanID == "" { - logger.Error(planIdMissingKey, planIdError) - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: planIdError.Error(), - }) - return - } - - binding, err := h.serviceBroker.Bind(req.Context(), instanceID, bindingID, details, asyncAllowed) - if err != nil { - switch err := err.(type) { - case *apiresponses.FailureResponse: - statusCode := err.ValidatedStatusCode(logger) - errorResponse := err.ErrorResponse() - if err == apiresponses.ErrInstanceDoesNotExist { - // work around ErrInstanceDoesNotExist having different pre-refactor behaviour to other actions - errorResponse = apiresponses.ErrorResponse{ - Description: err.Error(), - } - statusCode = http.StatusNotFound - } - logger.Error(err.LoggerAction(), err) - h.respond(w, statusCode, requestId, errorResponse) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - if binding.AlreadyExists { - h.respond(w, http.StatusOK, requestId, apiresponses.BindingResponse{ - Credentials: binding.Credentials, - SyslogDrainURL: binding.SyslogDrainURL, - RouteServiceURL: binding.RouteServiceURL, - VolumeMounts: binding.VolumeMounts, - BackupAgentURL: binding.BackupAgentURL, - }) - return - } - - if binding.IsAsync { - h.respond(w, http.StatusAccepted, requestId, apiresponses.AsyncBindResponse{ - OperationData: binding.OperationData, - }) - return - } - - if version.Minor == 8 || version.Minor == 9 { - experimentalVols := []domain.ExperimentalVolumeMount{} - - for _, vol := range binding.VolumeMounts { - experimentalConfig, err := json.Marshal(vol.Device.MountConfig) - if err != nil { - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{Description: err.Error()}) - return - } - - experimentalVols = append(experimentalVols, domain.ExperimentalVolumeMount{ - ContainerPath: vol.ContainerDir, - Mode: vol.Mode, - Private: domain.ExperimentalVolumeMountPrivate{ - Driver: vol.Driver, - GroupID: vol.Device.VolumeId, - Config: string(experimentalConfig), - }, - }) - } - - experimentalBinding := apiresponses.ExperimentalVolumeMountBindingResponse{ - Credentials: binding.Credentials, - RouteServiceURL: binding.RouteServiceURL, - SyslogDrainURL: binding.SyslogDrainURL, - VolumeMounts: experimentalVols, - BackupAgentURL: binding.BackupAgentURL, - } - h.respond(w, http.StatusCreated, requestId, experimentalBinding) - return - } - - h.respond(w, http.StatusCreated, requestId, apiresponses.BindingResponse{ - Credentials: binding.Credentials, - SyslogDrainURL: binding.SyslogDrainURL, - RouteServiceURL: binding.RouteServiceURL, - VolumeMounts: binding.VolumeMounts, - BackupAgentURL: binding.BackupAgentURL, - }) -} diff --git a/v7/handlers/catalog.go b/v7/handlers/catalog.go deleted file mode 100644 index bc436ff8..00000000 --- a/v7/handlers/catalog.go +++ /dev/null @@ -1,26 +0,0 @@ -package handlers - -import ( - "fmt" - "net/http" - - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" -) - -func (h *APIHandler) Catalog(w http.ResponseWriter, req *http.Request) { - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - services, err := h.serviceBroker.Services(req.Context()) - if err != nil { - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - return - } - - catalog := apiresponses.CatalogResponse{ - Services: services, - } - - h.respond(w, http.StatusOK, requestId, catalog) -} diff --git a/v7/handlers/deprovision.go b/v7/handlers/deprovision.go deleted file mode 100644 index a4906e07..00000000 --- a/v7/handlers/deprovision.go +++ /dev/null @@ -1,71 +0,0 @@ -package handlers - -import ( - "fmt" - "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", - } - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - if details.ServiceID == "" { - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: serviceIdError.Error(), - }) - logger.Error(serviceIdMissingKey, serviceIdError) - return - } - - if details.PlanID == "" { - h.respond(w, http.StatusBadRequest, requestId, 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), requestId, err.ErrorResponse()) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - if deprovisionSpec.IsAsync { - h.respond(w, http.StatusAccepted, requestId, apiresponses.DeprovisionResponse{OperationData: deprovisionSpec.OperationData}) - } else { - h.respond(w, http.StatusOK, requestId, apiresponses.EmptyResponse{}) - } -} diff --git a/v7/handlers/get_binding.go b/v7/handlers/get_binding.go deleted file mode 100644 index 90048c6a..00000000 --- a/v7/handlers/get_binding.go +++ /dev/null @@ -1,69 +0,0 @@ -package handlers - -import ( - "errors" - "fmt" - "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 getBindLogKey = "getBinding" - -func (h APIHandler) GetBinding(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) - instanceID := vars["instance_id"] - bindingID := vars["binding_id"] - - logger := h.logger.Session(getBindLogKey, lager.Data{ - instanceIDLogKey: instanceID, - bindingIDLogKey: bindingID, - }, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey)) - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - 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, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - logger.Error(middlewares.ApiVersionInvalidKey, err) - return - } - - details := domain.FetchBindingDetails{ - ServiceID: req.URL.Query().Get("service_id"), - PlanID: req.URL.Query().Get("plan_id"), - } - - binding, err := h.serviceBroker.GetBinding(req.Context(), instanceID, bindingID, details) - if err != nil { - switch err := err.(type) { - case *apiresponses.FailureResponse: - logger.Error(err.LoggerAction(), err) - h.respond(w, err.ValidatedStatusCode(logger), requestId, err.ErrorResponse()) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - h.respond(w, http.StatusOK, requestId, apiresponses.GetBindingResponse{ - BindingResponse: apiresponses.BindingResponse{ - Credentials: binding.Credentials, - SyslogDrainURL: binding.SyslogDrainURL, - RouteServiceURL: binding.RouteServiceURL, - VolumeMounts: binding.VolumeMounts, - }, - Parameters: binding.Parameters, - }) -} diff --git a/v7/handlers/get_instance.go b/v7/handlers/get_instance.go deleted file mode 100644 index 67185047..00000000 --- a/v7/handlers/get_instance.go +++ /dev/null @@ -1,64 +0,0 @@ -package handlers - -import ( - "errors" - "fmt" - "github.com/pivotal-cf/brokerapi/v7/domain" - "net/http" - - "code.cloudfoundry.org/lager" - "github.com/gorilla/mux" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" - "github.com/pivotal-cf/brokerapi/v7/middlewares" - "github.com/pivotal-cf/brokerapi/v7/utils" -) - -const getInstanceLogKey = "getInstance" - -func (h APIHandler) GetInstance(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) - instanceID := vars["instance_id"] - - logger := h.logger.Session(getInstanceLogKey, lager.Data{ - instanceIDLogKey: instanceID, - }, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey)) - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - version := getAPIVersion(req) - if version.Minor < 14 { - err := errors.New("get instance endpoint only supported starting with OSB version 2.14") - h.respond(w, http.StatusPreconditionFailed, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - logger.Error(middlewares.ApiVersionInvalidKey, err) - return - } - - details := domain.FetchInstanceDetails{ - ServiceID: req.URL.Query().Get("service_id"), - PlanID: req.URL.Query().Get("plan_id"), - } - - instanceDetails, err := h.serviceBroker.GetInstance(req.Context(), instanceID, details) - if err != nil { - switch err := err.(type) { - case *apiresponses.FailureResponse: - logger.Error(err.LoggerAction(), err) - h.respond(w, err.ValidatedStatusCode(logger), requestId, err.ErrorResponse()) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - h.respond(w, http.StatusOK, requestId, apiresponses.GetInstanceResponse{ - ServiceID: instanceDetails.ServiceID, - PlanID: instanceDetails.PlanID, - DashboardURL: instanceDetails.DashboardURL, - Parameters: instanceDetails.Parameters, - }) -} diff --git a/v7/handlers/last_binding_operation.go b/v7/handlers/last_binding_operation.go deleted file mode 100644 index 27ed7d99..00000000 --- a/v7/handlers/last_binding_operation.go +++ /dev/null @@ -1,68 +0,0 @@ -package handlers - -import ( - "errors" - "fmt" - "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 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)) - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - 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, requestId, 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), requestId, err.ErrorResponse()) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, 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, requestId, lastOperationResponse) -} diff --git a/v7/handlers/last_operation.go b/v7/handlers/last_operation.go deleted file mode 100644 index 6a8b1af7..00000000 --- a/v7/handlers/last_operation.go +++ /dev/null @@ -1,57 +0,0 @@ -package handlers - -import ( - "fmt" - "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 lastOperationLogKey = "lastOperation" - -func (h APIHandler) LastOperation(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) - instanceID := vars["instance_id"] - pollDetails := domain.PollDetails{ - PlanID: req.FormValue("plan_id"), - ServiceID: req.FormValue("service_id"), - OperationData: req.FormValue("operation"), - } - - logger := h.logger.Session(lastOperationLogKey, lager.Data{ - instanceIDLogKey: instanceID, - }, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey)) - - logger.Info("starting-check-for-operation") - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - lastOperation, err := h.serviceBroker.LastOperation(req.Context(), instanceID, pollDetails) - if err != nil { - switch err := err.(type) { - case *apiresponses.FailureResponse: - logger.Error(err.LoggerAction(), err) - h.respond(w, err.ValidatedStatusCode(logger), requestId, err.ErrorResponse()) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - logger.WithData(lager.Data{"state": lastOperation.State}).Info("done-check-for-operation") - - lastOperationResponse := apiresponses.LastOperationResponse{ - State: lastOperation.State, - Description: lastOperation.Description, - } - - h.respond(w, http.StatusOK, requestId, lastOperationResponse) -} diff --git a/v7/handlers/provision.go b/v7/handlers/provision.go deleted file mode 100644 index e4916eea..00000000 --- a/v7/handlers/provision.go +++ /dev/null @@ -1,139 +0,0 @@ -package handlers - -import ( - "encoding/json" - "fmt" - "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 ( - provisionLogKey = "provision" - - instanceDetailsLogKey = "instance-details" - - invalidServiceID = "invalid-service-id" - invalidPlanID = "invalid-plan-id" -) - -func (h *APIHandler) Provision(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) - instanceID := vars["instance_id"] - - logger := h.logger.Session(provisionLogKey, lager.Data{ - instanceIDLogKey: instanceID, - }, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey)) - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - var details domain.ProvisionDetails - if err := json.NewDecoder(req.Body).Decode(&details); err != nil { - logger.Error(invalidServiceDetailsErrorKey, err) - h.respond(w, http.StatusUnprocessableEntity, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - return - } - - if details.ServiceID == "" { - logger.Error(serviceIdMissingKey, serviceIdError) - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: serviceIdError.Error(), - }) - return - } - - if details.PlanID == "" { - logger.Error(planIdMissingKey, planIdError) - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: planIdError.Error(), - }) - return - } - - valid := false - services, _ := h.serviceBroker.Services(req.Context()) - for _, service := range services { - if service.ID == details.ServiceID { - req = req.WithContext(utils.AddServiceToContext(req.Context(), &service)) - valid = true - break - } - } - if !valid { - logger.Error(invalidServiceID, invalidServiceIDError) - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: invalidServiceIDError.Error(), - }) - return - } - - valid = false - for _, service := range services { - for _, plan := range service.Plans { - if plan.ID == details.PlanID { - req = req.WithContext(utils.AddServicePlanToContext(req.Context(), &plan)) - valid = true - break - } - } - } - if !valid { - logger.Error(invalidPlanID, invalidPlanIDError) - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: invalidPlanIDError.Error(), - }) - return - } - - asyncAllowed := req.FormValue("accepts_incomplete") == "true" - - logger = logger.WithData(lager.Data{ - instanceDetailsLogKey: details, - }) - - provisionResponse, err := h.serviceBroker.Provision(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), requestId, err.ErrorResponse()) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - var metadata interface{} - if !provisionResponse.Metadata.IsEmpty() { - metadata = provisionResponse.Metadata - } - - if provisionResponse.AlreadyExists { - h.respond(w, http.StatusOK, requestId, apiresponses.ProvisioningResponse{ - DashboardURL: provisionResponse.DashboardURL, - Metadata: metadata, - }) - } else if provisionResponse.IsAsync { - h.respond(w, http.StatusAccepted, requestId, apiresponses.ProvisioningResponse{ - DashboardURL: provisionResponse.DashboardURL, - OperationData: provisionResponse.OperationData, - Metadata: metadata, - }) - } else { - h.respond(w, http.StatusCreated, requestId, apiresponses.ProvisioningResponse{ - DashboardURL: provisionResponse.DashboardURL, - Metadata: metadata, - }) - } -} diff --git a/v7/handlers/unbind.go b/v7/handlers/unbind.go deleted file mode 100644 index 74d9da09..00000000 --- a/v7/handlers/unbind.go +++ /dev/null @@ -1,74 +0,0 @@ -package handlers - -import ( - "fmt" - "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 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)) - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - details := domain.UnbindDetails{ - PlanID: req.FormValue("plan_id"), - ServiceID: req.FormValue("service_id"), - } - - if details.ServiceID == "" { - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: serviceIdError.Error(), - }) - logger.Error(serviceIdMissingKey, serviceIdError) - return - } - - if details.PlanID == "" { - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: planIdError.Error(), - }) - logger.Error(planIdMissingKey, planIdError) - return - } - - asyncAllowed := req.FormValue("accepts_incomplete") == "true" - 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), requestId, err.ErrorResponse()) - default: - logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - if unbindResponse.IsAsync { - h.respond(w, http.StatusAccepted, requestId, apiresponses.UnbindResponse{ - OperationData: unbindResponse.OperationData, - }) - } else { - h.respond(w, http.StatusOK, requestId, apiresponses.EmptyResponse{}) - } - -} diff --git a/v7/handlers/update.go b/v7/handlers/update.go deleted file mode 100644 index c64236bf..00000000 --- a/v7/handlers/update.go +++ /dev/null @@ -1,71 +0,0 @@ -package handlers - -import ( - "encoding/json" - "fmt" - "net/http" - "strconv" - - "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 updateLogKey = "update" - -func (h APIHandler) Update(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) - instanceID := vars["instance_id"] - - logger := h.logger.Session(updateLogKey, lager.Data{ - instanceIDLogKey: instanceID, - }, utils.DataForContext(req.Context(), middlewares.CorrelationIDKey)) - - requestId := fmt.Sprintf("%v", req.Context().Value("requestIdentity")) - - var details domain.UpdateDetails - if err := json.NewDecoder(req.Body).Decode(&details); err != nil { - h.logger.Error(invalidServiceDetailsErrorKey, err) - h.respond(w, http.StatusUnprocessableEntity, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - return - } - - if details.ServiceID == "" { - logger.Error(serviceIdMissingKey, serviceIdError) - h.respond(w, http.StatusBadRequest, requestId, apiresponses.ErrorResponse{ - Description: serviceIdError.Error(), - }) - return - } - - acceptsIncompleteFlag, _ := strconv.ParseBool(req.URL.Query().Get("accepts_incomplete")) - - updateServiceSpec, err := h.serviceBroker.Update(req.Context(), instanceID, details, acceptsIncompleteFlag) - if err != nil { - switch err := err.(type) { - case *apiresponses.FailureResponse: - h.logger.Error(err.LoggerAction(), err) - h.respond(w, err.ValidatedStatusCode(h.logger), requestId, err.ErrorResponse()) - default: - h.logger.Error(unknownErrorKey, err) - h.respond(w, http.StatusInternalServerError, requestId, apiresponses.ErrorResponse{ - Description: err.Error(), - }) - } - return - } - - statusCode := http.StatusOK - if updateServiceSpec.IsAsync { - statusCode = http.StatusAccepted - } - h.respond(w, statusCode, requestId, apiresponses.UpdateResponse{ - OperationData: updateServiceSpec.OperationData, - DashboardURL: updateServiceSpec.DashboardURL, - }) -} diff --git a/v7/maintenance_info.go b/v7/maintenance_info.go deleted file mode 100644 index 3abe4d4d..00000000 --- a/v7/maintenance_info.go +++ /dev/null @@ -1,8 +0,0 @@ -package brokerapi - -import ( - "github.com/pivotal-cf/brokerapi/v7/domain" -) - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type MaintenanceInfo = domain.MaintenanceInfo diff --git a/v7/middlewares/api_version_header.go b/v7/middlewares/api_version_header.go deleted file mode 100644 index 5e4369cb..00000000 --- a/v7/middlewares/api_version_header.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package middlewares - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - - "code.cloudfoundry.org/lager" -) - -const ApiVersionInvalidKey = "broker-api-version-invalid" - -type APIVersionMiddleware struct { - LoggerFactory lager.Logger -} - -type ErrorResponse struct { - Description string -} - -func (m APIVersionMiddleware) ValidateAPIVersionHdr(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - logger := m.LoggerFactory.Session("version-header-check", lager.Data{}) - - err := checkBrokerAPIVersionHdr(req) - if err != nil { - logger.Error(ApiVersionInvalidKey, err) - - w.Header().Set("Content-type", "application/json") - setBrokerRequestIdentityHeader(req, w) - - statusResponse := http.StatusPreconditionFailed - w.WriteHeader(statusResponse) - errorResp := ErrorResponse{ - Description: err.Error(), - } - err = json.NewEncoder(w).Encode(errorResp) - if err != nil { - logger.Error("encoding response", err, lager.Data{"status": statusResponse, "response": errorResp}) - } - - return - } - - next.ServeHTTP(w, req) - }) -} - -func setBrokerRequestIdentityHeader(req *http.Request, w http.ResponseWriter) { - requestID := req.Header.Get("X-Broker-API-Request-Identity") - if requestID != "" { - w.Header().Set("X-Broker-API-Request-Identity", requestID) - } -} - -func checkBrokerAPIVersionHdr(req *http.Request) error { - var version struct { - Major int - Minor int - } - apiVersion := req.Header.Get("X-Broker-API-Version") - if apiVersion == "" { - return errors.New("X-Broker-API-Version Header not set") - } - if n, err := fmt.Sscanf(apiVersion, "%d.%d", &version.Major, &version.Minor); err != nil || n < 2 { - return errors.New("X-Broker-API-Version Header must contain a version") - } - - if version.Major != 2 { - return errors.New("X-Broker-API-Version Header must be 2.x") - } - return nil -} diff --git a/v7/middlewares/correlation_id_header.go b/v7/middlewares/correlation_id_header.go deleted file mode 100644 index c90ec1ce..00000000 --- a/v7/middlewares/correlation_id_header.go +++ /dev/null @@ -1,35 +0,0 @@ -package middlewares - -import ( - "context" - "net/http" - - "github.com/pborman/uuid" -) - -const CorrelationIDKey = "correlation-id" - -var correlationIDHeaders = []string{"X-Correlation-ID", "X-CorrelationID", "X-ForRequest-ID", "X-Request-ID", "X-Vcap-Request-Id"} - -func AddCorrelationIDToContext(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - var correlationID string - var found bool - - for _, header := range correlationIDHeaders { - headerValue := req.Header.Get(header) - if headerValue != "" { - correlationID = headerValue - found = true - break - } - } - - if !found { - correlationID = uuid.New() - } - - newCtx := context.WithValue(req.Context(), CorrelationIDKey, correlationID) - next.ServeHTTP(w, req.WithContext(newCtx)) - }) -} diff --git a/v7/middlewares/info_location_header.go b/v7/middlewares/info_location_header.go deleted file mode 100644 index f23acc90..00000000 --- a/v7/middlewares/info_location_header.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package middlewares - -import ( - "context" - "net/http" -) - -const ( - infoLocationKey = "infoLocation" -) - -func AddInfoLocationToContext(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - infoLocation := req.Header.Get("X-Api-Info-Location") - newCtx := context.WithValue(req.Context(), infoLocationKey, infoLocation) - next.ServeHTTP(w, req.WithContext(newCtx)) - }) -} diff --git a/v7/middlewares/originating_identity_header.go b/v7/middlewares/originating_identity_header.go deleted file mode 100644 index a95fb891..00000000 --- a/v7/middlewares/originating_identity_header.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package middlewares - -import ( - "context" - "net/http" -) - -const ( - originatingIdentityKey = "originatingIdentity" -) - -func AddOriginatingIdentityToContext(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - originatingIdentity := req.Header.Get("X-Broker-API-Originating-Identity") - newCtx := context.WithValue(req.Context(), originatingIdentityKey, originatingIdentity) - next.ServeHTTP(w, req.WithContext(newCtx)) - }) -} diff --git a/v7/middlewares/request_identity_header.go b/v7/middlewares/request_identity_header.go deleted file mode 100644 index 0305a4c7..00000000 --- a/v7/middlewares/request_identity_header.go +++ /dev/null @@ -1,16 +0,0 @@ -package middlewares - -import ( - "context" - "net/http" -) - -const RequestIdentityKey = "requestIdentity" - -func AddRequestIdentityToContext(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - requestIdentity := req.Header.Get("X-Broker-API-Request-Identity") - newCtx := context.WithValue(req.Context(), RequestIdentityKey, requestIdentity) - next.ServeHTTP(w, req.WithContext(newCtx)) - }) -} diff --git a/v7/response.go b/v7/response.go deleted file mode 100644 index 4313dae8..00000000 --- a/v7/response.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package brokerapi - -import ( - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" -) - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type EmptyResponse = apiresponses.EmptyResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type ErrorResponse = apiresponses.ErrorResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type CatalogResponse = apiresponses.CatalogResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type ProvisioningResponse = apiresponses.ProvisioningResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type GetInstanceResponse = apiresponses.GetInstanceResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type UpdateResponse = apiresponses.UpdateResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type DeprovisionResponse = apiresponses.DeprovisionResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type LastOperationResponse = apiresponses.LastOperationResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type AsyncBindResponse = apiresponses.AsyncBindResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type BindingResponse = apiresponses.BindingResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type GetBindingResponse = apiresponses.GetBindingResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type UnbindResponse = apiresponses.UnbindResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -type ExperimentalVolumeMountBindingResponse = apiresponses.ExperimentalVolumeMountBindingResponse - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ExperimentalVolumeMount = domain.ExperimentalVolumeMount - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ExperimentalVolumeMountPrivate = domain.ExperimentalVolumeMountPrivate diff --git a/v7/service_broker.go b/v7/service_broker.go deleted file mode 100644 index 34de1e50..00000000 --- a/v7/service_broker.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (C) 2015-Present Pivotal Software, Inc. All rights reserved. - -// This program and the accompanying materials are made available under -// the terms of the under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package brokerapi - -import ( - "github.com/pivotal-cf/brokerapi/v7/domain" - "github.com/pivotal-cf/brokerapi/v7/domain/apiresponses" -) - -//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o fakes/auto_fake_service_broker.go -fake-name AutoFakeServiceBroker . ServiceBroker - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -//Each method of the ServiceBroker interface maps to an individual endpoint of the Open Service Broker API. -// -//The specification is available here: https://github.com/openservicebrokerapi/servicebroker/blob/v2.14/spec.md -// -//The OpenAPI documentation is available here: http://petstore.swagger.io/?url=https://raw.githubusercontent.com/openservicebrokerapi/servicebroker/v2.14/openapi.yaml -type ServiceBroker interface { - domain.ServiceBroker -} - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type DetailsWithRawParameters interface { - domain.DetailsWithRawParameters -} - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type DetailsWithRawContext interface { - domain.DetailsWithRawContext -} - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ProvisionDetails = domain.ProvisionDetails - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type ProvisionedServiceSpec = domain.ProvisionedServiceSpec - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type GetInstanceDetailsSpec = domain.GetInstanceDetailsSpec - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type UnbindSpec = domain.UnbindSpec - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type BindDetails = domain.BindDetails - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type BindResource = domain.BindResource - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type UnbindDetails = domain.UnbindDetails - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type UpdateServiceSpec = domain.UpdateServiceSpec - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type DeprovisionServiceSpec = domain.DeprovisionServiceSpec - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type DeprovisionDetails = domain.DeprovisionDetails - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type UpdateDetails = domain.UpdateDetails - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type PreviousValues = domain.PreviousValues - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type PollDetails = domain.PollDetails - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type LastOperation = domain.LastOperation - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type LastOperationState = domain.LastOperationState - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -const ( - InProgress LastOperationState = "in progress" - Succeeded LastOperationState = "succeeded" - Failed LastOperationState = "failed" -) - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type Binding = domain.Binding - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type GetBindingSpec = domain.GetBindingSpec - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type VolumeMount = domain.VolumeMount - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain -type SharedDevice = domain.SharedDevice - -//Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses -var ( - ErrInstanceAlreadyExists = apiresponses.ErrInstanceAlreadyExists - - ErrInstanceDoesNotExist = apiresponses.ErrInstanceDoesNotExist - - ErrInstanceLimitMet = apiresponses.ErrInstanceLimitMet - - ErrBindingAlreadyExists = apiresponses.ErrBindingAlreadyExists - - ErrBindingDoesNotExist = apiresponses.ErrBindingDoesNotExist - - ErrBindingNotFound = apiresponses.ErrBindingNotFound - - ErrAsyncRequired = apiresponses.ErrAsyncRequired - - ErrPlanChangeNotSupported = apiresponses.ErrPlanChangeNotSupported - - ErrRawParamsInvalid = apiresponses.ErrRawParamsInvalid - - ErrAppGuidNotProvided = apiresponses.ErrAppGuidNotProvided - - ErrPlanQuotaExceeded = apiresponses.ErrPlanQuotaExceeded - - ErrServiceQuotaExceeded = apiresponses.ErrServiceQuotaExceeded - - ErrConcurrentInstanceAccess = apiresponses.ErrConcurrentInstanceAccess - - ErrMaintenanceInfoConflict = apiresponses.ErrMaintenanceInfoConflict - - ErrMaintenanceInfoNilConflict = apiresponses.ErrMaintenanceInfoNilConflict -) diff --git a/v7/utils/context.go b/v7/utils/context.go deleted file mode 100644 index 34e4ce88..00000000 --- a/v7/utils/context.go +++ /dev/null @@ -1,54 +0,0 @@ -package utils - -import ( - "context" - - "code.cloudfoundry.org/lager" - "github.com/pivotal-cf/brokerapi/v7/domain" -) - -type contextKey string - -const ( - contextKeyService contextKey = "brokerapi_service" - contextKeyPlan contextKey = "brokerapi_plan" -) - -func AddServiceToContext(ctx context.Context, service *domain.Service) context.Context { - if service != nil { - return context.WithValue(ctx, contextKeyService, service) - } - return ctx -} - -func RetrieveServiceFromContext(ctx context.Context) *domain.Service { - if value := ctx.Value(contextKeyService); value != nil { - return value.(*domain.Service) - } - return nil -} - -func AddServicePlanToContext(ctx context.Context, plan *domain.ServicePlan) context.Context { - if plan != nil { - return context.WithValue(ctx, contextKeyPlan, plan) - } - return ctx -} - -func RetrieveServicePlanFromContext(ctx context.Context) *domain.ServicePlan { - if value := ctx.Value(contextKeyPlan); value != nil { - return value.(*domain.ServicePlan) - } - return nil -} - -func DataForContext(context context.Context, dataKeys ...string) lager.Data { - data := lager.Data{} - for _, key := range dataKeys { - if value := context.Value(key); value != nil { - data[key] = value - } - } - - return data -}