model

package
v0.33.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ObjectNameSeparator       = "^"
	SubjectRelationSeparator  = "#"
	GeneratedPermissionPrefix = "$"
)
View Source
const (
	ModelVersion int = 5

	ArrowSymbol    = "->"
	WildcardSymbol = "*"
)

Variables

This section is empty.

Functions

func AllowPermissionInArrowBase

func AllowPermissionInArrowBase(opts *validationOptions)

Types

type ArrowPermission

type ArrowPermission struct {
	Relation   string `json:"relation,omitempty"`
	Permission string `json:"permission,omitempty"`
}

type ExclusionPermission

type ExclusionPermission struct {
	Include *PermissionTerm `json:"include,omitempty"`
	Exclude *PermissionTerm `json:"exclude,omitempty"`
}

type Metadata

type Metadata struct {
	UpdatedAt time.Time `json:"updated_at"`
	ETag      string    `json:"etag"`
}

type Model

type Model struct {
	Version  int                    `json:"version"`
	Objects  map[ObjectName]*Object `json:"types"`
	Metadata *Metadata              `json:"metadata"`
	// contains filtered or unexported fields
}

func New

func New(r io.Reader) (*Model, error)

func (*Model) Invert

func (m *Model) Invert() *Model

func (*Model) Reader

func (m *Model) Reader() (io.Reader, error)

func (*Model) StepRelation

func (m *Model) StepRelation(r *Relation, subjs ...ObjectName) []*RelationRef

func (*Model) Validate

func (m *Model) Validate(opts ...ValidationOption) error

Validate enforces the model's internal consistency.

It enforces the following rules:

  • Within an object, a permission cannot share the same name as a relation.
  • Direct relations must reference existing objects .
  • Wildcard relations must reference existing objects.
  • Subject relations must reference existing object#relation pairs.
  • Arrow permissions (relation->rel_or_perm) must reference existing relations/permissions.

func (*Model) ValidateRelation

func (m *Model) ValidateRelation(on ObjectName, oid ObjectID, rn RelationName, sn ObjectName, sid ObjectID, srn RelationName) error

func (*Model) Write

func (m *Model) Write(w io.Writer) error

type Object

type Object struct {
	Relations   Relations   `json:"relations,omitempty"`
	Permissions Permissions `json:"permissions,omitempty"`
}

func NewObject

func NewObject() *Object

func (*Object) HasPermission

func (o *Object) HasPermission(name RelationName) bool

func (*Object) HasRelOrPerm

func (o *Object) HasRelOrPerm(name RelationName) bool

func (*Object) HasRelation

func (o *Object) HasRelation(name RelationName) bool

func (*Object) SubjectTypes

func (o *Object) SubjectTypes(name RelationName) []ObjectName

SubjectTypes returns the list of possible subject types for the given relation or permission.

type ObjectID

type ObjectID string

func (ObjectID) IsWildcard

func (id ObjectID) IsWildcard() bool

func (ObjectID) String

func (id ObjectID) String() string

type ObjectName

type ObjectName string

func (ObjectName) String

func (on ObjectName) String() string

type Permission

type Permission struct {
	Union        PermissionTerms      `json:"union,omitempty"`
	Intersection PermissionTerms      `json:"intersection,omitempty"`
	Exclusion    *ExclusionPermission `json:"exclusion,omitempty"`

	SubjectTypes  []ObjectName `json:"subject_types,omitempty"`
	Intermediates RelationRefs `json:"intermediates,omitempty"`
}

func (*Permission) AddTerm

func (p *Permission) AddTerm(pt *PermissionTerm)

func (*Permission) IsExclusion

func (p *Permission) IsExclusion() bool

func (*Permission) IsIntersection

func (p *Permission) IsIntersection() bool

func (*Permission) IsUnion

func (p *Permission) IsUnion() bool

func (*Permission) Terms

func (p *Permission) Terms() []*PermissionTerm

func (*Permission) Types

func (p *Permission) Types() RelationRefs

func (*Permission) TypesContain

func (p *Permission) TypesContain(rr RelationRef) bool

type PermissionTerm

type PermissionTerm struct {
	Base      RelationName `json:"base,omitempty"`
	RelOrPerm RelationName `json:"rel_or_perm"`

	SubjectTypes  []ObjectName `json:"subject_types,omitempty"`
	Intermediates RelationRefs `json:"intermediates,omitempty"`
}

func (*PermissionTerm) IsArrow

func (pr *PermissionTerm) IsArrow() bool

func (*PermissionTerm) String

func (pr *PermissionTerm) String() string

func (*PermissionTerm) Types

func (pr *PermissionTerm) Types() RelationRefs

type PermissionTerms

type PermissionTerms []*PermissionTerm

func (PermissionTerms) Contains

func (pts PermissionTerms) Contains(pt *PermissionTerm) bool

type Permissions

type Permissions map[RelationName]*Permission

type RelOrPerm

type RelOrPerm interface {
	TypesContain(rel RelationRef) bool
}

type Relation

type Relation struct {
	Union         []*RelationRef `json:"union,omitempty"`
	SubjectTypes  []ObjectName   `json:"subject_types,omitempty"`
	Intermediates RelationRefs   `json:"intermediates,omitempty"`
}

func (*Relation) AddRef

func (r *Relation) AddRef(rr *RelationRef)

func (*Relation) AllRefs

func (r *Relation) AllRefs() []RelationRef

func (*Relation) Types

func (r *Relation) Types() RelationRefs

func (*Relation) TypesContain

func (r *Relation) TypesContain(rr RelationRef) bool

type RelationAssignment

type RelationAssignment int
const (
	RelationAssignmentUnknown RelationAssignment = iota
	RelationAssignmentDirect
	RelationAssignmentSubject
	RelationAssignmentWildcard
)

type RelationName

type RelationName string

func InverseRelation

func InverseRelation(on ObjectName, rn RelationName, srn ...RelationName) RelationName

func PermForRel

func PermForRel(rn RelationName) RelationName

func (RelationName) String

func (rn RelationName) String() string

type RelationRef

type RelationRef struct {
	Object   ObjectName   `json:"object,omitempty"`
	Relation RelationName `json:"relation,omitempty"`
}

func NewRelationRef

func NewRelationRef(on ObjectName, rn RelationName) *RelationRef

func (*RelationRef) Assignment

func (rr *RelationRef) Assignment() RelationAssignment

func (*RelationRef) IsDirect

func (rr *RelationRef) IsDirect() bool

func (*RelationRef) IsSubject

func (rr *RelationRef) IsSubject() bool

func (*RelationRef) IsWildcard

func (rr *RelationRef) IsWildcard() bool

func (*RelationRef) String

func (rr *RelationRef) String() string

type RelationRefs

type RelationRefs []RelationRef

type Relations

type Relations map[RelationName]*Relation

type ValidationOption

type ValidationOption func(*validationOptions)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL