authz

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 5 Imported by: 0

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 added in v0.1.1

func EntityString[E Entities](e E) string

EntitiesString is a type that represents a list of entities.

func NewEntity added in v0.1.1

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 added in v0.1.1

type Entities interface {
	User | Relation | Object
}

Entities is a type that represents a list of entities.

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 added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

type Stringer func() string

Stringer create a string an adds it to the representation.

func Join added in v0.1.1

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

Join joins the entities with the separator.

func Namespace added in v0.1.1

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

Namespace adds a namespace to the entity.

func String added in v0.1.2

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 added in v0.1.1

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