cilod

package
v0.0.0-...-50e3f6b Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCilodPort = 8080

DefaultCilodPort is the default port for cilod HTTP API

Variables

This section is empty.

Functions

func EnsureHostPrefix

func EnsureHostPrefix(host string) string

EnsureHostPrefix ensures the host has http:// or https:// prefix

func ResolveCilodHost

func ResolveCilodHost(host string) string

ResolveCilodHost resolves a cilod host to a full URL If host is just an IP or hostname without port, adds default port

Types

type AuthChallengeRequest

type AuthChallengeRequest struct {
	PublicKey string `json:"public_key"`
}

AuthChallengeRequest requests a new authentication challenge Client calls this before attempting authentication

type AuthChallengeResponse

type AuthChallengeResponse struct {
	Challenge string    `json:"challenge"`
	ExpiresAt time.Time `json:"expires_at"`
}

AuthChallengeResponse returns a challenge to be signed Client must sign this challenge with their SSH private key

type AuthConnectRequest

type AuthConnectRequest struct {
	Challenge string `json:"challenge"`
	Signature string `json:"signature"`
	// SignatureFormat is the ssh.Signature.Format returned by the signer.
	// For RSA keys this may be "rsa-sha2-256"/"rsa-sha2-512" rather than "ssh-rsa".
	SignatureFormat string `json:"signature_format,omitempty"`
	PublicKey       string `json:"public_key"`
}

AuthConnectRequest sends the signed challenge to authenticate

type AuthConnectResponse

type AuthConnectResponse struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
}

AuthConnectResponse returns the session token after successful auth

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the cilod API client for CLI-to-cilod communication

func NewClient

func NewClient(host string, token string) *Client

NewClient creates a new cilod client host can be a hostname (e.g., "cilod.example.com") or IP with port (e.g., "192.168.1.100:8080") token is the session token for authenticated requests (can be empty for unauthenticated calls)

func (*Client) Connect

func (c *Client) Connect(sshPrivateKeyPath string) (string, error)

Connect authenticates with the cilod server using SSH key challenge-response Returns a session token that must be used for subsequent requests

func (*Client) DestroyEnvironment

func (c *Client) DestroyEnvironment(name string) error

DestroyEnvironment permanently destroys an environment

func (*Client) DownEnvironment

func (c *Client) DownEnvironment(name string) error

DownEnvironment stops an environment

func (*Client) Exec

func (c *Client) Exec(name string, service string, cmd []string) error

Exec executes a command in a container This is a stub - full WebSocket implementation in Task 11

func (*Client) GetStatus

func (c *Client) GetStatus(name string) (*EnvironmentStatus, error)

GetStatus returns detailed status for an environment

func (*Client) ListEnvironments

func (c *Client) ListEnvironments() ([]Environment, error)

ListEnvironments returns all environments managed by this cilod

func (*Client) SetRetryPolicy

func (c *Client) SetRetryPolicy(maxRetries int, delay time.Duration)

SetRetryPolicy sets the retry policy for transient failures

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout sets the HTTP client timeout

func (*Client) SetToken

func (c *Client) SetToken(token string)

SetToken sets the authentication token for subsequent requests

func (*Client) StreamLogs

func (c *Client) StreamLogs(name string, service string) (io.ReadCloser, error)

StreamLogs returns a reader for streaming logs from a service The caller must close the returned ReadCloser when done

func (*Client) SyncWorkspace

func (c *Client) SyncWorkspace(name string, localPath string) error

SyncWorkspace syncs local workspace files to the cilod environment This is a stub - full rsync over SSH implementation later

func (*Client) UpEnvironment

func (c *Client) UpEnvironment(name string, opts UpOptions) error

func (*Client) UpEnvironmentWithResponse

func (c *Client) UpEnvironmentWithResponse(name string, opts UpOptions) (*EnvironmentUpResponse, error)

func (*Client) WireGuardExchange

func (c *Client) WireGuardExchange(publicKey string) (*WGConfig, error)

WireGuardExchange performs WireGuard key exchange with the cilod server

type Environment

type Environment struct {
	Name      string    `json:"name"`
	Status    string    `json:"status"` // running, stopped, error
	CreatedAt time.Time `json:"created_at"`
	Services  []string  `json:"services"`
	Subnet    string    `json:"subnet"`
}

Environment represents a cilod environment

type EnvironmentDestroyRequest

type EnvironmentDestroyRequest struct {
	Force bool `json:"force,omitempty"` // Skip confirmation
}

EnvironmentDestroyRequest destroys an environment permanently DELETE /environments/:name

type EnvironmentDestroyResponse

type EnvironmentDestroyResponse struct {
	Name   string `json:"name"`
	Status string `json:"status"`
}

EnvironmentDestroyResponse confirms environment is destroyed

type EnvironmentDownRequest

type EnvironmentDownRequest struct {
	Force bool `json:"force,omitempty"` // Force stop even if busy
}

EnvironmentDownRequest stops an environment POST /environments/:name/down

type EnvironmentDownResponse

type EnvironmentDownResponse struct {
	Name   string `json:"name"`
	Status string `json:"status"`
}

EnvironmentDownResponse confirms environment is stopped

type EnvironmentExecRequest

type EnvironmentExecRequest struct {
	Service string   `json:"service"`         // Target service/container
	Command []string `json:"command"`         // Command to execute
	TTY     bool     `json:"tty,omitempty"`   // Allocate pseudo-TTY
	Stdin   bool     `json:"stdin,omitempty"` // Attach stdin
}

EnvironmentExecRequest executes a command in a container POST /environments/:name/exec Upgrades to WebSocket for interactive sessions

type EnvironmentStatus

type EnvironmentStatus struct {
	Name       string          `json:"name"`
	Status     string          `json:"status"`
	Services   []ServiceStatus `json:"services"`
	Networks   []NetworkInfo   `json:"networks"`
	LastActive time.Time       `json:"last_active"`
}

EnvironmentStatus represents detailed environment status

type EnvironmentUpRequest

type EnvironmentUpRequest struct {
	WorkspacePath string   `json:"workspace_path,omitempty"` // Optional: override workspace
	Build         bool     `json:"build,omitempty"`          // Rebuild containers
	Recreate      bool     `json:"recreate,omitempty"`       // Force recreate
	Project       string   `json:"project,omitempty"`
	Shared        []string `json:"shared,omitempty"`
	Isolate       []string `json:"isolate,omitempty"`
}

EnvironmentUpRequest starts or creates an environment POST /environments/:name/up

type EnvironmentUpResponse

type EnvironmentUpResponse struct {
	Name     string            `json:"name"`
	Status   string            `json:"status"`
	Services map[string]string `json:"services"` // service name -> IP
	Subnet   string            `json:"subnet"`
}

EnvironmentUpResponse confirms environment is running

type ExecOptions

type ExecOptions struct {
	Service string
	Command []string
	TTY     bool
	Stdin   bool
}

ExecOptions provides options for remote exec

type FileSync

type FileSync struct {
	Path    string `json:"path"`     // Relative path in workspace
	Content []byte `json:"content"`  // File content (base64 encoded for JSON)
	Mode    uint32 `json:"mode"`     // File permissions
	ModTime int64  `json:"mod_time"` // Unix timestamp
	Hash    string `json:"hash"`     // SHA256 hash for verification
}

FileSync describes a single file to sync

type ListEnvironmentsResponse

type ListEnvironmentsResponse struct {
	Environments []Environment `json:"environments"`
}

ListEnvironmentsResponse contains all environments managed by this cilod

type LogOptions

type LogOptions struct {
	Service string
	Follow  bool
	Tail    int
}

LogOptions provides options for log streaming

type NetworkInfo

type NetworkInfo struct {
	Name    string `json:"name"`
	Subnet  string `json:"subnet"`
	Gateway string `json:"gateway"`
}

NetworkInfo describes a Docker network

type ServiceStatus

type ServiceStatus struct {
	Name   string `json:"name"`
	State  string `json:"state"`  // running, exited, etc.
	Status string `json:"status"` // Up 2 hours, Exited (0), etc.
	Health string `json:"health,omitempty"`
	IP     string `json:"ip,omitempty"`
}

ServiceStatus provides detailed service information

type Streamer

type Streamer struct {
	// contains filtered or unexported fields
}

Streamer provides WebSocket-based streaming for exec and logs

func NewStreamer

func NewStreamer(baseURL, token string) *Streamer

NewStreamer creates a new WebSocket streamer

func (*Streamer) SetTimeout

func (s *Streamer) SetTimeout(timeout time.Duration)

SetTimeout sets the WebSocket handshake timeout

func (*Streamer) StreamExec

func (s *Streamer) StreamExec(ctx context.Context, env, service string, cmd []string, stdin io.Reader, stdout, stderr io.Writer, tty bool) error

StreamExec executes a command in a container via WebSocket Supports bidirectional streaming (stdin/stdout/stderr) and PTY allocation

func (*Streamer) StreamLogs

func (s *Streamer) StreamLogs(ctx context.Context, env, service string, follow bool, stdout io.Writer) error

StreamLogs streams logs from a service via WebSocket Supports following logs with --follow flag

type UpOptions

type UpOptions struct {
	WorkspacePath string
	Build         bool
	Recreate      bool
	Project       string
	Shared        []string
	Isolate       []string
}

UpOptions provides options for creating/starting an environment

type WGConfig

type WGConfig struct {
	ServerPublicKey   string
	ServerEndpoint    string
	ServerAddress     string
	AssignedIP        string
	AllowedIPs        []string
	EnvironmentSubnet string
}

WGConfig is the client-side WireGuard configuration

type WebSocketMessage

type WebSocketMessage struct {
	Type     string `json:"type"`                // "stdout", "stderr", "stdin", "error", "exit", "signal", "eof"
	Data     []byte `json:"data"`                // Message payload
	ExitCode int    `json:"exit_code,omitempty"` // For exec exit
}

WebSocketMessage is the envelope for WebSocket communication

type WireGuardExchangeRequest

type WireGuardExchangeRequest struct {
	PublicKey     string `json:"public_key"`     // Client's WireGuard public key
	EnvironmentID string `json:"environment_id"` // Optional: env to connect to
	UserID        string `json:"user_id"`        // Optional: for multi-user tracking
}

WireGuardExchangeRequest initiates peer connection POST /wireguard/exchange

type WireGuardExchangeResponse

type WireGuardExchangeResponse struct {
	ServerPublicKey   string   `json:"server_public_key"` // cilod's WG public key
	ServerEndpoint    string   `json:"server_endpoint"`   // cilod's WG endpoint (IP:port)
	ServerAddress     string   `json:"server_address"`    // cilod's WG tunnel IP (for proxy/DNS)
	AssignedIP        string   `json:"assigned_ip"`       // IP assigned to client in WG subnet
	AllowedIPs        []string `json:"allowed_ips"`       // Routes through tunnel
	EnvironmentSubnet string   `json:"environment_subnet,omitempty"`
}

WireGuardExchangeResponse provides server details for client configuration Client uses this to configure their WireGuard interface

type WorkspaceSyncRequest

type WorkspaceSyncRequest struct {
	EnvironmentName string     `json:"environment_name"`       // URL param
	SyncType        string     `json:"sync_type"`              // "full" or "incremental"
	Files           []FileSync `json:"files"`                  // Files to sync
	DeletePaths     []string   `json:"delete_paths,omitempty"` // Paths to delete
}

WorkspaceSyncRequest receives workspace file sync POST /sync/:name Supports both full sync and incremental (rsync-style) updates

type WorkspaceSyncResponse

type WorkspaceSyncResponse struct {
	EnvironmentName string   `json:"environment_name"`
	FilesReceived   int      `json:"files_received"`
	FilesUpdated    int      `json:"files_updated"`
	FilesDeleted    int      `json:"files_deleted"`
	Errors          []string `json:"errors,omitempty"`
}

WorkspaceSyncResponse confirms sync completion

Jump to

Keyboard shortcuts

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