privacy

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: Apache-2.0 Imports: 3 Imported by: 137

Documentation

Overview

Package privacy provides sets of types and helpers for writing privacy rules in user schemas, and deal with their evaluation at runtime.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Allow may be returned by rules to indicate that the policy
	// evaluation should terminate with an allow decision.
	Allow = errors.New("ent/privacy: allow rule")

	// Deny may be returned by rules to indicate that the policy
	// evaluation should terminate with an deny decision.
	Deny = errors.New("ent/privacy: deny rule")

	// Skip may be returned by rules to indicate that the policy
	// evaluation should continue to the next rule.
	Skip = errors.New("ent/privacy: skip rule")
)

List of policy decisions.

Functions

func DecisionContext

func DecisionContext(parent context.Context, decision error) context.Context

DecisionContext creates a new context from the given parent context with a policy decision attach to it.

func DecisionFromContext

func DecisionFromContext(ctx context.Context) (error, bool)

DecisionFromContext retrieves the policy decision from the context.

func NewPolicies

func NewPolicies(schemas ...interface{ Policy() ent.Policy }) ent.Policy

NewPolicies creates an ent.Policy from list of mixin.Schema and ent.Schema that implement the ent.Policy interface.

Types

type MutationPolicy

type MutationPolicy []MutationRule

MutationPolicy combines multiple mutation rules into a single policy.

func (MutationPolicy) EvalMutation

func (policies MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error

EvalMutation evaluates a mutation against a mutation policy.

type MutationRule

type MutationRule interface {
	EvalMutation(context.Context, ent.Mutation) error
}

MutationRule defines the interface deciding whether a mutation is allowed and optionally modify it.

type Policies

type Policies []ent.Policy

Policies combines multiple policies into a single policy.

func (Policies) EvalMutation

func (policies Policies) EvalMutation(ctx context.Context, m ent.Mutation) error

EvalMutation evaluates the mutation policies. If the Allow error is returned from one of the policies, it stops the evaluation with a nil error.

func (Policies) EvalQuery

func (policies Policies) EvalQuery(ctx context.Context, q ent.Query) error

EvalQuery evaluates the query policies. If the Allow error is returned from one of the policies, it stops the evaluation with a nil error.

type QueryPolicy

type QueryPolicy []QueryRule

QueryPolicy combines multiple query rules into a single policy.

func (QueryPolicy) EvalQuery

func (policies QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error

EvalQuery evaluates a query against a query policy.

type QueryRule

type QueryRule interface {
	EvalQuery(context.Context, ent.Query) error
}

QueryRule defines the interface deciding whether a query is allowed and optionally modify it.

Jump to

Keyboard shortcuts

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