util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

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

Addon constants - these match the ServiceCreateAddons from the API

Variables

This section is empty.

Functions

func AnySlice

func AnySlice[T any](in []T) []any

func ConvertAddonsToAPI added in v0.1.2

func ConvertAddonsToAPI(addons []string) []api.ServiceCreateAddons

ConvertAddonsToAPI converts a slice of addon strings to the API format Returns nil if addons slice is empty or nil (for PostgreSQL-only services)

func Deref

func Deref[T any](val *T) T

func DerefStr

func DerefStr[T ~string](val *T) string

func GenerateServiceName

func GenerateServiceName() string

Matches front-end logic for generating a random service name

func IsValidAddon added in v0.1.2

func IsValidAddon(addon string) bool

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

func Must

func Must[T any](v T, err error) T

func ParseCPUMemory

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

ParseCPUMemory parses a CPU/Memory combination string (e.g., "2 CPU/8GB") and returns millicores and GB

func Ptr

func Ptr[T any](val T) *T

func ValidAddons added in v0.1.2

func ValidAddons() []string

ValidAddons returns a slice of all valid add-on values

func ValidateAddons added in v0.1.2

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

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

func ValidateAndNormalizeCPUMemory

func ValidateAndNormalizeCPUMemory(cpuMillis int, memoryGbs int, cpuFlagSet, memoryFlagSet bool) (int, int, error)

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

Types

type CPUMemoryConfig

type CPUMemoryConfig struct {
	CPUMillis int // CPU in millicores
	MemoryGbs int // Memory in GB
}

CPUMemoryConfig represents an allowed CPU/Memory configuration

func (*CPUMemoryConfig) CPUString

func (c *CPUMemoryConfig) CPUString() string

func (*CPUMemoryConfig) MemoryString

func (c *CPUMemoryConfig) MemoryString() string

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 TODO: It would be great if we could fetch these from the API instead of hard coding them.

func (CPUMemoryConfigs) CPUString

func (c CPUMemoryConfigs) CPUString() string

String returns a user-friendly string of allowed CPU values

func (CPUMemoryConfigs) MemoryString

func (c CPUMemoryConfigs) MemoryString() string

String returns a user-friendly string of allowed memory values

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 KeyringStorage

type KeyringStorage struct{}

KeyringStorage implements password storage using system keyring

func (*KeyringStorage) Get

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

func (*KeyringStorage) GetStorageResult

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

func (*KeyringStorage) Remove

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

func (*KeyringStorage) Save

func (k *KeyringStorage) Save(service api.Service, password 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) (string, error)

func (*NoStorage) GetStorageResult

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

func (*NoStorage) Remove

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

func (*NoStorage) Save

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

type PasswordStorage

type PasswordStorage interface {
	Save(service api.Service, password string) error
	Get(service api.Service) (string, error)
	Remove(service api.Service) 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) (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) (string, error)

func (*PgpassStorage) GetStorageResult

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

func (*PgpassStorage) Remove

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

func (*PgpassStorage) Save

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

Jump to

Keyboard shortcuts

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