Documentation ¶
Overview ¶
Example ¶
ctx := context.Background() // new ArangoDB-connection conn, _ := http.NewConnection(http.ConnectionConfig{Endpoints: []string{"http://localhost:8529"}}) // new ArangoDB client client, _ := driver.NewClient(driver.ClientConfig{Connection: conn}) // generate UUID for a random db- and SPOC name uid := strconv.FormatInt(time.Now().UnixNano(), 10) s, _ := spoc.NewSPOC(ctx, "test-"+uid, uid, client) // Sebastian belongs to Admin _ = s.Subjects.AddRelation(ctx, "Sebastian", "Admin", true) // read belongs to owns _ = s.Predicates.AddRelation(ctx, "read", "owns", true) // File1 belongs to Root _ = s.Objects.AddRelation(ctx, "File1", "Root", true) // Admin may read Root _, _ = s.AddRule(ctx, "Admin", "owns", "Root", false) // Test whether Sebastian is allowed to read File1 allowed, _ := s.Allowed(ctx, "Sebastian", "read", "File1") fmt.Println(allowed)
Output: true
Index ¶
- Constants
- Variables
- func IsSPOCError(err error) bool
- func IsSPOCErrorWithCode(err error, status int) bool
- func IsSPOCErrorWithNumber(err error, number int) bool
- type AllowMatch
- type RelationMatch
- type RuleMatch
- type SPOC
- func (s *SPOC) AddRule(ctx context.Context, subjectKey, predicateKey, objectKey string, ...) (meta driver.DocumentMeta, err error)
- func (s *SPOC) Allowed(ctx context.Context, subjectKey, predicateKey, objectKey string) (allowed bool, err error)
- func (s *SPOC) DelRule(ctx context.Context, subjectKey, predicateKey, objectKey string) (err error)
- func (s *SPOC) Explain(ctx context.Context, subjectKey, predicateKey, objectKey string, ...) (matches []AllowMatch, err error)
- func (s *SPOC) GetRule(ctx context.Context, subjectKey, predicateKey, objectKey string) (meta driver.DocumentMeta, err error)
- func (s *SPOC) GetRules(ctx context.Context, offset, count uint) (matches []RuleMatch, err error)
- func (s *SPOC) SetQueryLogging(queryLogging bool)
- func (s *SPOC) Which(ctx context.Context, subjectKey, predicateKey string, offset, count uint) (matches []string, err error)
- func (s *SPOC) Who(ctx context.Context, predicateKey, objectKey string, offset, count uint) (matches []string, err error)
- type SPOCError
- type Thing
- func (t *Thing) Add(ctx context.Context, key string, data interface{}) (meta driver.DocumentMeta, err error)
- func (t *Thing) AddRelation(ctx context.Context, childKey, parentKey string, createVertices bool) (err error)
- func (t *Thing) Del(ctx context.Context, key string) (err error)
- func (t *Thing) DelRelation(ctx context.Context, childKey, parentKey string) (err error)
- func (t *Thing) Get(ctx context.Context, key string, data interface{}) (meta driver.DocumentMeta, err error)
- func (t *Thing) IsRelation(ctx context.Context, childKey, parentKey string) (exists bool, err error)
- func (t *Thing) List(ctx context.Context, offset, count uint) (keys []string, err error)
- func (t *Thing) ListRelations(ctx context.Context, offset, count uint) (matches []RelationMatch, err error)
- func (t *Thing) Replace(ctx context.Context, key string, data interface{}) (meta driver.DocumentMeta, err error)
- func (t *Thing) Update(ctx context.Context, key string, data interface{}) (meta driver.DocumentMeta, err error)
- type WhichMatch
Examples ¶
Constants ¶
View Source
const (
SPOCErrNotFound = 2001
)
Variables ¶
View Source
var Cause = func(err error) error { return err }
Functions ¶
func IsSPOCError ¶
IsSPOCError returns true when the given error is an SPOCError.
func IsSPOCErrorWithCode ¶
func IsSPOCErrorWithNumber ¶
Types ¶
type AllowMatch ¶
type RelationMatch ¶
type SPOC ¶
type SPOC struct { Subjects *Thing Predicates *Thing Objects *Thing Rules driver.Collection // contains filtered or unexported fields }
func (*SPOC) SetQueryLogging ¶
SetQueryLogging enables or disables query logging.
type Thing ¶
Thing embeds a DAG for SPOC-extensions.
func (*Thing) Add ¶
func (t *Thing) Add(ctx context.Context, key string, data interface{}) (meta driver.DocumentMeta, err error)
Add adds a new thing.
func (*Thing) AddRelation ¶
func (t *Thing) AddRelation(ctx context.Context, childKey, parentKey string, createVertices bool) (err error)
AddRelation adds an "is a" relation between two things.
func (*Thing) DelRelation ¶
DelRelation deletes an "is a" relation between two things.
func (*Thing) Get ¶
func (t *Thing) Get(ctx context.Context, key string, data interface{}) (meta driver.DocumentMeta, err error)
Get returns a thing.
func (*Thing) IsRelation ¶
func (t *Thing) IsRelation(ctx context.Context, childKey, parentKey string) (exists bool, err error)
IsRelation returns true, if an "is a" relation between two things exists.
func (*Thing) List ¶
List returns an ordered list of (max) count keys of things - starting with offset.
func (*Thing) ListRelations ¶
func (t *Thing) ListRelations(ctx context.Context, offset, count uint) (matches []RelationMatch, err error)
ListRelations returns an ordered list of (max) count "is a" relations - starting with offset.
type WhichMatch ¶
type WhichMatch struct { Object string `json:"object"` Rules []AllowMatch `json:"rules"` }
Click to show internal directories.
Click to hide internal directories.