common

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 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

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

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

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

func NewCreateRelationshipExistsError(relationship *core.RelationTuple) error

NewCreateRelationshipExistsError creates a new CreateRelationshipExistsError.

func NewReadOnlyTransactionError added in v0.0.3

func NewReadOnlyTransactionError(err error) error

NewReadOnlyTransactionError creates a new ReadOnlyTransactionError.

func NewRevisionUnavailableError added in v0.0.3

func NewRevisionUnavailableError(err error) error

NewRevisionUnavailableError creates a new RevisionUnavailableError.

func NewSerializationError

func NewSerializationError(err error) error

NewSerializationError creates a new SerializationError

func NewSliceRelationshipIterator

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

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

func RedactAndLogSensitiveConnString

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

func RegisterGCMetrics() error

RegisterGCMetrics registers garbage collection metrics to the default registry.

func RunGarbageCollection

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

RunGarbageCollection runs garbage collection for the datastore.

func StartGarbageCollector

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

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

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

Types

type Changes

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

func NewChanges[R datastore.Revision, K comparable](keyFunc func(R) K, content datastore.WatchContent, maxByteSize uint64) *Changes[R, K]

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

func (*Changes[R, K]) AddChangedDefinition

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

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

func (*Changes[R, K]) AddDeletedCaveat

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

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

func (*Changes[R, K]) AddDeletedNamespace

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

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

func (*Changes[R, K]) AddRelationshipChange

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

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

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

func (*Changes[R, K]) FilterAndRemoveRevisionChanges

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

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

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

IsEmpty returns if the change set is empty.

func (*Changes[R, K]) SetRevisionMetadata added in v0.0.3

func (ch *Changes[R, K]) SetRevisionMetadata(ctx context.Context, rev R, metadata map[string]any) error

SetRevisionMetadata sets the metadata for the given revision.

type CreateRelationshipExistsError

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

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

GRPCStatus implements retrieving the gRPC status for the error.

type DeletionCounts

type DeletionCounts struct {
	Relationships int64
	Transactions  int64
	Namespaces    int64
}

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

func (DeletionCounts) MarshalZerologObject

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

type ExecuteQueryFunc

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

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

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

type QueryExecutor struct {
	Executor ExecuteQueryFunc
}

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

func (QueryExecutor) ExecuteQuery

ExecuteQuery executes the query.

type ReadOnlyTransactionError added in v0.0.3

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

ReadOnlyTransactionError is returned when an otherwise read-write transaction fails on writes with an error indicating that the datastore is currently in a read-only mode.

func (ReadOnlyTransactionError) GRPCStatus added in v0.0.3

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

type RevisionUnavailableError added in v0.0.3

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

RevisionUnavailableError is returned when a revision is not available on a replica.

type SchemaInformation

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

SchemaInformation holds the schema information from the SQL datastore implementation.

func NewSchemaInformation

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

type SchemaQueryFilterer

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

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

NewSchemaQueryFilterer creates a new SchemaQueryFilterer object.

func (SchemaQueryFilterer) After

func (SchemaQueryFilterer) FilterToRelation

func (sqf SchemaQueryFilterer) FilterToRelation(relation string) SchemaQueryFilterer

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

func (SchemaQueryFilterer) FilterToResourceID

func (sqf SchemaQueryFilterer) FilterToResourceID(objectID string) SchemaQueryFilterer

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

func (SchemaQueryFilterer) FilterToResourceIDs

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

func (sqf SchemaQueryFilterer) FilterToResourceType(resourceType string) SchemaQueryFilterer

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

func (SchemaQueryFilterer) FilterToSubjectFilter

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

func (sqf SchemaQueryFilterer) FilterWithCaveatName(caveatName string) SchemaQueryFilterer

func (SchemaQueryFilterer) FilterWithRelationshipsFilter

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

func (SchemaQueryFilterer) FilterWithResourceIDPrefix

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

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

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

func (SchemaQueryFilterer) MustFilterWithRelationshipsFilter

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

func (sqf SchemaQueryFilterer) MustFilterWithResourceIDPrefix(prefix string) SchemaQueryFilterer

func (SchemaQueryFilterer) MustFilterWithSubjectsSelectors

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

func (SchemaQueryFilterer) UnderlyingQueryBuilder

func (sqf SchemaQueryFilterer) UnderlyingQueryBuilder() sq.SelectBuilder

type SerializationError

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

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

func (SerializationError) Unwrap

func (err SerializationError) Unwrap() error

type TxCleanupFunc

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