cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCacheDir is the default cache directory name
	DefaultCacheDir = "cache"

	// DefaultTTL is the default cache TTL
	DefaultTTL = 1 * time.Hour

	// CacheFileExtension is the extension for cache files
	CacheFileExtension = ".enc"
)
View Source
const (
	// KeySize is the size of the encryption key in bytes (AES-256)
	KeySize = 32

	// KeyFileName is the name of the encryption key file
	KeyFileName = ".key"
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key, ciphertext []byte) ([]byte, error)

Decrypt decrypts data using AES-256-GCM

func Encrypt

func Encrypt(key, plaintext []byte) ([]byte, error)

Encrypt encrypts data using AES-256-GCM

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey generates a new random encryption key

func IsDisabled

func IsDisabled() bool

IsDisabled checks if caching is disabled via environment variable

func KeyExists

func KeyExists(configDir string) bool

KeyExists checks if the encryption key file exists

func LoadKey

func LoadKey(configDir string) ([]byte, error)

LoadKey loads the encryption key from file

func SaveKey

func SaveKey(configDir string, key []byte) error

SaveKey saves the encryption key to a file with restricted permissions

Types

type Cache

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

Cache manages credential caching

func New

func New(cfg Config) (*Cache, error)

New creates a new cache manager

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all cached credentials

func (*Cache) ClearEnv

func (c *Cache) ClearEnv(env string) error

ClearEnv removes all cached credentials for an environment

func (*Cache) Delete

func (c *Cache) Delete(service, env string) error

Delete removes cached credentials for a service/env

func (*Cache) Get

func (c *Cache) Get(service, env string) (*types.ResolvedCredentials, error)

Get retrieves cached credentials for a service/env

func (*Cache) Set

func (c *Cache) Set(service, env string, creds *types.ResolvedCredentials) error

Set caches credentials for a service/env

func (*Cache) Status

func (c *Cache) Status() (*Status, error)

Status returns cache status

type Config

type Config struct {
	ConfigDir string
	TTL       time.Duration
}

Config holds cache configuration

type Entry

type Entry struct {
	Service     string                     `json:"service"`
	Env         string                     `json:"env"`
	CachedAt    time.Time                  `json:"cached_at"`
	TTLSeconds  int                        `json:"ttl_seconds"`
	Credentials *types.ResolvedCredentials `json:"credentials"`
}

Entry represents a cached credential entry

func (*Entry) ExpiresAt

func (e *Entry) ExpiresAt() time.Time

ExpiresAt returns when the entry expires

func (*Entry) IsExpired

func (e *Entry) IsExpired() bool

IsExpired checks if the cache entry has expired

type EntryInfo

type EntryInfo struct {
	Service   string
	Env       string
	CachedAt  time.Time
	ExpiresAt time.Time
	Size      int64
	Expired   bool
}

EntryInfo contains information about a cache entry

type Status

type Status struct {
	Enabled    bool
	CacheDir   string
	TTL        time.Duration
	EntryCount int
	TotalSize  int64
	Entries    []EntryInfo
}

Status returns cache status information

Jump to

Keyboard shortcuts

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