namespace

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNamespaceNotFoundErr

func NewNamespaceNotFoundErr(nsName string) error

NewNamespaceNotFoundErr constructs a new namespace not found error.

func NewRelationNotFoundErr

func NewRelationNotFoundErr(nsName string, relationName string) error

NewRelationNotFoundErr constructs a new relation not found error.

Types

type AllowedDirectRelation

type AllowedDirectRelation int

AllowedDirectRelation indicates whether a relation is allowed on the right side of another relation.

const (
	// UnknownIfRelationAllowed indicates that no type information is defined for
	// this relation.
	UnknownIfRelationAllowed AllowedDirectRelation = iota

	// DirectRelationValid indicates that the specified subject relation is valid as
	// part of a *direct* tuple on the relation.
	DirectRelationValid

	// DirectRelationNotValid indicates that the specified subject relation is not
	// valid as part of a *direct* tuple on the relation.
	DirectRelationNotValid
)

type AllowedPublicSubject added in v1.3.0

type AllowedPublicSubject int

AllowedPublicSubject indicates whether a public subject of a particular kind is allowed on the right side of another relation.

const (
	// UnknownIfPublicAllowed indicates that no type information is defined for
	// this relation.
	UnknownIfPublicAllowed AllowedPublicSubject = iota

	// PublicSubjectAllowed indicates that the specified subject wildcard is valid as
	// part of a *direct* tuple on the relation.
	PublicSubjectAllowed

	// PublicSubjectNotAllowed indicates that the specified subject wildcard is not
	// valid as part of a *direct* tuple on the relation.
	PublicSubjectNotAllowed
)

type Delta

type Delta struct {
	// Type is the type of this delta.
	Type DeltaType

	// RelationName is the name of the relation to which this delta applies, if any.
	RelationName string

	// DirectType is the direct relation type added or removed, if any.
	DirectType *v0.RelationReference

	// WildcardType is the wildcard type added or removed, if any.
	WildcardType string
}

type DeltaType

type DeltaType string

DeltaType defines the type of namespace deltas.

const (
	// NamespaceAdded indicates that the namespace was newly added/created.
	NamespaceAdded DeltaType = "namespace-added"

	// NamespaceRemoved indicates that the namespace was removed.
	NamespaceRemoved DeltaType = "namespace-removed"

	// AddedRelation indicates that the relation was added to the namespace.
	AddedRelation DeltaType = "added-relation"

	// RemovedRelation indicates that the relation was removed from the namespace.
	RemovedRelation DeltaType = "removed-relation"

	// ChangedRelationImpl indicates that the implementation of the relation has changed in some
	// way.
	ChangedRelationImpl DeltaType = "changed-relation-implementation"

	// RelationDirectTypeAdded indicates that an allowed direct relation type has been added to
	// the relation.
	RelationDirectTypeAdded DeltaType = "relation-direct-type-added"

	// RelationDirectTypeRemoved indicates that an allowed direct relation type has been removed from
	// the relation.
	RelationDirectTypeRemoved DeltaType = "relation-direct-type-removed"

	// RelationDirectWildcardTypeAdded indicates that an allowed relation wildcard type has been added to
	// the relation.
	RelationDirectWildcardTypeAdded DeltaType = "relation-direct-type-added"

	// RelationDirectWildcardTypeRemoved indicates that an allowed relation wildcard type has been removed from
	// the relation.
	RelationDirectWildcardTypeRemoved DeltaType = "relation-direct-type-removed"
)

type ErrNamespaceNotFound

type ErrNamespaceNotFound struct {
	// contains filtered or unexported fields
}

ErrNamespaceNotFound occurs when a namespace was not found.

func (ErrNamespaceNotFound) MarshalZerologObject

func (enf ErrNamespaceNotFound) MarshalZerologObject(e *zerolog.Event)

func (ErrNamespaceNotFound) NotFoundNamespaceName

func (enf ErrNamespaceNotFound) NotFoundNamespaceName() string

NotFoundNamespaceName returns the name of the namespace that was not found.

type ErrRelationNotFound

type ErrRelationNotFound struct {
	// contains filtered or unexported fields
}

ErrRelationNotFound occurs when a relation was not found under a namespace.

func (ErrRelationNotFound) MarshalZerologObject

func (erf ErrRelationNotFound) MarshalZerologObject(e *zerolog.Event)

func (ErrRelationNotFound) NamespaceName

func (erf ErrRelationNotFound) NamespaceName() string

NamespaceName returns the name of the namespace in which the relation was not found.

func (ErrRelationNotFound) NotFoundRelationName

func (erf ErrRelationNotFound) NotFoundRelationName() string

NotFoundRelationName returns the name of the relation not found.

type LookupNamespace added in v0.0.2

type LookupNamespace func(ctx context.Context, name string) (*v0.NamespaceDefinition, error)

LookupNamespace is a function used to lookup a namespace.

type Manager

type Manager interface {
	// ReadNamespace reads a namespace definition and version and returns it if found.
	//
	// Returns ErrNamespaceNotFound if the namespace cannot be found.
	// Returns the direct downstream error for all other unknown error.
	ReadNamespace(ctx context.Context, nsName string, revision decimal.Decimal) (*v0.NamespaceDefinition, error)

	// CheckNamespaceAndRelation checks that the specified namespace and relation exist in the
	// datastore.
	//
	// Returns ErrNamespaceNotFound if the namespace cannot be found.
	// Returns ErrRelationNotFound if the relation was not found in the namespace.
	// Returns the direct downstream error for all other unknown error.
	CheckNamespaceAndRelation(ctx context.Context, namespace, relation string, allowEllipsis bool, revision decimal.Decimal) error

	// ReadNamespaceAndTypes reads a namespace definition, version, and type system and returns it if found.
	ReadNamespaceAndTypes(ctx context.Context, nsName string, revision decimal.Decimal) (*v0.NamespaceDefinition, *NamespaceTypeSystem, error)

	// Close closes the namespace manager, disposing of any resources.
	//
	// NOTE: Should *not* call Close on the datastore.
	Close() error
}

Manager is a subset of the datastore interface that can read (and possibly cache) namespaces.

func NewCachingNamespaceManager

func NewCachingNamespaceManager(
	delegate datastore.Datastore,
	expiration time.Duration,
	cacheConfig *ristretto.Config,
) (Manager, error)

type NamespaceDiff

type NamespaceDiff struct {
	// contains filtered or unexported fields
}

NamespaceDiff holds the diff between two namespaces.

func DiffNamespaces

func DiffNamespaces(existing *v0.NamespaceDefinition, updated *v0.NamespaceDefinition) (*NamespaceDiff, error)

DiffNamespaces performs a diff between two namespace definitions. One or both of the definitions can be `nil`, which will be treated as an add/remove as applicable.

func (NamespaceDiff) Deltas

func (nd NamespaceDiff) Deltas() []Delta

Deltas returns the deltas between the two namespaces.

type NamespaceTypeSystem

type NamespaceTypeSystem struct {
	// contains filtered or unexported fields
}

NamespaceTypeSystem represents typing information found in a namespace.

func BuildNamespaceTypeSystem

func BuildNamespaceTypeSystem(nsDef *v0.NamespaceDefinition, lookupNamespace LookupNamespace) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystem constructs a type system view of a namespace definition.

func BuildNamespaceTypeSystemForDefs added in v0.0.2

func BuildNamespaceTypeSystemForDefs(nsDef *v0.NamespaceDefinition, allDefs []*v0.NamespaceDefinition) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystemForDefs constructs a type system view of a namespace definition, with lookup in the list of definitions given.

func BuildNamespaceTypeSystemForManager added in v0.0.2

func BuildNamespaceTypeSystemForManager(nsDef *v0.NamespaceDefinition, manager Manager, revision decimal.Decimal) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystemForManager constructs a type system view of a namespace definition, with automatic lookup via the namespace manager.

func BuildNamespaceTypeSystemWithFallback added in v0.0.2

func BuildNamespaceTypeSystemWithFallback(nsDef *v0.NamespaceDefinition, manager Manager, additionalDefs []*v0.NamespaceDefinition, revision decimal.Decimal) (*NamespaceTypeSystem, error)

BuildNamespaceTypeSystemWithFallback constructs a type system view of a namespace definition, with automatic lookup via the additional defs first, and then the namespace manager as a fallback.

func (*NamespaceTypeSystem) AllowedDirectRelationsAndWildcards added in v1.3.0

func (nts *NamespaceTypeSystem) AllowedDirectRelationsAndWildcards(sourceRelationName string) ([]*v0.AllowedRelation, error)

AllowedDirectRelationsAndWildcards returns the allowed subject relations for a source relation. Note that this function will return wildcards.

func (*NamespaceTypeSystem) AllowedSubjectRelations added in v1.3.0

func (nts *NamespaceTypeSystem) AllowedSubjectRelations(sourceRelationName string) ([]*v0.RelationReference, error)

AllowedSubjectRelations returns the allowed subject relations for a source relation. Note that this function will *not* return wildcards.

func (*NamespaceTypeSystem) HasRelation

func (nts *NamespaceTypeSystem) HasRelation(relationName string) bool

HasRelation returns true if the namespace has the given relation defined.

func (*NamespaceTypeSystem) HasTypeInformation added in v0.0.2

func (nts *NamespaceTypeSystem) HasTypeInformation(relationName string) bool

HasTypeInformation returns true if the relation with the given name exists and has type information defined.

func (*NamespaceTypeSystem) IsAllowedDirectRelation

func (nts *NamespaceTypeSystem) IsAllowedDirectRelation(sourceRelationName string, targetNamespaceName string, targetRelationName string) (AllowedDirectRelation, error)

IsAllowedDirectRelation returns whether the subject relation is allowed to appear on the right hand side of a tuple placed in the source relation with the given name.

func (*NamespaceTypeSystem) IsAllowedPublicNamespace added in v1.3.0

func (nts *NamespaceTypeSystem) IsAllowedPublicNamespace(sourceRelationName string, targetNamespaceName string) (AllowedPublicSubject, error)

IsAllowedPublicNamespace returns whether the target namespace is defined as public on the source relation.

func (*NamespaceTypeSystem) IsPermission added in v0.0.2

func (nts *NamespaceTypeSystem) IsPermission(relationName string) bool

IsPermission returns true if the namespace has the given relation defined and it is a permission.

func (*NamespaceTypeSystem) ReferencesWildcardType added in v1.3.0

func (nts *NamespaceTypeSystem) ReferencesWildcardType(ctx context.Context, relationName string) (*WildcardTypeReference, error)

ReferencesWildcardType returns true if the relation references a wildcard type, either directly or via another relation.

func (*NamespaceTypeSystem) Validate

func (nts *NamespaceTypeSystem) Validate(ctx context.Context) error

Validate runs validation on the type system for the namespace to ensure it is consistent.

type WildcardTypeReference added in v1.3.0

type WildcardTypeReference struct {
	// ReferencingRelation is the relation referencing the wildcard type.
	ReferencingRelation *v0.RelationReference

	// WildcardType is the wildcard type referenced.
	WildcardType *v0.AllowedRelation
}

WildcardTypeReference represents a relation that references a wildcard type.

Jump to

Keyboard shortcuts

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