Help us shape the future of Go! Take the 2026 Go Developer Survey

app

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package app wires configuration, the read credential, the API client, the local runner and the audit log into one registry.Env for the CLI and the MCP server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Registry   *registry.Registry
	Env        *registry.Env
	Loaded     *config.Loaded  // nil when no configuration exists
	Context    string          // selected context name
	Tailnet    string          // its tailnet ID
	Provider   config.Provider // its read provider
	Credential string          // a description of the read credential that never includes a secret
	CredKind   creds.Kind
	KeyID      string // the credential's key ID (OAuth client ID, federated identity ID or API key ID)
	AuditPath  string
	Audit      *audit.Log // nil when the log could not be opened; AuditErr says why
	AuditErr   error
	AuditReads string // "metadata" or "none"
}

App is everything a surface needs.

func Build

func Build(ctx context.Context, o Options) (*App, error)

Build loads the configuration and wires the registry.

It returns an error only when no tool may run: the configuration is unsafe or invalid, and the exec provider runs commands the configuration names. Problems that affect only API tools (no configuration, no context, no credential, or the exec provider still needing its wrapper) are kept in Env.APIErr so local tools keep working; creds.ErrReexecRequired there tells the caller to re-exec.

ctx must outlive the App: the API client requests tokens under it, so API reads fail once it ends (api.New).

func (*App) Record

func (a *App) Record(fields map[string]any) error

Record appends a metadata-only read event unless audit.reads is "none". A read is never refused for want of an audit line (spec §14); the error is returned so the surface can warn once. Context and tailnet always come from the App, and a line the audit log refuses (it held a credential shape) is replaced by one that says so, so the read is still recorded.

type Options

type Options struct {
	Context  string                            // --context flag value
	Getenv   func(string) string               // default os.Getenv
	Dirs     *config.Dirs                      // default config.DefaultDirs()
	Check    config.Checker                    // default config.CheckOwnership
	Stat     func(string) (fs.FileInfo, error) // default os.Stat, for finding the CLI
	ReadFile func(string) ([]byte, error)      // default os.ReadFile
	API      api.Options                       // BaseURL and retry settings (tests)
	Now      func() time.Time                  // default time.Now
}

Options configures Build. Zero values use the real system.

Jump to

Keyboard shortcuts

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