tenantpolicy

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tenantpolicy defines CloudPath's v0.1 anti-abuse limits and tenant-scoped retention policy. It is a pure domain package; persistence and HTTP/WS wiring live in store/server.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPolicy = errors.New("tenantpolicy: invalid policy")
	ErrQuotaExceeded = errors.New("tenantpolicy: quota exceeded")
)

Functions

This section is empty.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter atomically admits and releases concurrent resources such as Edge or browser WebSocket connections. A release function is idempotent.

func NewCounter

func NewCounter() *Counter

func (*Counter) Acquire

func (c *Counter) Acquire(tenant string, resource Resource, limit int) (release func(), err error)

func (*Counter) Usage

func (c *Counter) Usage(tenant string, resource Resource) int

type Policy

type Policy struct {
	Retention RetentionDays
	Quotas    Quotas
}

Policy is the resolved policy used by runtime enforcement.

func Defaults

func Defaults() Policy

Defaults returns the fail-safe v0.1 policy.

func (Policy) Limit

func (p Policy) Limit(resource Resource) (int, error)

Limit returns the resolved limit for resource.

func (Policy) Validate

func (p Policy) Validate() error

Validate rejects unlimited, negative, or unreasonably large settings.

type QuotaError

type QuotaError struct {
	Tenant   string
	Resource Resource
	Limit    int
	Usage    int
}

QuotaError carries only non-sensitive usage facts.

func (*QuotaError) Code

func (e *QuotaError) Code() string

func (*QuotaError) Error

func (e *QuotaError) Error() string

func (*QuotaError) Unwrap

func (e *QuotaError) Unwrap() error

type Quotas

type Quotas struct {
	Devices         int
	Edges           int
	BrowserWS       int
	Tokens          int
	Users           int
	EventsPerMinute int
	PluginInstances int
}

Quotas contains resolved hard limits. Zero/unlimited is deliberately invalid.

type Resource

type Resource string

Resource is a stable machine identifier used by HTTP error codes and audit.

const (
	ResourceDevices         Resource = "devices"
	ResourceEdges           Resource = "edges"
	ResourceBrowserWS       Resource = "browser_ws"
	ResourceTokens          Resource = "tokens"
	ResourceUsers           Resource = "users"
	ResourceEventsPerMin    Resource = "events_per_min"
	ResourcePluginInstances Resource = "plugin_instances"
)

type RetentionDays

type RetentionDays struct {
	Events             int
	TerminalCommands   int
	Audit              int
	RevokedTokens      int
	PluginObservations int
}

RetentionDays contains resolved, non-null retention values.

type WindowLimiter

type WindowLimiter struct {
	// contains filtered or unexported fields
}

WindowLimiter is an in-memory fixed-window limiter for high-rate resources such as events. It is tenant/resource scoped and uses an injectable clock.

func NewWindowLimiter

func NewWindowLimiter(window time.Duration, now func() time.Time) *WindowLimiter

func (*WindowLimiter) Allow

func (l *WindowLimiter) Allow(tenant string, resource Resource, limit int) error

Jump to

Keyboard shortcuts

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