Documentation
¶
Index ¶
- Constants
- func WriteProfilesEnv(path string, profile *Profile, cred *Credential) error
- type Credential
- type CredentialStore
- type FileStore
- func (f *FileStore) Delete(_ context.Context, _ string) error
- func (f *FileStore) Exists() bool
- func (f *FileStore) Get(_ context.Context, name string) (*Credential, error)
- func (f *FileStore) GetProfile(name string) (*Profile, error)
- func (f *FileStore) List(_ context.Context) ([]string, error)
- func (f *FileStore) ListProfiles() ([]*Profile, error)
- func (f *FileStore) Set(_ context.Context, _ string, _ *Credential) error
- type KeyringStore
- func (k *KeyringStore) Delete(_ context.Context, profileName string) error
- func (k *KeyringStore) Get(_ context.Context, profileName string) (*Credential, error)
- func (k *KeyringStore) List(_ context.Context) ([]string, error)
- func (k *KeyringStore) Set(_ context.Context, profileName string, cred *Credential) error
- type Profile
- type ProfileManager
- func (pm *ProfileManager) DeleteProfile(name string) error
- func (pm *ProfileManager) GetActiveProfile() (string, error)
- func (pm *ProfileManager) GetProfile(name string) (*Profile, error)
- func (pm *ProfileManager) ListProfiles() ([]*Profile, error)
- func (pm *ProfileManager) SaveProfile(p *Profile) error
- func (pm *ProfileManager) SetActiveProfile(name string) error
- type Region
- type StoreType
Constants ¶
const ProfilesEnvFile = "profiles.env"
ProfilesEnvFile is the fixed filename for the file-based credential store.
Variables ¶
This section is empty.
Functions ¶
func WriteProfilesEnv ¶
func WriteProfilesEnv(path string, profile *Profile, cred *Credential) error
WriteProfilesEnv writes a profile and credential to a profiles.env file. If the file already exists, the new record is appended (separated by a blank line). This is the write path for `auth login --store-type file`, bypassing the read-only FileStore.Set() by design.
Types ¶
type Credential ¶
type Credential struct {
Token string `json:"token"`
Region Region `json:"region"`
StoreType StoreType `json:"store_type"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
Credential holds an API token and its metadata.
type CredentialStore ¶
type CredentialStore interface {
// Get retrieves the credential for a named profile.
Get(ctx context.Context, profileName string) (*Credential, error)
// Set stores a credential for a named profile.
Set(ctx context.Context, profileName string, cred *Credential) error
// Delete removes the credential for a named profile.
Delete(ctx context.Context, profileName string) error
// List returns all profile names with stored credentials.
List(ctx context.Context) ([]string, error)
}
CredentialStore is the interface for credential storage backends. Current implementations: KeyringStore (OS keychain) and FileStore (project-level profiles.env). Routing to the right backend is handled by the commands layer per ADR-006 Sub-decision 6.
type FileStore ¶
type FileStore struct {
Path string // absolute path to profiles.env
}
FileStore reads profiles and credentials from a project-local profiles.env. The CLI reads this file but never writes to it (ADR-006 Sub-decision 3). The file is developer- or pipeline-authored.
The file lives at <projectRoot>/profiles.env — project root, outside .wk/. Developer-authored files don't belong inside the CLI's tool-managed directory: .wk/ is CLI-created by `wk init`, so a file that init must *read* cannot live in a directory init is responsible for *creating*. `wk init` appends `profiles.env` to <projectRoot>/.gitignore as the replacement safety net (the .wk/ self-gitignore no longer covers it).
func NewFileStore ¶
NewFileStore returns a FileStore anchored at <projectRoot>/profiles.env.
func (*FileStore) GetProfile ¶
GetProfile returns the profile metadata for name.
func (*FileStore) ListProfiles ¶
ListProfiles returns all profiles in file order.
type KeyringStore ¶
type KeyringStore struct{}
KeyringStore stores credentials in the OS keychain via go-keyring.
func (*KeyringStore) Delete ¶
func (k *KeyringStore) Delete(_ context.Context, profileName string) error
func (*KeyringStore) Get ¶
func (k *KeyringStore) Get(_ context.Context, profileName string) (*Credential, error)
func (*KeyringStore) Set ¶
func (k *KeyringStore) Set(_ context.Context, profileName string, cred *Credential) error
type Profile ¶
type Profile struct {
Name string `json:"name"`
Workspace string `json:"workspace"`
WorkspaceID int `json:"workspace_id,omitempty"`
Environment string `json:"environment"`
Email string `json:"email,omitempty"`
Region Region `json:"region"`
StoreType StoreType `json:"store_type"`
BaseURL string `json:"base_url"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
}
Profile represents a named authentication profile targeting a specific workspace, environment, and region combination.
Workspace, WorkspaceID, and Email are populated from GET /users/me at login time (see ADR-006). Environment is user-provided.
type ProfileManager ¶
type ProfileManager struct {
Dir string // defaults to ~/.wk/
}
ProfileManager handles reading and writing profile metadata on disk.
func NewProfileManager ¶
func NewProfileManager() *ProfileManager
NewProfileManager creates a ProfileManager with the default directory ~/.wk/.
func (*ProfileManager) DeleteProfile ¶
func (pm *ProfileManager) DeleteProfile(name string) error
DeleteProfile removes a profile by name.
func (*ProfileManager) GetActiveProfile ¶
func (pm *ProfileManager) GetActiveProfile() (string, error)
GetActiveProfile reads the active profile name from disk.
func (*ProfileManager) GetProfile ¶
func (pm *ProfileManager) GetProfile(name string) (*Profile, error)
GetProfile returns a profile by name.
func (*ProfileManager) ListProfiles ¶
func (pm *ProfileManager) ListProfiles() ([]*Profile, error)
ListProfiles returns all saved profiles.
func (*ProfileManager) SaveProfile ¶
func (pm *ProfileManager) SaveProfile(p *Profile) error
SaveProfile adds or updates a profile in profiles.json. Returns ErrDuplicateTarget if another profile already targets the same (workspace, environment, region) tuple.
func (*ProfileManager) SetActiveProfile ¶
func (pm *ProfileManager) SetActiveProfile(name string) error
SetActiveProfile writes the active profile name to disk.