Documentation
¶
Overview ¶
Package limits provides subscription resource limit checking for the rysh daemon. When upstream is enabled and an API key is configured, the daemon fetches the user's subscription limits from the server and caches them. Before creating panes, the WorkspaceActor calls CheckCreate to validate that the creation is permitted under the current subscription plan.
When upstream is not enabled (local-only mode), all operations are allowed.
Index ¶
- type Checker
- func (c *Checker) CachedLimits() *ResourceLimits
- func (c *Checker) CheckCreate(usage ResourceUsage, addPanes int) error
- func (c *Checker) Enabled() bool
- func (c *Checker) FetchLimits() error
- func (c *Checker) ServerCheckCreate(usage ResourceUsage) (*LimitCheckResult, error)
- func (c *Checker) SessionLimitWarning() string
- type LimitCheckResult
- type ResourceLimits
- type ResourceUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker validates resource limits against the server's subscription system. It caches limits locally and refreshes them periodically.
func NewChecker ¶
NewChecker creates a Checker that talks to the given server URL with the given API key. If serverURL or apiKey is empty, the checker is a no-op (all operations are allowed).
func (*Checker) CachedLimits ¶
func (c *Checker) CachedLimits() *ResourceLimits
CachedLimits returns the cached limits, or nil if not yet fetched.
func (*Checker) CheckCreate ¶
func (c *Checker) CheckCreate(usage ResourceUsage, addPanes int) error
CheckCreate validates whether a resource creation is allowed given the current usage plus the resources about to be added. Returns nil if allowed, or an error describing which limit was exceeded.
Parameters:
- usage: current resource counts in the workspace
- addPanes: panes being added
func (*Checker) FetchLimits ¶
FetchLimits synchronously fetches the user's resource limits from the server. This should be called once during daemon startup.
func (*Checker) ServerCheckCreate ¶
func (c *Checker) ServerCheckCreate(usage ResourceUsage) (*LimitCheckResult, error)
ServerCheckCreate performs a server-side limit check via HTTP POST. This is used for authoritative validation (e.g., before actually spawning actors).
func (*Checker) SessionLimitWarning ¶ added in v0.2.11
SessionLimitWarning asks the server whether this account is over its plan's session cap (GET /api/resource/check-session-limit) and returns one line naming the limit and where to upgrade — or "" when there is nothing to say.
It only informs. The server does not refuse a rysh daemon for the session cap (every daemon dial is connection_type=share or channel, which the proxy exempts), so an over-cap account keeps working and, before this, was never told. Anything other than a 402 with a message — within cap, an older server without the endpoint, an error, a timeout — yields "" and never an error: a status command must not fail because a billing hint could not be fetched.
type LimitCheckResult ¶
type LimitCheckResult struct {
Allowed bool `json:"allowed"`
Resource string `json:"resource,omitempty"`
Limit int `json:"limit,omitempty"`
Current int `json:"current,omitempty"`
Error string `json:"error,omitempty"`
PlanID string `json:"plan_id"`
PlanName string `json:"plan_name"`
// UpgradeURL — see ResourceLimits.UpgradeURL.
UpgradeURL string `json:"upgrade_url,omitempty"`
}
LimitCheckResult mirrors the server's check-limits response.
type ResourceLimits ¶
type ResourceLimits struct {
PlanID string `json:"plan_id"`
PlanName string `json:"plan_name"`
MaxWorkspaces int `json:"max_workspaces"`
MaxSessions int `json:"max_sessions"`
MaxPanes int `json:"max_panes"`
// UpgradeURL is where the server wants a user who just hit a limit to go.
// It may be relative to the server (the default) or absolute; resolve it
// with resolveUpgradeURL before showing it. Empty means the deployment
// configured none, and nothing is shown — a self-hosted rysh must never
// advertise somebody else's billing page.
UpgradeURL string `json:"upgrade_url,omitempty"`
}
ResourceLimits mirrors the server's UserLimits response.
type ResourceUsage ¶
type ResourceUsage struct {
Panes int `json:"panes"`
}
ResourceUsage describes the current resource counts in the workspace.