Documentation
¶
Index ¶
- Constants
- func ActiveRegion(cfg *Config) string
- func CredentialStoreLabel(cfg *Config) string
- func Delete() error
- func Dir() string
- func FilePath() string
- func IsConfigured() bool
- func KeyringAvailable() bool
- func Save(cfg *Config) error
- type Config
- type CredentialStore
- type KeyringStore
- type RegionConfig
- type TokenStore
- func (ts *TokenStore) ActiveStore() string
- func (ts *TokenStore) DeleteSession(region, username string) error
- func (ts *TokenStore) DeleteTokens(region, username string) error
- func (ts *TokenStore) LoadSession(region, username string) (sessionID, csrfToken string, err error)
- func (ts *TokenStore) LoadTokens(region, username string) (accessToken, refreshToken string, err error)
- func (ts *TokenStore) SaveSession(region, username, sessionID, csrfToken string) error
- func (ts *TokenStore) SaveTokens(region, username, accessToken, refreshToken string) error
Constants ¶
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。
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 ¶
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 ¶
CredentialStoreLabel describes where secrets are stored for the given config.
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.
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 ¶
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.
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.