generated from TrueCloudLab/basic
[#7] engine: Move globMatch to common util package
Signed-off-by: Airat Arifullin <aarifullin@yadro.com>
This commit is contained in:
parent
38985e4ec8
commit
9472a7123e
3 changed files with 13 additions and 7 deletions
10
chain.go
10
chain.go
|
@ -4,6 +4,8 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/policy-engine/util"
|
||||
)
|
||||
|
||||
// Engine ...
|
||||
|
@ -159,9 +161,9 @@ func (c *Condition) Match(req Request) bool {
|
|||
case CondStringNotEqualsIgnoreCase:
|
||||
return !strings.EqualFold(val, c.Value)
|
||||
case CondStringLike:
|
||||
return globMatch(val, c.Value)
|
||||
return util.GlobMatch(val, c.Value)
|
||||
case CondStringNotLike:
|
||||
return !globMatch(val, c.Value)
|
||||
return !util.GlobMatch(val, c.Value)
|
||||
case CondStringLessThan:
|
||||
return val < c.Value
|
||||
case CondStringLessThanEquals:
|
||||
|
@ -176,7 +178,7 @@ func (c *Condition) Match(req Request) bool {
|
|||
func (r *Rule) Match(req Request) (status Status, matched bool) {
|
||||
found := len(r.Resources.Names) == 0
|
||||
for i := range r.Resources.Names {
|
||||
if globMatch(req.Resource().Name(), r.Resources.Names[i]) != r.Resources.Inverted {
|
||||
if util.GlobMatch(req.Resource().Name(), r.Resources.Names[i]) != r.Resources.Inverted {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
@ -185,7 +187,7 @@ func (r *Rule) Match(req Request) (status Status, matched bool) {
|
|||
return NoRuleFound, false
|
||||
}
|
||||
for i := range r.Actions.Names {
|
||||
if globMatch(req.Operation(), r.Actions.Names[i]) != r.Actions.Inverted {
|
||||
if util.GlobMatch(req.Operation(), r.Actions.Names[i]) != r.Actions.Inverted {
|
||||
return r.matchCondition(req)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package policyengine
|
||||
|
||||
import (
|
||||
"git.frostfs.info/TrueCloudLab/policy-engine/util"
|
||||
)
|
||||
|
||||
type inmemory struct {
|
||||
namespace map[Name][]chain
|
||||
resource map[Name][]chain
|
||||
|
@ -52,7 +56,7 @@ func (s *inmemory) IsAllowed(name Name, namespace string, r Request) (Status, bo
|
|||
|
||||
func matchArray(cs []chain, object string, r Request) (Status, bool) {
|
||||
for _, c := range cs {
|
||||
if !globMatch(object, c.object) {
|
||||
if !util.GlobMatch(object, c.object) {
|
||||
continue
|
||||
}
|
||||
if status, matched := c.chain.Match(r); matched {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package policyengine
|
||||
package util
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
@ -9,7 +9,7 @@ import (
|
|||
// ? in pattern correspond to any symbol.
|
||||
// * in pattern correspond to any sequence of symbols.
|
||||
// Currently only '*' in the suffix is supported.
|
||||
func globMatch(s, pattern string) bool {
|
||||
func GlobMatch(s, pattern string) bool {
|
||||
index := strings.IndexByte(pattern, '*')
|
||||
switch index {
|
||||
default:
|
Loading…
Reference in a new issue