policy

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateLocalPolicy

func ValidateLocalPolicy(p *LocalPolicy) error

func ValidatePolicy

func ValidatePolicy(p *RemotePolicy) error

Types

type Cache

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

func NewCache

func NewCache(dir string) *Cache

func (*Cache) Clear

func (c *Cache) Clear() error

func (*Cache) GetFromDisk

func (c *Cache) GetFromDisk(url string) (*RemotePolicy, *CacheMetadata, error)

func (*Cache) GetFromMemory

func (c *Cache) GetFromMemory(url string) *RemotePolicy

func (*Cache) KeyFor

func (c *Cache) KeyFor(url string) string

func (*Cache) SaveToDisk

func (c *Cache) SaveToDisk(url string, policy *RemotePolicy, policyData []byte, etag string) error

func (*Cache) SetInMemory

func (c *Cache) SetInMemory(url string, policy *RemotePolicy)

type CacheMetadata

type CacheMetadata struct {
	URL         string    `json:"url"`
	ETag        string    `json:"etag"`
	LastFetched time.Time `json:"lastFetched"`
}

type CommitMessageRule

type CommitMessageRule struct {
	Regex string `json:"regex" yaml:"regex"`
	Error string `json:"error" yaml:"error"`
}

type EvalResult

type EvalResult struct {
	Passed     bool
	Violations []Violation
}

func Evaluate

func Evaluate(rules *PolicyRules, files []string, commitMsg string) EvalResult

func (EvalResult) String

func (r EvalResult) String() string

type Fetcher

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

func NewFetcher

func NewFetcher(cacheDir string) *Fetcher

func (*Fetcher) ClearCache

func (f *Fetcher) ClearCache() error

func (*Fetcher) LoadPolicy

func (f *Fetcher) LoadPolicy(url string) (*RemotePolicy, error)

type ForbiddenContentPattern

type ForbiddenContentPattern struct {
	Pattern     string `json:"pattern" yaml:"pattern"`
	Description string `json:"description" yaml:"description"`
}

type LocalPolicy

type LocalPolicy struct {
	Name        string            `json:"name" yaml:"name"`
	Version     string            `json:"version" yaml:"version"`
	Description string            `json:"description" yaml:"description"`
	Rules       PolicyRules       `json:"rules" yaml:"rules"`
	Metadata    map[string]string `json:"metadata" yaml:"metadata"`
}

func (*LocalPolicy) Identifier

func (p *LocalPolicy) Identifier() string

type MergedPolicy

type MergedPolicy struct {
	RemotePolicies []RemotePolicy
	LocalPolicies  []LocalPolicy
	EffectiveRules PolicyRules
}

type PolicyRef

type PolicyRef struct {
	URL string `json:"url" yaml:"url"`
}

type PolicyRules

type PolicyRules struct {
	ForbidFiles          []string                  `json:"forbid_files" yaml:"forbid_files"`
	ForbidDirectories    []string                  `json:"forbid_directories" yaml:"forbid_directories"`
	ForbidFileExtensions []string                  `json:"forbid_file_extensions" yaml:"forbid_file_extensions"`
	RequiredFiles        []string                  `json:"required_files" yaml:"required_files"`
	MaxFileSizeKB        int                       `json:"max_file_size_kb" yaml:"max_file_size_kb"`
	MaxFilesChanged      int                       `json:"max_files_changed" yaml:"max_files_changed"`
	ForbidFileContent    []ForbiddenContentPattern `json:"forbid_file_content" yaml:"forbid_file_content"`
	RegexBlock           []string                  `json:"regex_block" yaml:"regex_block"`
	CommitMessage        *CommitMessageRule        `json:"commit_message" yaml:"commit_message"`
	EnforceHooks         []string                  `json:"enforce_hooks" yaml:"enforce_hooks"`
	HookTimeBudgetMs     map[string]int            `json:"hook_time_budget_ms" yaml:"hook_time_budget_ms"`
	MaxParallelHooks     int                       `json:"max_parallel_hooks" yaml:"max_parallel_hooks"`
}

func (*PolicyRules) Merge

func (r *PolicyRules) Merge(other PolicyRules) PolicyRules

type Registry

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

func NewRegistry

func NewRegistry(workDir, cacheDir string) *Registry

func (*Registry) ClearCache

func (r *Registry) ClearCache() error

func (*Registry) Load

func (r *Registry) Load(config *UserConfig) (*MergedPolicy, error)

func (*Registry) Refresh

func (r *Registry) Refresh(config *UserConfig) error

type RemotePolicy

type RemotePolicy struct {
	Name        string            `json:"name" yaml:"name"`
	ID          string            `json:"id" yaml:"id"`
	Version     string            `json:"version" yaml:"version"`
	Description string            `json:"description" yaml:"description"`
	Severity    string            `json:"severity" yaml:"severity"`
	Rules       PolicyRules       `json:"rules" yaml:"rules"`
	Metadata    map[string]string `json:"metadata" yaml:"metadata"`
}

func ParseRemotePolicy

func ParseRemotePolicy(data []byte) (*RemotePolicy, error)

func (*RemotePolicy) Identifier

func (p *RemotePolicy) Identifier() string

type UserConfig

type UserConfig struct {
	Type          string        `json:"type" yaml:"type"`
	Policies      []PolicyRef   `json:"policies" yaml:"policies"`
	LocalPolicies []LocalPolicy `json:"localPolicies" yaml:"localPolicies"`
}

type Violation

type Violation struct {
	Rule    string
	Message string
}

Jump to

Keyboard shortcuts

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