common

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CaveatNameKey is a tracing attribute representing a caveat name
	CaveatNameKey = attribute.Key("authzed.com/spicedb/sql/caveatName")

	// ObjNamespaceNameKey is a tracing attribute representing the resource
	// object type.
	ObjNamespaceNameKey = attribute.Key("authzed.com/spicedb/sql/objNamespaceName")

	// ObjRelationNameKey is a tracing attribute representing the resource
	// relation.
	ObjRelationNameKey = attribute.Key("authzed.com/spicedb/sql/objRelationName")

	// ObjIDKey is a tracing attribute representing the resource object ID.
	ObjIDKey = attribute.Key("authzed.com/spicedb/sql/objId")

	// SubNamespaceNameKey is a tracing attribute representing the subject object
	// type.
	SubNamespaceNameKey = attribute.Key("authzed.com/spicedb/sql/subNamespaceName")

	// SubRelationNameKey is a tracing attribute representing the subject
	// relation.
	SubRelationNameKey = attribute.Key("authzed.com/spicedb/sql/subRelationName")

	// SubObjectIDKey is a tracing attribute representing the the subject object
	// ID.
	SubObjectIDKey = attribute.Key("authzed.com/spicedb/sql/subObjectId")
)
View Source
var MaxGCInterval = 60 * time.Minute

Functions

func ContextualizedCaveatFrom added in v1.14.0

func ContextualizedCaveatFrom(name string, context map[string]any) (*core.ContextualizedCaveat, error)

ContextualizedCaveatFrom convenience method that handles creation of a contextualized caveat given the possibility of arguments with zero-values.

func LogOnError added in v1.14.0

func LogOnError(ctx context.Context, f func() error)

LogOnError executes the function and logs the error. Useful to avoid silently ignoring errors in defer statements

func MustIteratorBeClosed added in v1.21.0

func MustIteratorBeClosed(iter *sliceRelationshipIterator)

MustIteratorBeClosed is a function which can be used as a finalizer to make sure that tuples are getting closed before they are garbage collected.

func NewCreateRelationshipExistsError added in v1.12.0

func NewCreateRelationshipExistsError(relationship *core.RelationTuple) error

NewCreateRelationshipExistsError creates a new CreateRelationshipExistsError.

func NewSliceRelationshipIterator added in v1.21.0

func NewSliceRelationshipIterator(tuples []*core.RelationTuple, order options.SortOrder) datastore.RelationshipIterator

NewSliceRelationshipIterator creates a datastore.TupleIterator instance from a materialized slice of tuples.

func RegisterGCMetrics added in v1.10.0

func RegisterGCMetrics() error

RegisterGCMetrics registers garbage collection metrics to the default registry.

func RunGarbageCollection added in v1.16.0

func RunGarbageCollection(gc GarbageCollector, window, timeout time.Duration) error

RunGarbageCollection runs garbage collection for the datastore.

func StartGarbageCollector added in v1.10.0

func StartGarbageCollector(ctx context.Context, gc GarbageCollector, interval, window, timeout time.Duration) error

StartGarbageCollector loops forever until the context is canceled and performs garbage collection on the provided interval.

func UpdateTuplesInDatastore added in v1.12.0

func UpdateTuplesInDatastore(ctx context.Context, ds datastore.Datastore, updates ...*core.RelationTupleUpdate) (datastore.Revision, error)

UpdateTuplesInDatastore is a convenience method to perform multiple relation update operations on a Datastore

func WithJitter added in v1.5.0

func WithJitter(factor float64, interval time.Duration) time.Duration

WithJitter adjusts an interval by a random amount within some factor of the original interval. Intervals near half of max int64 can return durations outside the jitter factor.

func WriteTuples added in v1.12.0

WriteTuples is a convenience method to perform the same update operation on a set of tuples

Types

type Changes added in v1.3.0

type Changes[R datastore.Revision, K comparable] struct {
	// contains filtered or unexported fields
}

Changes represents a set of tuple mutations that are kept self-consistent across one or more transaction revisions.

func NewChanges added in v1.3.0

func NewChanges[R datastore.Revision, K comparable](keyFunc func(R) K) Changes[R, K]

NewChanges creates a new Changes object for change tracking and de-duplication.

func (Changes[R, K]) AddChange added in v1.3.0

func (ch Changes[R, K]) AddChange(
	ctx context.Context,
	rev R,
	tpl *core.RelationTuple,
	op core.RelationTupleUpdate_Operation,
)

AddChange adds a specific change to the complete list of tracked changes

func (Changes[R, K]) AsRevisionChanges added in v1.3.0

func (ch Changes[R, K]) AsRevisionChanges(lessThanFunc func(lhs, rhs K) bool) []datastore.RevisionChanges

AsRevisionChanges returns the list of changes processed so far as a datastore watch compatible, ordered, changelist.

type CreateRelationshipExistsError added in v1.12.0

type CreateRelationshipExistsError struct {

	// Relationship is the relationship that caused the error. May be nil, depending on the datastore.
	Relationship *core.RelationTuple
	// contains filtered or unexported fields
}

CreateRelationshipExistsError is an error returned when attempting to CREATE an already-existing relationship.

type DeletionCounts added in v1.10.0

type DeletionCounts struct {
	Relationships int64
	Transactions  int64
	Namespaces    int64
}

DeletionCounts tracks the amount of deletions that occurred when calling DeleteBeforeTx.

func (DeletionCounts) MarshalZerologObject added in v1.10.0

func (g DeletionCounts) MarshalZerologObject(e *zerolog.Event)

type ExecuteQueryFunc added in v1.5.0

type ExecuteQueryFunc func(ctx context.Context, sql string, args []any) ([]*core.RelationTuple, error)

ExecuteQueryFunc is a function that can be used to execute a single rendered SQL query.

type GarbageCollector added in v1.10.0

type GarbageCollector interface {
	ReadyState(context.Context) (datastore.ReadyState, error)
	Now(context.Context) (time.Time, error)
	TxIDBefore(context.Context, time.Time) (datastore.Revision, error)
	DeleteBeforeTx(ctx context.Context, txID datastore.Revision) (DeletionCounts, error)
}

GarbageCollector represents any datastore that supports external garbage collection.

type PaginationFilterType added in v1.21.0

type PaginationFilterType uint8

PaginationFilterType is an enumerator

const (
	// TupleComparison uses a comparison with a compound key,
	// e.g. (namespace, object_id, relation) > ('ns', '123', 'viewer')
	// which is not compatible with all datastores.
	TupleComparison PaginationFilterType = iota

	// ExpandedLogicComparison comparison uses a nested tree of ANDs and ORs to properly
	// filter out already received relationships. Useful for databases that do not support
	// tuple comparison, or do not execute it efficiently
	ExpandedLogicComparison
)

type SchemaInformation

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

SchemaInformation holds the schema information from the SQL datastore implementation.

func NewSchemaInformation added in v1.21.0

func NewSchemaInformation(
	colNamespace,
	colObjectID,
	colRelation,
	colUsersetNamespace,
	colUsersetObjectID,
	colUsersetRelation,
	colCaveatName string,
	paginationFilterType PaginationFilterType,
) SchemaInformation

type SchemaQueryFilterer added in v1.3.0

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

SchemaQueryFilterer wraps a SchemaInformation and SelectBuilder to give an opinionated way to build query objects.

func NewSchemaQueryFilterer added in v1.3.0

func NewSchemaQueryFilterer(schema SchemaInformation, initialQuery sq.SelectBuilder) SchemaQueryFilterer

NewSchemaQueryFilterer creates a new SchemaQueryFilterer object.

func (SchemaQueryFilterer) After added in v1.21.0

func (SchemaQueryFilterer) FilterToRelation added in v1.3.0

func (sqf SchemaQueryFilterer) FilterToRelation(relation string) SchemaQueryFilterer

FilterToRelation returns a new SchemaQueryFilterer that is limited to resources with the specified relation.

func (SchemaQueryFilterer) FilterToResourceID added in v1.3.0

func (sqf SchemaQueryFilterer) FilterToResourceID(objectID string) SchemaQueryFilterer

FilterToResourceID returns a new SchemaQueryFilterer that is limited to resources with the specified ID.

func (SchemaQueryFilterer) FilterToResourceIDs added in v1.12.0

func (sqf SchemaQueryFilterer) FilterToResourceIDs(resourceIds []string) (SchemaQueryFilterer, error)

FilterToResourceIDs returns a new SchemaQueryFilterer that is limited to resources with any of the specified IDs.

func (SchemaQueryFilterer) FilterToResourceType added in v1.3.0

func (sqf SchemaQueryFilterer) FilterToResourceType(resourceType string) SchemaQueryFilterer

FilterToResourceType returns a new SchemaQueryFilterer that is limited to resources of the specified type.

func (SchemaQueryFilterer) FilterToSubjectFilter added in v1.3.0

func (sqf SchemaQueryFilterer) FilterToSubjectFilter(filter *v1.SubjectFilter) SchemaQueryFilterer

FilterToSubjectFilter returns a new SchemaQueryFilterer that is limited to resources with subjects that match the specified filter.

func (SchemaQueryFilterer) FilterWithCaveatName added in v1.14.0

func (sqf SchemaQueryFilterer) FilterWithCaveatName(caveatName string) SchemaQueryFilterer

func (SchemaQueryFilterer) FilterWithRelationshipsFilter added in v1.12.0

func (sqf SchemaQueryFilterer) FilterWithRelationshipsFilter(filter datastore.RelationshipsFilter) (SchemaQueryFilterer, error)

func (SchemaQueryFilterer) FilterWithSubjectsSelectors added in v1.16.0

func (sqf SchemaQueryFilterer) FilterWithSubjectsSelectors(selectors ...datastore.SubjectsSelector) (SchemaQueryFilterer, error)

FilterWithSubjectsSelectors returns a new SchemaQueryFilterer that is limited to resources with subjects that match the specified selector(s).

func (SchemaQueryFilterer) MustFilterToResourceIDs added in v1.16.0

func (sqf SchemaQueryFilterer) MustFilterToResourceIDs(resourceIds []string) SchemaQueryFilterer

func (SchemaQueryFilterer) MustFilterWithRelationshipsFilter added in v1.16.0

func (sqf SchemaQueryFilterer) MustFilterWithRelationshipsFilter(filter datastore.RelationshipsFilter) SchemaQueryFilterer

MustFilterWithRelationshipsFilter returns a new SchemaQueryFilterer that is limited to resources with resources that match the specified filter.

func (SchemaQueryFilterer) MustFilterWithSubjectsSelectors added in v1.16.0

func (sqf SchemaQueryFilterer) MustFilterWithSubjectsSelectors(selectors ...datastore.SubjectsSelector) SchemaQueryFilterer

MustFilterWithSubjectsSelectors returns a new SchemaQueryFilterer that is limited to resources with subjects that match the specified selector(s).

func (SchemaQueryFilterer) TupleOrder added in v1.21.0

type TupleQuerySplitter added in v1.3.0

type TupleQuerySplitter struct {
	Executor         ExecuteQueryFunc
	UsersetBatchSize uint16
}

TupleQuerySplitter is a tuple query runner shared by SQL implementations of the datastore.

func (TupleQuerySplitter) SplitAndExecuteQuery added in v1.5.0

SplitAndExecuteQuery is used to split up the usersets in a very large query and execute them as separate queries.

type TxCleanupFunc added in v1.8.0

type TxCleanupFunc func(context.Context)

TxCleanupFunc is a function that should be executed when the caller of TransactionFactory is done with the transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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