brokerapi

package module
v11.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 7

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 or brokerapi.NewWithOptions, which returns an http.Handler that you can use to serve handle HTTP requests.

Alternatively, if you already have a *chi.Mux 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 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

Documentation

Index

Constants

View Source
const (
	PermissionRouteForwarding = domain.PermissionRouteForwarding
	PermissionSyslogDrain     = domain.PermissionSyslogDrain
	PermissionVolumeMount     = domain.PermissionVolumeMount
)

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

Variables

View Source
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
)

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

Functions

func AddServicePlanToContext

func AddServicePlanToContext(ctx context.Context, plan *ServicePlan) context.Context

func AddServiceToContext

func AddServiceToContext(ctx context.Context, service *Service) context.Context

func AttachRoutes

func AttachRoutes(router chi.Router, serviceBroker ServiceBroker, logger *slog.Logger)

func BindableValue deprecated

func BindableValue(v bool) *bool

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

func FreeValue deprecated

func FreeValue(v bool) *bool

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

func GetJsonNames deprecated

func GetJsonNames(s reflect.Value) (res []string)

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

func New

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

func NewFailureResponse deprecated

func NewFailureResponse(err error, statusCode int, loggerAction string) error

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses NewFailureResponse returns an error of type 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 NewWithCustomAuth

func NewWithCustomAuth(serviceBroker ServiceBroker, logger *slog.Logger, authMiddleware middlewareFunc) http.Handler

func NewWithOptions

func NewWithOptions(serviceBroker domain.ServiceBroker, logger *slog.Logger, opts ...Option) http.Handler

Types

type AsyncBindResponse deprecated

type AsyncBindResponse = apiresponses.AsyncBindResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type BindDetails deprecated

type BindDetails = domain.BindDetails

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type BindResource deprecated

type BindResource = domain.BindResource

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type Binding deprecated

type Binding = domain.Binding

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type BindingResponse deprecated

type BindingResponse = apiresponses.BindingResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type BrokerCredentials

type BrokerCredentials struct {
	Username string
	Password string
}

type CatalogResponse deprecated

type CatalogResponse = apiresponses.CatalogResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type DeprovisionDetails deprecated

type DeprovisionDetails = domain.DeprovisionDetails

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type DeprovisionResponse deprecated

type DeprovisionResponse = apiresponses.DeprovisionResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type DeprovisionServiceSpec deprecated

type DeprovisionServiceSpec = domain.DeprovisionServiceSpec

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type DetailsWithRawContext deprecated

type DetailsWithRawContext interface {
	domain.DetailsWithRawContext
}

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type DetailsWithRawParameters deprecated

type DetailsWithRawParameters interface {
	domain.DetailsWithRawParameters
}

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type EmptyResponse deprecated

type EmptyResponse = apiresponses.EmptyResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type ErrorResponse deprecated

type ErrorResponse = apiresponses.ErrorResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type ExperimentalVolumeMount deprecated

type ExperimentalVolumeMount = domain.ExperimentalVolumeMount

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ExperimentalVolumeMountBindingResponse deprecated

type ExperimentalVolumeMountBindingResponse = apiresponses.ExperimentalVolumeMountBindingResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type ExperimentalVolumeMountPrivate deprecated

type ExperimentalVolumeMountPrivate = domain.ExperimentalVolumeMountPrivate

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type FailureResponse deprecated

type FailureResponse = apiresponses.FailureResponse

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 FailureResponseBuilder deprecated

type FailureResponseBuilder = apiresponses.FailureResponseBuilder

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses FailureResponseBuilder provides a fluent set of methods to build a *FailureResponse.

func NewFailureResponseBuilder deprecated

func NewFailureResponseBuilder(err error, statusCode int, loggerAction string) *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.

type GetBindingResponse deprecated

type GetBindingResponse = apiresponses.GetBindingResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type GetBindingSpec deprecated

type GetBindingSpec = domain.GetBindingSpec

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type GetInstanceDetailsSpec deprecated

type GetInstanceDetailsSpec = domain.GetInstanceDetailsSpec

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type GetInstanceResponse deprecated

type GetInstanceResponse = apiresponses.GetInstanceResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type LastOperation deprecated

type LastOperation = domain.LastOperation

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type LastOperationResponse deprecated

type LastOperationResponse = apiresponses.LastOperationResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type LastOperationState deprecated

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 MaintenanceInfo deprecated

type MaintenanceInfo = domain.MaintenanceInfo

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type Option

type Option func(*config)

func WithAdditionalMiddleware

func WithAdditionalMiddleware(m middlewareFunc) Option

WithAdditionalMiddleware adds the specified middleware *after* the default middleware. Can be called multiple times. This option is ignored if `WithRouter()` is used.

func WithBrokerCredentials

func WithBrokerCredentials(brokerCredentials BrokerCredentials) Option

func WithCustomAuth

func WithCustomAuth(authMiddleware middlewareFunc) Option

WithCustomAuth adds the specified middleware *before* any other middleware. Despite the name, any middleware can be added whether nor not it has anything to do with authentication. But `WithAdditionalMiddleware()` may be a better choice if the middleware is not related to authentication. Can be called multiple times.

func WithEncodedPath deprecated

func WithEncodedPath() Option

WithEncodedPath used to opt in to a gorilla/mux behaviour that would treat encoded slashes "/" as IDs. For example, it would change `PUT /v2/service_instances/foo%2Fbar` to treat `foo%2Fbar` as an instance ID, while the default behavior was to treat it as `foo/bar`. However, with moving to go-chi/chi, this is now the default behavior so this option no longer does anything.

Deprecated: no longer has any effect

func WithOptions

func WithOptions(opts ...Option) Option

func WithRouter

func WithRouter(router chi.Router) Option

type PollDetails deprecated

type PollDetails = domain.PollDetails

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type PreviousValues deprecated

type PreviousValues = domain.PreviousValues

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ProvisionDetails deprecated

type ProvisionDetails = domain.ProvisionDetails

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ProvisionedServiceSpec deprecated

type ProvisionedServiceSpec = domain.ProvisionedServiceSpec

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ProvisioningResponse deprecated

type ProvisioningResponse = apiresponses.ProvisioningResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type RequiredPermission deprecated

type RequiredPermission = domain.RequiredPermission

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type Schema deprecated

type Schema = domain.Schema

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type Service deprecated

type Service = domain.Service

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

func RetrieveServiceFromContext

func RetrieveServiceFromContext(ctx context.Context) *Service

type ServiceBindingSchema deprecated

type ServiceBindingSchema = domain.ServiceBindingSchema

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ServiceBroker deprecated

type ServiceBroker interface {
	domain.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 ServiceDashboardClient deprecated

type ServiceDashboardClient = domain.ServiceDashboardClient

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ServiceInstanceSchema deprecated

type ServiceInstanceSchema = domain.ServiceInstanceSchema

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ServiceMetadata deprecated

type ServiceMetadata = domain.ServiceMetadata

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ServicePlan deprecated

type ServicePlan = domain.ServicePlan

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

func RetrieveServicePlanFromContext

func RetrieveServicePlanFromContext(ctx context.Context) *ServicePlan

type ServicePlanCost deprecated

type ServicePlanCost = domain.ServicePlanCost

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ServicePlanMetadata deprecated

type ServicePlanMetadata = domain.ServicePlanMetadata

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type ServiceSchemas deprecated

type ServiceSchemas = domain.ServiceSchemas

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type SharedDevice deprecated

type SharedDevice = domain.SharedDevice

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type UnbindDetails deprecated

type UnbindDetails = domain.UnbindDetails

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type UnbindResponse deprecated

type UnbindResponse = apiresponses.UnbindResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type UnbindSpec deprecated

type UnbindSpec = domain.UnbindSpec

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type UpdateDetails deprecated

type UpdateDetails = domain.UpdateDetails

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type UpdateResponse deprecated

type UpdateResponse = apiresponses.UpdateResponse

Deprecated: Use github.com/pivotal-cf/brokerapi/domain/apiresponses

type UpdateServiceSpec deprecated

type UpdateServiceSpec = domain.UpdateServiceSpec

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

type VolumeMount deprecated

type VolumeMount = domain.VolumeMount

Deprecated: Use github.com/pivotal-cf/brokerapi/domain

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.
fakes
Code generated by counterfeiter.
Code generated by counterfeiter.
internal
blog
Package blog is the brokerapi logger BrokerAPI was originally written to use the CloudFoundry Lager logger (https://github.com/cloudfoundry/lager), and it relied on some idiosyncrasies of that logger that are not found in the (subsequently written) Go standard library log/slog logger.
Package blog is the brokerapi logger BrokerAPI was originally written to use the CloudFoundry Lager logger (https://github.com/cloudfoundry/lager), and it relied on some idiosyncrasies of that logger that are not found in the (subsequently written) Go standard library log/slog logger.

Jump to

Keyboard shortcuts

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