config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 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 config reads Agent GM's environment. There is no config file (spec section 15.1), and secrets are read from nowhere but the environment.

Index

Constants

View Source
const MinAdminSecretLength = 43

MinAdminSecretLength is spec section 12.1's floor. 43 characters is the length of a base64url-encoded 256-bit value, so a secret generated the documented way (`devbox run gen-secret`) always clears it and a hand-typed passphrase generally does not.

Variables

View Source
var ErrFakeNotAllowed = errors.New(
	"AGENT_GM_BACKEND=fake also requires AGENT_GM_ALLOW_FAKE=1; " +
		"refusing to serve an empty in-memory phone")

ErrFakeNotAllowed is spec section 15.1: AGENT_GM_BACKEND=fake without AGENT_GM_ALLOW_FAKE=1 refuses to start.

Functions

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration accepts an integer plus a unit of s, m, h or d (spec section 11.1). Anything else is a usage error naming the value.

func StateDir

func StateDir() string

StateDir is $XDG_STATE_HOME/agent-gm, where the kept Chrome profiles and the credentials file live (spec sections 11.4, 11.5).

Types

type Backend

type Backend string

Backend selects the Google Messages implementation.

const (
	// BackendLibGM is the real thing.
	BackendLibGM Backend = "libgm"
	// BackendFake is the deterministic in-memory Google Messages. It
	// requires AGENT_GM_ALLOW_FAKE=1 as well, so a production deployment
	// cannot be talked into serving an empty in-memory phone.
	BackendFake Backend = "fake"
)

type Config

type Config struct {
	// PublicURL is AGENT_GM_PUBLIC_URL: the issuer, the canonical resource,
	// and the base of every URL Agent GM hands out. It is NEVER derived from
	// the request's Host, so an agent in a sandbox on another machine
	// reaches the same origin the tunnel exposes (spec sections 10.3, 12.3).
	PublicURL string
	// ListenAddr is AGENT_GM_LISTEN_ADDR.
	ListenAddr string
	// AdminSecret is AGENT_GM_ADMIN_SECRET, the owner bootstrap credential.
	// It lives in the environment only and is at least 43 characters; the
	// server refuses to start with a shorter one (spec section 12.1).
	AdminSecret string
	// TrustedProxyCIDRs is AGENT_GM_TRUSTED_PROXY_CIDRS, parsed. An invalid
	// value refuses to start: an operator who mistypes the list should find
	// out immediately, not discover months later that the trust they
	// configured was never in force (spec section 12.3).
	TrustedProxyCIDRs []netip.Prefix
	// TrustedProxyRaw is the value as given, for the one startup log line
	// that reports which mode is in force.
	TrustedProxyRaw string

	DataDir        string
	DataKey        store.DataKey
	Backend        Backend
	LogLevel       string
	LogFormat      string
	UnsafeTrace    bool
	Chrome         string
	PairingTimeout time.Duration
	DefaultAccount string
	StateDir       string
}

Config is the environment Agent GM was started with.

func Load

func Load() (Config, error)

Load reads the environment.

func LoadServer

func LoadServer() (Config, error)

LoadServer is Load plus the variables only the server needs: AGENT_GM_PUBLIC_URL, AGENT_GM_LISTEN_ADDR, AGENT_GM_ADMIN_SECRET and AGENT_GM_TRUSTED_PROXY_CIDRS.

It is separate from Load because `agm` is the same binary and does not hold the admin secret, does not bind a port, and has no public URL of its own -- requiring them of every invocation would make the CLI unusable on a machine that is not also the server (spec sections 11.5, 15.1).

func (Config) ClientSourceMode

func (c Config) ClientSourceMode() string

ClientSourceMode is what the one startup log line reports (spec section 12.3), so a misconfiguration where every caller collapses to one source is visible from the first line of the log.

Jump to

Keyboard shortcuts

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