Skip to content
A Go package for implementing the V2 Open Service Broker API
Go
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
auth use constant time when authenticating users Oct 16, 2018
domain Expand tests to verify maintenance info fields individually Aug 22, 2019
fakes added unit test for LastBindingOperation May 16, 2019
fixtures catalog has new field maintenance_info Nov 16, 2018
handlers added unit test for LastBindingOperation May 16, 2019
middlewares Capture the X-Api-Info-Location header in all broker requests Jun 14, 2019
utils Moved Catalog, Deprovision, Provision and Update handlers Apr 29, 2019
.gitignore update gitignore Apr 10, 2018
.travis.yml unsupported versions of golang are no longer supported Sep 20, 2018
Gopkg.lock Merge pull request #74 from pivotal-cf/dependabot/dep/github.com/gori… Aug 22, 2019
Gopkg.toml Use releases of Gomega and Ginkgo rather than master Aug 21, 2019
LICENSE Add Apache 2.0 license Jan 27, 2015
NOTICE Update NOTICE May 10, 2018
README.md adding documentation for request context Mar 5, 2019
api.go Capture the X-Api-Info-Location header in all broker requests Jun 14, 2019
api_suite_test.go Add copyright notice to files where it was missing May 10, 2018
api_test.go
catalog.go Extracted domain structures into its own package Apr 26, 2019
catalog_test.go Added maintenance_info.version [#165346357] Apr 16, 2019
context_utils.go Moved Catalog, Deprovision, Provision and Update handlers Apr 29, 2019
context_utils_test.go adding context utilities and tests Mar 5, 2019
failure_response.go Extracted domain structures into its own package Apr 26, 2019
failure_response_test.go Prepare for merge with upstream Sep 27, 2018
maintenance_info.go Extracted domain structures into its own package Apr 26, 2019
maintenance_info_test.go Made maintenance_info a pointer in Update and Provision Request struc… Jul 4, 2019
response.go Extracted domain structures into its own package Apr 26, 2019
response_test.go Merge branch 'master' into osb214-for-merge Oct 25, 2018
service_broker.go Extracted domain structures into its own package Apr 26, 2019

README.md

brokerapi

Build Status

A Go package for building V2 Open Service Broker API compliant Service Brokers.

Docs

Dependencies

We use dep to manager our dependencies. Use dep ensure in order to download the required packages.

Usage

brokerapi defines a ServiceBroker interface. Pass an implementation of this to brokerapi.New, which returns an http.Handler that you can use to serve handle HTTP requests.

Alternatively, if you already have a *mux.Router that you want to attach service broker routes to, you can use brokerapi.AttachRoutes. Note in this case, the Basic Authentication and Originating Identity middleware will not be set up, so you will have to attach them manually if required.

Error types

brokerapi defines a handful of error types in service_broker.go for some common error cases that your service broker may encounter. Return these from your ServiceBroker methods where appropriate, and brokerapi will do the "right thing" (™), and give Cloud Foundry an appropriate status code, as per the Service Broker API specification.

Custom Errors

NewFailureResponse() allows you to return a custom error from any of the ServiceBroker interface methods which return an error. Within this you must define an error, a HTTP response status code and a logging key. You can also use the NewFailureResponseBuilder() to add a custom Error: value in the response, or indicate that the broker should return an empty response rather than the error message.

Request Context

When provisioning a service brokerapi validates the service_id and plan_id in the request, attaching the found instances to the request Context. These values can be retrieved in a brokerapi.ServiceBroker implementation using utility methods RetrieveServiceFromContext and RetrieveServicePlanFromContext as shown below.

func (sb *ServiceBrokerImplementation) Provision(ctx context.Context,
  instanceID string, details brokerapi.ProvisionDetails, asyncAllowed bool) {

  service := brokerapi.RetrieveServiceFromContext(ctx)
  if service == nil {
    // Lookup service
  }

  // [..]
}

Originating Identity

The request context for every request contains the unparsed X-Broker-API-Originating-Identity header under the key originatingIdentityKey. More details on how the Open Service Broker API manages request originating identity is available here.

Example Service Broker

You can see the cf-redis service broker uses the BrokerAPI package to create a service broker for Redis.

You can’t perform that action at this time.