entitlements

package
v0.7.16 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package entitlements is the product seam: the one place that answers "how much of this may this subject have?" and "is this feature on?".

The OSS default answers "everything on, limits from config". The hosted overlay swaps in a Resolver backed by the billing plan. Nothing in this repo may branch on "is this cloud?", so every quota consumer asks the Resolver instead of reading a constant, and the OSS answer happens to be constant.

The seam is the deliverable: by design the default Resolver reproduces the default quota numbers exactly, so wiring it changes no behaviour.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchiveLimits

type ArchiveLimits struct {
	MaxBytes          int64
	MaxFiles          int
	MaxFileBytes      int64
	MaxImageFileBytes int64
	// MaxTextBytes caps the total of the text files in the include set
	// (the instruction-file total).
	MaxTextBytes int64
}

ArchiveLimits mirrors pkg/manifest.Quotas. It is restated here rather than imported so that the entitlements contract does not drag the manifest package into every consumer; internal/registry converts between the two at the one place that needs both.

type Cap

type Cap struct {
	Enabled bool
	Max     int64
}

Cap is a feature with a cap: Enabled says whether the subject may use it at all, Max how many it may hold (0 = no cap).

type ConfigResolver

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

ConfigResolver is the OSS default: limits come from config, every feature is on, and the answer does not depend on the subject beyond its namespace kind.

func Default

func Default() *ConfigResolver

Default is the Resolver used when none has been wired: the shipped defaults. It exists so a half-constructed server enforces quotas rather than none at all — an unwired seam must not be an open door.

func NewConfigResolver

func NewConfigResolver(l config.Limits) *ConfigResolver

NewConfigResolver builds the default Resolver from the limits config block.

func (*ConfigResolver) Features

Features implements Resolver: the OSS build caps nothing and switches nothing off, but for the knowledge cap a self-hoster may set (limits.knowledgeBytesPerAccount; 0, the default, is none).

func (*ConfigResolver) Limits

func (r *ConfigResolver) Limits(_ context.Context, s Subject) (Limits, error)

Limits implements Resolver.

type Features

type Features struct {
	// PrivateAgents caps the private agents a namespace holds.
	PrivateAgents Cap
	// Seats caps the people an organization may license — active members
	// plus open invitations (org subjects; meaningless for a user).
	Seats Cap
	// SSO and SCIM say whether the organization's subscription includes
	// single sign-on through its own identity provider and provisioning
	// from it. The server has neither; an extension that provides them
	// gates on these.
	SSO  bool
	SCIM bool
	// Branding says whether the organization may set a logo.
	Branding bool
	// AlertRouting says whether the organization may route dependency
	// alerts to a destination of its own.
	AlertRouting bool
	// UnscannedAgents says whether the organization's admins may mark a
	// private agent as skipping the pipeline.
	UnscannedAgents bool
	// SSHKeys says whether a person may register an SSH key for the git
	// transport (user subjects). It gates only the adding: a
	// key already held keeps working, stays listed and can be removed.
	SSHKeys bool
	// KnowledgeBytes caps the bytes of knowledge packs a subject keeps in
	// the registry: only what is stored here counts, and over the cap no
	// pack is added or grown, none deleted.
	KnowledgeBytes Cap
}

Features is what a subject may hold, as opposed to how fast it may act (Limits): the caps and switches a subscription tier sets. The core resolver answers every cap enabled with no maximum and every switch on (a self-hosted registry has no tiers and ships no crippled stub); a closed build's resolver answers by tier. A cap never deletes: over it, nothing can be added and nothing is lost.

type Limits

type Limits struct {
	// AgentsPerNamespace caps agents in one namespace.
	AgentsPerNamespace int64
	// VersionsPerDay caps submissions per agent per day.
	VersionsPerDay int64
	// WebhookEndpoints caps configured endpoints per org.
	WebhookEndpoints int64
	// WebhookDeliveriesPerSecond is the per-org delivery rate.
	WebhookDeliveriesPerSecond float64
	// GitPushesPerHour is the per-repo push budget.
	GitPushesPerHour int
	// RepoQuotaBytes / RepoMaxBlobBytes are the git-side size caps.
	RepoQuotaBytes   int64
	RepoMaxBlobBytes int64
	// Archive bounds the release archive (enforced by manifest rule V8).
	Archive ArchiveLimits
}

Limits is the resolved quota set.

type NamespaceKind

type NamespaceKind string

NamespaceKind distinguishes the two namespace flavours that get different agent quotas.

const (
	NamespaceUser NamespaceKind = "user"
	NamespaceOrg  NamespaceKind = "org"
)

type Resolver

type Resolver interface {
	// Limits returns the quota set for a subject. An error means "unknown" —
	// callers must fail closed rather than fall back to a default, or a
	// Resolver outage would silently lift every quota at once.
	Limits(ctx context.Context, s Subject) (Limits, error)
	// Features returns the caps for a subject; an error means "unknown" and
	// callers fail closed, as for Limits.
	Features(ctx context.Context, s Subject) (Features, error)
}

Resolver answers entitlement questions.

type Subject

type Subject struct {
	// Kind selects the namespace quota row (200 agents for a user
	// namespace, 500 for an org). Empty is treated as NamespaceUser — the
	// stricter of the two, so a caller that forgets to set it is not handed
	// the larger budget by accident.
	Kind NamespaceKind
	// OrgID is the owning organisation, or uuid.Nil for a personal namespace.
	OrgID uuid.UUID
	// UserID is the acting user, when known.
	UserID uuid.UUID
}

Subject is whose entitlements are being resolved. Exactly one of OrgID or UserID is meaningful for a given lookup; both are carried because a SaaS Resolver may need the user (personal plan) or the org (team plan) depending on which namespace the request touches.

func ForOrg

func ForOrg(orgID uuid.UUID) Subject

ForOrg builds a Subject for an org-owned resource.

func ForUser

func ForUser(userID uuid.UUID) Subject

ForUser builds a Subject for a personal namespace.

Jump to

Keyboard shortcuts

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