apiserver

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2014 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package apiserver contains the code that provides a RESTful api service.

Index

Constants

View Source
const (
	StatusUnprocessableEntity = 422
)

Variables

This section is empty.

Functions

func CORS

func CORS(handler http.Handler, allowedOriginPatterns []*regexp.Regexp, allowedMethods []string, allowedHeaders []string, allowCredentials string) http.Handler

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 Handle

func Handle(storage map[string]RESTStorage, codec runtime.Codec, prefix string, selfLinker runtime.SelfLinker) http.Handler

Handle returns a Handler function that exposes the provided storage interfaces as RESTful resources at prefix, serialized by codec, and also includes the support http resources.

func InstallLogsSupport

func InstallLogsSupport(mux mux)

InstallLogsSupport registers the APIServer log support function into a mux.

func InstallSupport

func InstallSupport(mux mux)

InstallSupport registers the APIServer support functions into a mux.

func MakeAsync

func MakeAsync(fn WorkFunc) <-chan runtime.Object

MakeAsync takes a function and executes it, delivering the result in the way required by RESTStorage's Update, Delete, and Create methods.

func NewValidator

func NewValidator(servers map[string]string) (http.Handler, error)

NewValidator creates a validator for a set of servers.

func RecoverPanics

func RecoverPanics(handler http.Handler) http.Handler

RecoverPanics wraps an http Handler to recover and log panics.

Types

type APIGroup

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

APIGroup is a http.Handler that exposes multiple RESTStorage objects It handles URLs of the form: /${storage_key}[/${object_name}] Where 'storage_key' points to a RESTStorage object stored in storage.

TODO: consider migrating this to go-restful which is a more full-featured version of the same thing.

func NewAPIGroup

func NewAPIGroup(storage map[string]RESTStorage, codec runtime.Codec, canonicalPrefix string, selfLinker runtime.SelfLinker) *APIGroup

NewAPIGroup returns an object that will serve a set of REST resources and their associated operations. The provided codec controls serialization and deserialization. This is a helper method for registering multiple sets of REST handlers under different prefixes onto a server. TODO: add multitype codec serialization

func (*APIGroup) InstallREST

func (g *APIGroup) InstallREST(mux mux, paths ...string)

InstallREST registers the REST handlers (storage, watch, and operations) into a mux. It is expected that the provided prefix will serve all operations. Path MUST NOT end in a slash.

type Operation

type Operation struct {
	ID string
	// contains filtered or unexported fields
}

Operation represents an ongoing action which the server is performing.

func (*Operation) StatusOrResult

func (op *Operation) StatusOrResult() (description runtime.Object, finished bool)

StatusOrResult returns status information or the result of the operation if it is complete, with a bool indicating true in the latter case.

func (*Operation) WaitFor

func (op *Operation) WaitFor(timeout time.Duration)

WaitFor waits for the specified duration, or until the operation finishes, whichever happens first.

type OperationHandler

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

func (*OperationHandler) ServeHTTP

func (h *OperationHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Operations

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

Operations tracks all the ongoing operations.

func NewOperations

func NewOperations() *Operations

NewOperations returns a new Operations repository.

func (*Operations) Get

func (ops *Operations) Get(id string) *Operation

Get returns the operation with the given ID, or nil.

func (*Operations) List

func (ops *Operations) List() *api.ServerOpList

List lists operations for an API client.

func (*Operations) NewOperation

func (ops *Operations) NewOperation(from <-chan runtime.Object, onReceive func(runtime.Object)) *Operation

NewOperation adds a new operation. It is lock-free. 'onReceive' will be called with the value read from 'from', when it is read.

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 RESTHandler

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

func (*RESTHandler) ServeHTTP

func (h *RESTHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP handles requests to all RESTStorage objects.

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

	// List selects resources in the storage which match to the selector.
	List(ctx api.Context, label, field labels.Selector) (runtime.Object, error)

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

	// 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(ctx api.Context, id string) (<-chan runtime.Object, error)

	Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error)
	Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error)
}

RESTStorage is a generic interface for RESTful storage services. Resources which are exported to the RESTful API of apiserver need to implement this interface.

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 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, field labels.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 ServerStatus

type ServerStatus struct {
	Component  string        `json:"component,omitempty"`
	Health     string        `json:"health,omitempty"`
	HealthCode health.Status `json:"healthCode,omitempty"`
	Msg        string        `json:"msg,omitempty"`
	Err        string        `json:"err,omitempty"`
}

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.

type WorkFunc

type WorkFunc func() (result runtime.Object, err error)

WorkFunc is used to perform any time consuming work for an api call, after the input has been validated. Pass one of these to MakeAsync to create an appropriate return value for the Update, Delete, and Create methods.

Jump to

Keyboard shortcuts

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