config

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModeSession authenticates with a Django session cookie (default).
	ModeSession = "session"
	// ModeJWT authenticates with a REST Bearer token.
	ModeJWT = "jwt"
)

Transport modes. Session is the default:普通账号即可用,走 Archery 的 AJAX 端点 + Django 会话 cookie。JWT 保留为可选高级模式,走 /api REST。

View Source
const (

	// CredentialStoreKeyring stores secrets in the OS credential manager.
	CredentialStoreKeyring = "keyring"
	// CredentialStoreNone means no persistent credential store is available.
	CredentialStoreNone = "none"
)

Variables

This section is empty.

Functions

func ActiveRegion

func ActiveRegion(cfg *Config) string

ActiveRegion returns the name of the active region, determined by:

ARCHERY_CLI_REGION env var (highest precedence)
Config.DefaultRegion

Returns empty string if neither is set.

func CredentialStoreLabel

func CredentialStoreLabel(cfg *Config) string

CredentialStoreLabel describes where secrets are stored for the given config.

func Delete

func Delete() error

Delete removes the configuration file and any keyring secrets.

func Dir

func Dir() string

Dir returns the configuration directory path ~/.archery-cli/

func FilePath

func FilePath() string

FilePath returns the configuration file path ~/.archery-cli/config.json

func IsConfigured

func IsConfigured() bool

IsConfigured reports whether credentials are available for the active region.

func KeyringAvailable

func KeyringAvailable() bool

KeyringAvailable reports whether the OS secret store accepts read/write.

func Save

func Save(cfg *Config) error

Save writes the configuration to disk.

JWT tokens are stored in the OS keyring (not in config.json). Passwords are never persisted after login. File permissions are set to 0600 (owner-readable only) to restrict access.

Types

type Config

type Config struct {
	DefaultRegion   string                  `json:"default_region"`
	CredentialStore string                  `json:"credentialStore,omitempty"`
	Regions         map[string]RegionConfig `json:"regions"`
}

Config stores Archery configuration with support for multiple regions.

func Load

func Load() (*Config, error)

Load reads the configuration with env var overrides:

ARCHERY_CLI_URL      — overrides region URL
ARCHERY_CLI_USERNAME — overrides region username
ARCHERY_CLI_PASSWORD — overrides region password
ARCHERY_CLI_REGION   — selects active region

Returns an empty Config (no error) if no source has values. Corrupt config JSON returns an explicit error.

func MustLoad

func MustLoad() (*Config, error)

MustLoad reads the configuration and validates required fields.

type CredentialStore

type CredentialStore interface {
	// Store saves a secret value under the given service and key.
	Store(service, key, value string) error
	// Retrieve reads a secret value for the given service and key.
	Retrieve(service, key string) (string, error)
	// Delete removes a secret for the given service and key.
	Delete(service, key string) error
	// IsAvailable reports whether this store can accept read/write operations.
	IsAvailable() bool
}

CredentialStore abstracts secret persistence.

type KeyringStore

type KeyringStore struct {
	Service string
}

KeyringStore implements CredentialStore using the OS credential manager (Windows Credential Manager, macOS Keychain, Linux Secret Service).

func NewKeyringStore

func NewKeyringStore() *KeyringStore

NewKeyringStore creates a KeyringStore with the default service name.

func (*KeyringStore) Delete

func (k *KeyringStore) Delete(service, key string) error

func (*KeyringStore) IsAvailable

func (k *KeyringStore) IsAvailable() bool

func (*KeyringStore) Retrieve

func (k *KeyringStore) Retrieve(service, key string) (string, error)

func (*KeyringStore) Store

func (k *KeyringStore) Store(service, key, value string) error

type RegionConfig

type RegionConfig struct {
	URL      string `json:"url"`
	Username string `json:"username"`
	// Mode selects the transport: "session" (default) or "jwt".
	Mode         string `json:"mode,omitempty"`
	Password     string `json:"password,omitempty"`
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	TokenExpiry  string `json:"token_expiry,omitempty"`
	// SessionID / CSRFToken are the cached Django session cookies (session mode).
	// Persisted only in the OS keyring, never on disk.
	SessionID string `json:"session_id,omitempty"`
	CSRFToken string `json:"csrf_token,omitempty"`
}

RegionConfig stores Archery authentication information for a single region. Password is never persisted; tokens and session cookies live only in the OS keyring.

func (RegionConfig) EffectiveMode added in v1.0.4

func (r RegionConfig) EffectiveMode() string

EffectiveMode returns the region's transport mode, defaulting to session.

type TokenStore

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

TokenStore manages JWT token persistence through the OS keyring.

func NewTokenStore

func NewTokenStore() *TokenStore

NewTokenStore creates a TokenStore that uses the OS keyring when available.

func (*TokenStore) ActiveStore

func (ts *TokenStore) ActiveStore() string

ActiveStore returns a label describing which credential store is in use.

func (*TokenStore) DeleteSession added in v1.0.4

func (ts *TokenStore) DeleteSession(region, username string) error

DeleteSession removes persisted session cookies for a region from the keyring.

func (*TokenStore) DeleteTokens

func (ts *TokenStore) DeleteTokens(region, username string) error

DeleteTokens removes persisted tokens for a region from the keyring.

func (*TokenStore) LoadSession added in v1.0.4

func (ts *TokenStore) LoadSession(region, username string) (sessionID, csrfToken string, err error)

LoadSession retrieves the cached session cookies for a region. Returns empty strings if none are found.

func (*TokenStore) LoadTokens

func (ts *TokenStore) LoadTokens(region, username string) (accessToken, refreshToken string, err error)

LoadTokens retrieves access and refresh tokens for a region. Returns empty strings if no tokens are found.

func (*TokenStore) SaveSession added in v1.0.4

func (ts *TokenStore) SaveSession(region, username, sessionID, csrfToken string) error

SaveSession persists the Django session cookies (sessionid + csrftoken) for a region. Stored in the keyring; fails if no secret store is available.

func (*TokenStore) SaveTokens

func (ts *TokenStore) SaveTokens(region, username, accessToken, refreshToken string) error

SaveTokens persists access and refresh tokens for a region. Tokens are stored in the keyring. If the keyring is unavailable, persistence fails.

Jump to

Keyboard shortcuts

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