connections

package
v0.2.0-rc.2 Latest Latest
Warning

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

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

Documentation

Overview

Package connections stores explicitly named dispatcher connections for local commands. Saved profiles are not a global dispatcher discovery service.

Index

Constants

View Source
const CredentialFileMode fs.FileMode = 0600

CredentialFileMode is the permission the credential file is written with and required to have; one readable by anyone else is refused rather than used.

View Source
const CredentialFileName = "credentials.json"

CredentialFileName is the credential file, beside the connections file.

Variables

View Source
var ErrCredentialEndpointMismatch = errors.New("stored credential belongs to another dispatcher endpoint")

ErrCredentialEndpointMismatch means a saved session belongs to a different endpoint than the profile now selects. Callers may forget it locally, but must never present it to the newly selected endpoint.

Functions

func CredentialPath

func CredentialPath(path string) (string, error)

CredentialPath returns the credential file beside the given connections file, or beside the default one when path is empty.

func DefaultPath

func DefaultPath() (string, error)

func Remove

func Remove(path, name string) error

func RemoveCredential

func RemoveCredential(path, name string) error

RemoveCredential forgets the credential of one profile. Forgetting one that is not there is the state the caller asked for, not an error.

func Save

func Save(path string, profile Profile, selectCurrent bool) error

Save replaces a named profile chosen by the operator and selects it when requested, or when there is no current connection yet.

func SaveCredential

func SaveCredential(path, name string, credential Credential) error

SaveCredential records the credential of one profile, replacing its own.

func Select

func Select(path, name string) error

func ValidateName

func ValidateName(name string) error

Types

type Config

type Config struct {
	SchemaVersion int       `json:"schema_version"`
	Current       string    `json:"current"`
	Dispatchers   []Profile `json:"dispatchers"`
}

func Load

func Load(path string) (Config, error)

Load returns an empty schema-1 configuration when the file does not exist.

type Credential

type Credential struct {
	Endpoint  string `json:"endpoint"`
	Token     string `json:"token"`
	ExpiresAt int64  `json:"expires_at,omitempty"`
}

Credential is what one CLI profile presents to one dispatcher. Endpoint records which dispatcher issued it, so it can never be sent to another one. Only the session is kept, so a copy of this file yields one expiring session rather than permanent access to the account.

func CredentialFor

func CredentialFor(path, name, endpoint string) (Credential, error)

CredentialFor returns the credential to present at endpoint for one saved connection. One recorded for a different endpoint is refused rather than sent, so selecting another profile can never deliver one dispatcher's credential to another origin; a connection with none stored yields an empty credential, because unauthenticated requests still reach a dispatcher serving the local development profile. An empty name is an endpoint the operator named directly, so nothing is looked up and the client configuration directory is not even located: commands that need no saved connection keep working where there is no such directory.

type CredentialStore

type CredentialStore struct {
	SchemaVersion int                   `json:"schema_version"`
	Credentials   map[string]Credential `json:"credentials"`
}

CredentialStore is the on-disk credential file.

func LoadCredentials

func LoadCredentials(path string) (CredentialStore, error)

LoadCredentials reads the credential file. An absent file is an empty store; one other users can read is refused rather than used.

type Profile

type Profile struct {
	Name         string `json:"name"`
	Endpoint     string `json:"endpoint"`
	GRPCAddress  string `json:"grpc_address"`
	YamuxAddress string `json:"yamux_address"`
}

func Discover

func Discover(ctx context.Context, endpoint string) (Profile, error)

Discover validates the server's announced local control listeners without reading or changing saved profiles. The caller chooses the profile name.

func Resolve

func Resolve(path, name string) (Profile, error)

Jump to

Keyboard shortcuts

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