validator

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 14 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 NewOCMClientAuthError added in v0.12.0

func NewOCMClientAuthError(err error) ocmClientError

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 DefaultOCMClient added in v0.12.0

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

DefaultOCMClient implements the 'types.OCMClient' interface and exposes methods by which validators can communicate with OCM.

func NewDefaultOCMClient added in v0.12.0

func NewDefaultOCMClient(opts ...DefaultOCMClientOption) (*DefaultOCMClient, error)

NewDefaultOCMClient takes a variadic slice of options to configure a default OCM client and applies defaults if no appropriate option is given. An error may be returned if an unusable OCM token is provided or a connection cannot be initialized otherwise the default client is returned.

func (*DefaultOCMClient) CloseConnection added in v0.12.0

func (c *DefaultOCMClient) CloseConnection() error

func (*DefaultOCMClient) Option added in v0.12.0

Option applies the given option to an instance of the DefaultOCMClient.

func (*DefaultOCMClient) QuotaRuleExists added in v0.12.0

func (c *DefaultOCMClient) QuotaRuleExists(ctx context.Context, quotaName string) (bool, error)

type DefaultOCMClientOption added in v0.12.0

type DefaultOCMClientOption func(c *DefaultOCMClient)

DefaultOCMClientOption describes a function which configures a DefaultOCMClient instance.

func DefaultOCMClientAPIURL added in v0.12.0

func DefaultOCMClientAPIURL(url string) DefaultOCMClientOption

DefaultOCMClientAPIURL updates the URL used to connect to OCM. This option only takes effect if applied prior to connection initialization.

func DefaultOCMClientTokenProvider added in v0.12.0

func DefaultOCMClientTokenProvider(tp OCMTokenProvider) DefaultOCMClientOption

DefaultOCMClientAPIURL updates the URL used to connect to OCM. This option only takes effect if applied prior to connection initialization.

type DefaultV2RegistryClient added in v0.12.0

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

func NewDefaultV2RegistryClient added in v0.12.0

func NewDefaultV2RegistryClient(url string) *DefaultV2RegistryClient

func NewQuayClient added in v0.12.0

func NewQuayClient() *DefaultV2RegistryClient

func (*DefaultV2RegistryClient) HasReference added in v0.12.0

func (c *DefaultV2RegistryClient) HasReference(ctx context.Context, ref ImageReference) (bool, error)

type Dependencies

type Dependencies struct {
	Logger     logr.Logger
	OCMClient  OCMClient
	QuayClient QuayClient
}

Dependencies abstracts common dependencies for Validators.

type EnvOCMTokenProvider added in v0.12.0

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

EnvOCMTokenProvider provides OCM tokens from the current environment.

func NewEnvOCMTokenProvider added in v0.12.0

func NewEnvOCMTokenProvider(envVar string) EnvOCMTokenProvider

NewEnvOCMTokenProvider returns an instance of EnvOCMTokenProvider which retrieves OCM tokens from the environment by the given envVar name.

func (EnvOCMTokenProvider) ProvideToken added in v0.12.0

func (tp EnvOCMTokenProvider) ProvideToken() (string, error)

type Filter

type Filter func(Validator) bool

func MatchesCodes

func MatchesCodes(codes ...Code) Filter

func Not

func Not(f Filter) Filter

type ImageReference added in v0.12.0

type ImageReference interface {
	ShortName() string
	Tag() string
}

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 OCMResponseError added in v0.12.0

type OCMResponseError int

OCMResponseError is used to wrap HTTP error (400 - 599) response codes which are returned from a request to OCM.

func (OCMResponseError) Error added in v0.12.0

func (e OCMResponseError) Error() string

func (OCMResponseError) ServerSide added in v0.12.0

func (e OCMResponseError) ServerSide() bool

type OCMTokenProvider added in v0.12.0

type OCMTokenProvider interface {
	// ProvideToken returns either an access token as an encoded JWT token
	// or an error if a token could not be provided.
	ProvideToken() (string, error)
}

OCMTokenProvider provides OCM tokens to clients.

type QuayClient added in v0.12.0

type QuayClient interface {
	HasReference(context.Context, ImageReference) (bool, error)
}

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
	QuayClient   QuayClient
}

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)

type WithQuayClient added in v0.12.0

type WithQuayClient struct{ QuayClient }

func (WithQuayClient) ApplyToRunnerConfig added in v0.12.0

func (q WithQuayClient) ApplyToRunnerConfig(c *RunnerConfig)

Jump to

Keyboard shortcuts

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