v0.0.0-...-fe161b3 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2020 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0



Build Status

A go package for building V2 CF Service Brokers in Go. Depends on lager and gorilla/mux.

Requires go 1.4 or greater.


brokerapi defines a ServiceBroker interface with 7 methods. Simply create a concrete type that implements these methods, and pass an instance of it to brokerapi.New, along with a lager.Logger for logging and a brokerapi.BrokerCredentials containing some HTTP basic auth credentials.


package main

import (

type myServiceBroker struct {}

func (*myServiceBroker) Services() brokerapi.CatalogResponse {
    // Return the services's catalog offered by the broker

func (*myServiceBroker) Provision(instanceID string, details brokeapi.ProvisionDetails, acceptsIncomplete bool) (brokerapi.ProvisioningResponse, bool, error) {
    // Provision a new instance here

func (*myServiceBroker) Update(instanceID string, details brokerapi.UpdateDetails, acceptsIncomplete bool) (bool, error) {
    // Update instance here

func (*myServiceBroker) Deprovision(instanceID string, details brokeapi.DeprovisionDetails, acceptsIncomplete bool) (bool, error) {
    // Deprovision instance here

func (*myServiceBroker) Bind(instanceID string, bindingID string, details brokerapi.BindDetails) (brokerapi.BindingResponse, error) {
    // Bind to instance here

func (*myServiceBroker) Unbind(instanceID string, bindingID string, details brokerapi.UnbindDetails) error {
    // Unbind from instance here

func (*myServiceBroker) LastOperation(instanceID string) (brokeapi.LastOperationResponse, error) {
    // Return the status of the last instance operation

func main() {
    serviceBroker := &myServiceBroker{}
    logger := lager.NewLogger("my-service-broker")
    credentials := brokerapi.BrokerCredentials{
        Username: "username",
        Password: "password",

    brokerAPI := brokerapi.New(serviceBroker, logger, credentials)
    http.Handle("/", brokerAPI)
    http.ListenAndServe(":3000", nil)

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 V2 Service Broker API specification.

The error types are:





View Source
const LastOperationFailed = "failed"
View Source
const LastOperationInProgress = "in progress"
View Source
const LastOperationSucceeded = "succeeded"


View Source
var (
	ErrInstanceAlreadyExists = errors.New("instance already exists")
	ErrInstanceDoesNotExist  = errors.New("instance does not exist")
	ErrInstanceLimitMet      = errors.New("instance limit for this service has been reached")
	ErrInstanceNotUpdateable = errors.New("instance is not updateable")
	ErrInstanceNotBindable   = errors.New("instance is not bindable")
	ErrBindingAlreadyExists  = errors.New("binding already exists")
	ErrBindingDoesNotExist   = errors.New("binding does not exist")
	ErrAsyncRequired         = errors.New("This service plan requires client support for asynchronous service operations.")
	ErrAppGUIDRequired       = errors.New("This service supports generation of credentials through binding an application only.")


func New

func New(serviceBroker ServiceBroker, logger lager.Logger, brokerCredentials BrokerCredentials) http.Handler


type BindDetails

type BindDetails struct {
	ServiceID  string                 `json:"service_id"`
	PlanID     string                 `json:"plan_id"`
	AppGUID    string                 `json:"app_guid,omitempty"`
	Parameters map[string]interface{} `json:"parameters,omitempty"`

type BindingResponse

type BindingResponse struct {
	Credentials    interface{} `json:"credentials"`
	SyslogDrainURL string      `json:"syslog_drain_url,omitempty"`

type BrokerCredentials

type BrokerCredentials struct {
	Username string
	Password string

type Catalog

type Catalog struct {
	Services []Service `json:"services"`

func (Catalog) FindService

func (c Catalog) FindService(serviceID string) (service Service, found bool)

func (Catalog) FindServicePlan

func (c Catalog) FindServicePlan(planID string) (plan ServicePlan, found bool)

func (Catalog) Validate

func (c Catalog) Validate() error

type CatalogResponse

type CatalogResponse struct {
	Services []Service `json:"services"`

type Cost

type Cost struct {
	Amount map[string]interface{} `json:"amount,omitempty"`
	Unit   string                 `json:"unit,omitempty"`

type CredentialsHash

type CredentialsHash struct {
	Host     string `json:"host,omitempty"`
	Port     int64  `json:"port,omitempty"`
	Name     string `json:"name,omitempty"`
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	URI      string `json:"uri,omitempty"`
	JDBCURI  string `json:"jdbcUrl,omitempty"`

type DashboardClient

type DashboardClient struct {
	ID          string `json:"id,omitempty"`
	Secret      string `json:"secret,omitempty"`
	RedirectURI string `json:"redirect_uri,omitempty"`

type DeprovisionDetails

type DeprovisionDetails struct {
	ServiceID string `json:"service_id"`
	PlanID    string `json:"plan_id"`

type EmptyResponse

type EmptyResponse struct{}

type ErrorResponse

type ErrorResponse struct {
	Error       string `json:"error,omitempty"`
	Description string `json:"description"`

type LastOperationResponse

type LastOperationResponse struct {
	State       string `json:"state"`
	Description string `json:"description,omitempty"`

type PreviousValues

type PreviousValues struct {
	PlanID         string `json:"plan_id"`
	ServiceID      string `json:"service_id"`
	OrganizationID string `json:"organization_id"`
	SpaceID        string `json:"space_id"`

type ProvisionDetails

type ProvisionDetails struct {
	OrganizationGUID string                 `json:"organization_guid"`
	PlanID           string                 `json:"plan_id"`
	ServiceID        string                 `json:"service_id"`
	SpaceGUID        string                 `json:"space_guid"`
	Parameters       map[string]interface{} `json:"parameters,omitempty"`

type ProvisioningResponse

type ProvisioningResponse struct {
	DashboardURL string `json:"dashboard_url,omitempty"`

type Service

type Service struct {
	ID              string           `json:"id"`
	Name            string           `json:"name"`
	Description     string           `json:"description"`
	Bindable        bool             `json:"bindable,omitempty"`
	Tags            []string         `json:"tags,omitempty"`
	Metadata        *ServiceMetadata `json:"metadata,omitempty"`
	Requires        []string         `json:"requires,omitempty"`
	PlanUpdateable  bool             `json:"plan_updateable"`
	Plans           []ServicePlan    `json:"plans"`
	DashboardClient *DashboardClient `json:"dashboard_client,omitempty"`

func (Service) Validate

func (s Service) Validate() error

type ServiceBroker

type ServiceBroker interface {
	Services() CatalogResponse

	Provision(instanceID string, details ProvisionDetails, acceptsIncomplete bool) (ProvisioningResponse, bool, error)
	Update(instanceID string, details UpdateDetails, acceptsIncomplete bool) (bool, error)
	Deprovision(instanceID string, details DeprovisionDetails, acceptsIncomplete bool) (bool, error)

	Bind(instanceID string, bindingID string, details BindDetails) (BindingResponse, error)
	Unbind(instanceID string, bindingID string, details UnbindDetails) error

	LastOperation(instanceID string) (LastOperationResponse, error)

type ServiceMetadata

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"`

type ServicePlan

type ServicePlan struct {
	ID          string               `json:"id"`
	Name        string               `json:"name"`
	Description string               `json:"description"`
	Metadata    *ServicePlanMetadata `json:"metadata,omitempty"`
	Free        bool                 `json:"free"`

func (ServicePlan) Validate

func (sp ServicePlan) Validate() error

type ServicePlanMetadata

type ServicePlanMetadata struct {
	Bullets     []string `json:"bullets,omitempty"`
	Costs       []Cost   `json:"costs,omitempty"`
	DisplayName string   `json:"displayName,omitempty"`

type UnbindDetails

type UnbindDetails struct {
	ServiceID string `json:"service_id"`
	PlanID    string `json:"plan_id"`

type UpdateDetails

type UpdateDetails struct {
	ServiceID      string                 `json:"service_id"`
	PlanID         string                 `json:"plan_id"`
	Parameters     map[string]interface{} `json:"parameters"`
	PreviousValues PreviousValues         `json:"previous_values"`


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL