Documentation
¶
Overview ¶
Package register provides the brev register command for device registration
Index ¶
- Constants
- func ClearTestSSHPort()
- func DevplaneAuthorizedKeysComment(portID, userID string) string
- func FormatHardwareProfile(s *HardwareProfile) string
- func FormatPortLabel(p *nodev1.Port) string
- func InstallAuthorizedKey(u *user.User, pubKey, portID, brevUserID string) (bool, error)
- func InstallNetbird() error
- func NewCmdRegister(t *terminal.Terminal, store RegisterStore) *cobra.Command
- func NewNodeServiceClient(provider externalnode.TokenProvider, baseURL string) nodev1connect.ExternalNodeServiceClient
- func OpenSSHPort(ctx context.Context, t *terminal.Terminal, ...) (string, error)
- func PromptSSHPort(t *terminal.Terminal) (int32, error)
- func RemoveAuthorizedKey(u *user.User, pubKey string) error
- func RemoveAuthorizedKeyLine(u *user.User, line string) error
- func RemoveBrevAuthorizedKeys(u *user.User) ([]string, error)
- func ResolveSSHAccessPort(ctx context.Context, t *terminal.Terminal, prompter terminal.Selector, ...) (string, error)
- func SelectNodeFromList(ctx context.Context, t *terminal.Terminal, prompter terminal.Selector, ...) (*nodev1.ExternalNode, error)
- func SelectPortFromList(_ context.Context, t *terminal.Terminal, prompter terminal.Selector, ...) (*nodev1.Port, error)
- func SetTestSSHPort(port int32)
- func SetupAndRegisterNodeSSHAccess(ctx context.Context, t *terminal.Terminal, ...) error
- func UninstallNetbird() error
- type BrevAuthorizedKey
- type DefaultNodeClientFactory
- type DeviceRegistration
- type FileRegistrationStore
- type GPU
- type HardwareProfile
- type HardwareProfiler
- type Interconnect
- type LinuxPlatform
- type NetBirdManager
- type Netbird
- type RegisterStore
- type RegistrationStore
- type SetupRunner
- type ShellSetupRunner
- type StorageDevice
- type SystemHardwareProfiler
- type TerminalPrompter
Constants ¶
const ( // PortChoiceUseExisting is the interactive option to grant SSH on an allocated port. PortChoiceUseExisting = "Use an existing port" // PortChoiceOpenNew is the interactive option to open a new port before granting SSH. PortChoiceOpenNew = "Open a new port" )
const BrevKeyPrefix = BrevKeyPrefixLegacy
BrevKeyPrefix is an alias for BrevKeyPrefixLegacy (tests and migration).
const BrevKeyPrefixLegacy = "# brev-cli"
BrevKeyPrefixLegacy marks keys written by older CLI versions (# brev-cli).
Variables ¶
This section is empty.
Functions ¶
func ClearTestSSHPort ¶ added in v0.6.318
func ClearTestSSHPort()
ClearTestSSHPort clears the test port override.
func DevplaneAuthorizedKeysComment ¶ added in v0.6.325
DevplaneAuthorizedKeysComment is the suffix on Brev-managed authorized_keys lines. The CLI writes this before GrantNodeSSHAccess so devplane need not modify the file.
func FormatHardwareProfile ¶ added in v0.6.318
func FormatHardwareProfile(s *HardwareProfile) string
FormatHardwareProfile returns a human-readable summary of the hardware profile.
func FormatPortLabel ¶ added in v0.6.325
FormatPortLabel formats a port as "nodePort->connectPort" (e.g. "11640->22").
func InstallAuthorizedKey ¶ added in v0.6.318
InstallAuthorizedKey adds an authorized_keys line for this port and user. The same public key may appear on multiple lines (one per port). Untagged or legacy-tagged lines are upgraded in place; lines that already have a #brev-portID tag are left alone and a new line is appended.
func InstallNetbird ¶ added in v0.6.318
func InstallNetbird() error
InstallNetbird installs NetBird if it is not already present.
func NewCmdRegister ¶
func NewCmdRegister(t *terminal.Terminal, store RegisterStore) *cobra.Command
func NewNodeServiceClient ¶ added in v0.6.318
func NewNodeServiceClient(provider externalnode.TokenProvider, baseURL string) nodev1connect.ExternalNodeServiceClient
NewNodeServiceClient creates a ConnectRPC ExternalNodeServiceClient using the given token provider for authentication.
func OpenSSHPort ¶ added in v0.6.319
func OpenSSHPort( ctx context.Context, t *terminal.Terminal, nodeClients externalnode.NodeClientFactory, tokenProvider externalnode.TokenProvider, reg *DeviceRegistration, port int32, ) (string, error)
OpenSSHPort calls the OpenPort RPC to allocate a port on the node for SSH access. The call is idempotent — if the port is already open, the server returns the existing allocation.
func PromptSSHPort ¶ added in v0.6.318
PromptSSHPort prompts the user for the target SSH port, defaulting to 22 if they press Enter or leave it empty. Re-prompts on invalid input until a valid port is provided. Only returns an error for unrecoverable I/O failures.
func RemoveAuthorizedKey ¶ added in v0.6.318
RemoveAuthorizedKey removes a specific public key from the user's ~/.ssh/authorized_keys. It matches the key content regardless of whether the brev-cli comment tag is present.
func RemoveAuthorizedKeyLine ¶ added in v0.6.318
RemoveAuthorizedKeyLine removes an exact line from authorized_keys.
func RemoveBrevAuthorizedKeys ¶ added in v0.6.318
RemoveBrevAuthorizedKeys removes all Brev-managed SSH keys from authorized_keys.
func ResolveSSHAccessPort ¶ added in v0.6.325
func ResolveSSHAccessPort( ctx context.Context, t *terminal.Terminal, prompter terminal.Selector, nodeClients externalnode.NodeClientFactory, tokenProvider externalnode.TokenProvider, reg *DeviceRegistration, node *nodev1.ExternalNode, ) (string, error)
ResolveSSHAccessPort prompts for an existing or new port and returns its Brev port ID.
func SelectNodeFromList ¶ added in v0.6.320
func SelectNodeFromList(ctx context.Context, t *terminal.Terminal, prompter terminal.Selector, registrationStore RegistrationStore, nodes []*nodev1.ExternalNode) (*nodev1.ExternalNode, error)
SelectNodeFromList prompts the user to select a node from the list, then fetches and returns the full node. When this machine is registered, that node is marked " — this node" in the list. Call this after ListNodes when in interactive mode (same pattern as SelectOrganizationInteractive).
func SelectPortFromList ¶ added in v0.6.325
func SetTestSSHPort ¶ added in v0.6.318
func SetTestSSHPort(port int32)
SetTestSSHPort sets the port returned by PromptSSHPort without prompting. Only for use in tests; call ClearTestSSHPort when done.
func SetupAndRegisterNodeSSHAccess ¶ added in v0.6.320
func SetupAndRegisterNodeSSHAccess( ctx context.Context, t *terminal.Terminal, nodeClients externalnode.NodeClientFactory, tokenProvider externalnode.TokenProvider, reg *DeviceRegistration, targetUser *entity.User, linuxUsername string, brevPortID string, ) error
SetupAndRegisterNodeSSHAccess installs the user's public key in authorized_keys with the devplane comment tag, then calls GrantNodeSSHAccess. The key must be present locally before devplane can grant; matching tags make the grant a no-op on the authorized_keys file.
func UninstallNetbird ¶ added in v0.6.318
func UninstallNetbird() error
UninstallNetbird stops, uninstalls the service, and removes the NetBird package or binary. It reads /etc/netbird/install.conf (written by the install script) to determine the original installation method. The down/stop steps are best-effort since the service may already be disconnected or stopped after deregistration.
Types ¶
type BrevAuthorizedKey ¶ added in v0.6.318
type BrevAuthorizedKey struct {
Line string // full line from authorized_keys
KeyContent string // key type + material (and optional ssh comment), without brev suffix
PortID string // from devplane #brev-portID:...
UserID string // from devplane brev-userID:... or legacy user_id=
}
BrevAuthorizedKey represents a single Brev-managed key found in authorized_keys.
func ListBrevAuthorizedKeys ¶ added in v0.6.318
func ListBrevAuthorizedKeys(u *user.User) ([]BrevAuthorizedKey, error)
ListBrevAuthorizedKeys reads ~/.ssh/authorized_keys and returns Brev-managed lines.
type DefaultNodeClientFactory ¶ added in v0.6.318
type DefaultNodeClientFactory struct{}
DefaultNodeClientFactory creates real ConnectRPC clients.
func (DefaultNodeClientFactory) NewNodeClient ¶ added in v0.6.318
func (DefaultNodeClientFactory) NewNodeClient(provider externalnode.TokenProvider, baseURL string) nodev1connect.ExternalNodeServiceClient
type DeviceRegistration ¶ added in v0.6.318
type DeviceRegistration struct {
ExternalNodeID string `json:"external_node_id"`
DisplayName string `json:"display_name"`
OrgID string `json:"org_id"`
OrgName string `json:"org_name"`
DeviceID string `json:"device_id"`
RegisteredAt string `json:"registered_at"`
HardwareProfile HardwareProfile `json:"hardware_profile"`
}
DeviceRegistration is the persistent identity file for a registered device. Fields align with the AddNodeResponse from dev-plane.
type FileRegistrationStore ¶ added in v0.6.318
type FileRegistrationStore struct{}
FileRegistrationStore implements RegistrationStore using the global /etc/brev/ path.
func NewFileRegistrationStore ¶ added in v0.6.318
func NewFileRegistrationStore() *FileRegistrationStore
NewFileRegistrationStore returns a FileRegistrationStore that reads/writes from /etc/brev/device_registration.json.
func (*FileRegistrationStore) Delete ¶ added in v0.6.318
func (s *FileRegistrationStore) Delete() error
func (*FileRegistrationStore) Exists ¶ added in v0.6.318
func (s *FileRegistrationStore) Exists() (bool, error)
func (*FileRegistrationStore) Load ¶ added in v0.6.318
func (s *FileRegistrationStore) Load() (*DeviceRegistration, error)
Load reads the registration file and returns the parsed DeviceRegistration
func (*FileRegistrationStore) Save ¶ added in v0.6.318
func (s *FileRegistrationStore) Save(reg *DeviceRegistration) error
type GPU ¶ added in v0.6.318
type GPU struct {
Model string `json:"model"`
Architecture string `json:"architecture,omitempty"`
Count int32 `json:"count"`
MemoryBytes *int64 `json:"memory_bytes,omitempty"`
}
GPU describes a group of identical GPUs on the system.
type HardwareProfile ¶ added in v0.6.318
type HardwareProfile struct {
GPUs []GPU `json:"gpus"`
RAMBytes *int64 `json:"ram_bytes,omitempty"`
CPUCount *int32 `json:"cpu_count,omitempty"`
Architecture string `json:"architecture,omitempty"`
Storage []StorageDevice `json:"storage,omitempty"`
OS string `json:"os,omitempty"`
OSVersion string `json:"os_version,omitempty"`
ProductName string `json:"product_name,omitempty"`
Interconnects []Interconnect `json:"interconnects,omitempty"`
}
HardwareProfile is the full hardware snapshot collected by a HardwareProfiler.
type HardwareProfiler ¶ added in v0.6.318
type HardwareProfiler interface {
Profile() (*HardwareProfile, error)
}
HardwareProfiler abstracts system hardware detection so it can be replaced in tests and implemented per-platform via build tags.
type Interconnect ¶ added in v0.6.318
type Interconnect struct {
Type string `json:"type"`
Device string `json:"device"`
ActiveLinks int `json:"active_links,omitempty"`
Version uint32 `json:"version,omitempty"`
Generation int `json:"generation,omitempty"`
Width int `json:"width,omitempty"`
}
Interconnect describes a GPU interconnect (NVLink, PCIe, etc.).
type LinuxPlatform ¶ added in v0.6.318
type LinuxPlatform struct{}
LinuxPlatform reports compatibility based on whether the OS is Linux.
func (LinuxPlatform) IsCompatible ¶ added in v0.6.318
func (LinuxPlatform) IsCompatible() bool
type NetBirdManager ¶ added in v0.6.318
type NetBirdManager interface {
Install() error
Uninstall() error
// EnsureRunning checks whether the NetBird service is active and
// connected, starting or reconnecting it if needed. Returns nil when
// the tunnel is healthy.
EnsureRunning() error
}
NetBirdManager installs, uninstalls, and monitors the NetBird network agent.
type Netbird ¶ added in v0.6.318
type Netbird struct{}
Netbird handles NetBird installation and uninstallation.
func (Netbird) EnsureRunning ¶ added in v0.6.318
EnsureRunning checks if the netbird systemd service is active and attempts to start it if it is not. It also checks the netbird peer connection status and runs "netbird up" if the peer is disconnected.
type RegisterStore ¶ added in v0.6.318
type RegisterStore interface {
GetCurrentUser() (*entity.User, error)
GetActiveOrganizationOrDefault() (*entity.Organization, error)
GetOrganizationsByName(name string) ([]entity.Organization, error)
ListOrganizations() ([]entity.Organization, error)
GetAccessToken() (string, error)
}
RegisterStore defines the store methods needed by the register command.
type RegistrationStore ¶ added in v0.6.318
type RegistrationStore interface {
Save(reg *DeviceRegistration) error
Load() (*DeviceRegistration, error)
Delete() error
Exists() (bool, error)
}
RegistrationStore defines the contract for persisting device registration data.
type SetupRunner ¶ added in v0.6.318
SetupRunner runs a setup script on the local machine.
type ShellSetupRunner ¶ added in v0.6.318
type ShellSetupRunner struct{}
ShellSetupRunner runs setup scripts via shell.
func (ShellSetupRunner) RunSetup ¶ added in v0.6.318
func (ShellSetupRunner) RunSetup(script string) error
type StorageDevice ¶ added in v0.6.318
type StorageDevice struct {
Name string `json:"name,omitempty"`
StorageBytes int64 `json:"storage_bytes"`
StorageType string `json:"storage_type,omitempty"` // "SSD", "HDD", or "NVMe"
}
StorageDevice represents a single block storage device.
type SystemHardwareProfiler ¶ added in v0.6.318
type SystemHardwareProfiler struct{}
SystemHardwareProfiler probes hardware on Linux using NVML, sysfs, and procfs.
func (*SystemHardwareProfiler) Profile ¶ added in v0.6.318
func (p *SystemHardwareProfiler) Profile() (*HardwareProfile, error)
type TerminalPrompter ¶ added in v0.6.318
type TerminalPrompter struct{}
TerminalPrompter wraps terminal.PromptSelectInput for interactive prompts.
func (TerminalPrompter) ConfirmYesNo ¶ added in v0.6.318
func (TerminalPrompter) ConfirmYesNo(label string) bool