web

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: Apache-2.0, BSD-3-Clause, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package web exposes the extension points of the Service Manager. One can add additional controllers, filters and plugins to already built SM.

Index

Constants

View Source
const (

	// BrokersURL is the URL path to manage service brokers
	BrokersURL = "/" + apiVersion + "/service_brokers"

	// ServiceOfferingsURL is the URL path to manage service offerings
	ServiceOfferingsURL = "/" + apiVersion + "/service_offerings"

	// ServicePlansURL is the URL path to manage service plans
	ServicePlansURL = "/" + apiVersion + "/service_plans"

	// VisibilitiesURL is the URL path to manage visibilities
	VisibilitiesURL = "/" + apiVersion + "/visibilities"

	// PlatformsURL is the URL path to manage platforms
	PlatformsURL = "/" + apiVersion + "/platforms"

	// OSBURL is the OSB API base URL path
	OSBURL = "/" + apiVersion + "/osb"

	// MonitorHealthURL is the path of the healthcheck endpoint
	MonitorHealthURL = "/" + apiVersion + "/monitor/health"

	// InfoURL is the path of the info endpoint
	InfoURL = "/" + apiVersion + "/info"
)

Variables

This section is empty.

Functions

func ContextWithAuthorization added in v0.1.1

func ContextWithAuthorization(ctx context.Context) context.Context

ContextWithAuthorization sets the boolean flag isAuthorized in the request context

func ContextWithUser added in v0.1.1

func ContextWithUser(ctx context.Context, user *UserContext) context.Context

ContextWithUser sets the authenticated user in the context

func IsAuthorized added in v0.1.1

func IsAuthorized(ctx context.Context) bool

IsAuthorized returns whether the request has been authorized

Types

type API

type API struct {
	// Controllers contains the registered controllers
	Controllers []Controller

	// Filters contains the registered filters
	Filters []Filter

	// Registry is the health indicators registry for this API
	health.Registry
}

API is the primary point for REST API registration

func (*API) RegisterControllers

func (api *API) RegisterControllers(controllers ...Controller)

RegisterControllers registers a set of controllers

func (*API) RegisterFilters

func (api *API) RegisterFilters(filters ...Filter)

RegisterFilters registers a set of filters

func (*API) RegisterFiltersAfter

func (api *API) RegisterFiltersAfter(afterFilterName string, filters ...Filter)

RegisterFiltersAfter registers the specified filter after the one with the given name. If for some routes, the filter with the given name does not match the routes of the provided filter, then the filter will be registered after the place at which the filter with this name would have been, had it been configured to match route.

func (*API) RegisterFiltersBefore

func (api *API) RegisterFiltersBefore(beforeFilterName string, filters ...Filter)

RegisterFiltersBefore registers the specified filters before the one with the given name. If for some routes, the filter with the given name does not match the routes of the provided filter, then the filters will be registered at the place at which the filter with this name would have been, had it been configured to match route.

func (*API) RegisterPlugins

func (api *API) RegisterPlugins(plugins ...Plugin)

RegisterPlugins registers a set of plugins

func (*API) RemoveFilter

func (api *API) RemoveFilter(name string)

RemoveFilter removes the filter with the given name

func (*API) ReplaceFilter

func (api *API) ReplaceFilter(replacedFilterName string, filter Filter)

ReplaceFilter registers the given filter in the place of the filter with the given name.

type Binder

type Binder interface {
	Plugin

	Bind(request *Request, next Handler) (*Response, error)
}

Binder should be implemented by plugins that need to intercept OSB call for bind service operation

type BindingFetcher

type BindingFetcher interface {
	Plugin

	FetchBinding(request *Request, next Handler) (*Response, error)
}

BindingFetcher should be implemented by plugins that need to intercept OSB call for unbind service operation

type BindingPoller

type BindingPoller interface {
	Plugin

	PollBinding(request *Request, next Handler) (*Response, error)
}

BindingPoller should be implemented by plugins that need to intercept OSB Calls for polling last operation for service bindings

type CatalogFetcher

type CatalogFetcher interface {
	Plugin

	FetchCatalog(request *Request, next Handler) (*Response, error)
}

CatalogFetcher should be implemented by plugins that need to intercept OSB call for get catalog operation

type Controller

type Controller interface {
	// Routes returns the set of routes for this controller
	Routes() []Route
}

Controller is an entity that wraps a set of HTTP Routes

type CredentialsAdapter added in v0.1.5

type CredentialsAdapter interface {
	Plugin

	AdaptCredentials(request *Request, next Handler) (*Response, error)
}

type Data added in v0.1.6

type Data interface {
	// Data reads the additional data from the context into the specified struct
	Data(v interface{}) error
}

type Deprovisioner

type Deprovisioner interface {
	Plugin

	Deprovision(request *Request, next Handler) (*Response, error)
}

Deprovisioner should be implemented by plugins that need to intercept OSB call for deprovision operation

type Endpoint

type Endpoint struct {
	Method string
	Path   string
}

Endpoint is a combination of a Path and an HTTP Method

type Filter

type Filter interface {
	Named
	Middleware

	// FilterMatchers Returns a set of FilterMatchers each containing a set of Matchers. Each FilterMatcher represents
	// one place where the Filter would run.
	FilterMatchers() []FilterMatcher
}

Filter is an interface that Named Middlewares that should satisfy a set of Matchers (conditions) should implement.

type FilterMatcher

type FilterMatcher struct {
	// Matchers represents a set of conditions that need to be matched
	Matchers []Matcher
}

FilterMatcher type represents a set of conditions (Matchers) that need to match if order for a FilterMatcher to match

type Filters

type Filters []Filter

Filters represents a slice of Filter elements

func (Filters) Chain

func (fs Filters) Chain(h Handler) Handler

Chain chains the Filters around the specified Handler and returns a Handler. It also adds logic for logging before entering and after exiting from filters.

func (Filters) ChainMatching

func (fs Filters) ChainMatching(route Route) Handler

ChainMatching builds a pkg/web.Handler that chains up the filters that match the provided route and the actual handler

func (Filters) Matching

func (fs Filters) Matching(endpoint Endpoint) Filters

Matching returns a subset of Filters that match the specified endpoint

type Handler

type Handler interface {
	// Handle processes a Request and returns a corresponding Response or error
	Handle(req *Request) (resp *Response, err error)
}

Handler is an interface that objects can implement to be registered in the SM REST API.

type HandlerFunc

type HandlerFunc func(req *Request) (resp *Response, err error)

HandlerFunc is an adapter that allows to use regular functions as Handler interface implementations.

func (HandlerFunc) Handle

func (rhf HandlerFunc) Handle(req *Request) (resp *Response, err error)

Handle allows HandlerFunc to act as a Handler

type InstancePoller

type InstancePoller interface {
	Plugin

	PollInstance(request *Request, next Handler) (*Response, error)
}

InstancePoller should be implemented by plugins that need to intercept OSB calls for polling last operation for service instances

type Matcher

type Matcher interface {
	// Matches matches a route against a particular condition
	Matches(endpoint Endpoint) (bool, error)
}

Matcher allows checking whether an Endpoint matches a particular condition

func Methods

func Methods(methods ...string) Matcher

Methods returns a Matcher that matches to routes that contain any of the specified methods

func Path

func Path(patterns ...string) Matcher

Path returns a Matcher that matches to routes a path that matches any of the specified patterns

type MatcherFunc

type MatcherFunc func(endpoint Endpoint) (bool, error)

MatcherFunc is an adapter that allows regular functions to act as Matchers

func (MatcherFunc) Matches

func (m MatcherFunc) Matches(endpoint Endpoint) (bool, error)

Matches allows MatcherFunc to act as a Matcher

type Middleware

type Middleware interface {
	// Run returns a handler that contains the handling logic of the Middleware. The implementation of Run
	// should invoke next's Handle if the request should be chained to the next Handler.
	// It may also terminate the request by not invoking the next Handler.
	Run(req *Request, next Handler) (*Response, error)
}

Middleware is an interface that objects that should act as filters or plugins need to implement. It intercepts the request before reaching the final handler and allows during preprocessing and postprocessing.

type MiddlewareFunc

type MiddlewareFunc func(req *Request, next Handler) (*Response, error)

MiddlewareFunc is an adapter that allows to use regular functions as Middleware

func (MiddlewareFunc) Run

func (mf MiddlewareFunc) Run(req *Request, handler Handler) (*Response, error)

Run allows MiddlewareFunc to act as a Middleware

type Named

type Named interface {
	// Name returns the string identifier for the object
	Name() string
}

Named is an interface that objects that need to be identified by a particular name should implement.

type Plugin

type Plugin interface {
	Named
}

Plugin can intercept Service Manager operations and augment them with additional logic. To intercept SM operations a plugin implements one or more of the interfaces defined in this package.

type Provisioner

type Provisioner interface {
	Plugin

	Provision(request *Request, next Handler) (*Response, error)
}

Provisioner should be implemented by plugins that need to intercept OSB call for provision operation

type Request

type Request struct {
	// Request is the original http.Request
	*http.Request

	// PathParams contains the URL path parameters
	PathParams map[string]string

	// Body is the loaded request body (usually JSON)
	Body []byte
}

Request contains the original http.Request, path parameters and the raw body Request.Request.Body should not be used as it would be already processed by internal implementation

type Response

type Response struct {
	// StatusCode is the HTTP status code
	StatusCode int

	// Header contains the response headers
	Header http.Header

	// Body is the response body (usually JSON)
	Body []byte
}

Response defines the attributes of the HTTP response that will be sent to the client

type Route

type Route struct {
	// Endpoint is the combination of Path and HTTP Method for the specified route
	Endpoint Endpoint

	// Handler is the function that should handle incoming requests for this endpoint
	Handler HandlerFunc
}

Route is a mapping between an Endpoint and a REST API SMHandler

type ServiceFetcher

type ServiceFetcher interface {
	Plugin

	FetchService(request *Request, next Handler) (*Response, error)
}

ServiceFetcher should be implemented by plugins that need to intercept OSB call for get service operation

type ServiceUpdater

type ServiceUpdater interface {
	Plugin

	UpdateService(request *Request, next Handler) (*Response, error)
}

ServiceUpdater should be implemented by plugins that need to intercept OSB call for update service operation

type Unbinder

type Unbinder interface {
	Plugin

	Unbind(request *Request, next Handler) (*Response, error)
}

Unbinder should be implemented by plugins that need to intercept OSB call for unbind service operation

type UserContext added in v0.1.6

type UserContext struct {
	Data

	Name string
}

UserContext holds the information for the current user

func UserFromContext

func UserFromContext(ctx context.Context) (*UserContext, bool)

UserFromContext gets the authenticated user from the context

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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