state

package
v0.36.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BrowserOpener added in v0.25.0

type BrowserOpener func(url string) error

BrowserOpener opens a URL in the user's default browser.

type OAuth added in v0.34.0

type OAuth interface {
	Discover(ctx context.Context, endpoint string) (oauth.Discovery, error)
	Login(ctx context.Context, opts oauth.LoginOptions) (oauth.LoginResult, error)
	// Session returns the stored session without its tokens, or false when there is none.
	Session(endpoint string) (oauth.Token, bool, error)
	// Token returns the session with a fresh access token.
	Token(ctx context.Context, endpoint string) (oauth.Token, error)
	TokenSource(ctx context.Context, endpoint string) (oauth2.TokenSource, error)
	Logout(ctx context.Context, endpoint string) (warnings []error, err error)
}

OAuth is the OAuth login: discovery of the login server, the browser and device logins, and the stored session of each endpoint, which it refreshes and removes.

type State

type State struct {
	Version string
	Config  *config.Config
	Logger  *slog.Logger
	// contains filtered or unexported fields
}

State holds shared dependencies for all commands.

func New

func New(version string) *State

New creates a new State with the given version string.

func (*State) AccountID

func (s *State) AccountID() (string, error)

AccountID returns the configured account ID or an error.

func (*State) Client

func (s *State) Client(ctx context.Context) (*qcloudapi.Client, error)

Client returns the gRPC client, creating it lazily on first call. It uses the configured API key, or else the OAuth login of the endpoint.

func (*State) ConfigDir added in v0.34.0

func (s *State) ConfigDir() string

ConfigDir is the directory of the config file, or of the default one when none was loaded.

func (*State) HasCredentials added in v0.35.0

func (s *State) HasCredentials() (bool, error)

HasCredentials reports whether Client can authenticate: an API key is configured, or there is an OAuth login for the endpoint. An expired login still counts, Client refreshes it.

func (*State) OAuth added in v0.34.0

func (s *State) OAuth() OAuth

OAuth returns the OAuth login, creating it lazily on first call: the OS keychain, and credentials.yaml next to the config file.

func (*State) OAuthClient added in v0.34.0

func (s *State) OAuthClient(ctx context.Context) (*qcloudapi.Client, error)

OAuthClient returns the gRPC client that uses the OAuth login of the endpoint, whatever API key is configured, creating it lazily on first call.

func (*State) OpenBrowser added in v0.25.0

func (s *State) OpenBrowser(url string) error

OpenBrowser opens the given URL in the user's default browser.

func (*State) SetBrowserOpener added in v0.25.0

func (s *State) SetBrowserOpener(fn BrowserOpener)

SetBrowserOpener injects a browser opener, bypassing the default. For testing.

func (*State) SetClient

func (s *State) SetClient(c *qcloudapi.Client)

SetClient injects a pre-built client, bypassing lazy creation.

func (*State) SetOAuth added in v0.34.0

func (s *State) SetOAuth(o OAuth)

SetOAuth injects an OAuth implementation.

func (*State) SetOAuthClient added in v0.34.0

func (s *State) SetOAuthClient(c *qcloudapi.Client)

SetOAuthClient injects a pre-built OAuth client, bypassing lazy creation.

func (*State) SetUnAuthenticatedClient added in v0.29.0

func (s *State) SetUnAuthenticatedClient(c *qcloudapi.Client)

SetUnAuthenticatedClient injects a pre-built unauthenticated client, bypassing lazy creation.

func (*State) SetUpdater added in v0.5.0

func (s *State) SetUpdater(u Updater)

SetUpdater injects an Updater implementation.

func (*State) UnAuthenticatedClient added in v0.29.0

func (s *State) UnAuthenticatedClient(ctx context.Context) (*qcloudapi.Client, error)

UnAuthenticatedClient returns the gRPC client without authentication, creating it lazily on first call.

func (*State) Updater added in v0.5.0

func (s *State) Updater() (Updater, error)

Updater returns the CLI updater, creating it lazily on first call.

type Updater added in v0.5.0

type Updater interface {
	DetectLatest(ctx context.Context) (*selfupgrade.ReleaseInfo, bool, error)
	UpdateSelf(ctx context.Context, currentVersion string) (*selfupgrade.ReleaseInfo, error)
}

Updater checks for and applies CLI updates.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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