validator

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsOCMClientAuthError

func IsOCMClientAuthError(err error) bool

func IsOCMServerSideError

func IsOCMServerSideError(err error) bool

IsOCMServerSideError determines if the given error is both an instance of OCMError and was caused by a server-side issue.

func Register

func Register(init Initializer)

Register queues an "Initializer" which the "Runner" will invoke upon startup.

Types

type Base

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

Base implements the base functionality used by Validator instances.

func NewBase

func NewBase(code Code, opts ...BaseOption) (*Base, error)

NewBase returns a base Validator implementation with a given code and optional parameters. An error is returned if an invalid code is given.

func (*Base) Code

func (b *Base) Code() Code

func (*Base) Default

func (b *Base) Default()

Default applies default values for any unconfigured options.

func (*Base) Description

func (b *Base) Description() string

func (*Base) Error

func (b *Base) Error(err error) Result

Error is a helper which returns a populated Error result. An error instnace is passed to give context for what error caused a validation task to exit.

func (*Base) Fail

func (b *Base) Fail(msgs ...string) Result

Fail is a helper which returns a populated Fail result. A variadic slice of messages are passed to describe the reason(s) that a validation task failed.

func (*Base) Name

func (b *Base) Name() string

func (*Base) Option

func (b *Base) Option(opts ...BaseOption)

Option applies a variadic slice of options to a Base instance.

func (*Base) RetryableError

func (b *Base) RetryableError(err error) Result

RetryableError is a helper which returns a populated RetryableError result. A RetryableError indicates to middleware that the error is temporary and may be retried.

func (*Base) Success

func (b *Base) Success() Result

Success is a helper which returns a populated Success result.

type BaseOption

type BaseOption func(*Base)

BaseOption abstracts functions which apply optional parameters to a Base instance.

func BaseDesc

func BaseDesc(desc string) BaseOption

BaseDesc applies the given description to a base instance.

func BaseName

func BaseName(name string) BaseOption

BaseName applies the given name to a base instance.

type Code

type Code int

Code is a prefixed integer ID used to distinguish Validator implementations.

func ParseCode

func ParseCode(maybeCode string) (Code, error)

ParseCode converts a given string to a Code value. An error is returned if the string is incorrectly formatted.

func (Code) String

func (c Code) String() string

type Dependencies

type Dependencies struct {
	Logger    logr.Logger
	OCMClient OCMClient
}

Dependencies abstracts common dependencies for Validators.

type Filter

type Filter func(Validator) bool

func MatchesCodes

func MatchesCodes(codes ...Code) Filter

func Not

func Not(f Filter) Filter

type Initializer

type Initializer func(Dependencies) (Validator, error)

Initializer is a function which will initialize a Validator with dependencies. An error is returned if the Validator cannot be initalized properly.

type Middleware

type Middleware interface {
	Wrap(RunFunc) RunFunc
}

type OCMClient

type OCMClient interface {
	QuotaRuleGetter
	// Stuck here until OCM Client can be injected via Params...
	CloseConnection() error
}

OCMClient abstracts behavior required for validators which request data from OCM to be implemented by OCM API clients.

type OCMClientError

type OCMClientError interface {
	IsAuthRelated() bool
}

type OCMError

type OCMError interface {
	// ServerSide returns 'true' if an instance of OCMError was caused
	// by a server-side issue.
	ServerSide() bool
}

OCMError abstracts behavior required for validators to identify the underlying causes of OCM related errors.

type QuotaRuleGetter

type QuotaRuleGetter interface {
	QuotaRuleExists(context.Context, string) (bool, error)
}

type Result

type Result struct {
	Code        Code
	Name        string
	Description string
	FailureMsgs []string
	Error       error
	// contains filtered or unexported fields
}

Result encapsulates the status and reason for the result of a Validator task running against a types.MetaBundle.

func (Result) IsError

func (r Result) IsError() bool

IsError returns 'true' if the Validator task which returned it encountered an error.

func (Result) IsRetryableError

func (r Result) IsRetryableError() bool

IsRetryableError returns 'true' if the Validator task which returned it encountered an error, but the error can be retried.

func (Result) IsSuccess

func (r Result) IsSuccess() bool

IsSuccess returns 'true' if the Validator task which returned it was successful.

type ResultList

type ResultList []Result

ResultList is a sortable slice of Result instances.

func (ResultList) Errors

func (l ResultList) Errors() []error

Errors returns a slice of errors from the ResultList members. If no errors were encountered then an empty slice is returned.

func (ResultList) HasFailure

func (l ResultList) HasFailure() bool

HasFailure returns 'true' if any of the ResultList members are failures or errors.

func (ResultList) Len

func (l ResultList) Len() int

func (ResultList) Less

func (l ResultList) Less(i, j int) bool

func (ResultList) Swap

func (l ResultList) Swap(i, j int)

type RetryMiddleware

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

func NewRetryMiddleware

func NewRetryMiddleware(opts ...RetryMiddlewareOption) *RetryMiddleware

func (*RetryMiddleware) Wrap

func (r *RetryMiddleware) Wrap(run RunFunc) RunFunc

type RetryMiddlewareConfig

type RetryMiddlewareConfig struct {
	MaxAttempts int
	Delay       time.Duration
}

func (*RetryMiddlewareConfig) Default

func (c *RetryMiddlewareConfig) Default()

func (*RetryMiddlewareConfig) Option

func (c *RetryMiddlewareConfig) Option(opts ...RetryMiddlewareOption)

type RetryMiddlewareOption

type RetryMiddlewareOption interface {
	ConfigureRetryMiddleware(*RetryMiddlewareConfig)
}

type RunFunc

type RunFunc func(context.Context, types.MetaBundle) Result

type Runner

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

func NewRunner

func NewRunner(opts ...RunnerOption) (*Runner, error)

NewRunner returns a Runner configured with a variadic slice of options or an error if an issue occurs.

func (*Runner) CleanUp

func (r *Runner) CleanUp() error

func (*Runner) GetValidators

func (r *Runner) GetValidators(filters ...Filter) []Validator

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, mb types.MetaBundle, filters ...Filter) <-chan Result

type RunnerConfig

type RunnerConfig struct {
	Initializers []Initializer
	Logger       logr.Logger
	Middleware   []Middleware
	OCMClient    OCMClient
}

func (*RunnerConfig) Default

func (c *RunnerConfig) Default() error

func (*RunnerConfig) Option

func (c *RunnerConfig) Option(opts ...RunnerOption)

type RunnerOption

type RunnerOption interface {
	ApplyToRunnerConfig(*RunnerConfig)
}

type Validator

type Validator interface {
	// Code returns the unique id of a Validator instance.
	Code() Code
	// Name returns the display name of a Validator instance.
	Name() string
	// Description returns the displayed description of a Validator instance.
	Description() string
	// Run executes validation tasks against a types.MetaBundle and returns the
	// result of that task. A context.Context instance is also passed to allow
	// for cancellation and timeouts to propogate through the validation task
	// and preempt any long-running processing step.
	Run(context.Context, types.MetaBundle) Result
}

Validator is a task which given a types.MetaBundle will perform checks and return a result.

type ValidatorList

type ValidatorList []Validator

ValidatorList is a sortable slice of Validators.

func (ValidatorList) Len

func (l ValidatorList) Len() int

func (ValidatorList) Less

func (l ValidatorList) Less(i, j int) bool

func (ValidatorList) Swap

func (l ValidatorList) Swap(i, j int)

type WithDelay

type WithDelay time.Duration

func (WithDelay) ConfigureRetryMiddleware

func (d WithDelay) ConfigureRetryMiddleware(c *RetryMiddlewareConfig)

type WithInitializers

type WithInitializers []Initializer

func (WithInitializers) ApplyToRunnerConfig

func (i WithInitializers) ApplyToRunnerConfig(c *RunnerConfig)

type WithLogger

type WithLogger struct{ logr.Logger }

func (WithLogger) ApplyToRunnerConfig

func (l WithLogger) ApplyToRunnerConfig(c *RunnerConfig)

type WithMaxAttempts

type WithMaxAttempts int

func (WithMaxAttempts) ConfigureRetryMiddleware

func (ma WithMaxAttempts) ConfigureRetryMiddleware(c *RetryMiddlewareConfig)

type WithMiddleware

type WithMiddleware []Middleware

func (WithMiddleware) ApplyToRunnerConfig

func (m WithMiddleware) ApplyToRunnerConfig(c *RunnerConfig)

type WithOCMClient

type WithOCMClient struct{ OCMClient }

func (WithOCMClient) ApplyToRunnerConfig

func (o WithOCMClient) ApplyToRunnerConfig(c *RunnerConfig)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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