sidecar

package
v0.7.31 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMutuallyExclusiveKeys indicates both a key string and key file were provided.
	ErrMutuallyExclusiveKeys = errors.New("public key and public key file are mutually exclusive")
	// ErrPublicKeyRequired indicates neither a key string nor key file was provided.
	ErrPublicKeyRequired = errors.New("public key is required")
	// ErrPrivateKeyProvided indicates a private key was given where a public key was expected.
	ErrPrivateKeyProvided = errors.New("provided key is a private key")
	// ErrAuthSockNotSet indicates the SSH agent socket is not configured.
	ErrAuthSockNotSet = errors.New("ssh auth socket not set")
)

Functions

func AddSSHKey

func AddSSHKey(ctx context.Context, client *circleci.Client, sidecarID, publicKey, publicKeyFile string) (*circleci.AddSSHKeyResponse, error)

func ClearActive

func ClearActive() error

ClearActive removes the .chunk/sidecar.json file found by walking up from cwd.

func Create

func Create(ctx context.Context, client *circleci.Client, orgID, name, provider, image string) (*circleci.Sidecar, error)

func DefaultKeyPath

func DefaultKeyPath() (string, error)

DefaultKeyPath returns the default SSH private key path used by chunk.

func Exec

func Exec(ctx context.Context, client *circleci.Client, sidecarID, command string, args []string) (*circleci.ExecResponse, error)

func GenerateKeyPair

func GenerateKeyPair(path string) error

GenerateKeyPair generates an ed25519 keypair and writes the private key to path and the public key to path+".pub". The .ssh directory is created if it does not exist.

func InteractiveShell

func InteractiveShell(ctx context.Context, session *Session, envVars map[string]string) (err error)

InteractiveShell opens an interactive shell session to the sidecar with PTY. It intentionally uses os.Stdin/os.Stdout/os.Stderr directly rather than iostream.Streams: term.MakeRaw and term.GetSize require a real *os.File fd, and PTY I/O must be wired to the process's actual terminal.

func List

func List(ctx context.Context, client *circleci.Client, orgID string) ([]circleci.Sidecar, error)

func LoadEnvFileAt

func LoadEnvFileAt(path string) (_ map[string]string, err error)

LoadEnvFileAt reads the env file at path. Returns nil, nil if the file does not exist. Returns an error for permission or parse failures.

func MergeEnv

func MergeEnv(layers ...map[string]string) map[string]string

MergeEnv merges maps left to right; later layers win on duplicate keys.

func ParseEnvFile

func ParseEnvFile(r io.Reader) (map[string]string, error)

ParseEnvFile reads dotenv-format KEY=VALUE lines from r. Supports blank lines, # comments, optional "export " prefix, and optional single/double quoting of values. No variable interpolation.

func ParseEnvPairs

func ParseEnvPairs(pairs []string) (map[string]string, error)

ParseEnvPairs parses a slice of KEY=VALUE strings and returns a map. Returns an error if any entry does not contain "=".

func SSH

func SSH(ctx context.Context, client *circleci.Client, sidecarID, identityFile, authSock string, args []string, envVars map[string]string, io iostream.Streams) error

SSH opens a session and either runs a command or starts an interactive shell.

func SaveActive

func SaveActive(a ActiveSidecar) error

SaveActive writes .chunk/sidecar.json. If the file already exists in a parent directory it is updated in place; otherwise the file is created in cwd's .chunk/ directory.

func ShellEscape

func ShellEscape(arg string) string

ShellEscape escapes a string for safe use in a POSIX shell single-quoted context.

func ShellJoin

func ShellJoin(args []string) string

ShellJoin joins args into a shell command string with POSIX single-quote escaping.

func Sync

func Sync(ctx context.Context,
	client *circleci.Client, sidecarID, identityFile, authSock, workdir string, status iostream.StatusFunc) error

Sync synchronises local changes to a sidecar over SSH. It ensures the workspace base exists, clones the repo into workdir if absent, then resets to the remote base and applies a patch of local changes. workdir overrides the destination path; defaults to /workspace/<repo>.

Types

type ActiveSidecar

type ActiveSidecar struct {
	SidecarID string `json:"sidecar_id"`
	Name      string `json:"name,omitempty"`
	Workspace string `json:"workspace,omitempty"`
}

ActiveSidecar holds the currently active sidecar for a project.

func LoadActive

func LoadActive() (*ActiveSidecar, error)

LoadActive walks up from cwd looking for .chunk/sidecar.json. Returns nil if not found.

type ExecResult

type ExecResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

ExecResult holds the output of a command executed over SSH.

func ExecOverSSH

func ExecOverSSH(ctx context.Context, session *Session, command string, stdin io.Reader, envVars map[string]string) (_ *ExecResult, err error)

ExecOverSSH connects to the sidecar via SSH-over-TLS and executes a command.

type KeyNotFoundError

type KeyNotFoundError struct {
	Path string
}

KeyNotFoundError indicates the SSH private key file does not exist.

func (*KeyNotFoundError) Error

func (e *KeyNotFoundError) Error() string

type PublicKeyNotFoundError

type PublicKeyNotFoundError struct {
	KeyPath      string
	IdentityFile string
}

PublicKeyNotFoundError indicates the SSH public key file does not exist.

func (*PublicKeyNotFoundError) Error

func (e *PublicKeyNotFoundError) Error() string

type RemoteBaseError

type RemoteBaseError struct {
	Err error
}

RemoteBaseError indicates the remote merge base could not be resolved.

func (*RemoteBaseError) Error

func (e *RemoteBaseError) Error() string

func (*RemoteBaseError) Unwrap

func (e *RemoteBaseError) Unwrap() error

type Session

type Session struct {
	URL          string // WebSocket tunnel URL (ws:// or wss://)
	IdentityFile string // path to SSH private key (empty when using agent)
	KnownHosts   string // path to known_hosts file
	UseAgent     bool   // true when authenticating via ssh-agent
	AuthSock     string // SSH_AUTH_SOCK path (only used when UseAgent is true)
}

Session holds the info needed to SSH into a sidecar. It is a plain value type with no open connections or resources to close. Each call to ExecOverSSH opens and closes its own SSH connection.

func OpenSession

func OpenSession(ctx context.Context, client *circleci.Client, sidecarID, identityFile, authSock string) (*Session, error)

OpenSession registers an SSH key with the sidecar and returns session info. authSock is the SSH_AUTH_SOCK path; when non-empty and no identityFile is given, the agent is tried first.

Jump to

Keyboard shortcuts

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