config

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultUpstreamIntervalMinutes = 1

DefaultUpstreamIntervalMinutes matches what a CashPilot worker sends, so a paired Desktop does not look stale next to the Docker workers on the same fleet page — the server marks a worker unreachable on heartbeat age.

Variables

This section is empty.

Functions

func FleetKey added in v0.10.0

func FleetKey(appDir string) (string, error)

FleetKey returns the stored fleet bearer token, mirroring MasterKey's keychain-preferred / file-fallback storage. It tries the OS keychain first, then a 0600 <appDir>/.fleet_api_key file (migrating that file's value into the keychain when found). An empty string with a nil error means "not stored yet" so the caller can generate a fresh token or migrate a legacy config.json value and persist it via SetFleetKey.

func MasterKey

func MasterKey(appDir string) ([]byte, error)

func SetFleetKey added in v0.10.0

func SetFleetKey(appDir, value string) error

SetFleetKey persists the fleet bearer token keychain-first, falling back to a 0600 <appDir>/.fleet_api_key file when the keychain is unavailable (headless Linux / CI), exactly like MasterKey's storage tail.

func SetUpstreamEnrolmentKey added in v0.12.0

func SetUpstreamEnrolmentKey(appDir, value string) error

SetUpstreamEnrolmentKey persists the shared enrolment token.

func SetUpstreamWorkerKey added in v0.12.0

func SetUpstreamWorkerKey(appDir, value string) error

SetUpstreamWorkerKey persists the per-worker key issued by the server.

func UpstreamEnrolmentKey added in v0.12.0

func UpstreamEnrolmentKey(appDir string) (string, error)

UpstreamEnrolmentKey returns the shared CashPilot token used to enrol this machine, or "" when not stored. Same keychain-first, 0600-file-fallback storage as FleetKey.

func UpstreamWorkerKey added in v0.12.0

func UpstreamWorkerKey(appDir string) (string, error)

UpstreamWorkerKey returns the per-worker key the server issued to this machine, or "" before enrolment completes.

Types

type AppConfig

type AppConfig struct {
	FirstRunComplete       bool   `json:"firstRunComplete"`
	DisplayCurrency        string `json:"displayCurrency"`
	RuntimeProvider        string `json:"runtimeProvider"`
	AutoUpdate             bool   `json:"autoUpdate"`
	HostnamePrefix         string `json:"hostnamePrefix"`
	CollectIntervalMinutes int    `json:"collectIntervalMinutes"`
	RetentionDays          int    `json:"retentionDays"`
	Timezone               string `json:"timezone"`
	// FleetAPIKey is the legacy plaintext location for the fleet bearer token. It is
	// no longer persisted here — the token lives in the OS keychain with a 0600 file
	// fallback via FleetKey/SetFleetKey. The field is retained with omitempty only so
	// an older config.json still unmarshals and ensureFleetAPIKey can migrate its
	// value into the keychain and then blank it from disk.
	FleetAPIKey      string `json:"fleetApiKey,omitempty"`
	FleetBindAddress string `json:"fleetBindAddress"`
	FleetPort        int    `json:"fleetPort"`
	// MetricsEnabled turns on the opt-in Prometheus /metrics endpoint on the fleet
	// server. It defaults to false (disabled) — the bool zero value, so applyDefaults
	// needs no change. Enabling it exposes earnings, health and fleet stats on the
	// fleet bind address (loopback by default) with no authentication, matching the
	// Prometheus scraping convention.
	MetricsEnabled bool `json:"metricsEnabled"`
	// WorkerURLPolicy selects how the SSRF worker-URL validator (internal/fleetnet)
	// classifies a remote worker endpoint before the desktop makes an authenticated
	// request to it. One of "strict" (only WorkerAllowedHosts), "private" (RFC1918 +
	// Tailscale CGNAT 100.64.0.0/10 + IPv6 ULA fc00::/7 + the allowlist — the sensible
	// homelab default), or "public" (any non-loopback/link-local/metadata/unspecified
	// address). Defaults to "private" via applyDefaults.
	WorkerURLPolicy string `json:"workerUrlPolicy"`
	// WorkerAllowedHosts is an explicit allowlist of worker hosts/IPs. It is the sole
	// allow-source in "strict" mode and is always honored in the other modes. Entries
	// may be an exact hostname, a "*.suffix" DNS suffix (e.g. Tailscale MagicDNS
	// "*.mango-alpha.ts.net"), a CIDR, or a literal IP. Defaults to empty (nil).
	WorkerAllowedHosts []string `json:"workerAllowedHosts"`
	// WorkerAllowMetadata, when false (the default, the bool zero value), makes the
	// cloud instance-metadata endpoints (169.254.169.254, fd00:ec2::254,
	// metadata.google.internal) ALWAYS blocked regardless of policy or allowlist.
	// Setting it true is the only way to reach a metadata address and should be rare.
	WorkerAllowMetadata bool `json:"workerAllowMetadata"`
	// FleetServerEnabled turns this Desktop into a HUB that accepts worker and
	// mobile heartbeats. It defaults to FALSE, which is the bool zero value, so
	// every existing install becomes a pure spoke on upgrade.
	//
	// CashPilot is hub-and-spoke: the CashPilot SERVER is the hub, and Desktop
	// and Android are spokes. Spokes do not collect from each other. Nothing
	// enforced that -- startFleetAPI ran unconditionally, so any worker or phone
	// could enrol into a Desktop and create a second, competing source of truth.
	//
	// Kept as a gate rather than deleted because the capability works and
	// someone may want it later; off is the right default until they ask.
	FleetServerEnabled bool `json:"fleetServerEnabled"`
	// UpstreamURL optionally pairs this Desktop with a CashPilot server, which it
	// then reports to as a worker. EMPTY IS THE DEFAULT AND MEANS STANDALONE:
	// Desktop keeps working exactly as before and nothing is sent anywhere.
	//
	// The credentials are deliberately NOT here — they live in the OS keychain
	// (0600 file fallback) via UpstreamEnrolmentKey/UpstreamWorkerKey, the same
	// way the fleet token does, so config.json never carries a bearer token.
	UpstreamURL string `json:"upstreamUrl,omitempty"`
	// UpstreamIntervalMinutes is how often to heartbeat when paired. Zero means
	// use the default; see DefaultUpstreamIntervalMinutes.
	UpstreamIntervalMinutes int `json:"upstreamIntervalMinutes,omitempty"`
	// UpstreamHistoryPushedTo is the server URL this Desktop has already handed
	// its pre-pairing earnings history to, or empty for none.
	//
	// The import itself is idempotent — the server keys a reading on (platform,
	// source, date) and updates rather than appends — so re-sending would be
	// harmless but wasteful: it is up to 400 days of readings on every
	// heartbeat, which is every minute by default.
	//
	// Storing the URL rather than a bare boolean is what makes re-pairing work:
	// pointing Desktop at a DIFFERENT server no longer matches, so that server
	// gets the history too. It is also why this is not a secret and belongs in
	// config.json — it records where data was sent, not how to authenticate.
	UpstreamHistoryPushedTo string `json:"upstreamHistoryPushedTo,omitempty"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager() (*Manager, error)

func (*Manager) AppDir

func (m *Manager) AppDir() string

func (*Manager) Config

func (m *Manager) Config() AppConfig

func (*Manager) DataDir

func (m *Manager) DataDir() string

func (*Manager) Save

func (m *Manager) Save(cfg AppConfig) error

func (*Manager) Update added in v0.15.0

func (m *Manager) Update(mutate func(cfg *AppConfig)) error

Update applies mutate to the current config and persists the result as ONE read-modify-write.

Save takes a whole AppConfig, so a caller that reads the config, does slow work, and then saves silently discards everything the user changed meanwhile. The pairing loop has exactly that shape — it reads the config, uploads up to 400 days of earnings over the network, then records where it sent them — and it runs while the settings screen is open. Holding the lock across the whole read-modify-write closes the window instead of narrowing it.

Use this for any single field written by background work. Save stays the right call for the settings form, which legitimately writes the whole object.

Jump to

Keyboard shortcuts

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