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 ¶
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).
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.