responsewriters

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeHeader  = "Content-Type"
	DefaultContentType = "application/json"
)

Variables

This section is empty.

Functions

func GetContentTypeHeader

func GetContentTypeHeader(header http.Header) string

GetContentTypeHeader checks for the presence of the "Content-Type" header and returns its value or returns the default content-type: "application/json".

func SetContentTypeHeader

func SetContentTypeHeader(w http.ResponseWriter, header http.Header)

SetContentTypeHeader checks for the presence of the "Content-Type" header and sets its media type value or sets the default content-type: "application/json".

Types

type Filter

type Filter interface {
	FilterObj
	FilterBuffer
}

Filter is the interface a Kubernetes Resource filter must implement.

type FilterBuffer

type FilterBuffer interface {
	// FilterBuffer receives a byte array, decodes the response into the appropriate
	// type and filters the resources based on allowed and denied rules configured.
	// After filtering them, it serializes the response and dumps it into output buffer.
	// If any error occurs, the call returns an error.
	FilterBuffer(buf []byte, output io.Writer) error
}

FilterBuffer is the interface a Kubernetes Resource response filter must implement.

type FilterObj

type FilterObj interface {
	// FilterObj receives a runtime.Object type and filters the resources on it
	// based on allowed and denied rules.
	// After filtering them, the obj is manipulated to hold the filtered information.
	// The isAllowed boolean returned indicates if the client is allowed to receive the event
	// with the object.
	// The isListObj boolean returned indicates if the object is a list of resources.
	FilterObj(obj runtime.Object) (isAllowed bool, isListObj bool, err error)
}

FilterObj is the interface a Kubernetes Resource Object filter must implement.

type FilterWrapper

type FilterWrapper func(contentType string, responseCode int) (Filter, error)

FilterWrapper is the wrapper function signature that once executed creates a runtime filter for Pods. The filter exclusion criteria is: - deniedPods: excluded if (namespace,name) matches an entry even if it matches the allowedPod's list. - allowedPods: excluded if (namespace,name) not match a single entry.

type MemoryResponseWriter

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

MemoryResponseWriter satisfies the http.ResponseWriter interface and accumulates the response body and headers into a memory for later usage.

func NewMemoryResponseWriter

func NewMemoryResponseWriter() *MemoryResponseWriter

NewMemoryResponseWriter creates a MemoryResponseWriter that satisfies the http.ResponseWriter interface and accumulates the response into a memory buffer for later decoding.

func (*MemoryResponseWriter) Buffer

func (f *MemoryResponseWriter) Buffer() *bytes.Buffer

Buffer exposes the memory buffer.

func (*MemoryResponseWriter) CopyInto

func (f *MemoryResponseWriter) CopyInto(dst http.ResponseWriter) error

CopyInto copies the headers, response code and body into the provided response writer.

func (*MemoryResponseWriter) Header

func (f *MemoryResponseWriter) Header() http.Header

Header returns the http.Header map.

func (*MemoryResponseWriter) Status

func (f *MemoryResponseWriter) Status() int

Status returns the http response code.

func (*MemoryResponseWriter) Write

func (f *MemoryResponseWriter) Write(b []byte) (int, error)

Write appends b into the memory buffer.

func (*MemoryResponseWriter) WriteHeader

func (f *MemoryResponseWriter) WriteHeader(status int)

WriteHeader stores the response status code.

type WatcherResponseWriter

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

WatcherResponseWriter satisfies the http.ResponseWriter interface and once the server writes the headers and response code spins a goroutine that parses each event frame, decodes it and analyzes if the user is allowed to receive the events for that pod. If the user is not allowed, the event is ignored. If allowed, the event is encoded into the user's response.

func NewWatcherResponseWriter

func NewWatcherResponseWriter(
	target http.ResponseWriter,
	negotiator runtime.ClientNegotiator,
	filter FilterWrapper,
) (*WatcherResponseWriter, error)

NewWatcherResponseWriter creates a new WatcherResponseWriter.

func (*WatcherResponseWriter) Close

func (w *WatcherResponseWriter) Close() error

Close closes the reader part of the pipe with io.EOF and waits until the spinned goroutine terminates. After closes the writer pipe and flushes the response into target.

func (*WatcherResponseWriter) Flush

func (w *WatcherResponseWriter) Flush()

Flush flushes the response into the target and returns.

func (*WatcherResponseWriter) Header

func (w *WatcherResponseWriter) Header() http.Header

Header returns the target headers.

func (*WatcherResponseWriter) Status

func (w *WatcherResponseWriter) Status() int

Status returns the http status response.

func (*WatcherResponseWriter) Write

func (w *WatcherResponseWriter) Write(buf []byte) (int, error)

Write writes buf into the pipeWriter.

func (*WatcherResponseWriter) WriteHeader

func (w *WatcherResponseWriter) WriteHeader(code int)

WriteHeader writes the status code and headers into the target http.ResponseWriter and spins a go-routine that will wait for events received in w.pipeReader and analyze if they must be forwarded to target.

Jump to

Keyboard shortcuts

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