feat(aa): add rule constructors from internal parser.
This commit is contained in:
parent
ac9d6d859f
commit
163c5be61c
19 changed files with 456 additions and 75 deletions
|
|
@ -33,6 +33,17 @@ type MountConditions struct {
|
|||
Options []string
|
||||
}
|
||||
|
||||
func newMountConditions(rule rule) (MountConditions, error) {
|
||||
options, err := toValues(MOUNT, "flags", rule.GetValuesAsString("options"))
|
||||
if err != nil {
|
||||
return MountConditions{}, err
|
||||
}
|
||||
return MountConditions{
|
||||
FsType: rule.GetValuesAsString("fstype"),
|
||||
Options: options,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newMountConditionsFromLog(log map[string]string) MountConditions {
|
||||
if _, present := log["flags"]; present {
|
||||
return MountConditions{
|
||||
|
|
@ -62,6 +73,35 @@ type Mount struct {
|
|||
MountPoint string
|
||||
}
|
||||
|
||||
func newMount(q Qualifier, rule rule) (Rule, error) {
|
||||
mount, src := "", ""
|
||||
r := rule.GetSlice()
|
||||
if len(r) > 0 {
|
||||
if r[0] != tokARROW {
|
||||
src = r[0]
|
||||
r = r[1:]
|
||||
}
|
||||
if len(r) == 2 {
|
||||
if r[0] != tokARROW {
|
||||
return nil, fmt.Errorf("missing '%s' in rule: %s", tokARROW, rule)
|
||||
}
|
||||
mount = r[1]
|
||||
}
|
||||
}
|
||||
|
||||
conditions, err := newMountConditions(rule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Mount{
|
||||
RuleBase: newBase(rule),
|
||||
Qualifier: q,
|
||||
MountConditions: conditions,
|
||||
Source: src,
|
||||
MountPoint: mount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newMountFromLog(log map[string]string) Rule {
|
||||
return &Mount{
|
||||
RuleBase: newBaseFromLog(log),
|
||||
|
|
@ -112,6 +152,24 @@ type Umount struct {
|
|||
MountPoint string
|
||||
}
|
||||
|
||||
func newUmount(q Qualifier, rule rule) (Rule, error) {
|
||||
mount := ""
|
||||
r := rule.GetSlice()
|
||||
if len(r) > 0 {
|
||||
mount = r[0]
|
||||
}
|
||||
conditions, err := newMountConditions(rule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Umount{
|
||||
RuleBase: newBase(rule),
|
||||
Qualifier: q,
|
||||
MountConditions: conditions,
|
||||
MountPoint: mount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newUmountFromLog(log map[string]string) Rule {
|
||||
return &Umount{
|
||||
RuleBase: newBaseFromLog(log),
|
||||
|
|
@ -158,6 +216,25 @@ type Remount struct {
|
|||
MountPoint string
|
||||
}
|
||||
|
||||
func newRemount(q Qualifier, rule rule) (Rule, error) {
|
||||
mount := ""
|
||||
r := rule.GetSlice()
|
||||
if len(r) > 0 {
|
||||
mount = r[0]
|
||||
}
|
||||
|
||||
conditions, err := newMountConditions(rule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Remount{
|
||||
RuleBase: newBase(rule),
|
||||
Qualifier: q,
|
||||
MountConditions: conditions,
|
||||
MountPoint: mount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newRemountFromLog(log map[string]string) Rule {
|
||||
return &Remount{
|
||||
RuleBase: newBaseFromLog(log),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue