Documentation
¶
Index ¶
- func DeleteAPIKey(profile string) error
- func ExportAPIKey(apiKey string, dest ExportDestination) error
- func GetAPIKey(profile string) (string, error)
- func GetActiveProfile() string
- func GetStoredAPIKey(profile string) (string, error)
- func InitStore() error
- func IsInteractiveTerminal() bool
- func ListProfiles() (profiles []string, activeProfile string, err error)
- func Login(profile, operatorID, keyTitle string, progress *LoginProgress) (string, error)
- func SetActiveProfile(profile string) error
- func StoreAPIKey(apiKey, profile string) error
- type ExportDestination
- type LoginProgress
- type LoginResponse
- type PollResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteAPIKey ¶
DeleteAPIKey removes the API key for a profile.
func ExportAPIKey ¶
func ExportAPIKey(apiKey string, dest ExportDestination) error
ExportAPIKey exports the API key to the specified destination.
func GetActiveProfile ¶
func GetActiveProfile() string
GetActiveProfile returns the currently active profile name.
func GetStoredAPIKey ¶
GetStoredAPIKey retrieves the API key from the credential store only, ignoring PE_API_KEY.
func IsInteractiveTerminal ¶
func IsInteractiveTerminal() bool
IsInteractiveTerminal returns true if stdin is a terminal.
func ListProfiles ¶
ListProfiles returns all stored profile names and the active profile.
func Login ¶
func Login(profile, operatorID, keyTitle string, progress *LoginProgress) (string, error)
Login authenticates via browser and stores the API key for the given profile. If progress is nil, no progress messages are printed.
func SetActiveProfile ¶
SetActiveProfile sets the active profile.
func StoreAPIKey ¶
StoreAPIKey stores an API key for a profile.
Types ¶
type ExportDestination ¶
type ExportDestination string
ExportDestination represents where to export the API key beyond the stored credentials file (e.g. into an OpenClaw config or a shell profile).
const ( ExportOpenClaw ExportDestination = "openclaw" ExportShell ExportDestination = "shell" ExportNone ExportDestination = "none" )
func PromptExportDestination ¶
func PromptExportDestination(in io.Reader, out io.Writer) ExportDestination
PromptExportDestination shows an interactive menu and returns the user's choice.
type LoginProgress ¶
type LoginProgress struct {
// OnUserCode is called with the code the user must type in the browser, before the browser is
// opened. Only called when the server issued one. Implementations MUST display it — a user who
// never sees it cannot complete the login.
OnUserCode func(code string)
// OnBrowserOpen is called when the browser is about to open, with the fallback URL.
OnBrowserOpen func(loginURL string)
// OnWaiting is called when polling starts.
OnWaiting func()
// OnServerMessage is called with the server's advisory message, if any. Used to reach CLI
// versions we can't otherwise update (e.g. deprecation notices), so it should be shown.
OnServerMessage func(message string)
}
LoginProgress reports login progress to the caller.
type LoginResponse ¶
type LoginResponse struct {
SessionToken string `json:"sessionToken"`
PollSecret string `json:"pollSecret"`
LoginURL string `json:"loginUrl"`
ExpiresAt time.Time `json:"expiresAt"`
Message string `json:"message"`
// UserCode is the device-flow user code (RFC 8628 §3.3). The user types it in the browser to
// confirm they're authorizing this terminal. Present only when we advertised supportsUserCode.
//
// Display it, and nothing more: it must reach the browser by the user reading it here and typing
// it in. Never put it in a URL, and don't log it.
UserCode string `json:"userCode"`
}