web

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0, BSD-3-Clause, MIT Imports: 9 Imported by: 27

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 (
	// PathParamID is the value used to denote the id of the requested entity
	PathParamID = "id"

	// PathParamResourceID is the value used to denote the id of the requested resource
	PathParamResourceID = "resource_id"

	// QueryParamAsync is the value used to denote the query key used to convey a client's intent whether the request should be executed async or not
	QueryParamAsync = "async"

	// QueryParamCascade is the value used to denote the action to be applied on requested resource should include child sub-resources
	QueryParamCascade = "cascade"

	// QueryParamForce is the value used to denote if the requested resource should be purged from db
	QueryParamForce = "force"
)
View Source
const (

	// ServiceBrokersURL is the URL path to manage service brokers
	ServiceBrokersURL = "/" + 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"

	// ServiceInstancesURL is the URL path to manage service instances
	ServiceInstancesURL = "/" + apiVersion + "/service_instances"

	// ServiceBindingsURL is the URL path to manage service bindings
	ServiceBindingsURL = "/" + apiVersion + "/service_bindings"

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

	// NotificationsURL is the URL path to manage notifications
	NotificationsURL = "/" + apiVersion + "/notifications"

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

	// ConfigURL is the Configuration API base URL path
	ConfigURL = "/" + apiVersion + "/config"

	// LoggingConfigURL is the Logging Configuration API URL path
	LoggingConfigURL = ConfigURL + "/logging"

	// ResourceOperationsURL is the URL path fetch operations for a resource
	ResourceOperationsURL = "/operations"

	ParametersURL = "/parameters"

	// OperationsURL is the operations API base URL path
	OperationsURL = "/" + apiVersion + "/operations"

	// BrokerPlatformCredentialsURL is the URL path to manage service broker platform credentials
	BrokerPlatformCredentialsURL = "/" + apiVersion + "/credentials"

	// ProfileURL is the Configuration API base URL path
	ProfileURL = "/" + apiVersion + "/profile"

	TenantURL = "/" + apiVersion + "/tenants"
	AgentsURL = "/" + apiVersion + "/agents/versions"
)

Variables

This section is empty.

Functions

func AuthenticationErrorFromContext added in v0.9.7

func AuthenticationErrorFromContext(ctx context.Context) (bool, error)

func AuthorizationErrorFromContext added in v0.9.7

func AuthorizationErrorFromContext(ctx context.Context) (bool, error)

func ContextWithAuthenticationError added in v0.9.7

func ContextWithAuthenticationError(ctx context.Context, authNError error) context.Context

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 ContextWithAuthorizationError added in v0.9.7

func ContextWithAuthorizationError(ctx context.Context, authZError error) context.Context

func ContextWithGeneratePlatformCredentialsFlag added in v0.16.10

func ContextWithGeneratePlatformCredentialsFlag(ctx context.Context, generate bool) context.Context

func ContextWithOriginatingIdentity added in v0.19.1

func ContextWithOriginatingIdentity(ctx context.Context, info interface{}) context.Context

ContextWithOriginatingIdentity sets the originating user in the context

func ContextWithSMAAPOperatedFlag added in v0.18.2

func ContextWithSMAAPOperatedFlag(ctx context.Context, operated bool) context.Context

func ContextWithStoreBindingsFlag added in v0.13.4

func ContextWithStoreBindingsFlag(ctx context.Context, shouldStoreBindings bool) context.Context

ContextWithStoreBindings sets the shouldStoreBindings flag in the 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

func IsGeneratePlatformCredentialsRequired added in v0.16.10

func IsGeneratePlatformCredentialsRequired(ctx context.Context) bool

func IsSMAAPOperated added in v0.18.2

func IsSMAAPOperated(ctx context.Context) bool

IsSMAAPOperated indicates whether resource from another platform operated by SMAAP

func Matching added in v0.9.7

func Matching(filterMatchers []FilterMatcher, endpoint Endpoint) (bool, error)

func OriginatingIdentityFromContext added in v0.19.1

func OriginatingIdentityFromContext(ctx context.Context) interface{}

OriginatingIdentityFromContext gets the originating user from the context

func ShouldStoreBindings added in v0.13.4

func ShouldStoreBindings(ctx context.Context) bool

ShouldStoreBindings returns whether the request has to store bindings

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) RegisterPluginsBefore added in v0.9.1

func (api *API) RegisterPluginsBefore(beforePluginName string, plugins ...Plugin)

RegisterPluginsBefore registers a set of plugins before the plugin with the specified name

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 AccessLevel added in v0.7.0

type AccessLevel int

AccessLevel specifies the access level privileges that are stored in the user context

const (
	//NoAccess is the default value for access level - it is used when no explicit access was granted
	NoAccess AccessLevel = iota

	// TenantAccess means access was granted to manage the tenant's own resources. Such access might be granted to a user
	// so that he can manage his own data
	TenantAccess

	// AllTenantAccess means access was granted to manage the resources of all tenants. Such access might be granted
	// to systems that have to manage data across multiple tenants
	AllTenantAccess

	// GlobalAccess means access was granted to manage global resources (such resources are not scoped or associated with tenant.
	// Such access might be granted to systems that need to manage global resources
	GlobalAccess
)

func (AccessLevel) String added in v0.7.0

func (a AccessLevel) String() string

String implements Stringer and converts the decision to human-readable value

type AuthenticationType added in v0.4.1

type AuthenticationType int

AuthenticationType specifies the authentication type that is stored in the user context

const (
	Basic AuthenticationType = iota
	Bearer
)

func (AuthenticationType) String added in v0.7.0

func (a AuthenticationType) String() string

String implements Stringer and converts the decision to human-readable value

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 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 DynamicMatchingFilter added in v0.9.7

type DynamicMatchingFilter struct {
	// contains filtered or unexported fields
}

func NewDynamicMatchingFilter added in v0.9.7

func NewDynamicMatchingFilter(name string) *DynamicMatchingFilter

func (*DynamicMatchingFilter) AddFilter added in v0.9.7

func (dmf *DynamicMatchingFilter) AddFilter(dynamicFilter Filter)

func (*DynamicMatchingFilter) ClearFilters added in v0.9.9

func (dmf *DynamicMatchingFilter) ClearFilters()

func (*DynamicMatchingFilter) FilterMatchers added in v0.9.7

func (dmf *DynamicMatchingFilter) FilterMatchers() []FilterMatcher

func (*DynamicMatchingFilter) Name added in v0.9.7

func (dmf *DynamicMatchingFilter) Name() string

func (*DynamicMatchingFilter) Run added in v0.9.7

func (dmf *DynamicMatchingFilter) Run(req *Request, next Handler) (*Response, error)

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 Not added in v0.9.7

func Not(matchers ...Matcher) Matcher

Not returns matcher that matches the opposite of the provided Matchers

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
	// contains filtered or unexported fields
}

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

func (*Request) HijackResponseWriter added in v0.3.0

func (r *Request) HijackResponseWriter() http.ResponseWriter

func (*Request) IsResponseWriterHijacked added in v0.3.0

func (r *Request) IsResponseWriterHijacked() bool

func (*Request) SetResponseWriter added in v0.3.0

func (r *Request) SetResponseWriter(rw http.ResponseWriter)

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

	// DisableHTTPTimeouts if false (by default) will place timeout handler for the endpoint.
	// If explicitly set to true, will NOT use the timeout handler.
	// Mainly used for websocket connection endpoints
	DisableHTTPTimeouts bool
}

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 unmarshals the additional user context details into the specified struct
	Data func(data interface{}) error
	// AuthenticationType is the authentication type for this user context
	AuthenticationType AuthenticationType
	// Name is the name of the authenticated user
	Name string
	// AccessLevel is the user access level
	AccessLevel AccessLevel
}

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