api

package
v0.0.0-...-fb47ef5 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 33 Imported by: 7

Documentation

Index

Constants

View Source
const (
	RedocTemplate = `` /* 622-byte string literal not displayed */

	SwaggerTemplate = `` /* 1427-byte string literal not displayed */

)
View Source
const AnonymousUser = "anonymous" // anonymous username
View Source
const DefaultAuditLogCacheSize = 256
View Source
const MB = 1 << 20

Variables

View Source
var (
	NameRegexp          = regexp.MustCompile(`^[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*$`)
	NameWithSlashRegexp = regexp.MustCompile(`^[a-zA-Z0-9]+(?:[._/-][a-zA-Z0-9]+)*$`)
)
View Source
var DecisionDenyStatusNotFoundMessage = "not found"
View Source
var MethodActionMapPlural = map[string]string{
	"GET":    "list",
	"POST":   "create",
	"DELETE": "removeBatch",
	"PUT":    "updateBatch",
}

plural

View Source
var MethodActionMapSingular = map[string]string{
	"GET":    "get",
	"PUT":    "update",
	"DELETE": "remove",
	"PATCH":  "patch",
}

singular plural

Functions

func ExtracTokenFromRequest

func ExtracTokenFromRequest(r *http.Request) string

func ExtractClientIP

func ExtractClientIP(r *http.Request) string

func HttpHeaderToMap

func HttpHeaderToMap(header http.Header) map[string]string

func InCIDR

func InCIDR(ip string, cidrs []string) bool

func MatchMIME

func MatchMIME(accept string, supported []string) bool

func MediaTypeCheckFunc

func MediaTypeCheckFunc(accepts, produces []string, handler http.Handler) http.HandlerFunc

func MethodNotAllowed

func MethodNotAllowed(w http.ResponseWriter, r *http.Request)

func NewDefauBodyltValidation

func NewDefauBodyltValidation() func(r *http.Request, data any) error

func NewRedocUI

func NewRedocUI(specPath string) []byte

func NewSwaggerUI

func NewSwaggerUI(specPath string) []byte

func NotAcceptable

func NotAcceptable(w http.ResponseWriter, r *http.Request)

The HyperText Transfer Protocol (HTTP) 406 Not Acceptable client error response code indicates that the server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiation headers, and that the server is unwilling to supply a default representation.

func PathVars

func PathVars(r *http.Request) request.PathVarList

func ReadBodySafely

func ReadBodySafely(req *http.Request, allowsContentType []string, maxReadSize int) []byte

func RequestSourceIPInCIDR

func RequestSourceIPInCIDR(cidrs []string, r *http.Request) bool

func ResponseHeaderFromContext

func ResponseHeaderFromContext(ctx context.Context) http.Header

func SetAuditExtra

func SetAuditExtra(req *http.Request, k, v string)

func UnsupportedMediaType

func UnsupportedMediaType(w http.ResponseWriter, r *http.Request)

func WithAttributes

func WithAttributes(ctx context.Context, attributes *Attributes) context.Context

func WithAuditLog

func WithAuditLog(ctx context.Context, log *AuditLog) context.Context

func WithAuthenticate

func WithAuthenticate(ctx context.Context, info AuthenticateInfo) context.Context

func WithAuthorizationContext

func WithAuthorizationContext(ctx context.Context, decision Decision) context.Context

Types

type API

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

func NewAPI

func NewAPI() *API

func (*API) Build

func (m *API) Build() http.Handler

func (*API) Group

func (m *API) Group(groups ...Group) *API

func (*API) NotFound

func (m *API) NotFound(handler http.Handler) *API

func (*API) Plugin

func (m *API) Plugin(plugin ...Plugin) *API

func (*API) PrefixGroup

func (m *API) PrefixGroup(prefix string, groups ...Group) *API

func (*API) Route

func (m *API) Route(route Route) *API

func (*API) Serve

func (m *API) Serve(ctx context.Context, listenaddr string) error

func (*API) TLS

func (m *API) TLS(cert, key string) *API

type APIDocPlugin

type APIDocPlugin struct {
	Bbasepath string
	Swagger   *spec.Swagger
	Builder   *openapi.Builder
}

func NewAPIDocPlugin

func NewAPIDocPlugin(basepath string, fn func(swagger *spec.Swagger)) *APIDocPlugin

func (*APIDocPlugin) Install

func (s *APIDocPlugin) Install(m *API) error

Install implements Plugin.

func (*APIDocPlugin) OnRoute

func (s *APIDocPlugin) OnRoute(route *Route) error

OnRoute implements Plugin.

type AnonymousAuthenticator

type AnonymousAuthenticator struct{}

func NewAnonymousAuthenticator

func NewAnonymousAuthenticator() *AnonymousAuthenticator

func (*AnonymousAuthenticator) Authenticate

func (a *AnonymousAuthenticator) Authenticate(ctx context.Context, token string) (*AuthenticateInfo, error)

type AttrbuteResource

type AttrbuteResource struct {
	Resource string `json:"resource,omitempty"`
	Name     string `json:"name,omitempty"`
}

func DefaultRestAttributeExtractor

func DefaultRestAttributeExtractor(method string, path string) (string, []AttrbuteResource)

type AttributeExtractor

type AttributeExtractor func(r *http.Request) (*Attributes, error)

func PrefixedAttributesExtractor

func PrefixedAttributesExtractor(prefix string) AttributeExtractor

type Attributes

type Attributes struct {
	Action    string             `json:"action,omitempty"`
	Resources []AttrbuteResource `json:"resources,omitempty"`
	Path      string             `json:"path,omitempty"`
}

func AttributesFromContext

func AttributesFromContext(ctx context.Context) *Attributes

func (Attributes) ToWildcards

func (a Attributes) ToWildcards() (string, string)

return wildcards for action and expression e.g. action: get, resources: [AttrbuteResource{Resource: "namespaces", Name: "default"}] -> "get", "namespaces:default"

type AuditExtraMetadata

type AuditExtraMetadata map[string]string

type AuditLog

type AuditLog struct {
	SSH *AuditSSH `json:"ssh,omitempty"` // for ssh only
	// request
	Request  AuditRequest  `json:"request,omitempty"`
	Response AuditResponse `json:"response,omitempty"`
	// authz
	Subject string `json:"subject,omitempty"` // username
	// Resource is the resource type, e.g. "pods", "namespaces/default/pods/nginx-xxx"
	// we can detect the resource type and name from the request path.
	// GET  /zoos/{zoo_id}/animals/{animal_id} 	-> get zoos,zoo_id,animals,animal_id
	// GET  /zoos/{zoo_id}/animals 				-> list zoos,zoo_id,animals,animal_id
	// POST /zoos/{zoo_id}/animals:set-free 	-> set-free zoos,zoo_id,animals
	Action       string             `json:"action,omitempty"`       // create, update, delete, get, list, set-free, etc.
	Domain       string             `json:"domain,omitempty"`       // for multi-tenant
	Parents      []AttrbuteResource `json:"parents,omitempty"`      // parent resources, e.g. "zoos/{zoo_id}",
	Resource     string             `json:"resource,omitempty"`     // resource type, e.g. "animals"
	ResourceName string             `json:"resourceName,omitempty"` //  "{animal_id}", or "" if list
	// metadata
	StartTime time.Time          `json:"startTime,omitempty"` // request start time
	EndTime   time.Time          `json:"endTime,omitempty"`   // request end time
	Metadata  AuditExtraMetadata `json:"metadata,omitempty"`  // extra metadata
}

func AuditLogFromContext

func AuditLogFromContext(ctx context.Context) *AuditLog

type AuditRequest

type AuditRequest struct {
	HttpVersion string            `json:"httpVersion,omitempty"` // http version
	Method      string            `json:"method,omitempty"`      // method
	URL         string            `json:"url,omitempty"`         // full url
	Header      map[string]string `json:"header,omitempty"`      // header
	Body        []byte            `json:"body,omitempty"`        // ignore body if size > 1MB or stream.
	ClientIP    string            `json:"clientIP,omitempty"`    // client ip
	RemoteAddr  string            `json:"remoteAddr,omitempty"`
	LocalAddr   string            `json:"localAddr,omitempty"`
}

type AuditResponse

type AuditResponse struct {
	StatusCode   int               `json:"statusCode,omitempty"`   // status code
	Header       map[string]string `json:"header,omitempty"`       // header
	ResponseBody []byte            `json:"responseBody,omitempty"` // ignore body if size > 1MB or stream.
}

type AuditSSH

type AuditSSH struct {
	User          string   `json:"user,omitempty"`
	RemoteAddr    string   `json:"remoteAddr,omitempty"`
	LocalAddr     string   `json:"localAddr,omitempty"`
	SessionID     string   `json:"sessionID,omitempty"`
	ClientVersion string   `json:"clientVersion,omitempty"`
	ServerVersion string   `json:"serverVersion,omitempty"`
	PublicKey     string   `json:"publicKey,omitempty"`
	Command       string   `json:"command,omitempty"`
	Env           []string `json:"env,omitempty"`
}

type AuditSink

type AuditSink interface {
	Save(log *AuditLog) error
}

func NewCachedAuditSink

func NewCachedAuditSink(ctx context.Context, sink AuditSink, maxCacheSize int) AuditSink

type Auditor

type Auditor interface {
	OnRequest(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *AuditLog)
	OnResponse(w http.ResponseWriter, r *http.Request, auditlog *AuditLog)
}

type AuthenticateErrorHandleFunc

type AuthenticateErrorHandleFunc func(w http.ResponseWriter, r *http.Request, err error)

type AuthenticateFunc

type AuthenticateFunc func(w http.ResponseWriter, r *http.Request) (*AuthenticateInfo, error)

type AuthenticateInfo

type AuthenticateInfo struct {
	// Audiences is the set of audiences the authenticator was able to validate
	// the token against. If the authenticator is not audience aware, this field
	// will be empty.
	Audiences []string
	// User is the UserInfo associated with the authentication context.
	User UserInfo
}

func AuthenticateFromContext

func AuthenticateFromContext(ctx context.Context) AuthenticateInfo

type AuthenticatorChain

type AuthenticatorChain []TokenAuthenticator

func (AuthenticatorChain) Authenticate

func (c AuthenticatorChain) Authenticate(ctx context.Context, token string) (*AuthenticateInfo, error)

type Authorizer

type Authorizer interface {
	Authorize(ctx context.Context, user UserInfo, a Attributes) (authorized Decision, reason string, err error)
}

func NewAlwaysAllowAuthorizer

func NewAlwaysAllowAuthorizer() Authorizer

func NewAlwaysDenyAuthorizer

func NewAlwaysDenyAuthorizer() Authorizer

func NewCacheAuthorizer

func NewCacheAuthorizer(authorizer Authorizer, size int, ttl time.Duration) Authorizer

type AuthorizerChain

type AuthorizerChain []Authorizer

func (AuthorizerChain) Authorize

func (c AuthorizerChain) Authorize(ctx context.Context, user UserInfo, a Attributes) (Decision, string, error)

type AuthorizerFunc

type AuthorizerFunc func(ctx context.Context, user UserInfo, a Attributes) (authorized Decision, reason string, err error)

func (AuthorizerFunc) Authorize

func (f AuthorizerFunc) Authorize(ctx context.Context, user UserInfo, a Attributes) (authorized Decision, reason string, err error)

type CachedAuditSink

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

func (*CachedAuditSink) Save

func (c *CachedAuditSink) Save(log *AuditLog) error

type CachedBody

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

func NewCachedBody

func NewCachedBody(body io.ReadCloser, cached []byte, earlyerr error) *CachedBody

NewCachedBody returns a new CachedBody. a CachedBody is a io.ReadCloser that read from cached first, then read from body.

func (*CachedBody) Close

func (w *CachedBody) Close() error

func (*CachedBody) Read

func (w *CachedBody) Read(p []byte) (n int, err error)

type CompresseWriter

type CompresseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*CompresseWriter) Flush

func (cw *CompresseWriter) Flush()

type ContextKey

type ContextKey string

type Decision

type Decision int
const (
	DecisionDeny Decision = iota
	DecisionAllow
	DecisionNoOpinion
)

func AuthorizationContextFromContext

func AuthorizationContextFromContext(ctx context.Context) (Decision, bool)

type Filter

type Filter interface {
	Process(w http.ResponseWriter, r *http.Request, next http.Handler)
}

func CORSFilter

func CORSFilter() Filter

func LoggingFilter

func LoggingFilter(log logr.Logger) Filter

func NewAttributeFilter

func NewAttributeFilter(attributer AttributeExtractor) Filter

func NewAuditEndFilter

func NewAuditEndFilter(auditor Auditor, sink AuditSink) Filter

func NewAuditFilter

func NewAuditFilter(auditor Auditor, sink AuditSink) Filter

func NewAuditStartFilter

func NewAuditStartFilter(auditor Auditor) Filter

func NewAuthenticateFilter

func NewAuthenticateFilter(onauth AuthenticateFunc, onerr AuthenticateErrorHandleFunc) Filter

func NewAuthorizationFilter

func NewAuthorizationFilter(authorizer Authorizer) Filter

func NewCompressionFilter

func NewCompressionFilter() Filter

NewCompressionFilter returns a filter that compresses the response body

func NewConditionFilter

func NewConditionFilter(cond func(r *http.Request) bool, filter Filter) Filter

func NewRequestAuthorizationFilter

func NewRequestAuthorizationFilter(on RequestAuthorizerFunc) Filter

func NewTokenAuthenticationFilter

func NewTokenAuthenticationFilter(authenticator TokenAuthenticator) Filter

func NewTokenAuthenticationFilterWithErrHandle

func NewTokenAuthenticationFilterWithErrHandle(authenticator TokenAuthenticator, errhandle AuthenticateErrorHandleFunc) Filter

func NoopFilter

func NoopFilter() Filter

type FilterFunc

type FilterFunc func(w http.ResponseWriter, r *http.Request, next http.Handler)

func NewOpenTelemetryFilter

func NewOpenTelemetryFilter(tracer trace.Tracer) FilterFunc

func (FilterFunc) Process

func (f FilterFunc) Process(w http.ResponseWriter, r *http.Request, next http.Handler)

type Filters

type Filters []Filter

func (Filters) Process

func (fs Filters) Process(w http.ResponseWriter, r *http.Request, next http.Handler)

type Group

type Group struct {
	Path      string
	Filters   Filters
	Tags      []string
	Params    []Param // common params apply to all routes in the group
	Routes    []Route
	SubGroups []Group // sub groups
	Consumes  []string
	Produces  []string
}

func NewGroup

func NewGroup(path string) Group

func (Group) Accept

func (g Group) Accept(mime ...string) Group

Accept match request Accept header

func (Group) Build

func (t Group) Build() map[string]map[string]Route

func (Group) ContentType

func (g Group) ContentType(mime ...string) Group

ContentType match request Content-Type header

func (Group) Filter

func (g Group) Filter(filters ...Filter) Group

func (Group) Param

func (g Group) Param(params ...Param) Group

func (Group) Route

func (g Group) Route(rs ...Route) Group

func (Group) SubGroup

func (g Group) SubGroup(groups ...Group) Group

func (Group) Tag

func (g Group) Tag(name string) Group

type HTTPAuthenticateFunc

type HTTPAuthenticateFunc func(ctx context.Context, r *http.Request) (*AuthenticateInfo, error)

func (HTTPAuthenticateFunc) Authenticate

type HTTPAuthenticator

type HTTPAuthenticator interface {
	Authenticate(ctx context.Context, r *http.Request) (*AuthenticateInfo, error)
}

type HealthCheckPlugin

type HealthCheckPlugin struct {
	NoopPlugin
	CheckFun func() error
}

func (HealthCheckPlugin) Install

func (h HealthCheckPlugin) Install(m *API) error

type LRUCache

type LRUCache[T any] struct {
	// contains filtered or unexported fields
}

func NewLRUCache

func NewLRUCache[T any](size int, ttl time.Duration) LRUCache[T]

func (LRUCache[T]) GetOrAdd

func (c LRUCache[T]) GetOrAdd(key string, fn func() (T, error)) (T, error)

type LRUCacheAuthenticator

type LRUCacheAuthenticator struct {
	Authenticator TokenAuthenticator
	Cache         LRUCache[*AuthenticateInfo]
}

func NewCacheAuthenticator

func NewCacheAuthenticator(authenticator TokenAuthenticator, size int, ttl time.Duration) *LRUCacheAuthenticator

func (*LRUCacheAuthenticator) Authenticate

func (a *LRUCacheAuthenticator) Authenticate(ctx context.Context, token string) (*AuthenticateInfo, error)

Authenticate implements TokenAuthenticator.

type LRUCacheAuthorizer

type LRUCacheAuthorizer struct {
	Authorizer Authorizer
	// contains filtered or unexported fields
}

func (*LRUCacheAuthorizer) Authorize

func (c *LRUCacheAuthorizer) Authorize(ctx context.Context, user UserInfo, a Attributes) (authorized Decision, reason string, err error)

Authorize implements Authorizer.

type LRUCacheSSHAuthenticator

type LRUCacheSSHAuthenticator struct {
	Authenticator SSHAuthenticator
	Cache         LRUCache[*AuthenticateInfo]
}

func NewCachedSSHAuthenticator

func NewCachedSSHAuthenticator(authenticator SSHAuthenticator, size int, ttl time.Duration) *LRUCacheSSHAuthenticator

func (*LRUCacheSSHAuthenticator) Authenticate

func (a *LRUCacheSSHAuthenticator) Authenticate(ctx context.Context, username, password string) (*AuthenticateInfo, error)

AuthenticatePassword implements SSHAuthenticator.

func (*LRUCacheSSHAuthenticator) AuthenticatePublibcKey

func (a *LRUCacheSSHAuthenticator) AuthenticatePublibcKey(ctx context.Context, pubkey ssh.PublicKey) (*AuthenticateInfo, error)

AuthenticatePublibcKey implements SSHAuthenticator.

type LoggerAuditSink

type LoggerAuditSink struct {
	Sink   AuditSink
	Logger logr.Logger
}

func (*LoggerAuditSink) Save

func (l *LoggerAuditSink) Save(log *AuditLog) error

type MethodsHandler

type MethodsHandler map[string]http.Handler

func (MethodsHandler) ServeHTTP

func (h MethodsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Mux

type Mux struct {
	NotFound http.Handler
	Tree     matcher.Node[MethodsHandler]
}

func NewMux

func NewMux() *Mux

func (*Mux) Handle

func (m *Mux) Handle(method, pattern string, handler http.Handler) error

func (*Mux) HandleRoute

func (m *Mux) HandleRoute(route *Route) error

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Mux) SetNotFound

func (m *Mux) SetNotFound(handler http.Handler)

type NoopPlugin

type NoopPlugin struct{}

func (NoopPlugin) Install

func (n NoopPlugin) Install(m *API) error

func (NoopPlugin) OnRoute

func (n NoopPlugin) OnRoute(route *Route) error

type OIDCAuthenticator

type OIDCAuthenticator struct {
	Verifier               *oidc.IDTokenVerifier
	UsernameClaimCandidate []string
	EmailClaimCandidate    []string
	GroupsClaimCandidate   []string
	EmailToUsername        func(email string) string
}

func NewOIDCAuthenticator

func NewOIDCAuthenticator(ctx context.Context, opts *OIDCOptions) (*OIDCAuthenticator, error)

func (*OIDCAuthenticator) Authenticate

func (o *OIDCAuthenticator) Authenticate(ctx context.Context, token string) (*AuthenticateInfo, error)

type OIDCOptions

type OIDCOptions struct {
	Issuer   string `json:"issuer" description:"oidc issuer url"`
	Insecure bool   `json:"insecure" description:"skip issuer and audience verification"`

	// ClientID is the OAuth2 client ID for this server.
	ClientID string `json:"clientID" description:"oidc client id"`

	// ClientSecret is the secret for the client ID. If no secret is provided,
	// the client is assumed to be a public client and authentication will
	// proceed without a client secret.
	ClientSecret string `json:"clientSecret" description:"oidc client secret"`

	// Scopes is the set of scopes to request.
	Scope []string `json:"scope" description:"oidc scope"`
}

func NewDefaultOIDCOptions

func NewDefaultOIDCOptions() *OIDCOptions

type OpenTelemetryPlugin

type OpenTelemetryPlugin struct {
	TraceProvider trace.TracerProvider
}

func (OpenTelemetryPlugin) Install

func (o OpenTelemetryPlugin) Install(m *API) error

func (OpenTelemetryPlugin) OnRoute

func (o OpenTelemetryPlugin) OnRoute(route *Route) error

type Param

type Param struct {
	Name        string
	Kind        ParamKind
	Type        string
	Enum        []any
	Default     any
	IsOptional  bool
	Description string
	Example     any
	Pattern     string
}

func BodyParam

func BodyParam(name string, value any) Param

func FormParam

func FormParam(name string, description string) Param

func PathParam

func PathParam(name string, description string) Param

func QueryParam

func QueryParam(name string, description string) Param

func (Param) DataType

func (p Param) DataType(t string) Param

func (Param) Def

func (p Param) Def(def string) Param

func (Param) Desc

func (p Param) Desc(desc string) Param

func (Param) In

func (p Param) In(t ...any) Param

func (Param) Optional

func (p Param) Optional() Param

type ParamKind

type ParamKind string
const (
	ParamKindPath   ParamKind = "path"
	ParamKindQuery  ParamKind = "query"
	ParamKindHeader ParamKind = "header"
	ParamKindForm   ParamKind = "formData"
	ParamKindBody   ParamKind = "body"
)

type Plugin

type Plugin interface {
	Install(m *API) error
	OnRoute(route *Route) error
}

type PredicatedFilter

type PredicatedFilter struct {
	Predicate func(r *http.Request) bool
	Filter    Filter
}

func (PredicatedFilter) Process

func (f PredicatedFilter) Process(w http.ResponseWriter, r *http.Request, next http.Handler)

type RequestAuthorizer

type RequestAuthorizer interface {
	AuthorizeRequest(r *http.Request) (Decision, string, error)
}

func NewAllowCIDRAuthorizer

func NewAllowCIDRAuthorizer(cidrs []string, defaultDec Decision) RequestAuthorizer

type RequestAuthorizerFunc

type RequestAuthorizerFunc func(r *http.Request) (Decision, string, error)

func (RequestAuthorizerFunc) AuthorizeRequest

func (f RequestAuthorizerFunc) AuthorizeRequest(r *http.Request) (Decision, string, error)

type ResponseInfo

type ResponseInfo struct {
	Code        int
	Headers     map[string]string
	Body        interface{}
	Description string
}

type Route

type Route struct {
	Summary    string
	Path       string
	Method     string
	Deprecated bool
	Handler    http.Handler
	Filters    Filters
	Tags       []string
	Consumes   []string
	Produces   []string
	Params     []Param
	Responses  []ResponseInfo
	Properties map[string]interface{}
}

func Any

func Any(path string) Route

func DELETE

func DELETE(path string) Route

func Do

func Do(method string, path string) Route

func GET

func GET(path string) Route
func HEAD(path string) Route

func OPTIONS

func OPTIONS(path string) Route

func PATCH

func PATCH(path string) Route

func POST

func POST(path string) Route

func PUT

func PUT(path string) Route

func (Route) Accept

func (n Route) Accept(mime ...string) Route

Accept match request Accept header

func (Route) ContentType

func (n Route) ContentType(mime ...string) Route

ContentType match request Content-Type header

func (Route) Doc

func (n Route) Doc(summary string) Route

func (Route) Param

func (n Route) Param(params ...Param) Route

func (Route) Property

func (n Route) Property(k string, v interface{}) Route

func (Route) Response

func (n Route) Response(body interface{}, desc ...string) Route

func (Route) ResponseStatus

func (n Route) ResponseStatus(status int, body interface{}, desc ...string) Route

func (Route) ServeHTTP

func (route Route) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (Route) Tag

func (n Route) Tag(tags ...string) Route

func (Route) To

func (n Route) To(fun http.HandlerFunc) Route

type Router

type Router interface {
	HandleRoute(route *Route) error
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	SetNotFound(handler http.Handler)
}

type SSHAuthenticator

type SSHAuthenticator interface {
	UsernamePasswordAuthenticator
	AuthenticatePublibcKey(ctx context.Context, pubkey ssh.PublicKey) (*AuthenticateInfo, error)
}

type SimpleAuditor

type SimpleAuditor struct {
	RecordReadBody                bool     // Record read actions
	RecordRequestBodyContentTypes []string // Record only for these content types
	MaxBodySize                   int      // Max body size to record,0 means disable
	WhiteList                     []string // White list
}

func NewSimpleAuditor

func NewSimpleAuditor() *SimpleAuditor

func (*SimpleAuditor) OnRequest

func (*SimpleAuditor) OnResponse

func (a *SimpleAuditor) OnResponse(w http.ResponseWriter, r *http.Request, auditlog *AuditLog)

type StatusResponseWriter

type StatusResponseWriter struct {
	Inner        http.ResponseWriter
	Code         int
	Cache        []byte
	MaxCacheSize int
}

func (*StatusResponseWriter) Header

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

func (*StatusResponseWriter) Write

func (w *StatusResponseWriter) Write(p []byte) (n int, err error)

func (*StatusResponseWriter) WriteHeader

func (w *StatusResponseWriter) WriteHeader(statusCode int)

type TokenAuthenticator

type TokenAuthenticator interface {
	// Authenticate authenticates the token and returns the authentication info.
	// if can't authenticate, return nil, "reason message", nil
	// if unexpected error, return nil, "", err
	Authenticate(ctx context.Context, token string) (*AuthenticateInfo, error)
}

type UserInfo

type UserInfo struct {
	ID            string              `json:"id,omitempty"`
	Name          string              `json:"name,omitempty"`
	Email         string              `json:"email,omitempty"`
	EmailVerified bool                `json:"email_verified,omitempty"`
	Groups        []string            `json:"groups,omitempty"`
	Extra         map[string][]string `json:"extra,omitempty"`
}

type UsernamePasswordAuthenticator

type UsernamePasswordAuthenticator interface {
	Authenticate(ctx context.Context, username, password string) (*AuthenticateInfo, error)
}

type VersionPlugin

type VersionPlugin struct {
	NoopPlugin
	Version any
}

func (VersionPlugin) Install

func (v VersionPlugin) Install(m *API) error

Jump to

Keyboard shortcuts

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