Documentation
¶
Overview ¶
Package config manages all configuration files for AgentSecrets.
This mirrors the Python SecretsCLI's config.py and parts of credentials.py.
File layout:
~/.agentsecrets/ ├── config.json # User email, workspace cache, selected workspace └── token.json # JWT access/refresh tokens ./.agentsecrets/ └── project.json # Project binding for current directory
Note: Private key is stored in OS keychain (see pkg/keyring), not in files.
Index ¶
- Variables
- func ClearProjectConfig() error
- func ClearSession() error
- func GetAccessToken() string
- func GetEmail() string
- func GetProjectWorkspaceKey() ([]byte, error)
- func GetSelectedWorkspaceID() string
- func GetStorageMode() int
- func GetWorkspaceKey(workspaceID string) ([]byte, error)
- func GlobalConfigExists() bool
- func InitGlobalConfig() error
- func InitProjectConfig() error
- func IsAuthenticated() bool
- func SaveGlobalConfig(config *GlobalConfig) error
- func SaveProjectConfig(config *ProjectConfig) error
- func SaveTokens(tokens *TokenConfig) error
- func SetEmail(email string) error
- func SetSelectedWorkspaceID(id string) error
- func SetStorageMode(mode int) error
- func StoreTokens(accessToken, refreshToken, expiresAt string) error
- func StoreWorkspaceCache(workspaces map[string]WorkspaceCacheEntry) error
- type GlobalConfig
- type Paths
- type ProjectConfig
- type TokenConfig
- type WorkspaceCacheEntry
Constants ¶
This section is empty.
Variables ¶
var HomeDirHook = os.UserHomeDir
HomeDirHook is used to determine the user's home directory. It can be overridden in tests to redirect config files.
Functions ¶
func ClearProjectConfig ¶
func ClearProjectConfig() error
ClearProjectConfig resets the local .agentsecrets/project.json file.
func ClearSession ¶
func ClearSession() error
ClearSession removes all stored credentials (logout). Does NOT clear project.json.
func GetAccessToken ¶
func GetAccessToken() string
GetAccessToken returns the current access token, or empty string.
func GetEmail ¶
func GetEmail() string
GetEmail returns the stored user email, or empty string if not logged in.
func GetProjectWorkspaceKey ¶
GetProjectWorkspaceKey returns the workspace key for the current project directory.
func GetSelectedWorkspaceID ¶
func GetSelectedWorkspaceID() string
GetSelectedWorkspaceID returns the selected workspace for new project creation.
func GetStorageMode ¶
func GetStorageMode() int
GetStorageMode returns the configured storage mode (1: keychain, 2: env_file). Defaults to 1 (keychain) if not set.
func GetWorkspaceKey ¶
GetWorkspaceKey returns the decrypted workspace key for a given workspace ID.
func GlobalConfigExists ¶
func GlobalConfigExists() bool
GlobalConfigExists returns true if ~/.agentsecrets/config.json already exists.
func InitGlobalConfig ¶
func InitGlobalConfig() error
InitGlobalConfig creates the ~/.agentsecrets/ directory and default config files.
func InitProjectConfig ¶
func InitProjectConfig() error
InitProjectConfig creates .agentsecrets/project.json in the current directory.
func IsAuthenticated ¶
func IsAuthenticated() bool
IsAuthenticated checks if the user has a valid session (token + email present).
func SaveGlobalConfig ¶
func SaveGlobalConfig(config *GlobalConfig) error
SaveGlobalConfig writes ~/.agentsecrets/config.json
func SaveProjectConfig ¶
func SaveProjectConfig(config *ProjectConfig) error
SaveProjectConfig writes .agentsecrets/project.json in the current directory.
func SaveTokens ¶
func SaveTokens(tokens *TokenConfig) error
SaveTokens writes ~/.agentsecrets/token.json
func SetSelectedWorkspaceID ¶
SetSelectedWorkspaceID sets the selected workspace for new project creation.
func SetStorageMode ¶
SetStorageMode updates the storage mode in the global config.
func StoreTokens ¶
StoreTokens saves authentication tokens.
func StoreWorkspaceCache ¶
func StoreWorkspaceCache(workspaces map[string]WorkspaceCacheEntry) error
StoreWorkspaceCache saves decrypted workspace keys to global config.
Types ¶
type GlobalConfig ¶
type GlobalConfig struct {
Email string `json:"email,omitempty"`
SelectedWorkspaceID string `json:"selected_workspace_id,omitempty"`
Workspaces map[string]WorkspaceCacheEntry `json:"workspaces,omitempty"`
StorageMode int `json:"storage_mode,omitempty"` // 1 = keychain (default), 2 = env_file
}
GlobalConfig represents ~/.agentsecrets/config.json
func LoadGlobalConfig ¶
func LoadGlobalConfig() (*GlobalConfig, error)
LoadGlobalConfig reads ~/.agentsecrets/config.json
type Paths ¶
type Paths struct {
GlobalDir string // ~/.agentsecrets/
ConfigFile string // ~/.agentsecrets/config.json
TokenFile string // ~/.agentsecrets/token.json
}
Paths returns the standard config file paths
type ProjectConfig ¶
type ProjectConfig struct {
ProjectID string `json:"project_id"`
ProjectName string `json:"project_name"`
Description string `json:"description"`
Environment string `json:"environment"` // "development", "staging", "production"
WorkspaceID string `json:"workspace_id"`
WorkspaceName string `json:"workspace_name"`
LastPull string `json:"last_pull"`
LastPush string `json:"last_push"`
}
ProjectConfig represents ./.agentsecrets/project.json
func LoadProjectConfig ¶
func LoadProjectConfig() (*ProjectConfig, error)
LoadProjectConfig reads .agentsecrets/project.json from the current directory.
type TokenConfig ¶
type TokenConfig struct {
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresAt string `json:"expires_at,omitempty"`
}
TokenConfig represents ~/.agentsecrets/token.json
func LoadTokens ¶
func LoadTokens() (*TokenConfig, error)
LoadTokens reads ~/.agentsecrets/token.json
type WorkspaceCacheEntry ¶
type WorkspaceCacheEntry struct {
Name string `json:"name"`
Key string `json:"key"` // Base64-encoded decrypted workspace key
Role string `json:"role"` // "owner", "admin", "member"
Type string `json:"type"` // "personal", "shared"
}
WorkspaceCacheEntry is a cached workspace with its decrypted key