* Add rewrite support and fix existing tests * Add unit tests for policy matching * Compile regexes up front and store policies in map * Add test for verify flow with mirror * Rename ImageName -> ResolvedName And only set it when necessary * Rename Rewrite -> Replacement but keep it as rewrite in the yaml
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package config
|
|
|
|
import "regexp"
|
|
|
|
type policyMappingsFile struct {
|
|
Version string `yaml:"version"`
|
|
Kind string `yaml:"kind"`
|
|
Policies []*PolicyMapping `yaml:"policies"`
|
|
Rules []*policyRuleFile `yaml:"rules"`
|
|
}
|
|
|
|
type policyRuleFile struct {
|
|
Pattern string `yaml:"pattern"`
|
|
PolicyId string `yaml:"policy-id"`
|
|
Replacement string `yaml:"rewrite"`
|
|
}
|
|
|
|
type PolicyMappings struct {
|
|
Version string
|
|
Kind string
|
|
Policies map[string]*PolicyMapping
|
|
Rules []*PolicyRule
|
|
}
|
|
|
|
type AttestationStyle string
|
|
|
|
const (
|
|
AttestationStyleAttached AttestationStyle = "attached"
|
|
AttestationStyleReferrers AttestationStyle = "referrers"
|
|
)
|
|
|
|
type PolicyMapping struct {
|
|
Id string `yaml:"id"`
|
|
Description string `yaml:"description"`
|
|
Files []PolicyMappingFile `yaml:"files"`
|
|
Attestations *AttestationConfig `yaml:"attestations"`
|
|
}
|
|
|
|
type AttestationConfig struct {
|
|
Style AttestationStyle `yaml:"style"`
|
|
Repo string `yaml:"repo"`
|
|
}
|
|
|
|
type PolicyMappingFile struct {
|
|
Path string `yaml:"path"`
|
|
}
|
|
|
|
type PolicyRule struct {
|
|
Pattern *regexp.Regexp
|
|
PolicyId string
|
|
Replacement string
|
|
}
|