feat(aa): add initial profile validation structure.
This commit is contained in:
parent
2dd6046697
commit
92641e7e28
20 changed files with 222 additions and 2 deletions
|
|
@ -28,6 +28,7 @@ const (
|
|||
|
||||
// Rule generic interface for all AppArmor rules
|
||||
type Rule interface {
|
||||
Validate() error
|
||||
Less(other any) bool
|
||||
Equals(other any) bool
|
||||
String() string
|
||||
|
|
@ -37,6 +38,15 @@ type Rule interface {
|
|||
|
||||
type Rules []Rule
|
||||
|
||||
func (r Rules) Validate() error {
|
||||
for _, rule := range r {
|
||||
if err := rule.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Rules) String() string {
|
||||
return renderTemplate("rules", r)
|
||||
}
|
||||
|
|
@ -82,6 +92,18 @@ func Must[T any](v T, err error) T {
|
|||
return v
|
||||
}
|
||||
|
||||
func validateValues(rule string, key string, values []string) error {
|
||||
for _, v := range values {
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if !slices.Contains(requirements[rule][key], v) {
|
||||
return fmt.Errorf("invalid mode '%s'", v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Helper function to convert a string to a slice of rule values according to
|
||||
// the rule requirements as defined in the requirements map.
|
||||
func toValues(rule string, key string, input string) ([]string, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue