access

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package access applies context-scoped policies and row-level access controls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SoftDeleteColumn

func SoftDeleteColumn(table *schema.Table) *schema.Column

func WithContext

func WithContext(parent context.Context, value Context) context.Context

WithContext stores access metadata in a parent context.

func WithPolicy added in v0.1.1

func WithPolicy(parent context.Context, policy Policy) context.Context

WithPolicy stores the policy in a parent context.

Types

type Context

type Context struct {
	UserID         any
	CompanyID      any
	TenantID       any
	OrganizationID any
	WorkspaceID    any
	WarehouseID    any
	Values         map[string]any
	Policy         Policy
}

Context carries request-scoped access information for policy evaluation.

func FromContext

func FromContext(ctx context.Context) (Context, bool)

FromContext extracts access metadata from a context.

type Engine

type Engine struct{}

Engine applies access policies and injects scoped values.

func NewEngine

func NewEngine() Engine

NewEngine returns a default access engine.

func (Engine) Apply

func (Engine) Apply(ctx context.Context, table *schema.Table, op Operation, values map[string]any) ([]Predicate, []FieldValue, error)

type FieldValue

type FieldValue struct {
	Field string
	Value any
}

FieldValue represents a field assignment generated by access policy evaluation.

type MissingContextError added in v0.1.1

type MissingContextError struct {
	Base      *dormerrors.AccessError
	Operation Operation
	Field     string
	Reason    string
}

MissingContextError reports a required access context value that was absent.

func (*MissingContextError) Error added in v0.1.1

func (e *MissingContextError) Error() string

func (*MissingContextError) Is added in v0.1.1

func (e *MissingContextError) Is(target error) bool

func (*MissingContextError) Unwrap added in v0.3.0

func (e *MissingContextError) Unwrap() error

type Operation

type Operation string

Operation identifies the access engine operation being evaluated.

const (
	OpQuery  Operation = "query"
	OpInsert Operation = "insert"
	OpUpdate Operation = "update"
	OpDelete Operation = "delete"
)

type Policy added in v0.1.1

type Policy struct {
	Level PolicyLevel
}

Policy describes the active access policy for a request.

func Default added in v0.1.1

func Default() Policy

Default returns the default access policy.

func IgnoreCompany added in v0.1.1

func IgnoreCompany() Policy

IgnoreCompany disables company-level filtering.

func IgnoreRLS added in v0.1.1

func IgnoreRLS() Policy

IgnoreRLS disables row-level security policies except soft delete.

func PolicyFromContext added in v0.1.1

func PolicyFromContext(ctx context.Context) Policy

PolicyFromContext extracts the current policy from a context.

func System added in v0.1.1

func System() Policy

System disables all access policies.

func (Policy) AllowsScope added in v0.1.1

func (p Policy) AllowsScope(scope schema.ScopeKind) bool

AllowsScope reports whether a scoped column is active under the policy.

func (Policy) EnforcesAudit added in v0.1.1

func (p Policy) EnforcesAudit() bool

EnforcesAudit reports whether audit field injection remains active.

func (Policy) EnforcesSoftDelete added in v0.1.1

func (p Policy) EnforcesSoftDelete() bool

EnforcesSoftDelete reports whether soft delete remains active.

func (Policy) IsDefault added in v0.1.1

func (p Policy) IsDefault() bool

IsDefault reports whether the policy is the default policy.

func (Policy) IsSystem added in v0.1.1

func (p Policy) IsSystem() bool

IsSystem reports whether the policy disables all policy enforcement.

func (Policy) Name added in v0.1.1

func (p Policy) Name() string

Name returns the observable policy name.

func (Policy) Normalize added in v0.1.1

func (p Policy) Normalize() Policy

Normalize ensures the policy has a default level.

type PolicyLevel added in v0.1.1

type PolicyLevel string

PolicyLevel identifies a row-level access policy mode.

const (
	PolicyLevelDefault       PolicyLevel = "default"
	PolicyLevelIgnoreCompany PolicyLevel = "ignore_company"
	PolicyLevelIgnoreRLS     PolicyLevel = "ignore_rls"
	PolicyLevelSystem        PolicyLevel = "system"
)

type Predicate

type Predicate struct {
	SQL  string
	Args []any
}

Predicate represents a SQL predicate generated by access policy evaluation.

Jump to

Keyboard shortcuts

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