model

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

View Source
const ModelVersion int = 1

Variables

View Source
var ErrInvalidIdentifier = errors.New("invalid identifier")

Functions

func IsValidIdentifier added in v0.0.5

func IsValidIdentifier(in string) bool

func NormalizeIdentifier added in v0.0.5

func NormalizeIdentifier(in string) (string, error)

Types

type ArrowPermission

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

type Changes added in v0.0.5

type Changes struct {
	Objects   []ObjectName
	Relations map[ObjectName][]RelationName
}

type Diff added in v0.0.5

type Diff struct {
	Added   Changes
	Removed Changes
}

type ExclusionPermission

type ExclusionPermission struct {
	Base     string `json:"base,omitempty"`
	Subtract string `json:"subtract,omitempty"`
}

type Identifier added in v0.0.5

type Identifier string

Identifier is the string representation of an object, relation and permission type name.

Identifiers are bounded by the underlying defined regex definition (reIdentifier).

An identifier MUST be: - all lowercase characters - have a minimum length of 3 characters - have a maximum length of 64 characters - start with a character (a-z) - end with a character of a digit (a-z0-9) - can contain dots, underscores and dashes, between the first and last position.

func (Identifier) Valid added in v0.0.5

func (i Identifier) Valid() bool

type Metadata added in v0.0.4

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"`
}

func New added in v0.0.3

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

func (*Model) Diff added in v0.0.5

func (m *Model) Diff(newModel *Model) *Diff

func (*Model) Reader added in v0.0.3

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

func (*Model) Write added in v0.0.4

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

type Object

type Object struct {
	Relations   map[RelationName][]*Relation   `json:"relations,omitempty"`
	Permissions map[PermissionName]*Permission `json:"permissions,omitempty"`
}

type ObjectName

type ObjectName Identifier

type Permission

type Permission struct {
	Union        []string             `json:"union,omitempty"`
	Intersection []string             `json:"intersection,omitempty"`
	Exclusion    *ExclusionPermission `json:"exclusion,omitempty"`
	Arrow        *ArrowPermission     `json:"arrow,omitempty"`
}

type PermissionName

type PermissionName Identifier

type Relation

type Relation struct {
	Direct   ObjectName       `json:"direct,omitempty"`
	Subject  *SubjectRelation `json:"subject,omitempty"`
	Wildcard ObjectName       `json:"wildcard,omitempty"`
}

type RelationName

type RelationName Identifier

type SubjectRelation

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

Jump to

Keyboard shortcuts

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