engines

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkChecker

type BulkChecker struct {

	// input queue for permission check requests
	RequestChan chan BulkCheckerRequest
	// contains filtered or unexported fields
}

BulkChecker is a struct for checking permissions in bulk.

func NewBulkChecker

func NewBulkChecker(ctx context.Context, engine *CheckEngine, callback func(entityID string, result base.PermissionCheckResponse_Result), concurrencyLimit int) *BulkChecker

NewBulkChecker creates a new BulkChecker instance. ctx: context for managing goroutines and cancellation engine: the CheckEngine to use for permission checks callback: a callback function that handles the result of each permission check concurrencyLimit: the maximum number of concurrent permission checks

func (*BulkChecker) Start

func (c *BulkChecker) Start()

Start begins processing permission check requests from the RequestChan. It starts an errgroup that manages multiple goroutines for performing permission checks.

func (*BulkChecker) Stop

func (c *BulkChecker) Stop()

Stop stops input by closing the RequestChan.

func (*BulkChecker) Wait

func (c *BulkChecker) Wait() error

Wait waits for all goroutines in the errgroup to finish. Returns an error if any of the goroutines encounter an error.

type BulkCheckerRequest

type BulkCheckerRequest struct {
	Request *base.PermissionCheckRequest
	Result  base.PermissionCheckResponse_Result
}

BulkCheckerRequest is a struct for a permission check request and the channel to send the result.

type BulkPublisher

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

BulkPublisher is a struct for streaming permission check results.

func NewBulkPublisher

func NewBulkPublisher(ctx context.Context, request *base.PermissionLookupEntityRequest, bulkChecker *BulkChecker) *BulkPublisher

NewBulkPublisher creates a new BulkStreamer instance.

func (*BulkPublisher) Publish

Publish publishes a permission check request to the BulkChecker.

type CheckCombiner

type CheckCombiner func(ctx context.Context, functions []CheckFunction, limit int) (*base.PermissionCheckResponse, error)

CheckCombiner is a type that represents a function which takes a context, a slice of CheckFunctions, and a limit. It combines the results of multiple CheckFunctions according to a specific strategy and returns a PermissionCheckResponse along with an error.

type CheckEngine

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

CheckEngine is a core component responsible for performing permission checks. It reads schema and relationship information, and uses the engine key manager to validate permission requests.

func NewCheckEngine

func NewCheckEngine(sr storage.SchemaReader, rr storage.RelationshipReader, opts ...CheckOption) *CheckEngine

NewCheckEngine creates a new CheckEngine instance for performing permission checks. It takes a key manager, schema reader, and relationship reader as parameters. Additionally, it allows for optional configuration through CheckOption function arguments.

func (*CheckEngine) Check added in v0.4.0

func (engine *CheckEngine) Check(ctx context.Context, request *base.PermissionCheckRequest) (response *base.PermissionCheckResponse, err error)

Check executes a permission check based on the provided request. The permission field in the request can either be a relation or an permission. This function performs various checks and returns the permission check response along with any errors that may have occurred.

func (*CheckEngine) SetInvoker added in v0.4.0

func (engine *CheckEngine) SetInvoker(invoker invoke.Check)

SetInvoker sets the delegate for the CheckEngine.

type CheckFunction

type CheckFunction func(ctx context.Context) (*base.PermissionCheckResponse, error)

CheckFunction is a type that represents a function that takes a context and returns a PermissionCheckResponse along with an error. It is used to perform individual permission checks within the CheckEngine.

type CheckOption

type CheckOption func(engine *CheckEngine)

CheckOption - a functional option type for configuring the CheckEngine.

func CheckConcurrencyLimit

func CheckConcurrencyLimit(limit int) CheckOption

CheckConcurrencyLimit - a functional option that sets the concurrency limit for the CheckEngine.

type CheckResponse

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

CheckResponse - a struct that holds a PermissionCheckResponse and an error for a single check function.

type ERMap

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

ERMap - a thread-safe map of ENR records.

func (*ERMap) Add

func (s *ERMap) Add(onr *base.EntityAndRelation) bool

type EntityFilterEngine added in v0.4.1

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

EntityFilterEngine is responsible for executing linked entity operations

func NewEntityFilterEngine added in v0.4.1

func NewEntityFilterEngine(schemaReader storage.SchemaReader, relationshipReader storage.RelationshipReader) *EntityFilterEngine

NewEntityFilterEngine creates a new EntityFilter engine

func (*EntityFilterEngine) EntityFilter added in v0.4.1

func (engine *EntityFilterEngine) EntityFilter(
	ctx context.Context,
	request *base.PermissionEntityFilterRequest,
	visits *ERMap,
	publisher *BulkPublisher,
) (err error)

EntityFilter is a method of the EntityFilterEngine struct. It executes a permission request for linked entities.

type ExpandCombiner

type ExpandCombiner func(ctx context.Context, target *base.EntityAndRelation, functions []ExpandFunction) ExpandResponse

ExpandCombiner represents a function that combines the results of multiple ExpandFunction calls into a single ExpandResponse.

type ExpandEngine

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

ExpandEngine - This comment is describing a type called ExpandEngine. The ExpandEngine type contains two fields: schemaReader, which is a storage.SchemaReader object, and relationshipReader, which is a storage.RelationshipReader object. The ExpandEngine type is used to expand permission scopes based on a given user ID and a set of permission requirements.

func NewExpandEngine

NewExpandEngine - This function creates a new instance of ExpandEngine by taking a SchemaReader and a RelationshipReader as parameters and returning a pointer to the created instance. The SchemaReader is used to read schema definitions, while the RelationshipReader is used to read relationship definitions.

func (*ExpandEngine) Expand added in v0.4.0

func (engine *ExpandEngine) Expand(ctx context.Context, request *base.PermissionExpandRequest) (response *base.PermissionExpandResponse, err error)

Expand - This is the Run function of the ExpandEngine type, which takes a context, a PermissionExpandRequest, and returns a PermissionExpandResponse and an error. The function begins by starting a new OpenTelemetry span, with the name "permissions.expand.execute". It then checks if a snap token and schema version are included in the request. If not, it retrieves the head snapshot and head schema version, respectively, from the appropriate repository.

Finally, the function calls the expand function of the ExpandEngine type with the context, PermissionExpandRequest, and false value, and returns the resulting PermissionExpandResponse and error. If there is an error, the span records the error and sets the status to indicate an error.

type ExpandFunction

type ExpandFunction func(ctx context.Context, expandChain chan<- ExpandResponse)

ExpandFunction represents a function that expands the schema and relationships of a request and sends the response through the provided channel.

type ExpandResponse

type ExpandResponse struct {
	Response *base.PermissionExpandResponse
	Err      error
}

ExpandResponse is a struct that contains the response and error returned from the expand function in the ExpandEngine. It is used to return the response and error together as a single object.

type LookupEntityEngine

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

LookupEntityEngine is a struct that performs permission checks on a set of entities and returns the entities that have the requested permission.

func NewLookupEntityEngine

func NewLookupEntityEngine(check *CheckEngine, filter *EntityFilterEngine, opts ...LookupEntityOption) *LookupEntityEngine

NewLookupEntityEngine creates a new LookupEntityEngine instance. engine: the CheckEngine to use for permission checks reader: the RelationshipReader to retrieve entity relationships

func (*LookupEntityEngine) LookupEntity added in v0.4.0

LookupEntity performs a permission check on a set of entities and returns a response containing the IDs of the entities that have the requested permission.

func (*LookupEntityEngine) LookupEntityStream added in v0.4.0

LookupEntityStream performs a permission check on a set of entities and streams the results containing the IDs of the entities that have the requested permission.

type LookupEntityOption

type LookupEntityOption func(engine *LookupEntityEngine)

LookupEntityOption - a functional option type for configuring the LookupEntityEngine.

func LookupEntityConcurrencyLimit

func LookupEntityConcurrencyLimit(limit int) LookupEntityOption

LookupEntityConcurrencyLimit - a functional option that sets the concurrency limit for the LookupEntityEngine.

type LookupSubjectEngine added in v0.4.1

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

func NewLookupSubjectEngine added in v0.4.1

func NewLookupSubjectEngine(filter *SubjectFilterEngine, opts ...LookupSubjectOption) *LookupSubjectEngine

func (*LookupSubjectEngine) LookupSubject added in v0.4.1

func (*LookupSubjectEngine) LookupSubjectStream added in v0.4.1

type LookupSubjectOption added in v0.4.1

type LookupSubjectOption func(engine *LookupSubjectEngine)

LookupSubjectOption - a functional option type for configuring the LookupSubjectEngine.

func LookupSubjectConcurrencyLimit added in v0.4.1

func LookupSubjectConcurrencyLimit(limit int) LookupSubjectOption

LookupSubjectConcurrencyLimit - a functional option that sets the concurrency limit for the LookupSubjectEngine.

type Stream added in v0.4.1

type Stream struct {
	ResultChan chan *base.Subject

	// Results
	Results []*base.Subject
	// contains filtered or unexported fields
}

func NewStream added in v0.4.1

func NewStream(ctx context.Context, callback func(subject *base.Subject)) *Stream

func (*Stream) AddResult added in v0.4.1

func (s *Stream) AddResult(subject ...*base.Subject)

AddResult -

func (*Stream) ConsumeData added in v0.4.1

func (s *Stream) ConsumeData()

ConsumeData -

func (*Stream) Publish added in v0.4.1

func (s *Stream) Publish(d *base.Subject)

func (*Stream) Wait added in v0.4.1

func (s *Stream) Wait() error

Wait waits for all goroutines in the errgroup to finish. Returns an error if any of the goroutines encounter an error.

type SubjectFilterEngine added in v0.4.1

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

func NewSubjectFilterEngine added in v0.4.1

func NewSubjectFilterEngine(sr storage.SchemaReader, rr storage.RelationshipReader) *SubjectFilterEngine

func (*SubjectFilterEngine) SubjectFilter added in v0.4.1

func (engine *SubjectFilterEngine) SubjectFilter(
	ctx context.Context,
	request *base.PermissionSubjectFilterRequest,
	stream *Stream,
) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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