mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-01-30 23:05:11 +01:00
feat(aa): cleanup rules methods.
This commit is contained in:
parent
dc0e0084a0
commit
1333ec2025
2 changed files with 14 additions and 24 deletions
|
@ -159,7 +159,7 @@ func (f *AppArmorProfileFile) resolveInclude(include *Include) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert iFile in the place of include in the current file
|
// Insert iFile in the place of include in the current file
|
||||||
index := f.Preamble.IndexOf(include)
|
index := f.Preamble.Index(include)
|
||||||
f.Preamble = f.Preamble.Insert(index, includeCache[include].Preamble...)
|
f.Preamble = f.Preamble.Replace(index, includeCache[include].Preamble...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,8 @@ func (r Rules) String() string {
|
||||||
return renderTemplate("rules", r)
|
return renderTemplate("rules", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Rules) IndexOf(rule Rule) int {
|
// Index returns the index of the first occurrence of rule rin r, or -1 if not present.
|
||||||
|
func (r Rules) Index(rule Rule) int {
|
||||||
for idx, rr := range r {
|
for idx, rr := range r {
|
||||||
if rr.Kind() == rule.Kind() && rr.Equals(rule) {
|
if rr.Kind() == rule.Kind() && rr.Equals(rule) {
|
||||||
return idx
|
return idx
|
||||||
|
@ -60,31 +61,20 @@ func (r Rules) IndexOf(rule Rule) int {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Rules) Contains(rule Rule) bool {
|
// Replace replaces the elements r[i] by the given rules, and returns the
|
||||||
return r.IndexOf(rule) != -1
|
// modified slice.
|
||||||
|
func (r Rules) Replace(i int, rules ...Rule) Rules {
|
||||||
|
return append(r[:i], append(rules, r[i+1:]...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Rules) Add(rule Rule) Rules {
|
// Insert inserts the rules into r at index i, returning the modified slice.
|
||||||
if r.Contains(rule) {
|
func (r Rules) Insert(i int, rules ...Rule) Rules {
|
||||||
return r
|
return append(r[:i], append(rules, r[i:]...)...)
|
||||||
}
|
|
||||||
return append(r, rule)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Rules) Remove(rule Rule) Rules {
|
// Delete removes the elements r[i] from r, returning the modified slice.
|
||||||
idx := r.IndexOf(rule)
|
func (r Rules) Delete(i int) Rules {
|
||||||
if idx == -1 {
|
return append(r[:i], r[i+1:]...)
|
||||||
return r
|
|
||||||
}
|
|
||||||
return append(r[:idx], r[idx+1:]...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Rules) Insert(idx int, rules ...Rule) Rules {
|
|
||||||
return append(r[:idx], append(rules, r[idx+1:]...)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Rules) Sort() Rules {
|
|
||||||
return r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Rules) DeleteKind(kind string) Rules {
|
func (r Rules) DeleteKind(kind string) Rules {
|
||||||
|
|
Loading…
Reference in a new issue