Documentation
¶
Overview ¶
Package apiserver contains the code that provides a RESTful api service.
Index ¶
- Constants
- Variables
- func APIVersionHandler(versions ...string) restful.RouteFunction
- func AddApiWebService(container *restful.Container, apiPrefix string, versions []string)
- func CORS(handler http.Handler, allowedOriginPatterns []*regexp.Regexp, ...) http.Handler
- func CreateResource(r RESTCreater, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, ...) restful.RouteFunction
- func DeleteResource(r RESTDeleter, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, ...) restful.RouteFunction
- func GetResource(r RESTGetter, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec) restful.RouteFunction
- func IndexHandler(container *restful.Container, muxHelper *MuxHelper) func(http.ResponseWriter, *http.Request)
- func InstallLogsSupport(mux Mux)
- func InstallSupport(mux Mux, ws *restful.WebService)
- func InstallValidator(mux Mux, servers func() map[string]Server)
- func IsReadOnlyReq(req http.Request) bool
- func ListResource(r RESTLister, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, ...) restful.RouteFunction
- func NewAlwaysAllowAuthorizer() authorizer.Authorizer
- func NewAlwaysDenyAuthorizer() authorizer.Authorizer
- func NewAuthenticatorFromTokenFile(tokenAuthFile string) (authenticator.Request, error)
- func NewAuthorizerFromAuthorizationConfig(authorizationMode string, authorizationPolicyFile string) (authorizer.Authorizer, error)
- func NewValidator(servers func() map[string]Server) (http.Handler, error)
- func PatchResource(r RESTPatcher, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, ...) restful.RouteFunction
- func RateLimit(rl util.RateLimiter, handler http.Handler) http.Handler
- func ReadOnly(handler http.Handler) http.Handler
- func RecoverPanics(handler http.Handler) http.Handler
- func UpdateResource(r RESTUpdater, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, ...) restful.RouteFunction
- func WithAuthorizationCheck(handler http.Handler, getAttribs RequestAttributeGetter, ...) http.Handler
- type APIGroupVersion
- type APIInstaller
- type APIRequestInfo
- type APIRequestInfoResolver
- type Attributes
- type ContextFunc
- type Mux
- type MuxHelper
- type ProxyHandler
- type RESTCreater
- type RESTDeleter
- type RESTGetter
- type RESTLister
- type RESTPatcher
- type RESTResult
- type RESTStorage
- type RESTUpdater
- type RedirectHandler
- type Redirector
- type RequestAttributeGetter
- type ResourceWatcher
- type ScopeNamer
- type Server
- type ServerStatus
- type WatchHandler
- type WatchServer
Constants ¶
const ( ModeAlwaysAllow string = "AlwaysAllow" ModeAlwaysDeny string = "AlwaysDeny" ModeABAC string = "ABAC" )
Variables ¶
var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny, ModeABAC}
Keep this list in sync with constant list above.
Functions ¶
func APIVersionHandler ¶ added in v0.5.1
func APIVersionHandler(versions ...string) restful.RouteFunction
APIVersionHandler returns a handler which will list the provided versions as available.
func AddApiWebService ¶ added in v0.9.0
Adds a service to return the supported api versions.
func CORS ¶
func CORS(handler http.Handler, allowedOriginPatterns []*regexp.Regexp, allowedMethods []string, allowedHeaders []string, allowCredentials string) http.Handler
TODO: use restful.CrossOriginResourceSharing Simple CORS implementation that wraps an http Handler For a more detailed implementation use https://github.com/martini-contrib/cors or implement CORS at your proxy layer Pass nil for allowedMethods and allowedHeaders to use the defaults
func CreateResource ¶ added in v0.12.0
func CreateResource(r RESTCreater, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, typer runtime.ObjectTyper, resource string, admit admission.Interface) restful.RouteFunction
CreateResource returns a function that will handle a resource creation.
func DeleteResource ¶ added in v0.12.0
func DeleteResource(r RESTDeleter, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, resource, kind string, admit admission.Interface) restful.RouteFunction
DeleteResource returns a function that will handle a resource deletion
func GetResource ¶ added in v0.12.0
func GetResource(r RESTGetter, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec) restful.RouteFunction
GetResource returns a function that handles retrieving a single resource from a RESTStorage object.
func IndexHandler ¶ added in v0.10.0
func IndexHandler(container *restful.Container, muxHelper *MuxHelper) func(http.ResponseWriter, *http.Request)
func InstallLogsSupport ¶
func InstallLogsSupport(mux Mux)
InstallLogsSupport registers the APIServer log support function into a mux.
func InstallSupport ¶
func InstallSupport(mux Mux, ws *restful.WebService)
TODO: document all handlers InstallSupport registers the APIServer support functions
func InstallValidator ¶ added in v0.5.1
TODO: Convert to go-restful
func IsReadOnlyReq ¶ added in v0.5.1
IsReadOnlyReq() is true for any (or at least many) request which has no observable side effects on state of apiserver (though there may be internal side effects like caching and logging).
func ListResource ¶ added in v0.12.0
func ListResource(r RESTLister, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, version, apiResource string) restful.RouteFunction
ListResource returns a function that handles retrieving a list of resources from a RESTStorage object.
func NewAlwaysAllowAuthorizer ¶ added in v0.5.1
func NewAlwaysAllowAuthorizer() authorizer.Authorizer
func NewAlwaysDenyAuthorizer ¶ added in v0.5.1
func NewAlwaysDenyAuthorizer() authorizer.Authorizer
func NewAuthenticatorFromTokenFile ¶ added in v0.6.0
func NewAuthenticatorFromTokenFile(tokenAuthFile string) (authenticator.Request, error)
NewAuthenticatorFromTokenFile returns an authenticator.Request or an error
func NewAuthorizerFromAuthorizationConfig ¶ added in v0.5.1
func NewAuthorizerFromAuthorizationConfig(authorizationMode string, authorizationPolicyFile string) (authorizer.Authorizer, error)
NewAuthorizerFromAuthorizationConfig returns the right sort of authorizer.Authorizer based on the authorizationMode xor an error. authorizationMode should be one of AuthorizationModeChoices.
func NewValidator ¶
NewValidator creates a validator for a set of servers.
func PatchResource ¶ added in v0.13.0
func PatchResource(r RESTPatcher, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, typer runtime.ObjectTyper, resource string, admit admission.Interface) restful.RouteFunction
PatchResource returns a function that will handle a resource patch TODO: Eventually PatchResource should just use AtomicUpdate and this routine should be a bit cleaner
func ReadOnly ¶ added in v0.5.1
ReadOnly passes all GET requests on to handler, and returns an error on all other requests.
func RecoverPanics ¶
RecoverPanics wraps an http Handler to recover and log panics.
func UpdateResource ¶ added in v0.12.0
func UpdateResource(r RESTUpdater, ctxFn ContextFunc, namer ScopeNamer, codec runtime.Codec, typer runtime.ObjectTyper, resource string, admit admission.Interface) restful.RouteFunction
UpdateResource returns a function that will handle a resource update
func WithAuthorizationCheck ¶ added in v0.5.1
func WithAuthorizationCheck(handler http.Handler, getAttribs RequestAttributeGetter, a authorizer.Authorizer) http.Handler
WithAuthorizationCheck passes all authorized requests on to handler, and returns a forbidden error otherwise.
Types ¶
type APIGroupVersion ¶ added in v0.5.1
type APIGroupVersion struct { Storage map[string]RESTStorage Root string Version string Mapper meta.RESTMapper Codec runtime.Codec Typer runtime.ObjectTyper Creater runtime.ObjectCreater Linker runtime.SelfLinker Admit admission.Interface Context api.RequestContextMapper }
APIGroupVersion is a helper for exposing RESTStorage objects as http.Handlers via go-restful It handles URLs of the form: /${storage_key}[/${object_name}] Where 'storage_key' points to a RESTStorage object stored in storage.
func (*APIGroupVersion) InstallREST ¶ added in v0.5.1
func (g *APIGroupVersion) InstallREST(container *restful.Container) error
InstallREST registers the REST handlers (storage, watch, proxy and redirect) into a restful Container. It is expected that the provided path root prefix will serve all operations. Root MUST NOT end in a slash. A restful WebService is created for the group and version.
type APIInstaller ¶ added in v0.12.0
type APIInstaller struct {
// contains filtered or unexported fields
}
func (*APIInstaller) Install ¶ added in v0.12.0
func (a *APIInstaller) Install() (ws *restful.WebService, errors []error)
Installs handlers for API resources.
type APIRequestInfo ¶ added in v0.12.0
type APIRequestInfo struct { // Verb is the kube verb associated with the request, not the http verb. This includes things like list and watch. Verb string APIVersion string Namespace string // Resource is the name of the resource being requested. This is not the kind. For example: pods Resource string // Kind is the type of object being manipulated. For example: Pod Kind string // Name is empty for some verbs, but if the request directly indicates a name (not in body content) then this field is filled in. Name string // Parts are the path parts for the request, always starting with /{resource}/{name} Parts []string // Raw is the unparsed form of everything other than parts. // Raw + Parts = complete URL path Raw []string }
APIRequestInfo holds information parsed from the http.Request
func (APIRequestInfo) URLPath ¶ added in v0.12.0
func (info APIRequestInfo) URLPath() string
URLPath returns the URL path for this request, including /{resource}/{name} if present but nothing following that.
type APIRequestInfoResolver ¶ added in v0.12.0
type APIRequestInfoResolver struct { APIPrefixes util.StringSet RestMapper meta.RESTMapper }
func (*APIRequestInfoResolver) GetAPIRequestInfo ¶ added in v0.12.0
func (r *APIRequestInfoResolver) GetAPIRequestInfo(req *http.Request) (APIRequestInfo, error)
GetAPIRequestInfo returns the information from the http request. If error is not nil, APIRequestInfo holds the information as best it is known before the failure Valid Inputs: Storage paths /namespaces /namespaces/{namespace} /namespaces/{namespace}/{resource} /namespaces/{namespace}/{resource}/{resourceName} /{resource} /{resource}/{resourceName} /{resource}/{resourceName}?namespace={namespace} /{resource}?namespace={namespace}
Special verbs: /proxy/{resource}/{resourceName} /proxy/ns/{namespace}/{resource}/{resourceName} /redirect/ns/{namespace}/{resource}/{resourceName} /redirect/{resource}/{resourceName} /watch/{resource} /watch/ns/{namespace}/{resource}
Fully qualified paths for above: /api/{version}/* /api/{version}/*
type Attributes ¶ added in v0.5.1
type Attributes struct { }
Attributes implements authorizer.Attributes interface.
type ContextFunc ¶ added in v0.12.0
ContextFunc returns a Context given a request - a context must be returned
type Mux ¶ added in v0.5.1
type Mux interface { Handle(pattern string, handler http.Handler) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) }
mux is an object that can register http handlers.
type MuxHelper ¶ added in v0.10.0
Offers additional functionality over ServeMux, for ex: supports listing registered paths.
func (*MuxHelper) HandleFunc ¶ added in v0.10.0
type ProxyHandler ¶
type ProxyHandler struct {
// contains filtered or unexported fields
}
ProxyHandler provides a http.Handler which will proxy traffic to locations specified by items implementing Redirector.
func (*ProxyHandler) ServeHTTP ¶
func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type RESTCreater ¶ added in v0.9.0
type RESTCreater interface { // New returns an empty object that can be used with Create after request data has been put into it. // This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object) New() runtime.Object // Create creates a new version of a resource. Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) }
type RESTDeleter ¶ added in v0.9.0
type RESTDeleter interface { // Delete finds a resource in the storage and deletes it. // Although it can return an arbitrary error value, IsNotFound(err) is true for the // returned error value err when the specified resource is not found. // Delete *may* return the object that was deleted, or a status object indicating additional // information about deletion. Delete(ctx api.Context, id string) (runtime.Object, error) }
type RESTGetter ¶ added in v0.9.0
type RESTGetter interface { // Get finds a resource in the storage by id and returns it. // Although it can return an arbitrary error value, IsNotFound(err) is true for the // returned error value err when the specified resource is not found. Get(ctx api.Context, id string) (runtime.Object, error) }
type RESTLister ¶ added in v0.9.0
type RESTLister interface { // NewList returns an empty object that can be used with the List call. // This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object) NewList() runtime.Object // List selects resources in the storage which match to the selector. List(ctx api.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) }
type RESTPatcher ¶ added in v0.13.0
type RESTPatcher interface { RESTGetter RESTUpdater }
type RESTResult ¶ added in v0.5.1
type RESTResult struct { // The result of this operation. May be nil if the operation has no meaningful // result (like Delete) runtime.Object // May be set true to indicate that the Update operation resulted in the object // being created. Created bool }
RESTResult indicates the result of a REST transformation.
type RESTStorage ¶
type RESTStorage interface { // New returns an empty object that can be used with Create and Update after request data has been put into it. // This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object) New() runtime.Object }
RESTStorage is a generic interface for RESTful storage services. Resources which are exported to the RESTful API of apiserver need to implement this interface. It is expected that objects may implement any of the REST* interfaces. TODO: implement dynamic introspection (so GenericREST objects can indicate what they implement)
type RESTUpdater ¶ added in v0.9.0
type RESTUpdater interface { // New returns an empty object that can be used with Update after request data has been put into it. // This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object) New() runtime.Object // Update finds a resource in the storage and updates it. Some implementations // may allow updates creates the object - they should set the created boolean // to true. Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) }
type RedirectHandler ¶
type RedirectHandler struct {
// contains filtered or unexported fields
}
func (*RedirectHandler) ServeHTTP ¶
func (r *RedirectHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type Redirector ¶
type Redirector interface { // ResourceLocation should return the remote location of the given resource, or an error. ResourceLocation(ctx api.Context, id string) (remoteLocation string, err error) }
Redirector know how to return a remote resource's location.
type RequestAttributeGetter ¶ added in v0.5.1
type RequestAttributeGetter interface {
GetAttribs(req *http.Request) (attribs authorizer.Attributes)
}
RequestAttributeGetter is a function that extracts authorizer.Attributes from an http.Request
func NewRequestAttributeGetter ¶ added in v0.5.1
func NewRequestAttributeGetter(requestContextMapper api.RequestContextMapper, restMapper meta.RESTMapper, apiRoots ...string) RequestAttributeGetter
NewAttributeGetter returns an object which implements the RequestAttributeGetter interface.
type ResourceWatcher ¶
type ResourceWatcher interface { // 'label' selects on labels; 'field' selects on the object's fields. Not all fields // are supported; an error should be returned if 'field' tries to select on a field that // isn't supported. 'resourceVersion' allows for continuing/starting a watch at a // particular version. Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) }
ResourceWatcher should be implemented by all RESTStorage objects that want to offer the ability to watch for changes through the watch api.
type ScopeNamer ¶ added in v0.12.0
type ScopeNamer interface { // Namespace returns the appropriate namespace value from the request (may be empty) or an // error. Namespace(req *restful.Request) (namespace string, err error) // Name returns the name from the request, and an optional namespace value if this is a namespace // scoped call. An error is returned if the name is not available. Name(req *restful.Request) (namespace, name string, err error) // ObjectName returns the namespace and name from an object if they exist, or an error if the object // does not support names. ObjectName(obj runtime.Object) (namespace, name string, err error) // SetSelfLink sets the provided URL onto the object. The method should return nil if the object // does not support selfLinks. SetSelfLink(obj runtime.Object, url string) error // GenerateLink creates a path and query for a given runtime object that represents the canonical path. GenerateLink(req *restful.Request, obj runtime.Object) (path, query string, err error) // GenerateLink creates a path and query for a list that represents the canonical path. GenerateListLink(req *restful.Request) (path, query string, err error) }
ScopeNamer handles accessing names from requests and objects
type ServerStatus ¶
type WatchHandler ¶
type WatchHandler struct {
// contains filtered or unexported fields
}
func (*WatchHandler) ServeHTTP ¶
func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP processes watch requests.
type WatchServer ¶
type WatchServer struct {
// contains filtered or unexported fields
}
WatchServer serves a watch.Interface over a websocket or vanilla HTTP.
func (*WatchServer) HandleWS ¶
func (w *WatchServer) HandleWS(ws *websocket.Conn)
HandleWS implements a websocket handler.
func (*WatchServer) ServeHTTP ¶
func (self *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP serves a series of JSON encoded events via straight HTTP with Transfer-Encoding: chunked.