request

package
v0.0.0-...-0c42e4c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package request contains everything around extracting info from a http request object. TODO: this package is temporary. Handlers must move into pkg/apiserver/handlers to avoid dependency cycle

Index

Constants

This section is empty.

Variables

View Source
var NamespaceSubResourcesForTest = sets.NewString(namespaceSubresources.List()...)

NamespaceSubResourcesForTest exports namespaceSubresources for testing in pkg/master/master_test.go, so we never drift

Functions

func AuditEventFrom

func AuditEventFrom(ctx Context) *audit.Event

AuditEventFrom returns the audit event struct on the ctx

func IsEmpty

func IsEmpty(requestsToContexts RequestContextMapper) (bool, error)

IsEmpty returns true if there are no contexts registered, or an error if it could not be determined. Intended for use by tests.

func NamespaceFrom

func NamespaceFrom(ctx Context) (string, bool)

NamespaceFrom returns the value of the namespace key on the ctx

func NamespaceValue

func NamespaceValue(ctx Context) string

NamespaceValue returns the value of the namespace key on the ctx, or the empty string if none

func UIDFrom

func UIDFrom(ctx Context) (types.UID, bool)

UIDFrom returns the value of the uid key on the ctx

func UserAgentFrom

func UserAgentFrom(ctx Context) (string, bool)

UserAgentFrom returns the value of the userAgent key on the ctx

func UserFrom

func UserFrom(ctx Context) (user.Info, bool)

UserFrom returns the value of the user key on the ctx

func WithRequestContext

func WithRequestContext(handler http.Handler, mapper RequestContextMapper) http.Handler

WithRequestContext ensures there is a Context object associated with the request before calling the passed handler. After the passed handler runs, the context is cleaned up.

Types

type Context

type Context interface {
	// Value returns the value associated with key or nil if none.
	Value(key interface{}) interface{}

	// Deadline returns the time when this Context will be canceled, if any.
	Deadline() (deadline time.Time, ok bool)

	// Done returns a channel that is closed when this Context is canceled
	// or times out.
	Done() <-chan struct{}

	// Err indicates why this context was canceled, after the Done channel
	// is closed.
	Err() error
}

Context carries values across API boundaries. This context matches the context.Context interface (https://blog.golang.org/context), for the purposes of passing the api.Context through to the storage tier. TODO: Determine the extent that this abstraction+interface is used by the api, and whether we can remove.

func NewContext

func NewContext() Context

NewContext instantiates a base context object for request flows.

func NewDefaultContext

func NewDefaultContext() Context

NewDefaultContext instantiates a base context object for request flows in the default namespace

func WithAuditEvent

func WithAuditEvent(parent Context, ev *audit.Event) Context

WithAuditEvent returns set audit event struct.

func WithNamespace

func WithNamespace(parent Context, namespace string) Context

WithNamespace returns a copy of parent in which the namespace value is set

func WithNamespaceDefaultIfNone

func WithNamespaceDefaultIfNone(parent Context) Context

WithNamespaceDefaultIfNone returns a context whose namespace is the default if and only if the parent context has no namespace value

func WithRequestInfo

func WithRequestInfo(parent Context, info *RequestInfo) Context

WithRequestInfo returns a copy of parent in which the request info value is set

func WithUID

func WithUID(parent Context, uid types.UID) Context

WithUID returns a copy of parent in which the uid value is set

func WithUser

func WithUser(parent Context, user user.Info) Context

WithUser returns a copy of parent in which the user value is set

func WithUserAgent

func WithUserAgent(parent Context, userAgent string) Context

WithUserAgent returns a copy of parent in which the user value is set

func WithValue

func WithValue(parent Context, key interface{}, val interface{}) Context

WithValue returns a copy of parent in which the value associated with key is val.

type LongRunningRequestCheck

type LongRunningRequestCheck func(r *http.Request, requestInfo *RequestInfo) bool

LongRunningRequestCheck is a predicate which is true for long-running http requests.

type RequestContextMapper

type RequestContextMapper interface {
	// Get returns the context associated with the given request (if any), and true if the request has an associated context, and false if it does not.
	Get(req *http.Request) (Context, bool)
	// Update maps the request to the given context. If no context was previously associated with the request, an error is returned.
	// Update should only be called with a descendant context of the previously associated context.
	// Updating to an unrelated context may return an error in the future.
	// The context associated with a request should only be updated by a limited set of callers.
	// Valid examples include the authentication layer, or an audit/tracing layer.
	Update(req *http.Request, context Context) error
}

RequestContextMapper keeps track of the context associated with a particular request

func NewRequestContextMapper

func NewRequestContextMapper() RequestContextMapper

NewRequestContextMapper returns a new RequestContextMapper. The returned mapper must be added as a request filter using NewRequestContextFilter.

type RequestInfo

type RequestInfo struct {
	// IsResourceRequest indicates whether or not the request is for an API resource or subresource
	IsResourceRequest bool
	// Path is the URL path of the request
	Path string
	// Verb is the kube verb associated with the request for API requests, not the http verb.  This includes things like list and watch.
	// for non-resource requests, this is the lowercase http verb
	Verb string

	APIPrefix  string
	APIGroup   string
	APIVersion string
	Namespace  string
	// Resource is the name of the resource being requested.  This is not the kind.  For example: pods
	Resource string
	// Subresource is the name of the subresource being requested.  This is a different resource, scoped to the parent resource, but it may have a different kind.
	// For instance, /pods has the resource "pods" and the kind "Pod", while /pods/foo/status has the resource "pods", the sub resource "status", and the kind "Pod"
	// (because status operates on pods). The binding resource for a pod though may be /pods/foo/binding, which has resource "pods", subresource "binding", and kind "Binding".
	Subresource 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
}

RequestInfo holds information parsed from the http.Request

func RequestInfoFrom

func RequestInfoFrom(ctx Context) (*RequestInfo, bool)

RequestInfoFrom returns the value of the RequestInfo key on the ctx

type RequestInfoFactory

type RequestInfoFactory struct {
	APIPrefixes          sets.String // without leading and trailing slashes
	GrouplessAPIPrefixes sets.String // without leading and trailing slashes
}

func (*RequestInfoFactory) NewRequestInfo

func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, error)

TODO write an integration test against the swagger doc to test the RequestInfo and match up behavior to responses NewRequestInfo returns the information from the http request. If error is not nil, RequestInfo holds the information as best it is known before the failure It handles both resource and non-resource requests and fills in all the pertinent information for each. Valid Inputs: Resource paths /apis/{api-group}/{version}/namespaces /api/{version}/namespaces /api/{version}/namespaces/{namespace} /api/{version}/namespaces/{namespace}/{resource} /api/{version}/namespaces/{namespace}/{resource}/{resourceName} /api/{version}/{resource} /api/{version}/{resource}/{resourceName}

Special verbs without subresources: /api/{version}/proxy/{resource}/{resourceName} /api/{version}/proxy/namespaces/{namespace}/{resource}/{resourceName}

Special verbs with subresources: /api/{version}/watch/{resource} /api/{version}/watch/namespaces/{namespace}/{resource}

NonResource paths /apis/{api-group}/{version} /apis/{api-group} /apis /api/{version} /api /healthz /

type RequestInfoResolver

type RequestInfoResolver interface {
	NewRequestInfo(req *http.Request) (*RequestInfo, error)
}

Jump to

Keyboard shortcuts

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