cmd

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingSSHAuth = errors.New("no SSH auth found")
)
View Source
var (
	ErrMissingUser = errors.New("no user found")
)

Functions

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func NewCmdAuth

func NewCmdAuth() *cobra.Command

func NewCmdAuthLogin

func NewCmdAuthLogin() *cobra.Command

func NewCmdAuthLogout

func NewCmdAuthLogout() *cobra.Command

func NewCmdAuthSignup

func NewCmdAuthSignup() *cobra.Command

func NewCmdAuthWhoAmI

func NewCmdAuthWhoAmI() *cobra.Command

func NewCmdOpen

func NewCmdOpen() *cobra.Command

func NewCmdRoot

func NewCmdRoot() *cobra.Command

func NewCmdRun

func NewCmdRun() *cobra.Command

func NewCmdServe

func NewCmdServe() *cobra.Command

func NewCmdServer

func NewCmdServer() *cobra.Command

func NewCmdUp

func NewCmdUp() *cobra.Command

func NewCmdUpgrade

func NewCmdUpgrade() *cobra.Command

func PublicKeySha

func PublicKeySha(key string) string

PublicKeySha returns the SHA for a public key in hex format.

Types

type Client

type Client struct {
	Config *ClientConfig
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *ClientConfig) (*Client, error)

func NewClientWithDefaults

func NewClientWithDefaults() (*Client, error)

NewClientWithDefaults creates a new Charm client with default values.

func (*Client) DataPath

func (cc *Client) DataPath() (string, error)

type ClientConfig

type ClientConfig struct {
	Host    string `env:"SMALLWEB_HOST" envDefault:"smallweb.run"`
	SSHPort int    `env:"SMALLWEB_SSH_PORT" envDefault:"2222"`
	Debug   bool   `env:"SMALLWEB_DEBUG" envDefault:"false"`
	KeyType string `env:"SMALLWEB_KEY_TYPE" envDefault:"ed25519"`
	DataDir string `env:"SMALLWEB_DATA_DIR" envDefault:""`
}

func ConfigFromEnv

func ConfigFromEnv() (*ClientConfig, error)

ConfigFromEnv loads the configuration from the environment.

func (*ClientConfig) KeygenType

func (cfg *ClientConfig) KeygenType() keygen.KeyType

KeygenType returns the keygen key type.

type DB

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

func NewTursoDB

func NewTursoDB(dbURL string) (*DB, error)

func (*DB) SetUserName

func (me *DB) SetUserName(publicID string, name string) (*User, error)

SetUserName sets a user name for the given user id.

func (*DB) UserForKey

func (me *DB) UserForKey(key string) (*User, error)

UserForKey returns the user for the given key, or optionally creates a new user with it.

func (*DB) UserFromContext

func (me *DB) UserFromContext(ctx ssh.Context) (*User, error)

func (*DB) WrapTransaction

func (me *DB) WrapTransaction(f func(tx *sql.Tx) error) error

WrapTransaction runs the given function within a transaction.

type Email

type Email struct {
	From    string `json:"from,omitempty"`
	To      string `json:"to,omitempty"`
	Cc      string `json:"cc,omitempty"`
	Bcc     string `json:"bcc,omitempty"`
	Subject string `json:"subject,omitempty"`
	Text    string `json:"text,omitempty"`
	Html    string `json:"html,omitempty"`
}

func (*Email) App

func (me *Email) App() (string, error)

func (*Email) Username

func (me *Email) Username() (string, error)

type EmailInput

type EmailInput struct {
	Type       string `json:"type"`
	Entrypoint string `json:"entrypoint"`
	Email      Email  `json:"email"`
}

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Stack   string `json:"stack"`
}

type FetchInput

type FetchInput struct {
	Type       string  `json:"type"`
	Entrypoint string  `json:"entrypoint"`
	Req        Request `json:"req"`
}

type Forwarder

type Forwarder struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Forwarder can be enabled by creating a Forwarder and adding the HandleSSHRequest callback to the server's RequestHandlers under tcpip-forward and cancel-tcpip-forward.

func (*Forwarder) Email

func (me *Forwarder) Email(email *Email) error

func (*Forwarder) Fetch

func (me *Forwarder) Fetch(req *Request) (*Response, error)

func (*Forwarder) HandleSSHRequest

func (me *Forwarder) HandleSSHRequest(ctx ssh.Context, srv *ssh.Server, req *gossh.Request) (bool, []byte)

func (*Forwarder) KeepAlive

func (me *Forwarder) KeepAlive()

type LoginParams

type LoginParams struct {
	Email string
}

type Message

type Message struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

type PublicKey

type PublicKey struct {
	ID        int        `json:"id"`
	UserID    int        `json:"user_id,omitempty"`
	Key       string     `json:"key"`
	CreatedAt *time.Time `json:"created_at"`
}

PublicKey represents to public SSH key for a Smallweb user.

type Request

type Request struct {
	Url     string     `json:"url"`
	Method  string     `json:"method"`
	Headers [][]string `json:"headers"`
	Body    []byte     `json:"body,omitempty"`
}

func (Request) App

func (r Request) App() (string, error)

func (Request) Username

func (r Request) Username() (string, error)

type Response

type Response struct {
	Code    int        `json:"code"`
	Headers [][]string `json:"headers"`
	Body    []byte     `json:"body"`
}

type ServerConfig

type ServerConfig struct {
	Host             string `env:"SMALLWEB_HOST" envDefault:"smallweb.run"`
	SSHPort          int    `env:"SMALLWEB_SSH_PORT" envDefault:"2222"`
	TursoDatabaseURL string `env:"TURSO_DATABASE_URL"`
	TursoAuthToken   string `env:"TURSO_AUTH_TOKEN"`
	ValTownToken     string `env:"VALTOWN_TOKEN"`
	Debug            bool   `env:"SMALLWEB_DEBUG" envDefault:"false"`
}

func ServerConfigFromEnv

func ServerConfigFromEnv() (*ServerConfig, error)

type SignupParams

type SignupParams struct {
	Email    string
	Username string
}

type User

type User struct {
	ID        int        `json:"id"`
	PublicID  string     `json:"public_id"`
	PublicKey *PublicKey `json:"public_key,omitempty"`
	Name      string     `json:"name"`
	Email     string     `json:"email"`
	CreatedAt *time.Time `json:"created_at"`
}

type UserResponse

type UserResponse struct {
	ID    string
	Name  string
	Email string
}

type ValTownClient added in v0.1.4

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

func NewValTownClient added in v0.1.4

func NewValTownClient(token string) *ValTownClient

func (*ValTownClient) SendEmail added in v0.1.4

func (me *ValTownClient) SendEmail(email Email) error

type VerifyEmailParams

type VerifyEmailParams struct {
	Code string
}

type Worker

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

func NewWorker

func NewWorker(alias string) (*Worker, error)

func (*Worker) Cmd

func (me *Worker) Cmd(args ...string) (*exec.Cmd, error)

func (*Worker) Email

func (me *Worker) Email(email *Email) (*Email, error)

func (*Worker) Fetch

func (me *Worker) Fetch(req *Request) (*Response, error)

func (*Worker) Run

func (me *Worker) Run(runArgs []string) error

type WorkerEntrypoints

type WorkerEntrypoints struct {
	Http  string
	Email string
	Cli   string
}

Jump to

Keyboard shortcuts

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