management

package
v0.0.0-...-c4f087e Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package management holds the state changes the control-plane management interface applies. They live outside the handlers so they are reachable without gin: what these operations get wrong is never the HTTP.

Each one owns the cache evictions its own write invalidates, and reports failures as sentinel errors rather than database ones, so the routes above map outcomes to status codes without knowing what backs them.

Index

Constants

View Source
const (
	ProjectMemberRoleOwner  = "owner"
	ProjectMemberRoleMember = "member"
	ProjectMemberRoleViewer = "viewer"
)

Variables

View Source
var (
	ErrInvalidProjectLimits = errors.New("invalid project limits")

	// A pair the columns will not hold, currently a free disk allowance above
	// the ceiling. The caller sent values this side will not store, which is its
	// error to fix.
	ErrProjectLimitsRejected = errors.New("project limits violate a constraint")
)
View Source
var (
	ErrProjectNotFound            = errors.New("project not found")
	ErrInvalidProjectMember       = errors.New("invalid project member")
	ErrDuplicateProjectIdentity   = errors.New("duplicate project identity")
	ErrProjectIdentityOwnedByUser = errors.New("project identity is linked to another user")
)
View Source
var (
	// ErrProjectSlugTaken reports a slug already held on this cluster, possibly
	// by a project the caller has never heard of.
	ErrProjectSlugTaken = errors.New("project slug is already taken")

	// ErrProjectRaced reports an id inserted between the existence check and
	// this request's own insert.
	ErrProjectRaced = errors.New("project was created concurrently")
)
View Source
var ErrInvalidProjectBan = errors.New("invalid project ban state")
View Source
var ErrInvalidProjectBlock = errors.New("invalid project block state")

Functions

This section is empty.

Types

type JobInserter

type JobInserter interface {
	InsertTx(ctx context.Context, tx pgx.Tx, args river.JobArgs, opts *river.InsertOpts) (*rivertype.JobInsertResult, error)
}

type Project

type Project struct {
	ClusterID *uuid.UUID
	ID        uuid.UUID
	Name      string
	Slug      string
	Email     string
}

Project is the set of properties the caller synchronizes. It sends all of them on every push, so a reconcile is a complete statement rather than a patch.

Slug moves like the others, and the project's template aliases follow it in the same transaction: each one held under an earlier slug is also given under the new one. The old names stay, because rewriting them would break every reference a user has already scripted.

type ProjectBanProjection

type ProjectBanProjection struct {
	ProjectID uuid.UUID
	Revision  int64
	Banned    bool
	DecidedAt time.Time
}

type ProjectBlockProjection

type ProjectBlockProjection struct {
	ProjectID uuid.UUID
	Revision  int64
	Blocked   bool
	Reason    string
	// Zero when the caller did not say.
	DecidedAt time.Time
}

type ProjectLimitsProjection

type ProjectLimitsProjection struct {
	ProjectID uuid.UUID
	Revision  int64
	// Zero when the caller did not say.
	DecidedAt time.Time

	MaxLengthHours           int64
	ConcurrentSandboxes      int64
	ConcurrentTemplateBuilds int64
	MaxVCPU                  int64
	MaxRAMMB                 int64
	DiskMB                   int64
	EventsTTLDays            int64
	DefaultFreeDiskSizeMB    int64
	MaxFreeDiskSizeMB        int64
	APITeamRPSList           int64
	APITeamRPSDelete         int64
	MaxSecrets               int64
}

The values arrive absolute: the caller owns plans and add-ons and has already resolved them, which is what lets the team lookups prefer this row over default_limits.

type ProjectMemberIdentity

type ProjectMemberIdentity struct {
	Issuer  string
	Subject string
}

type ProjectMemberProjection

type ProjectMemberProjection struct {
	ProjectID uuid.UUID
	UserID    uuid.UUID
	Revision  int64
	Present   bool
	IsDefault bool
	// Role is empty when the source sent none: the stored role is kept, and a
	// new member is stored as a member.
	Role       string
	Identities []ProjectMemberIdentity
}

type Service

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

Auth and project state use separately configured pools; transactions cannot span them.

func NewService

func NewService(db *authdb.Client, projectDB *sqlcdb.Client, cache sharedauth.Service, meterProvider metric.MeterProvider) *Service

func (*Service) ApplyProjectBan

func (s *Service) ApplyProjectBan(ctx context.Context, jobs JobInserter, projection ProjectBanProjection) error

func (*Service) ApplyProjectBlock

func (s *Service) ApplyProjectBlock(ctx context.Context, projection ProjectBlockProjection) error

func (*Service) ApplyProjectLimits

func (s *Service) ApplyProjectLimits(ctx context.Context, projection ProjectLimitsProjection) error

ApplyProjectLimits records a project's effective limits, behind the revision that decides whether this delivery is the newest one.

The eviction runs whether or not the delivery wrote. An accepted write whose eviction did not finish -- the process died, or one key of several failed -- is retried by a caller carrying the same revision, which this side drops; skipping it there would leave the cache serving the old limits until the entry expires, with the retry that was meant to repair it reporting success.

func (*Service) ApplyProjectMember

func (s *Service) ApplyProjectMember(ctx context.Context, projection ProjectMemberProjection) error

func (*Service) UpsertProject

func (s *Service) UpsertProject(ctx context.Context, project Project) (stored Project, created bool, err error)

UpsertProject creates a project or reconciles an existing one, reporting which happened.

One operation serves both because the caller cannot tell them apart: it retries, and a retry after a response it never saw has to land on the same state as the original.

Jump to

Keyboard shortcuts

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