remote

package
v1.21.107 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package remote runs a clicky CLI's commands against a server that serves the same command tree over the rpc executor routes, instead of in this process.

A host installs it once, after the command tree is complete. A Resolve function decides per invocation whether a remote Target is active (a logged-in context); when it is, each command's parsed flags and args are encoded with rpc.EncodeRequest, sent, and the typed result is decoded into the command's declared response type and rendered locally through entity.RenderResult — so --format table/json/tree output is the same as a local run.

Index

Constants

View Source
const DefaultPathPrefix = "/api/v1"

DefaultPathPrefix is the executor mount the rpc server defaults to.

Variables

View Source
var ErrReauthRequired = errors.New("login required")

ErrReauthRequired is returned when a context's credential can no longer be refreshed and the user must log in again.

View Source
var ErrUnauthorized = errors.New("not authenticated")

ErrUnauthorized is returned when the server rejects the request's credentials; the target's LoginHint says how to recover.

Functions

func BrowserLogin

func BrowserLogin(ctx context.Context, opts BrowserLoginOptions) (*oidcclient.Tokens, error)

BrowserLogin runs the authorization code flow with PKCE through a loopback redirect and returns the issued tokens.

func Call

func Call(ctx context.Context, target *Target, cmd *cobra.Command, args []string, opts CallOptions) (any, error)

Call executes cmd with its parsed args on target and returns the decoded result: a value of the command's declared response type, or the execution envelope (with captured stdout) for a command that declares none. When the server answers with entity.TaskIDHeader the command started a background run: Call follows it (see Follow) and returns the run's result, or, with opts.NoWait, returns its entity.TaskHandle at once.

func DiscoverServer

func DiscoverServer(server string) (*oidcclient.Discovery, error)

DiscoverServer fetches the server's /.well-known/openid-configuration.

func Follow added in v1.21.106

func Follow(ctx context.Context, target *Target, runID string) (any, error)

Follow mirrors the task run runID on target into a local clicky task, so the terminal shows the server's progress and log lines as they happen, until the run finishes. It returns the run's result — the details the run published (task.WithDetailsProvider / ManagedRun.SetDetailsProvider), or its RunMeta when it published none — and an error naming the failures when the run did not succeed.

func Install

func Install(root *cobra.Command, opts Options)

Install wraps every runnable command under root so that, while Resolve returns a target, it runs on that server. Call it once the command tree is complete, after any other whole-tree pass that replaces RunE (for example entity.RefuseServedOnlyCommands, so served-only commands run remotely).

func IsClientCommand

func IsClientCommand(cmd *cobra.Command) bool

IsClientCommand reports whether cmd or a parent is marked as a client command.

func MarkClientCommand

func MarkClientCommand(cmd *cobra.Command)

MarkClientCommand makes a command (and its subtree) always run in this process, even with a remote target active: login, logout, context management, version, completion.

func ProbeServer

func ProbeServer(ctx context.Context, server string) (string, error)

ProbeServer checks that server answers GET /health with a 2xx, so a typo is reported at login instead of on the first command. It returns the server URL normalised without a trailing slash.

func Run

func Run(ctx context.Context, target *Target, cmd *cobra.Command, args []string, opts CallOptions) error

Run executes cmd with its parsed args on target and renders the result.

Types

type BrowserLoginOptions

type BrowserLoginOptions struct {
	Discovery *oidcclient.Discovery
	ClientID  string
	// Scopes defaults to "openid profile offline_access".
	Scopes string
	// Status receives the URL to open; nil discards it.
	Status io.Writer
	// OpenBrowser opens the authorization URL; nil only prints it.
	OpenBrowser func(string) error
	// Timeout bounds the wait for the browser; zero means 5 minutes.
	Timeout time.Duration
}

BrowserLoginOptions configures BrowserLogin.

type CallOptions added in v1.21.106

type CallOptions struct {
	// NoWait returns an entity.TaskHandle for a background run the server
	// started instead of following the run to its result.
	NoWait bool
}

CallOptions tunes one remote execution.

type Error

type Error struct {
	Target     string
	Operation  string
	StatusCode int
	ExitCode   int
	Code       string
	Message    string
	Hint       string
}

Error is a failed remote execution.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap lets callers test a 401 with errors.Is(err, ErrUnauthorized).

type Options

type Options struct {
	// Resolve returns the target cmd should run against, or nil to run it
	// locally. It is called after flag parsing and the persistent pre-runs, so
	// it may read --context style flags.
	Resolve func(cmd *cobra.Command) (*Target, error)
	// NoWait reports whether cmd should return the id of a background run the
	// server started instead of following it to completion, e.g. from a host
	// --no-wait flag. Nil always follows.
	NoWait func(cmd *cobra.Command) bool
}

Options configures Install.

type Session

type Session struct {
	// Context is the key the credential is stored under.
	Context string
	// Dir holds the file store and the cross-process lock.
	Dir string
	// Store is the credential store kind (credentials.KindFile or KindKeychain).
	Store string
	// Service is the OS keychain service, normally the application name.
	Service string
	// ClientID is the OAuth client the tokens were issued to.
	ClientID string
	// TokenEndpoint refreshes an OIDC credential; empty for a static token.
	TokenEndpoint string
	// LoginHint is quoted when the user must log in again.
	LoginHint string
}

Session is one context's credential: where it is stored and how it is refreshed. The context configuration that names the server belongs to the host application; a Session needs only what refreshing a token takes.

func (Session) Delete

func (s Session) Delete() error

Delete removes the context's credential.

func (Session) Load

func (s Session) Load() (*credentials.Credential, error)

Load returns the stored credential, or nil when there is none.

func (Session) Save

func (s Session) Save(cred *credentials.Credential) error

Save stores cred for the context, after checking the store is writable.

func (Session) Token

func (s Session) Token(context.Context) (string, error)

Token returns a usable bearer token for the context, refreshing an expiring OIDC access token first. It is shaped to be a Target.Token.

type Target

type Target struct {
	// Name identifies the target in messages, e.g. the context name.
	Name string
	// BaseURL is the server's origin plus any mount path, without the executor
	// prefix: https://oipa.example.com.
	BaseURL string
	// PathPrefix is the executor prefix the server mounts commands under; it
	// must match the server's ExecutorConfig.PathPrefix. Empty means /api/v1.
	PathPrefix string
	// Headers are sent on every request, e.g. a server-side context selector.
	Headers map[string]string
	// Token returns the bearer token for a request; nil sends none. It is
	// called per request so a refreshing source can rotate tokens.
	Token func(ctx context.Context) (string, error)
	// LoginHint is the command that re-authenticates, quoted in a 401 error.
	LoginHint string
	// HTTPClient sends the requests; nil means http.DefaultClient.
	HTTPClient *http.Client
	// TaskPathPrefix is where the server mounts the task API
	// (task.RegisterHandlers), followed when a command starts a background run.
	// Empty means the executor's PathPrefix.
	TaskPathPrefix string
}

Target is a server that runs commands for this CLI.

Directories

Path Synopsis
Package credentials persists a CLI's per-context secrets separately from its context configuration, with the durability guarantees a rotating single-use refresh token requires: writes are atomic, mutations are serialised across processes via WithLock, and Writable reports up-front whether a credential can be stored at all — before one is spent.
Package credentials persists a CLI's per-context secrets separately from its context configuration, with the durability guarantees a rotating single-use refresh token requires: writes are atomic, mutations are serialised across processes via WithLock, and Writable reports up-front whether a credential can be stored at all — before one is spent.
Package oidcclient is the client half of an OAuth 2.0 / OIDC login for a CLI: provider discovery, PKCE, the token endpoint grants (authorization code, refresh, password) and revocation.
Package oidcclient is the client half of an OAuth 2.0 / OIDC login for a CLI: provider discovery, PKCE, the token endpoint grants (authorization code, refresh, password) and revocation.

Jump to

Keyboard shortcuts

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