fga

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultNamespaceSeparator = ":"

DefaultNamespaceSeparator is the default separator for namespaces.

View Source
const DefaultSeparator = "/"

DefaultSeparator is the default separator for entities.

Variables

This section is empty.

Functions

func EntityString

func EntityString[E Entities](e E) string

EntitiesString is a type that represents a list of entities.

func NewEntity

func NewEntity[E Entities](s ...Stringer) E

NewEntity returns a new User.

Types

type AuthzError

type AuthzError struct {
	// Op is the operation that caused the error.
	Op string
	// Err is the error that occurred.
	Err error
}

AuthzError is an error that occurred while executing a query.

func NewQueryError

func NewQueryError(op string, err error) *AuthzError

NewQueryError returns a new QueryError.

func (*AuthzError) Error

func (e *AuthzError) Error() string

Error implements the error interface.

func (*AuthzError) Unwrap

func (e *AuthzError) Unwrap() error

Unwrap implements the errors.Wrapper interface.

type Entities

type Entities interface {
	User | Relation | Object
}

Entities is a type that represents a list of entities.

type NoopStore

type NoopStore struct{}

NoopStore is a store that does nothing.

func (*NoopStore) Allowed

func (n *NoopStore) Allowed(context.Context, User, Object, Relation) (bool, error)

Allowed checks if the user is allowed to perform the operation on the object.

func (*NoopStore) WriteTx

func (n *NoopStore) WriteTx(context.Context, func(context.Context, StoreTx) error) error

WriteTx starts a read write transaction.

type Object

type Object string

Object is the object that is being accessed.

const NoopObject Object = ""

NoopObject is an object that represents no object.

func NewObject

func NewObject(s ...Stringer) Object

NewObject returns a new Object.

type Relation

type Relation string

Relation is the relation between the user and the object.

const NoopRelation Relation = ""

NoopRelation is a relation that represents no relation.

func NewRelation

func NewRelation(s ...Stringer) Relation

NewRelation returns a new Relation.

type Store

type Store[Tx any] interface {
	// Allowed checks if the user is allowed to perform the operation on the object.
	Allowed(context.Context, User, Object, Relation) (bool, error)
	// WriteTx starts a read write transaction.
	WriteTx(context.Context, func(context.Context, Tx) error) error
}

Store is an interface that provides methods for transactional operations on the authz database.

func NewStore

func NewStore[Tx any](client *client.OpenFgaClient, tx StoreTxFactory[Tx]) (Store[Tx], error)

NewStore returns a new instance of authz store.

type StoreTx

type StoreTx interface {
	// WriteTuple writes a tuple to the authz database.
	WriteTuple(context.Context, User, Object, Relation) error
	// DeleteTuple deletes a tuple from the authz database.
	DeleteTuple(context.Context, User, Object, Relation) error
}

StoreTx is an interface that provides methods for transactional operations on the authz database.

type StoreTxFactory

type StoreTxFactory[Tx any] func(*client.OpenFgaClient, StoreTx) (Tx, error)

StoreTxFactory is a function that creates a new instance of authz store.

type Stringer

type Stringer func() string

Stringer create a string an adds it to the representation.

func Join

func Join(sep string, entities ...string) Stringer

Join joins the entities with the separator.

func Namespace

func Namespace(namespace string, sep ...string) Stringer

Namespace adds a namespace to the entity.

func String

func String(s string) Stringer

String returns the string representation of the entity.

type User

type User string

User is the user that is making the request.

const NoopUser User = ""

NoopUser is a user that represents no user.

func NewUser

func NewUser(s ...Stringer) User

NewUser returns a new User.

Jump to

Keyboard shortcuts

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