diff --git a/capability/policy/ipld.go b/capability/policy/ipld.go index 9ee02c1..c08b984 100644 --- a/capability/policy/ipld.go +++ b/capability/policy/ipld.go @@ -104,9 +104,9 @@ func statementFromIPLD(path string, node datamodel.Node) (Statement, error) { if err != nil { return nil, err } - statementsNodes, _ := node.LookupByIndex(2) - statements, err := statementsFromIPLD(path+"1/", statementsNodes) - return quantifier{kind: op, selector: sel, statements: statements}, nil + statementsNode, _ := node.LookupByIndex(2) + statement, err := statementFromIPLD(path+"1/", statementsNode) + return quantifier{kind: op, selector: sel, statement: statement}, nil default: return nil, ErrUnrecognizedOperator(path, op) @@ -243,7 +243,7 @@ func statementToIPLD(statement Statement) (datamodel.Node, error) { if err != nil { return nil, err } - args, err := statementsToIPLD(statement.statements) + args, err := statementToIPLD(statement.statement) if err != nil { return nil, err } diff --git a/capability/policy/match.go b/capability/policy/match.go index 3f9b1a9..eaca407 100644 --- a/capability/policy/match.go +++ b/capability/policy/match.go @@ -110,7 +110,7 @@ func matchStatement(statement Statement, node ipld.Node) bool { return false } for _, n := range many { - ok := Match(s.statements, n) + ok := matchStatement(s.statement, n) if !ok { return false } @@ -124,7 +124,7 @@ func matchStatement(statement Statement, node ipld.Node) bool { return false } for _, n := range many { - ok := Match(s.statements, n) + ok := matchStatement(s.statement, n) if ok { return true } diff --git a/capability/policy/match_test.go b/capability/policy/match_test.go index e41650d..5a84982 100644 --- a/capability/policy/match_test.go +++ b/capability/policy/match_test.go @@ -400,8 +400,7 @@ func TestMatch(t *testing.T) { pol := Policy{ Any( selector.MustParse(".[]"), - GreaterThan(selector.MustParse(".value"), literal.Int(10)), - LessThan(selector.MustParse(".value"), literal.Int(50)), + GreaterThan(selector.MustParse(".value"), literal.Int(60)), ), } ok := Match(pol, nd) diff --git a/capability/policy/policy.go b/capability/policy/policy.go index 7f435c9..111b350 100644 --- a/capability/policy/policy.go +++ b/capability/policy/policy.go @@ -40,23 +40,23 @@ func (e equality) Kind() string { } func Equal(selector selector.Selector, value ipld.Node) Statement { - return equality{KindEqual, selector, value} + return equality{kind: KindEqual, selector: selector, value: value} } func GreaterThan(selector selector.Selector, value ipld.Node) Statement { - return equality{KindGreaterThan, selector, value} + return equality{kind: KindGreaterThan, selector: selector, value: value} } func GreaterThanOrEqual(selector selector.Selector, value ipld.Node) Statement { - return equality{KindGreaterThanOrEqual, selector, value} + return equality{kind: KindGreaterThanOrEqual, selector: selector, value: value} } func LessThan(selector selector.Selector, value ipld.Node) Statement { - return equality{KindLessThan, selector, value} + return equality{kind: KindLessThan, selector: selector, value: value} } func LessThanOrEqual(selector selector.Selector, value ipld.Node) Statement { - return equality{KindLessThanOrEqual, selector, value} + return equality{kind: KindLessThanOrEqual, selector: selector, value: value} } type negation struct { @@ -68,7 +68,7 @@ func (n negation) Kind() string { } func Not(stmt Statement) Statement { - return negation{stmt} + return negation{statement: stmt} } type connective struct { @@ -81,11 +81,11 @@ func (c connective) Kind() string { } func And(stmts ...Statement) Statement { - return connective{KindAnd, stmts} + return connective{kind: KindAnd, statements: stmts} } func Or(stmts ...Statement) Statement { - return connective{KindOr, stmts} + return connective{kind: KindOr, statements: stmts} } type wildcard struct { @@ -103,23 +103,23 @@ func Like(selector selector.Selector, pattern string) (Statement, error) { if err != nil { return nil, err } - return wildcard{selector, pattern, g}, nil + return wildcard{selector: selector, pattern: pattern, glob: g}, nil } type quantifier struct { - kind string - selector selector.Selector - statements []Statement + kind string + selector selector.Selector + statement Statement } func (n quantifier) Kind() string { return n.kind } -func All(selector selector.Selector, policy ...Statement) Statement { - return quantifier{KindAll, selector, policy} +func All(selector selector.Selector, statement Statement) Statement { + return quantifier{kind: KindAll, selector: selector, statement: statement} } -func Any(selector selector.Selector, policy ...Statement) Statement { - return quantifier{KindAny, selector, policy} +func Any(selector selector.Selector, statement Statement) Statement { + return quantifier{kind: KindAny, selector: selector, statement: statement} }