32 lines
726 B
Go
32 lines
726 B
Go
|
package accessctl
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
// FilterNot wraps another Filter. If that filter matches, FilterNot does not
|
||
|
// match, and vice-versa.
|
||
|
type FilterNot struct {
|
||
|
Filter Filter `yaml:"filter"`
|
||
|
}
|
||
|
|
||
|
var _ FilterInterface = FilterNot{}
|
||
|
|
||
|
// MatchCommit implements the method for FilterInterface.
|
||
|
func (f FilterNot) MatchCommit(req CommitRequest) error {
|
||
|
fI, err := f.Filter.Interface()
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("casting %+v to a FilterInterface: %w", f.Filter, err)
|
||
|
|
||
|
} else if err := fI.MatchCommit(req); errors.As(err, new(ErrFilterNoMatch)) {
|
||
|
return nil
|
||
|
} else if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return ErrFilterNoMatch{Err: errors.New("sub-filter did match")}
|
||
|
}
|
||
|
|
||
|
// TODO FilterAll
|
||
|
// TODO FilterAny
|