feat(aa): add rule constructors from internal parser.

This commit is contained in:
Alexandre Pujol 2024-06-19 23:22:49 +01:00
parent ac9d6d859f
commit 163c5be61c
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
19 changed files with 456 additions and 75 deletions

View file

@ -4,6 +4,8 @@
package aa
import "fmt"
const PIVOTROOT Kind = "pivot_root"
type PivotRoot struct {
@ -14,6 +16,30 @@ type PivotRoot struct {
TargetProfile string
}
func newPivotRoot(q Qualifier, rule rule) (Rule, error) {
newroot, target := "", ""
r := rule.GetSlice()
if len(r) > 0 {
if r[0] != tokARROW {
newroot = r[0]
r = r[1:]
}
if len(r) == 2 {
if r[0] != tokARROW {
return nil, fmt.Errorf("missing '%s' in rule: %s", tokARROW, rule)
}
target = r[1]
}
}
return &PivotRoot{
RuleBase: newBase(rule),
Qualifier: q,
OldRoot: rule.GetValuesAsString("oldroot"),
NewRoot: newroot,
TargetProfile: target,
}, nil
}
func newPivotRootFromLog(log map[string]string) Rule {
return &PivotRoot{
RuleBase: newBaseFromLog(log),