Documentation
¶
Index ¶
- Constants
- func FleetKey(appDir string) (string, error)
- func MasterKey(appDir string) ([]byte, error)
- func SetFleetKey(appDir, value string) error
- func SetUpstreamEnrolmentKey(appDir, value string) error
- func SetUpstreamWorkerKey(appDir, value string) error
- func UpstreamEnrolmentKey(appDir string) (string, error)
- func UpstreamWorkerKey(appDir string) (string, error)
- type AppConfig
- type Manager
Constants ¶
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
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 SetFleetKey ¶ added in v0.10.0
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
SetUpstreamEnrolmentKey persists the shared enrolment token.
func SetUpstreamWorkerKey ¶ added in v0.12.0
SetUpstreamWorkerKey persists the per-worker key issued by the server.
func UpstreamEnrolmentKey ¶ added in v0.12.0
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
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
// "*.tailnet-example.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"`
// DriftWarningsOff turns off the "needs fixing" warning for a container that no
// longer matches what a redeploy would build. Its zero value keeps warnings on
// (CASHPILOT_DRIFT_WARNINGS on the web).
DriftWarningsOff bool `json:"driftWarningsOff,omitempty"`
// DriftIgnored maps a service slug to the catalog fingerprint
// (runtime.ShapeFingerprint) its drift warning was muted at. The mute holds
// until the catalog changes a field the check judges.
DriftIgnored map[string]string `json:"driftIgnored,omitempty"`
}
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) Update ¶ added in v0.15.0
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.