auth

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewFileStore(projectRoot string) *FileStore

NewFileStore returns a FileStore anchored at <projectRoot>/profiles.env.

func (*FileStore) Delete

func (f *FileStore) Delete(_ context.Context, _ string) error

Delete is not supported. The CLI does not write to profiles.env.

func (*FileStore) Exists

func (f *FileStore) Exists() bool

Exists reports whether the backing file is present.

func (*FileStore) Get

func (f *FileStore) Get(_ context.Context, name string) (*Credential, error)

Get implements CredentialStore. Returns the credential for name.

func (*FileStore) GetProfile

func (f *FileStore) GetProfile(name string) (*Profile, error)

GetProfile returns the profile metadata for name.

func (*FileStore) List

func (f *FileStore) List(_ context.Context) ([]string, error)

List returns all profile names in file order.

func (*FileStore) ListProfiles

func (f *FileStore) ListProfiles() ([]*Profile, error)

ListProfiles returns all profiles in file order.

func (*FileStore) Set

func (f *FileStore) Set(_ context.Context, _ string, _ *Credential) error

Set is not supported. The CLI does not write to profiles.env.

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) List

func (k *KeyringStore) List(_ context.Context) ([]string, 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.

type Region

type Region string

Region represents a Workato data center region.

const (
	RegionUS    Region = "us"
	RegionEU    Region = "eu"
	RegionJP    Region = "jp"
	RegionAU    Region = "au"
	RegionSG    Region = "sg"
	RegionIL    Region = "il"
	RegionCN    Region = "cn"
	RegionTrial Region = "trial"
)

func ValidRegions

func ValidRegions() []Region

ValidRegions returns all supported regions.

func (Region) IsValid

func (r Region) IsValid() bool

IsValid checks if a region string is a supported region.

type StoreType

type StoreType string

StoreType identifies the credential storage backend.

const (
	StoreKeychain StoreType = "keychain"
	StoreFile     StoreType = "file"
	StoreVault    StoreType = "vault"
)

Jump to

Keyboard shortcuts

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