MCPcopy Index your code
hub / github.com/cloudfoundry/brokerapi

github.com/cloudfoundry/brokerapi @v13.0.25

Chat with this repo
repository ↗ · DeepWiki ↗ · release v13.0.25 ↗ · + Follow
306 symbols 799 edges 67 files 44 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

brokerapi

test

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

Docs

Dependencies

  • Go
  • GNU Make 3.81

Contributing

We appreciate and welcome open source contribution. We will try to review the changes as soon as we can.

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.

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 originatingIdentity. More details on how the Open Service Broker API manages request originating identity is available here.

Request Identity

The request context for every request contains the unparsed X-Broker-API-Request-Identity header under the key requestIdentity. 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.

Releasing

Releasing steps can be found here

Extension points exported contracts — how you extend this code

DetailsWithRawParameters (Interface)
Deprecated: Use code.cloudfoundry.org/brokerapi/v13/domain [3 implementers]
service_broker.go
ServiceBroker (Interface)
go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate counterfeiter:generate -o ../fakes/auto_fake_servi [2 …
domain/service_broker.go
Option (FuncType)
(no doc)
api.go
DetailsWithRawContext (Interface)
Deprecated: Use code.cloudfoundry.org/brokerapi/v13/domain [3 implementers]
service_broker.go
DetailsWithRawParameters (Interface)
(no doc) [3 implementers]
domain/service_broker.go
ServiceBroker (Interface)
go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate counterfeiter:generate -o fakes/auto_fake_service_ [2 …
service_broker.go
DetailsWithRawContext (Interface)
(no doc) [3 implementers]
domain/service_broker.go

Core symbols most depended-on inside this repo

Error
called by 89
internal/blog/blog.go
respond
called by 55
handlers/api_handler.go
ErrorResponse
called by 22
domain/apiresponses/failure_responses.go
ValidatedStatusCode
called by 22
domain/apiresponses/failure_responses.go
LoggerAction
called by 22
domain/apiresponses/failure_responses.go
Build
called by 22
domain/apiresponses/failure_responses.go
NewFailureResponseBuilder
called by 17
domain/apiresponses/failure_responses.go
WithErrorKey
called by 13
domain/apiresponses/failure_responses.go

Shape

Method 150
Function 70
Struct 69
TypeAlias 9
Interface 6
FuncType 2

Languages

Go100%

Modules by API surface

fakes/auto_fake_service_broker.go63 symbols
domain/service_broker.go47 symbols
fakes/fake_service_broker.go21 symbols
handlers/fakes/fake_response_writer.go18 symbols
internal/blog/blog.go14 symbols
domain/apiresponses/responses.go13 symbols
api.go12 symbols
domain/service_catalog.go11 symbols
domain/apiresponses/failure_responses.go11 symbols
auth/auth.go8 symbols
api_test.go7 symbols
domain/service_plan_metadata.go6 symbols

For agents

$ claude mcp add brokerapi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact