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
- Variables
- func BrowserLogin(ctx context.Context, opts BrowserLoginOptions) (*oidcclient.Tokens, error)
- func Call(ctx context.Context, target *Target, cmd *cobra.Command, args []string) (any, error)
- func DiscoverServer(server string) (*oidcclient.Discovery, error)
- func Install(root *cobra.Command, opts Options)
- func IsClientCommand(cmd *cobra.Command) bool
- func MarkClientCommand(cmd *cobra.Command)
- func ProbeServer(ctx context.Context, server string) (string, error)
- func Run(ctx context.Context, target *Target, cmd *cobra.Command, args []string) error
- type BrowserLoginOptions
- type Error
- type Options
- type Session
- type Target
Constants ¶
const DefaultPathPrefix = "/api/v1"
DefaultPathPrefix is the executor mount the rpc server defaults to.
Variables ¶
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.
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 ¶
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.
func DiscoverServer ¶
func DiscoverServer(server string) (*oidcclient.Discovery, error)
DiscoverServer fetches the server's /.well-known/openid-configuration.
func Install ¶
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 ¶
IsClientCommand reports whether cmd or a parent is marked as a client command.
func MarkClientCommand ¶
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 ¶
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.
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 Error ¶
type Error struct {
Target string
Operation string
StatusCode int
ExitCode int
Code string
Message string
Hint string
}
Error is a failed remote execution.
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)
}
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) 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.
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
}
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. |