common

package
v0.19.8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitSuccess             = 0 // Success
	ExitGeneralError        = 1 // General error
	ExitTimeout             = 2 // Operation timeout (wait-timeout exceeded) or connection timeout
	ExitInvalidParameters   = 3 // Invalid parameters
	ExitAuthenticationError = 4 // Authentication error
	ExitPermissionDenied    = 5 // Permission denied
	ExitServiceNotFound     = 6 // Service not found
	ExitUpdateAvailable     = 7 // Update available
)

Exit codes as defined in the CLI specification

View Source
const (
	AddonNone       = "none" // Special value for no add-ons
	AddonTimeSeries = "time-series"
	AddonAI         = "ai"
)

Addon constants - these match the ServiceCreateAddons from the API

Variables

View Source
var (
	// GetCredentials can be overridden for testing
	GetCredentials = config.GetCredentials
)

Functions

func ExitWithCode

func ExitWithCode(code int, err error) error

ExitWithCode returns an error that will cause the program to exit with the specified code

func ExitWithErrorFromStatusCode

func ExitWithErrorFromStatusCode(statusCode int, err error) error

ExitWithErrorFromStatusCode maps HTTP status codes to CLI exit codes

func GenerateServiceName

func GenerateServiceName() string

Matches front-end logic for generating a random service name

func GetPassword

func GetPassword(service api.Service, role string) (string, error)

GetPassword fetches the password for the specified service from the configured password storage mechanism. It returns an error if it fails to find the password.

func IsValidAddon

func IsValidAddon(addon string) bool

IsValidAddon checks if the given add-on is valid (case-sensitive as per API spec)

func NewAPIClient added in v0.19.5

func NewAPIClient(ctx context.Context, cfg *config.Config) (*api.ClientWithResponses, string, error)

NewAPIClient initializes a api.ClientWithResponses and returns it along with the current project ID. Credentials are pulled from the environment (if present), or loaded from storage (either the keyring or fallback file). When pulled from the environment, the credentials are first validated by hitting the /auth/info endpoint (which also allows us to fetch the project ID), and the user is identified for the sake of analytics by hitting the /analytics/identify endpoint. When credentials are pulled from storage, those operations should have already been performed via `tiger auth login`.

func ParseCPUMemory

func ParseCPUMemory(cpuMemoryStr string) (string, string, error)

ParseCPUMemory parses a CPU/memory combination string (e.g., "2 CPU/8GB") and returns millicores and GB. If "shared" is given, returns "shared" for both CPU and memory.

func ValidAddons

func ValidAddons() []string

ValidAddons returns a slice of all valid add-on values

func ValidateAPIKey added in v0.19.5

func ValidateAPIKey(ctx context.Context, cfg *config.Config, client *api.ClientWithResponses) (*api.AuthInfo, error)

ValidateAPIKey validates the API key by calling the /auth/info endpoint, and returns authentication information. It also identifies the user for the sake of analytics.

func ValidateAddons

func ValidateAddons(addons []string) ([]string, error)

ValidateAddons validates a slice of add-ons and removes duplicate values

func ValidateAndNormalizeCPUMemory

func ValidateAndNormalizeCPUMemory(cpuMillis, memoryGBs string) (*string, *string, error)

ValidateAndNormalizeCPUMemory validates CPU/Memory values and applies auto-configuration logic

func WaitForService

func WaitForService(ctx context.Context, args WaitForServiceArgs) error

Types

type CPUMemoryConfig

type CPUMemoryConfig struct {
	Shared    bool // Shared CPU/Memory
	CPUMillis int  // CPU in millicores
	MemoryGBs int  // Memory in GB
}

CPUMemoryConfig represents an allowed CPU/Memory configuration

func (*CPUMemoryConfig) Matches

func (c *CPUMemoryConfig) Matches(cpuMillis, memoryGBs string) (string, string, bool)

func (*CPUMemoryConfig) String

func (c *CPUMemoryConfig) String() string

type CPUMemoryConfigs

type CPUMemoryConfigs []CPUMemoryConfig

func GetAllowedCPUMemoryConfigs

func GetAllowedCPUMemoryConfigs() CPUMemoryConfigs

GetAllowedCPUMemoryConfigs returns the allowed CPU/Memory configurations from the spec

func (CPUMemoryConfigs) String

func (c CPUMemoryConfigs) String() string

String returns a user-friendly string of allowed CPU/Memory combinations

func (CPUMemoryConfigs) Strings

func (c CPUMemoryConfigs) Strings() []string

Strings returns a slice of user-friendly strings of allowed CPU/Memory combinations

type Config added in v0.19.5

type Config struct {
	*config.Config
	Client    *api.ClientWithResponses `json:"-"`
	ProjectID string                   `json:"-"`
}

Config is a convenience wrapper around config.Config that adds an API client and the current project ID. Since most commands require all of these to function, it is often easier to load them and pass them around together. Functions that only require a config but not a client (i.e. functions that do not make any API calls) should call config.Load directly instead.

func LoadConfig added in v0.19.5

func LoadConfig(ctx context.Context) (*Config, error)

type ConnectionDetails

type ConnectionDetails struct {
	Role     string `json:"role,omitempty"`
	Password string `json:"password,omitempty"`
	Host     string `json:"host,omitempty"`
	Port     int    `json:"port,omitempty"`
	Database string `json:"database,omitempty"`
	IsPooler bool   `json:"is_pooler,omitempty"`
}

func GetConnectionDetails

func GetConnectionDetails(service api.Service, opts ConnectionDetailsOptions) (*ConnectionDetails, error)

func (*ConnectionDetails) String

func (d *ConnectionDetails) String() string

String creates a PostgreSQL connection string from service details

type ConnectionDetailsOptions

type ConnectionDetailsOptions struct {
	// Pooled determines whether to use the pooler endpoint (if available)
	Pooled bool

	// Role is the database role/username to use (e.g., "tsdbadmin")
	Role string

	// WithPassword determines whether to include the password in the output
	WithPassword bool

	// InitialPassword is an optional password to use directly (e.g., from service creation response)
	// If provided and WithPassword is true, this password will be used
	// instead of fetching from password storage. This is useful when password_storage=none.
	InitialPassword string
}

ConnectionDetailsOptions configures how the connection string is built

type DeletionWaitHandler

type DeletionWaitHandler struct {
	ServiceID string
}

func (*DeletionWaitHandler) Check

func (*DeletionWaitHandler) Message

func (h *DeletionWaitHandler) Message() string

type ExitCodeError

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

ExitCodeError creates an error that will cause the program to exit with the specified code

func (ExitCodeError) Error

func (e ExitCodeError) Error() string

func (ExitCodeError) ExitCode

func (e ExitCodeError) ExitCode() int

func (ExitCodeError) Unwrap added in v0.19.5

func (e ExitCodeError) Unwrap() error

type KeyringStorage

type KeyringStorage struct{}

KeyringStorage implements password storage using system keyring

func (*KeyringStorage) Get

func (k *KeyringStorage) Get(service api.Service, role string) (string, error)

func (*KeyringStorage) GetStorageResult

func (k *KeyringStorage) GetStorageResult(err error, password string) PasswordStorageResult

func (*KeyringStorage) Remove

func (k *KeyringStorage) Remove(service api.Service, role string) error

func (*KeyringStorage) Save

func (k *KeyringStorage) Save(service api.Service, password string, role string) error

type NoStorage

type NoStorage struct{}

NoStorage implements no password storage (passwords are not saved)

func (*NoStorage) Get

func (n *NoStorage) Get(service api.Service, role string) (string, error)

func (*NoStorage) GetStorageResult

func (n *NoStorage) GetStorageResult(err error, password string) PasswordStorageResult

func (*NoStorage) Remove

func (n *NoStorage) Remove(service api.Service, role string) error

func (*NoStorage) Save

func (n *NoStorage) Save(service api.Service, password string, role string) error

type PasswordStorage

type PasswordStorage interface {
	Save(service api.Service, password string, role string) error
	Get(service api.Service, role string) (string, error)
	Remove(service api.Service, role string) error
	GetStorageResult(err error, password string) PasswordStorageResult
}

PasswordStorage defines the interface for password storage implementations

func GetPasswordStorage

func GetPasswordStorage() PasswordStorage

GetPasswordStorage returns the appropriate PasswordStorage implementation based on configuration

type PasswordStorageResult

type PasswordStorageResult struct {
	Success bool   `json:"success"`
	Method  string `json:"method"`  // "keyring", "pgpass", or "none"
	Message string `json:"message"` // Human-readable message
}

PasswordStorageResult contains the result of password storage operations

func SavePasswordWithResult

func SavePasswordWithResult(service api.Service, password string, role string) (PasswordStorageResult, error)

SavePasswordWithResult handles saving a password and returns both error and result info

type PgpassStorage

type PgpassStorage struct{}

PgpassStorage implements password storage using ~/.pgpass file

func (*PgpassStorage) Get

func (p *PgpassStorage) Get(service api.Service, role string) (string, error)

func (*PgpassStorage) GetStorageResult

func (p *PgpassStorage) GetStorageResult(err error, password string) PasswordStorageResult

func (*PgpassStorage) Remove

func (p *PgpassStorage) Remove(service api.Service, role string) error

func (*PgpassStorage) Save

func (p *PgpassStorage) Save(service api.Service, password string, role string) error

type Spinner

type Spinner interface {
	// Update changes the spinner's displayed message.
	Update(message string)

	// Stop terminates the spinner program and waits for it to finish.
	Stop()
}

func NewSpinner

func NewSpinner(output io.Writer, message string) Spinner

NewSpinner creates and returns a new Spinner for displaying animated status messages. If the output is nil or io.Discard, it returns a no-op spinner. If output is a terminal, it uses bubbletea to dynamically update the spinner and message in place. If output is not a terminal, it prints each message on a new line without animation.

type StatusWaitHandler

type StatusWaitHandler struct {
	TargetStatus string
	Service      *api.Service
}

func (*StatusWaitHandler) Check

func (*StatusWaitHandler) Message

func (h *StatusWaitHandler) Message() string

type WaitForServiceArgs

type WaitForServiceArgs struct {
	Client     *api.ClientWithResponses
	ProjectID  string
	ServiceID  string
	Handler    WaitHandler
	Output     io.Writer
	Timeout    time.Duration
	TimeoutMsg string
}

type WaitHandler

type WaitHandler interface {
	// Message returns the current status message that should be displayed next
	// to the spinner while waiting for a service to reach some state.
	Message() string

	// Check returns true if we're done waiting/polling, and false if we should
	// continue. It also returns an error, which is either immediately returned
	// from WaitForService or temporarily shown next to the spinner depending
	// on the first return value.
	Check(resp *api.GetProjectsProjectIdServicesServiceIdResponse) (bool, error)
}

Jump to

Keyboard shortcuts

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