common

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 27 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 NewSerializationError added in v1.26.0

func NewSerializationError(err error) error

NewSerializationError creates a new SerializationError

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 RedactAndLogSensitiveConnString added in v1.27.0

func RedactAndLogSensitiveConnString(ctx context.Context, baseErr string, err error, pgURL string) error

RedactAndLogSensitiveConnString elides the given error, logging it only at trace level (after being redacted).

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 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 datastore 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, content datastore.WatchContent) *Changes[R, K]

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

func (*Changes[R, K]) AddChangedDefinition added in v1.29.0

func (ch *Changes[R, K]) AddChangedDefinition(
	ctx context.Context,
	rev R,
	def datastore.SchemaDefinition,
)

AddChangedDefinition adds a change indicating that the schema definition (namespace or caveat) was changed to the definition given.

func (*Changes[R, K]) AddDeletedCaveat added in v1.29.0

func (ch *Changes[R, K]) AddDeletedCaveat(
	_ context.Context,
	rev R,
	caveatName string,
)

AddDeletedCaveat adds a change indicating that the caveat with the name was deleted.

func (*Changes[R, K]) AddDeletedNamespace added in v1.29.0

func (ch *Changes[R, K]) AddDeletedNamespace(
	_ context.Context,
	rev R,
	namespaceName string,
)

AddDeletedNamespace adds a change indicating that the namespace with the name was deleted.

func (*Changes[R, K]) AddRelationshipChange added in v1.29.0

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

AddRelationshipChange 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.

func (*Changes[R, K]) FilterAndRemoveRevisionChanges added in v1.29.0

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

FilterAndRemoveRevisionChanges filters a list of changes processed up to the bound revision from the changes list, removing them and returning the filtered changes.

func (*Changes[R, K]) IsEmpty added in v1.29.0

func (ch *Changes[R, K]) IsEmpty() bool

IsEmpty returns if the change set is empty.

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.

func (CreateRelationshipExistsError) GRPCStatus added in v1.22.0

func (err CreateRelationshipExistsError) GRPCStatus() *status.Status

GRPCStatus implements retrieving the gRPC status for the error.

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 {
	HasGCRun() bool
	MarkGCCompleted()
	ResetGCCompleted()

	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 QueryExecutor added in v1.24.0

type QueryExecutor struct {
	Executor ExecuteQueryFunc
}

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

func (QueryExecutor) ExecuteQuery added in v1.24.0

ExecuteQuery executes the query.

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) FilterWithResourceIDPrefix added in v1.30.0

func (sqf SchemaQueryFilterer) FilterWithResourceIDPrefix(prefix string) (SchemaQueryFilterer, error)

FilterWithResourceIDPrefix returns new SchemaQueryFilterer that is limited to resources whose ID starts with the specified prefix.

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) MustFilterWithResourceIDPrefix added in v1.30.0

func (sqf SchemaQueryFilterer) MustFilterWithResourceIDPrefix(prefix string) SchemaQueryFilterer

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 SerializationError added in v1.26.0

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

SerializationError is returned when there's been a serialization error while performing a datastore operation

func (SerializationError) GRPCStatus added in v1.26.0

func (err SerializationError) GRPCStatus() *status.Status

func (SerializationError) Unwrap added in v1.26.0

func (err SerializationError) Unwrap() error

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.

Jump to

Keyboard shortcuts

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