Documentation ¶
Overview ¶
Package entfga is an ent extension that creates hooks for OpenFGA relationships
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedType is returned when the object type is not supported ErrUnsupportedType = errors.New("unsupported type") // ErrMissingRole is returned when an update request is made that contains no role ErrMissingRole = errors.New("missing role in update") // ErrFailedToGenerateTemplate is returned when the template cannot be generated ErrFailedToGenerateTemplate = errors.New("failed to generate template") // ErrFailedToWriteTemplate is returned when the template cannot be written ErrFailedToWriteTemplate = errors.New("failed to write template") )
Functions ¶
func AuthzHooks ¶
AuthzHooks returns a list of authorization hooks for create, update, and delete operations on a specific type of mutation.
Types ¶
type Annotations ¶
type Annotations struct { ObjectType string `yaml:"ObjectType,omitempty"` // Object type for the fga relationship IncludeHooks bool `yaml:"includeHooks,omitempty"` // Include hooks for the fga extension to add tuples to FGA IDField string `yaml:"idField,omitempty"` // ID field for the object type NillableIDField bool `yaml:"nillableIDField,omitempty"` // NillableIDField set to true if the id is optional field in the ent schema OrgOwnedField bool `yaml:"orgOwnedField,omitempty"` // OrgOwnedField set to true if the field is an org owned field and org automatically set by the system }
Annotations of the fga extension
type AuthzExtension ¶
type AuthzExtension struct { entc.DefaultExtension // contains filtered or unexported fields }
AuthzExtension implements entc.Extension.
func New ¶
func New(opts ...ConfigOption) *AuthzExtension
New creates a new fga extension with the provided config options
func (*AuthzExtension) Annotations ¶
func (e *AuthzExtension) Annotations() []entc.Annotation
Annotations of the AuthzExtension
func (*AuthzExtension) GenerateAuthzChecks ¶
func (e *AuthzExtension) GenerateAuthzChecks() error
GenerateAuthzChecks generates the authz checks for the ent schema this is separate to allow the function to be called outside the entc generation due to dependencies between the ent policies and the authz checks
func (*AuthzExtension) Templates ¶
func (e *AuthzExtension) Templates() []*gen.Template
Templates returns the generated templates which include the client and authz from mutation
type Config ¶
type Config struct { // SoftDeletes is used to determine if the schema uses soft deletes SoftDeletes bool // SchemaPath is the path to the schema directory SchemaPath string // GeneratedPath is the path to the generated directory GeneratedPath string // GeneratedPkg is the package that the generated code will be placed in GeneratedPkg string }
type ConfigOption ¶
type ConfigOption = func(*Config)
func WithGeneratedPath ¶
func WithGeneratedPath(generatedPath string) ConfigOption
WithGeneratedPath allows you to set an alternative ent generated path Defaults to "internal/ent/generated"
func WithGeneratedPkg ¶
func WithGeneratedPkg(generatedPkg string) ConfigOption
WithGeneratedPkg allows you to set an alternative generated package Defaults to "generated"
func WithSchemaPath ¶
func WithSchemaPath(schemaPath string) ConfigOption
WithSchemaPath allows you to set an alternative schemaPath Defaults to "./schema"
func WithSoftDeletes ¶
func WithSoftDeletes() ConfigOption
WithSoftDeletes ensure the delete hook is still used even when soft deletes change the Op to Update
type Mutation ¶
type Mutation interface { // Op is the ent operation being taken on the Mutation (Create, Update, UpdateOne, Delete, DeleteOne) Op() ent.Op // CreateTuplesFromCreate creates tuple relationships for the user/object type on Create Mutations CreateTuplesFromCreate(ctx context.Context) error // CreateTuplesFromUpdate creates new and deletes old tuple relationships for the user/object type on Update Mutations CreateTuplesFromUpdate(ctx context.Context) error // CreateTuplesFromDelete deletes tuple relationships for the user/object type on Delete Mutations CreateTuplesFromDelete(ctx context.Context) error // CheckAccessForEdit checks if the user has access to edit the object type CheckAccessForEdit(ctx context.Context) error // CheckAccessForDelete checks if the user has access to delete the object type CheckAccessForDelete(ctx context.Context) error }
Mutation interface that all generated Mutation types must implement These functions (with the exception of Op() which is already created) are generated by the ent extension for every schema that includes the `entfga.NewFGAExtension“ extension to satisfy the interface If hooks are skipped by the mutation, the functions are created to satisfy the interface but always return nil and are not added to the client
type Mutator ¶
Mutator is an interface thats defines a method for mutating a generic ent value based on a given mutation. This is used as a generic interface that ent generated Mutations will implement
type OpType ¶
type OpType string
OpType is the ent operation type in string form
func (OpType) MarshalGQL ¶
MarshalGQL implement the Marshaler interface for gqlgen
func (*OpType) Scan ¶
Scan implements the `database/sql.Scanner` interface for the `OpType` type and is used to convert a value from the database into an `OpType` value.
func (*OpType) UnmarshalGQL ¶
UnmarshalGQL implement the Unmarshaler interface for gqlgen
type Querier ¶
Querier is an interface thats defines a method for querying a generic ent value based on a given query. This is used as a generic interface that ent generated Query will implement
type Query ¶
type Query interface { // Op is the ent operation being taken on the Mutation (Create, Update, UpdateOne, Delete, DeleteOne) Op() ent.Op // CheckAccess checks if the user has read access to the object type CheckAccess(ctx context.Context) error }
Query interface that all generated Query types must implement
type Role ¶
type Role string
func (Role) MarshalGQL ¶
MarshalGQL implement the Marshaler interface for gqlgen
func (*Role) UnmarshalGQL ¶
UnmarshalGQL implement the Unmarshaler interface for gqlgen
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
basic/ent
Code generated by entfga, DO NOT EDIT.
|
Code generated by entfga, DO NOT EDIT. |
basic/ent/enums
Package enums has enums
|
Package enums has enums |