policy

package
v2.10.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConfigFileNotFound = errors.New("policy file isn't found")

Functions

func ParseEnv

func ParseEnv(env string) []string

Types

type Checker

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

func NewChecker

func NewChecker(param *config.Param) *Checker

func (*Checker) ValidatePackage

func (pc *Checker) ValidatePackage(logE *logrus.Entry, pkg *config.Package, policies []*Config) error

type Config

type Config struct {
	Path    string
	Allowed bool
	YAML    *ConfigYAML
}

func (*Config) Init

func (cfg *Config) Init() error

type ConfigFinder

type ConfigFinder interface {
	Find(policyFilePath, wd string) (string, error)
}

type ConfigFinderImpl

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

func NewConfigFinder

func NewConfigFinder(fs afero.Fs) *ConfigFinderImpl

func (*ConfigFinderImpl) Find

func (finder *ConfigFinderImpl) Find(policyFilePath, wd string) (string, error)

type ConfigReader

type ConfigReader interface {
	Read(policyConfigFiles []string) ([]*Config, error)
	ReadFile(policyConfigFile string) (*Config, error)
}

type ConfigReaderImpl

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

func NewConfigReader

func NewConfigReader(fs afero.Fs) *ConfigReaderImpl

func (*ConfigReaderImpl) Read

func (reader *ConfigReaderImpl) Read(files []string) ([]*Config, error)

func (*ConfigReaderImpl) ReadFile

func (reader *ConfigReaderImpl) ReadFile(file string) (*Config, error)

type ConfigYAML

type ConfigYAML struct {
	Registries []*Registry `json:"registries"`
	Packages   []*Package  `json:"packages,omitempty"`
}

type MockConfigFinder

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

func (*MockConfigFinder) Find

func (finder *MockConfigFinder) Find(policyFilePath, wd string) (string, error)

type MockConfigReader

type MockConfigReader struct {
	Cfgs []*Config
	Err  error
}

func (*MockConfigReader) Read

func (reader *MockConfigReader) Read(files []string) ([]*Config, error)

type MockReader

type MockReader struct {
	Config  *Config
	Configs []*Config
	Err     error
}

func (*MockReader) Append

func (reader *MockReader) Append(logE *logrus.Entry, khulnasoftYAMLPath string, policies []*Config, globalPolicyPaths map[string]struct{}) ([]*Config, error)

func (*MockReader) ReadFromEnv

func (reader *MockReader) ReadFromEnv(policyFilePaths []string) ([]*Config, error)

type MockValidator

type MockValidator struct {
	Err error
}

func (*MockValidator) Allow

func (validator *MockValidator) Allow(p string) error

func (*MockValidator) Deny

func (validator *MockValidator) Deny(p string) error

func (*MockValidator) Validate

func (validator *MockValidator) Validate(p string) error

func (*MockValidator) Warn

func (validator *MockValidator) Warn(logE *logrus.Entry, policyFilePath string, updated bool) error

type Package

type Package struct {
	Name         string    `json:"name"`
	Version      string    `json:"version,omitempty"`
	RegistryName string    `yaml:"registry" json:"registry,omitempty"`
	Registry     *Registry `yaml:"-" json:"-"`
}

type Reader

type Reader interface {
	ReadFromEnv(policyFilePaths []string) ([]*Config, error)
	Append(logE *logrus.Entry, khulnasoftYAMLPath string, policies []*Config, globalPolicyPaths map[string]struct{}) ([]*Config, error)
}

type ReaderImpl

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

func NewReader

func NewReader(fs afero.Fs, validator Validator, finder ConfigFinder, reader ConfigReader) *ReaderImpl

func (*ReaderImpl) Append

func (reader *ReaderImpl) Append(logE *logrus.Entry, khulnasoftYAMLPath string, policies []*Config, globalPolicyPaths map[string]struct{}) ([]*Config, error)

func (*ReaderImpl) ReadFromEnv

func (reader *ReaderImpl) ReadFromEnv(policyFilePaths []string) ([]*Config, error)

type Registry

type Registry struct {
	Name      string `json:"name,omitempty"`
	Type      string `validate:"required" json:"type,omitempty" jsonschema:"enum=standard,enum=local,enum=github_content"`
	RepoOwner string `yaml:"repo_owner" json:"repo_owner,omitempty"`
	RepoName  string `yaml:"repo_name" json:"repo_name,omitempty"`
	Ref       string `json:"ref,omitempty"`
	Path      string `validate:"required" json:"path,omitempty"`
}

type Validator

type Validator interface {
	Validate(p string) error
	Allow(p string) error
	Deny(p string) error
	Warn(logE *logrus.Entry, policyFilePath string, updated bool) error
}

type ValidatorImpl

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

func NewValidator

func NewValidator(param *config.Param, fs afero.Fs) *ValidatorImpl

func (*ValidatorImpl) Allow

func (validator *ValidatorImpl) Allow(p string) error

func (*ValidatorImpl) Deny

func (validator *ValidatorImpl) Deny(p string) error

func (*ValidatorImpl) Validate

func (validator *ValidatorImpl) Validate(p string) error

func (*ValidatorImpl) Warn

func (validator *ValidatorImpl) Warn(logE *logrus.Entry, policyFilePath string, updated bool) error

Jump to

Keyboard shortcuts

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