Documentation
¶
Index ¶
- Constants
- func ErrInvalidPattern(path string, err error) error
- func ErrInvalidSelector(path string, err error) error
- func ErrNotAString(path string) error
- func ErrNotATuple(path string) error
- func ErrUnrecognizedOperator(path string, op string) error
- func ErrUnrecognizedShape(path string) error
- type Constructor
- func All(selector string, cstor Constructor) Constructor
- func And(cstors ...Constructor) Constructor
- func Any(selector string, cstor Constructor) Constructor
- func Equal(selector string, value ipld.Node) Constructor
- func GreaterThan(selector string, value ipld.Node) Constructor
- func GreaterThanOrEqual(selector string, value ipld.Node) Constructor
- func LessThan(selector string, value ipld.Node) Constructor
- func LessThanOrEqual(selector string, value ipld.Node) Constructor
- func Like(selector string, pattern string) Constructor
- func Not(cstor Constructor) Constructor
- func NotEqual(selector string, value ipld.Node) Constructor
- func Or(cstors ...Constructor) Constructor
- type Policy
- type Statement
Examples ¶
Constants ¶
View Source
const ( KindEqual = "==" // implemented by equality KindNotEqual = "!=" // implemented by equality KindGreaterThan = ">" // implemented by equality KindGreaterThanOrEqual = ">=" // implemented by equality KindLessThan = "<" // implemented by equality KindLessThanOrEqual = "<=" // implemented by equality KindNot = "not" // implemented by negation KindAnd = "and" // implemented by connective KindOr = "or" // implemented by connective KindLike = "like" // implemented by wildcard KindAll = "all" // implemented by quantifier KindAny = "any" // implemented by quantifier )
Variables ¶
This section is empty.
Functions ¶
func ErrInvalidPattern ¶
func ErrInvalidSelector ¶
func ErrNotAString ¶
func ErrNotATuple ¶
func ErrUnrecognizedOperator ¶
func ErrUnrecognizedShape ¶
Types ¶
type Constructor ¶
func All ¶
func All(selector string, cstor Constructor) Constructor
func And ¶
func And(cstors ...Constructor) Constructor
func Any ¶
func Any(selector string, cstor Constructor) Constructor
func GreaterThan ¶
func GreaterThan(selector string, value ipld.Node) Constructor
func GreaterThanOrEqual ¶
func GreaterThanOrEqual(selector string, value ipld.Node) Constructor
func LessThanOrEqual ¶
func LessThanOrEqual(selector string, value ipld.Node) Constructor
func Like ¶
func Like(selector string, pattern string) Constructor
func Not ¶
func Not(cstor Constructor) Constructor
func Or ¶
func Or(cstors ...Constructor) Constructor
type Policy ¶
type Policy []Statement
Example ¶
package main
import (
"fmt"
"code.sonr.org/go/ucan/pkg/policy"
"code.sonr.org/go/ucan/pkg/policy/literal"
)
func main() {
pol := policy.MustConstruct(
policy.Equal(".status", literal.String("draft")),
policy.All(".reviewer",
policy.Like(".email", "*@example.com"),
),
policy.Any(".tags", policy.Or(
policy.Equal(".", literal.String("news")),
policy.Equal(".", literal.String("press")),
)),
)
fmt.Println(pol)
}
Output: [ ["==", ".status", "draft"], ["all", ".reviewer", ["like", ".email", "*@example.com"] ], ["any", ".tags", ["or", [ ["==", ".", "news"], ["==", ".", "press"] ]] ] ]
Example (Accumulate) ¶
package main
import (
"fmt"
"code.sonr.org/go/ucan/pkg/policy"
"code.sonr.org/go/ucan/pkg/policy/literal"
)
func main() {
var statements []policy.Constructor
statements = append(statements, policy.Equal(".status", literal.String("draft")))
statements = append(statements, policy.All(".reviewer",
policy.Like(".email", "*@example.com"),
))
statements = append(statements, policy.Any(".tags", policy.Or(
policy.Equal(".", literal.String("news")),
policy.Equal(".", literal.String("press")),
)))
pol := policy.MustConstruct(statements...)
fmt.Println(pol)
}
Output: [ ["==", ".status", "draft"], ["all", ".reviewer", ["like", ".email", "*@example.com"] ], ["any", ".tags", ["or", [ ["==", ".", "news"], ["==", ".", "press"] ]] ] ]
func Construct ¶
func Construct(cstors ...Constructor) (Policy, error)
func FromDagJson ¶
func MustConstruct ¶
func MustConstruct(cstors ...Constructor) Policy
func (Policy) Match ¶
Match determines if the IPLD node satisfies the policy. The first Statement failing to match is returned as well.
func (Policy) PartialMatch ¶
PartialMatch returns false IIF one non-optional Statement has the corresponding data and doesn't match. If the data is missing or the non-optional Statement is matching, true is returned.
This allows performing the policy checking in multiple steps, and find immediately if a Statement already failed. A final call to Match is necessary to make sure that the policy is fully matched, with no missing data (apart from optional values).
The first Statement failing to match is returned as well.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package literal holds a collection of functions to create IPLD types to use in policies, selector and args.
|
Package literal holds a collection of functions to create IPLD types to use in policies, selector and args. |
Click to show internal directories.
Click to hide internal directories.