handlers

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MPL-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpOnlyCookieName  = "wt-http-token-cookie"
	JsVisibleCookieName = "wt-js-token-cookie"

	StatusCodeHeader = "x-http-code"
)

Variables

This section is empty.

Functions

func ApiErrorWithCode

func ApiErrorWithCode(c codes.Code) error

ApiErrorWithCode returns an api error with the provided code.

func ApiErrorWithCodeAndMessage

func ApiErrorWithCodeAndMessage(c codes.Code, msg string, args ...interface{}) error

ApiErrorWithCodeAndMessage returns an api error with the provided code and message.

func ErrorHandler

func ErrorHandler() runtime.ErrorHandlerFunc

func ForbiddenError

func ForbiddenError() error

func GetOpts added in v0.2.0

func GetOpts(opt ...Option) options

GetOpts - iterate the inbound Options and return a struct

func JSONMarshaler added in v0.2.1

func JSONMarshaler() *runtime.JSONPb

JSONMarshaler provides marshaler used for marshaling all proto as JSON in a format expected by the user facing controller API.

func MaskContains

func MaskContains(paths []string, s string) bool

func NotFoundError

func NotFoundError() error

NotFoundError returns an ApiError indicating a resource couldn't be found.

func OutgoingResponseFilter added in v0.7.0

func OutgoingResponseFilter(ctx context.Context, w http.ResponseWriter, m proto.Message) error

OutgoingResponseFilter is a gRPC gateway WithForwardResponseOption. It's basically a filter that can manipulate the http response and has acesss to the outgoing proto msg

func ProtoToStruct

func ProtoToStruct(p proto.Message) (*structpb.Struct, error)

func SetStatusCode added in v0.7.0

func SetStatusCode(ctx context.Context, code int) error

SetStatusCode allows a grpc service handler to set the outgoing http status code

func StructToProto

func StructToProto(fields *structpb.Struct, p proto.Message, opt ...Option) error

func ToApiError added in v0.2.1

func ToApiError(e error) *pb.Error

func UnauthenticatedError

func UnauthenticatedError() error

func ValidId

func ValidId(i Id, prefixes ...string) bool

func ValidNameDescription added in v0.1.1

func ValidNameDescription(in string) bool

func ValidateCreateRequest

func ValidateCreateRequest(i ApiResource, fn CustomValidatorFunc) error

func ValidateDeleteRequest

func ValidateDeleteRequest(fn CustomValidatorFunc, r DeleteRequest, prefix ...string) error

func ValidateGetRequest

func ValidateGetRequest(fn CustomValidatorFunc, r GetRequest, prefix ...string) error

func ValidateUpdateRequest

func ValidateUpdateRequest(r UpdateRequest, i ApiResource, fn CustomValidatorFunc, prefix ...string) error

Types

type ApiError added in v0.7.0

type ApiError struct {
	Status int32
	Inner  *pb.Error
}

func InvalidArgumentErrorf

func InvalidArgumentErrorf(msg string, fields map[string]string) *ApiError

func NotFoundErrorf

func NotFoundErrorf(msg string, a ...interface{}) *ApiError

NotFoundErrorf returns an ApiError indicating a resource couldn't be found.

func (*ApiError) Error added in v0.7.0

func (e *ApiError) Error() string

func (*ApiError) Is added in v0.7.0

func (e *ApiError) Is(target error) bool

type ApiResource

type ApiResource interface {
	GetId() string
	GetScope() *scopes.ScopeInfo
	GetName() *wrappers.StringValue
	GetDescription() *wrappers.StringValue
	GetCreatedTime() *timestamp.Timestamp
	GetUpdatedTime() *timestamp.Timestamp
	GetVersion() uint32
}

type CustomValidatorFunc

type CustomValidatorFunc func() map[string]string
var NoopValidatorFn CustomValidatorFunc = func() map[string]string { return nil }

type DeleteRequest

type DeleteRequest interface {
	GetId() string
}

type Filter added in v0.1.8

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

func NewFilter added in v0.1.8

func NewFilter(f string) (*Filter, error)

NewFilter returns a Filter which can be evluated against. An empty string paramter indicates all items passed to it should succeed.

func (*Filter) Match added in v0.1.8

func (f *Filter) Match(item interface{}) bool

Match returns if the provided interface matches the filter. If the filter does not match the structure of the object being Matched, false is returned. TODO: Support more than just matching against the item being filtered. Also allow matching against

values in the request or the request context itself.

type GetRequest

type GetRequest interface {
	GetId() string
}

type Id added in v0.2.0

type Id string

A boundary resource identifier

type MaskDestination added in v0.4.0

type MaskDestination []protoreflect.ProtoMessage

type MaskManager

type MaskManager map[string]string

func NewMaskManager

func NewMaskManager(dest MaskDestination, src MaskSource) (MaskManager, error)

NewMaskManager returns a mask manager that can translate field masks into the first proto from all subsequent protos assuming they are both using the mask_mapping custom option. Error is returned if no mappings are found or if one of the passed protos has a mapping that doesn't reciprocate.

func (MaskManager) Translate

func (m MaskManager) Translate(paths []string, passedThroughPrefix ...string) []string

Translate takes a field mask's paths and returns paths translated for the destination's protobuf. If a translation doesn't exist for a specific path entry then nothing is returned for that specific path entry unless passedThroughPrefix is used and applies to that entry.

passedThroughPrefix is helpful when the field mask's paths cannot be mapped through the mask mapper for some reason (we don't know the mapping at compile time, for example) but we still want certain paths to be passed on. If a path entry isn't mapped to anything by the MaskManager but does contain a prefix which matches a passedThroughPrefix it will be added unmodified to the returned value.

type MaskSource added in v0.4.0

type MaskSource []protoreflect.ProtoMessage

type Option added in v0.2.0

type Option func(*options)

Option - how Options are passed as arguments. Some of these are used for types within the handlers package, and some are for handlers to re-use across the various handler types.

func WithAuthorizedActions added in v0.2.1

func WithAuthorizedActions(acts []string) Option

WithAuthorizedActions provides an option when creating responses to include the given authorized actions if allowed

func WithAuthorizedCollectionActions added in v0.2.1

func WithAuthorizedCollectionActions(colActs map[string]*structpb.ListValue) Option

WithAuthorizedCollectionActions provides an option when creating responses to include the given authorized collection actions if allowed

func WithDiscardUnknownFields added in v0.2.0

func WithDiscardUnknownFields(discard bool) Option

WithDiscardUnknownFields provides an option to cause StructToProto to ignore unknown fields. This is useful in some instances when we need to unmarshal a value from a pb.Struct after we've added some custom extra fields.

func WithHostSetIds added in v0.7.0

func WithHostSetIds(ids []string) Option

WithHostSetIds provides an option when creating responses to include the given host set IDs if allowed

func WithManagedGroupIds added in v0.3.0

func WithManagedGroupIds(ids []string) Option

WithManagedGroupIds provides an option when creating responses to include the given managed group IDs if allowed

func WithMemberIds added in v0.3.0

func WithMemberIds(ids []string) Option

WithMemberIds provides an option when creating responses to include the given member IDs if allowed

func WithOutputFields added in v0.2.1

func WithOutputFields(fields *perms.OutputFieldsMap) Option

WithOutputFields provides an option when creating responses to only include specific fields

func WithPlugin added in v0.7.0

func WithPlugin(plg *plugins.PluginInfo) Option

WithPlugin provides an option when creating responses to include the given plugin if allowed

func WithScope added in v0.2.1

func WithScope(scp *scopes.ScopeInfo) Option

WithScope provides an option when creating responses to include the given scope if allowed

func WithUserIsAnonymous added in v0.2.1

func WithUserIsAnonymous(anonListing bool) Option

DEPRECATED: Superceded by WithOutputFields. Will be removed once all handlers have been migrated to that.

type UpdateRequest

type UpdateRequest interface {
	GetId() string
	GetUpdateMask() *field_mask.FieldMask
}

Jump to

Keyboard shortcuts

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