validation

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownLicense = fmt.Errorf("unknown license")

Functions

This section is empty.

Types

type ChainedLicenseResolver

type ChainedLicenseResolver struct {
	LicenseResolvers []LicenseResolver
}

ChainedLicenseResolver calls all resolvers until success If no success calls happened it returns ErrUnknownLicense

func (*ChainedLicenseResolver) ResolveLicense

func (crl *ChainedLicenseResolver) ResolveLicense(ctx context.Context, m Module) (License, error)

type ChainedTranslator

type ChainedTranslator struct {
	Translators []Translator
}

ChainedTranslator calls all translators until error passing translated module to next translator

func (*ChainedTranslator) Translate

func (ct *ChainedTranslator) Translate(ctx context.Context, m Module) (translated Module, err error)

type ErrBlacklistedModule

type ErrBlacklistedModule struct {
	Module  LicensedModule
	Matcher ModuleMatcher
}

func (*ErrBlacklistedModule) Error

func (e *ErrBlacklistedModule) Error() string

type ErrDeniedLicense

type ErrDeniedLicense struct {
	Module LicensedModule
}

func (*ErrDeniedLicense) Error

func (e *ErrDeniedLicense) Error() string

type License

type License struct {
	// Name is a human-readable name
	Name string

	// SPDXID is a SPDX license id
	SPDXID string
}

func (*License) Equals

func (l *License) Equals(other *License) bool

func (*License) String

func (l *License) String() string

type LicenseResolver

type LicenseResolver interface {
	// ResolveLicense resolves license for module
	// It should return ErrUnknownLicense if module contains unknown license (not found in db-s)
	ResolveLicense(ctx context.Context, m Module) (License, error)
}

type LicenseResolverMock

type LicenseResolverMock struct {
	mock.Mock
}

func (*LicenseResolverMock) ResolveLicense

func (m *LicenseResolverMock) ResolveLicense(ctx context.Context, module Module) (License, error)

type LicensedModule

type LicensedModule struct {
	Module
	License License
}

LicensedModule represents a module with found license

func (*LicensedModule) String

func (lm *LicensedModule) String() string

type Module

type Module struct {
	Name    string
	Version *semver.Version
}

Module represents go module

func (*Module) String

func (m *Module) String() string

type ModuleMatcher

type ModuleMatcher struct {
	Name    *regexp.Regexp
	Version *semver.Constraints
}

ModuleMatcher defines a module matcher

func (*ModuleMatcher) Match

func (mm *ModuleMatcher) Match(m *Module) bool

func (*ModuleMatcher) String

func (mm *ModuleMatcher) String() string

type NotifyingValidator

type NotifyingValidator struct {
	NotifyingValidatorParams
	// contains filtered or unexported fields
}

NotifyingValidator is a wrapper for Validator interface which performs notifications if requested by user

func NewNotifyingValidator

func NewNotifyingValidator(log *zap.Logger, params NotifyingValidatorParams) *NotifyingValidator

func (*NotifyingValidator) Validate

func (v *NotifyingValidator) Validate(ctx context.Context, m Module) error

type NotifyingValidatorParams

type NotifyingValidatorParams struct {
	Validator              Validator
	UnknownLicenseAction   UnknownLicenseAction
	UnknownLicenseNotifier UnknownLicenseNotifier
}

type RuleSet

type RuleSet struct {
	// WhitelistedModules always gives positive validation result
	WhitelistedModules []ModuleMatcher

	// BlacklistedModules always gives negative validation result
	BlacklistedModules []ModuleMatcher

	// AllowedLicenses contains set of allowed licenses
	// If provided only modules with matched license will be allowed
	AllowedLicenses []License

	// DeniedLicenses contains set of denied licenses
	DeniedLicenses []License
}

RuleSet represents module validation rule set

func (*RuleSet) Validate

func (rs *RuleSet) Validate(lm LicensedModule) error

Validate validates provided module against rule set

type RuleSetValidator

type RuleSetValidator struct {
	RuleSetValidatorParams
	// contains filtered or unexported fields
}

func NewRuleSetValidator

func NewRuleSetValidator(logger *zap.Logger, validatorParams RuleSetValidatorParams) *RuleSetValidator

func (*RuleSetValidator) Validate

func (v *RuleSetValidator) Validate(ctx context.Context, m Module) error

type RuleSetValidatorParams

type RuleSetValidatorParams struct {
	Translator      Translator
	LicenseResolver LicenseResolver
	RuleSet         RuleSet
}

type Translator

type Translator interface {
	// Translate attempts to remap module name
	// Example case rsc.io/pdf -> github.com/rsc/pdf
	// Implementation should return original Module if translation wasn't made
	Translate(ctx context.Context, m Module) (translated Module, err error)
}

type TranslatorMock

type TranslatorMock struct {
	mock.Mock
}

func (*TranslatorMock) Translate

func (m *TranslatorMock) Translate(ctx context.Context, module Module) (translated Module, err error)

type UnknownLicenseAction

type UnknownLicenseAction int
const (
	// UnknownLicenseAllow allows modules with non-determined license
	UnknownLicenseAllow UnknownLicenseAction = iota

	// UnknownLicenseWarn acts as UnknownLicenseAllow but explicitly notifies about it
	UnknownLicenseWarn

	// UnknownLicenseDeny fails validation for modules with non-determined license
	UnknownLicenseDeny
)

type UnknownLicenseNotifier

type UnknownLicenseNotifier interface {
	// NotifyUnknownLicense triggered if unknown license found and UnknownLicenseWarn is set
	NotifyUnknownLicense(ctx context.Context, m Module) error
}

type UnknownLicenseNotifierMock

type UnknownLicenseNotifierMock struct {
	mock.Mock
}

func (*UnknownLicenseNotifierMock) NotifyUnknownLicense

func (m *UnknownLicenseNotifierMock) NotifyUnknownLicense(ctx context.Context, module Module) error

type Validator

type Validator interface {
	Validate(ctx context.Context, m Module) error
}

type ValidatorMock

type ValidatorMock struct {
	mock.Mock
}

func (*ValidatorMock) Validate

func (m *ValidatorMock) Validate(ctx context.Context, module Module) error

Jump to

Keyboard shortcuts

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