Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package cli implements the headmesh command-line tool.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAPIKey = errors.New("this command needs an API key: set HEADMESH_API_KEY")

ErrNoAPIKey is returned for commands that need HEADMESH_API_KEY when it is unset.

View Source
var ErrOtherTailnet = errors.New("this tailscaled is already connected to another tailnet")

ErrOtherTailnet means the target tailscaled is already on a different tailnet.

Functions

func NewRoot

func NewRoot(version string, deps Deps) *cobra.Command

NewRoot builds the command tree.

Types

type APIError

type APIError struct {
	Status int    `json:"status"`
	Title  string `json:"title"`
	Detail string `json:"detail"`
}

APIError is an RFC 9457 problem returned by the server.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL   string
	APIKey    string
	HTTP      *http.Client
	UserAgent string
}

Client is a small typed client for the Headmesh REST API.

func (*Client) CompleteEnrollment

func (c *Client) CompleteEnrollment(ctx context.Context, enrollmentID, secret string, nodeID uint64) (*Device, error)

CompleteEnrollment binds the registered node to the device.

func (*Client) CreateGrant

func (c *Client) CreateGrant(ctx context.Context, req map[string]any) (*Grant, error)

CreateGrant gives another org time-limited access to one device.

func (*Client) CreateInvite

func (c *Client) CreateInvite(ctx context.Context, roles []string, kind string, uses int, ttl time.Duration, ephemeral bool) (*InviteResponse, error)

CreateInvite creates an enrollment token.

func (*Client) Devices

func (c *Client) Devices(ctx context.Context) ([]Device, error)

Devices lists the org's devices.

func (*Client) Enroll

func (c *Client) Enroll(ctx context.Context, token, hostname, goos, arch string) (*EnrollResponse, error)

Enroll exchanges an enrollment token for a pre-auth key.

func (*Client) Grants

func (c *Client) Grants(ctx context.Context) ([]Grant, error)

Grants lists active grants.

func (*Client) RevokeGrant

func (c *Client) RevokeGrant(ctx context.Context, id string) (*Grant, error)

RevokeGrant revokes a grant.

type Deps

type Deps struct {
	Tailscale      Tailscale
	EnsureInstance func(ctx context.Context, inst Instance) error
	Hostname       func() (string, error)
	Getenv         func(string) string
}

Deps are the CLI's side effects, replaceable in tests.

type Device

type Device struct {
	ID        string   `json:"id"`
	ShortID   string   `json:"short_id"`
	Name      string   `json:"name"`
	GivenName string   `json:"given_name"`
	Kind      string   `json:"kind"`
	Roles     []string `json:"roles"`
	IPv4      string   `json:"ipv4,omitempty"`
	IPv6      string   `json:"ipv6,omitempty"`
	Online    bool     `json:"online"`
	State     string   `json:"state"`
}

Device mirrors the API's device.

type EnrollResponse

type EnrollResponse struct {
	EnrollmentID     string    `json:"enrollment_id"`
	DeviceID         string    `json:"device_id"`
	LoginServer      string    `json:"login_server"`
	AuthKey          string    `json:"auth_key"`
	Hostname         string    `json:"hostname"`
	Tags             []string  `json:"tags"`
	ExpiresAt        time.Time `json:"expires_at"`
	CompletionSecret string    `json:"completion_secret"`
}

EnrollResponse mirrors the API's enroll response.

type ExecTailscale

type ExecTailscale struct{ Binary string }

ExecTailscale shells out to the tailscale binary.

func (ExecTailscale) Run

func (e ExecTailscale) Run(ctx context.Context, inst Instance, args ...string) ([]byte, error)

Run implements Tailscale.

type Grant

type Grant struct {
	ID          string    `json:"id"`
	GranteeOrg  string    `json:"grantee_org,omitempty"`
	DstDeviceID string    `json:"dst_device_id"`
	Ports       []string  `json:"ports"`
	StartsAt    time.Time `json:"starts_at"`
	ExpiresAt   time.Time `json:"expires_at"`
	Revoked     bool      `json:"revoked"`
	ExternalRef string    `json:"external_ref,omitempty"`
	Enforced    bool      `json:"enforced"`
}

Grant mirrors the API's grant.

type Instance

type Instance struct {
	Name   string
	Socket string
}

Instance identifies which tailscaled to drive. The zero value is the system's default daemon; a named instance is a separate tailscaled (own state, socket, UDP port and TUN device) so a machine can join a Headmesh network while staying on another tailnet — the pattern Xcelsior's GPU hosts already use.

func NamedInstance

func NamedInstance(name string) (Instance, error)

NamedInstance returns the paths Headmesh uses for an isolated tailscaled.

func (Instance) Port

func (i Instance) Port() int

Port is the instance's WireGuard UDP port: stable per name, clear of the default 41641.

type InviteResponse

type InviteResponse struct {
	ID        string            `json:"id"`
	Token     string            `json:"token"`
	JoinURL   string            `json:"join_url"`
	Commands  map[string]string `json:"commands"`
	ExpiresAt time.Time         `json:"expires_at"`
}

InviteResponse mirrors the API's enrollment token response.

type Tailscale

type Tailscale interface {
	Run(ctx context.Context, inst Instance, args ...string) ([]byte, error)
}

Tailscale runs the tailscale CLI. Tests replace it.

Jump to

Keyboard shortcuts

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