wbconfig

package
v0.172.9 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package wbconfig resolves the user-level WB configuration file that several commands share (recipes for wb run, the remote section for wb remote).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns $XDG_CONFIG_HOME/wb/wb.yaml when configured, otherwise ~/.config/wb/wb.yaml.

func SetPeersUpstream added in v0.150.1

func SetPeersUpstream(path, hubURL, tokenFile string) error

SetPeersUpstream writes wb.yaml's peers.upstream section (peer-connectivity#req:invite-and-join). It touches only the top-level "peers:" key and leaves every other byte of the file — including the entire `remote:` block, at whatever indentation, comment style, line ending or key order the operator wrote it in — untouched. Remote state, claims and peer events are deliberately independent.

Round 3 and round 4 each tried to derive the exact line range an existing "peers:" key occupies from decoded YAML structure (a node's line number, or the newlines embedded in a decoded scalar's value) and each time a different construction — a multi-line quoted scalar, a folded plain scalar, a block scalar — made that derived range wrong in one direction or the other: too short (leaking a sibling's lines into the replacement and duplicating them) or too long (deleting a second document, a trailing comment block, or a comment that merely happens to sit nearby), sometimes even producing a range past the end of the file's own line count.

Round 5's answer is to stop trying to handle arbitrary YAML. This function supports exactly two shapes and refuses everything else outright, leaving the file completely untouched:

  • Shape A: no top-level "peers:" key exists yet. A new block is appended — before a trailing "---" or "..." document marker if the file has one, otherwise at EOF.
  • Shape B: an existing block-style "peers:" key sits at column 0 (matched by the literal, exact line "peers:" — no quoting, no trailing comment, no unusual spacing), and every line of its body, up to the first line whose first character is not a space, is either blank or a single-line "key: value" pair (a single-line plain or single-line quoted scalar, no escape sequences) — with at most one nested sub-block, "upstream:", whose own children follow the exact same single-line-scalar rule one level deeper. The block's extent is found with nothing but a plain line scan (isPeersBodyLine, scanPeersBlockEnd): never from a decoded node's line number or a decoded scalar's length, so a construction that confused the old line-range derivation cannot confuse this one — it simply fails to match this narrow grammar and falls through to the refusal below.

Anything else — a flow-style root or a flow-style peers: value, a multi-line quoted or plain scalar anywhere in the body, a block scalar, an anchor, alias or tag, a comment inside the body or immediately above "peers:", more than one "upstream:" child, or a body that fails to parse as YAML at all — is refused with a clear, actionable message rather than guessed at.

verifyPeersUpstreamEdit then re-parses the result independently of every line-scan decision splicePeersBody made — decoding every YAML document (not just the first) and requiring every one but the first to be unchanged, decoding the first document's top-level keys and every peers: child besides "upstream" for a structural deep-equal, and separately re-running the same plain line scan against both the original and the updated text to require every byte outside the block's own range to be identical — before the staged file is ever renamed into place. Any mismatch refuses and leaves the original file untouched.

func SetRemoteHub added in v0.116.0

func SetRemoteHub(path, hubURL, machine, tokenFile string) error

SetRemoteHub updates only the remote provider fields owned by hub enrollment. Other top-level configuration and remote settings are retained.

Types

type PeersUpstreamConfig added in v0.150.1

type PeersUpstreamConfig struct {
	URL       string `yaml:"url"`
	TokenFile string `yaml:"token_file"`
}

PeersUpstreamConfig is the peers.upstream section `wb peers list` reads on the laptop (upstream) side.

func LoadPeersUpstream added in v0.150.1

func LoadPeersUpstream(path string) (PeersUpstreamConfig, bool, error)

LoadPeersUpstream reads peers.upstream from path. found is false when the file, the peers section, or the upstream section is absent — the laptop simply has no configured hub yet, which is not an error.

Jump to

Keyboard shortcuts

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