Help us shape the future of Go! Take the 2026 Go Developer Survey

quota

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package quota provides storage quota management for hold services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatHumanBytes

func FormatHumanBytes(bytes int64) string

FormatHumanBytes formats bytes as a human-readable string

func ParseHumanBytes

func ParseHumanBytes(s string) (int64, error)

ParseHumanBytes parses human-readable byte sizes like "5GB", "100MB", "1.5TB"

Types

type Config

type Config struct {
	// Quota tiers ordered by rank (lowest to highest). Position determines rank.
	Tiers []TierConfig `yaml:"tiers" comment:"Quota tiers ordered by rank (lowest to highest). Position determines rank."`

	// Default tier settings.
	Defaults DefaultsConfig `yaml:"defaults" comment:"Default tier assignment for new crew members."`
}

Config represents quota tier configuration.

func (*Config) TierByName

func (c *Config) TierByName(name string) *TierConfig

TierByName returns the TierConfig for the given name, or nil if not found.

type DefaultsConfig

type DefaultsConfig struct {
	// Name of the tier assigned to new crew members.
	NewCrewTier string `yaml:"new_crew_tier" comment:"Tier assigned to new crew members who don't have an explicit tier."`
}

DefaultsConfig represents default settings.

type Manager

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

Manager manages quota configuration and tier resolution

func NewManager

func NewManager(configPath string) (*Manager, error)

NewManager creates a quota manager, loading config from file if present

func NewManagerFromConfig

func NewManagerFromConfig(cfg *Config) (*Manager, error)

NewManagerFromConfig creates a quota manager from an in-memory Config struct. If cfg is nil or has no tiers, quotas are disabled (same as missing file).

func (*Manager) GetDefaultTier

func (m *Manager) GetDefaultTier() string

GetDefaultTier returns the default tier name for new crew members

func (*Manager) GetTierLimit

func (m *Manager) GetTierLimit(tierKey string) *int64

GetTierLimit resolves the quota limit for a tier key Returns nil for unlimited (captain, no config, or tier not found with no default)

Resolution order: 1. If quotas disabled → nil (unlimited) 2. If tierKey provided and found → return that tier's limit 3. If tierKey not found or empty → use defaults.new_crew_tier 4. If default tier not found → nil (unlimited)

func (*Manager) GetTierName

func (m *Manager) GetTierName(tierKey string) string

GetTierName resolves the tier name for a tier key Returns the actual tier name being used (after fallback resolution)

func (*Manager) IsEnabled

func (m *Manager) IsEnabled() bool

IsEnabled returns true if quotas are being enforced

func (*Manager) ListTiers

func (m *Manager) ListTiers() []TierInfo

ListTiers returns all configured tiers with their limits, in rank order (lowest to highest).

func (*Manager) ScanOnPush

func (m *Manager) ScanOnPush(tierKey string) bool

ScanOnPush returns whether scan-on-push is enabled for a tier. Follows the same fallback logic as GetTierLimit:

  1. If quotas disabled → false (caller decides default)
  2. If tierKey provided and found → that tier's ScanOnPush
  3. If tierKey not found or empty → use defaults.new_crew_tier
  4. If default tier not found → false

func (*Manager) TierCount

func (m *Manager) TierCount() int

TierCount returns the number of configured tiers

type TierConfig

type TierConfig struct {
	// Tier name (e.g. "deckhand", "bosun", "quartermaster").
	Name string `yaml:"name" comment:"Tier name used as the key for crew assignments."`

	// Human-readable size limit, e.g. "5GB", "50GB", "1TB".
	Quota string `yaml:"quota" comment:"Storage quota limit (e.g. \"5GB\", \"50GB\", \"1TB\")."`

	// Whether pushing triggers an immediate vulnerability scan.
	ScanOnPush bool `` /* 140-byte string literal not displayed */
}

TierConfig represents a single tier's configuration.

type TierInfo

type TierInfo struct {
	Key        string
	Limit      *int64
	ScanOnPush bool
}

TierInfo represents tier information for listing

Jump to

Keyboard shortcuts

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