wishlist

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 32 Imported by: 2

README

Wishlist

Latest Release GoDoc Build Status

The SSH directory ✨

screencast

With Wishlist you can have a single entrypoint for multiple SSH endpoints, whether they are Wish apps or not.

As a server, it can be used to start multiple SSH apps within a single package and list them over SSH. You can list apps provided elsewhere, too.

You can also use the wishlist CLI to list and connect to servers in your ~/.ssh/config or a YAML config file.

Installation

Use your fave package manager:

# macOS or Linux
brew install charmbracelet/tap/wishlist

# Arch Linux (btw)
yay -S wishlist-bin (or wishlist)

# Windows (with Scoop)
scoop install wishlist

# Nix
nix-env -iA nixpkgs.wishlist

Or download a pre-compiled binary or package from the releases page.

Or just build it yourself (requires Go 1.18+):

git clone https://github.com/charmbracelet/wishlist.git
cd wishlist
go build ./cmd/wishlist/

Usage

CLI
Remote

If you just want a directory of existing servers, you can use the wishlist CLI and a YAML config file. You can also just run it without any arguments to list the servers in your ~/.ssh/config. To start wishlist in server mode, you'll need to use the serve subcommand:

wishlist serve

Check the example config file file as well as wishlist server --help for details.

Local

If you want to explore your ~/.ssh/config, you can run wishlist in local mode with:

wishlist

Note that not all options are supported at this moment. Check the commented example config for reference.

Library

Wishlist is also available as a library which allows you to start several apps within the same process. Check out the _example folder for a working example.

Auth

  • if ssh agent forwarding is available, it will be used
  • otherwise, each session will create a new ed25519 key and use it, in which case your app will be to allow access to any public key
  • password-based auth is not supported
Agent forwarding example
eval (ssh-agent)
ssh-add -k # adds all your pubkeys
ssh-add -l # should list the added keys

ssh \
  -o 'ForwardAgent=yes' \             # forwards the agent
  -o 'UserKnownHostsFile=/dev/null' \ # do not add to ~/.ssh/known_hosts, optional
  -p 2222 \                           # port
  foo.bar \                           # host
  -t list                             # optional, app name

You can also add this to your ~/.ssh/config, for instance:

Host wishlist
	HostName foo.bar
	Port 2222
	ForwardAgent yes
	UserKnownHostsFile /dev/null

Running it

Wishlist will read and store all its information in a .wishlist folder in the current working directory:

  • the server keys
  • the client keys
  • known hosts
  • config files

Config files may be provided in either YAML or SSH Config formats:

The config files are tried in the following order:

  • the -config flag in either YAML or SSH config formats
  • .wishlist/config.yaml
  • .wishlist/config.yml
  • $HOME/.ssh/config
  • /etc/ssh/ssh_config

The first one that is loaded and parsed without errors will be used. This means that if you have your common used hosts in your ~/.ssh/config, you can simply run wishlist and get it running right away. It also means that if you don't want that, you can pass a path to -config, and it can be either a YAML or a SSH config file.

Using the binary
wishlist
Using Docker
mkdir .wishlist
$EDITOR .wishlist/config.yaml # either an YAML or a SSH config
docker run \
  -p 2222:22 \
  -v $PWD/.wishlist:/.wishlist \
  docker.io/charmcli/wishlist:latest

Acknowledgments

The gif above shows a lot of Maas Lalani’s confeTTY.

Feedback

We'd love to hear your thoughts on this project. Feel free to drop us a note!

License

MIT


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source

Documentation

Overview

Package wishlist provides a library and binary to list and connect to SSH apps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(config *Config) error

Serve serves wishlist with the given config.

Types

type Config

type Config struct {
	Listen       string                              `yaml:"listen"`    // Address to listen on.
	Port         int64                               `yaml:"port"`      // Port to start the first server on.
	Endpoints    []*Endpoint                         `yaml:"endpoints"` // Endpoints to list.
	Factory      func(Endpoint) (*ssh.Server, error) `yaml:"-"`         // Factory used to create the SSH server for the given endpoint.
	Users        []User                              `yaml:"users"`     // Users allowed to access the list.
	EndpointChan chan []*Endpoint                    `yaml:"-"`         // Channel to update the endpoints. Used only in server mode.
	// contains filtered or unexported fields
}

Config represents the wishlist configuration.

type Endpoint

type Endpoint struct {
	Name          string            `yaml:"name"`           // Endpoint name.
	Address       string            `yaml:"address"`        // Endpoint address in the `host:port` format, if empty, will be the same address as the list, increasing the port number.
	User          string            `yaml:"user"`           // User to authenticate as.
	ForwardAgent  bool              `yaml:"forward_agent"`  // ForwardAgent defines wether to forward the current agent. Anologous to SSH's config ForwardAgent.
	RequestTTY    bool              `yaml:"request_tty"`    // RequestTTY defines wether to request a TTY. Anologous to SSH's config RequestTTY.
	RemoteCommand string            `yaml:"remote_command"` // RemoteCommand defines wether to request a TTY. Anologous to SSH's config RemoteCommand.
	IdentityFiles []string          `yaml:"-"`              // IdentityFiles is only set when parsing from a SSH Config file, and used only on local mode.
	Middlewares   []wish.Middleware `yaml:"-"`              // wish middlewares you can use in the factory method.
}

Endpoint represents an endpoint to list. If it has a Handler, wishlist will start an SSH server on the given address.

func (*Endpoint) Description

func (i *Endpoint) Description() string

Description to abide the list.Item interface.

func (*Endpoint) FilterValue

func (i *Endpoint) FilterValue() string

FilterValue to abide the list.Item interface.

func (Endpoint) ShouldListen

func (e Endpoint) ShouldListen() bool

ShouldListen returns true if we should start a server for this endpoint.

func (*Endpoint) String

func (e *Endpoint) String() string

String returns the endpoint in a friendly string format.

func (*Endpoint) Title

func (i *Endpoint) Title() string

Title to abide the list.Item interface.

func (Endpoint) Valid

func (e Endpoint) Valid() bool

Valid returns true if the endpoint is valid.

type ListModel added in v0.4.0

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

ListModel main wishlist model.

func NewListing added in v0.4.0

func NewListing(endpoints []*Endpoint, client SSHClient) *ListModel

NewListing creates a new listing model for the given endpoints and SSH session. If sessuion is nil, it is assume to be a local listing.

func (*ListModel) Init added in v0.4.0

func (m *ListModel) Init() tea.Cmd

Init comply with tea.Model interface.

func (*ListModel) SetItems added in v0.4.0

func (m *ListModel) SetItems(endpoints []*Endpoint) tea.Cmd

SetItems allows to update the listing items.

func (*ListModel) Update added in v0.4.0

func (m *ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update comply with tea.Model interface.

func (*ListModel) View added in v0.4.0

func (m *ListModel) View() string

View comply with tea.Model interface.

type SSHClient added in v0.2.0

type SSHClient interface {
	For(e *Endpoint) tea.ExecCommand
}

SSHClient is a SSH client.

func NewLocalSSHClient added in v0.2.0

func NewLocalSSHClient() SSHClient

NewLocalSSHClient returns a SSH Client for local usage.

type SetEndpointsMsg added in v0.5.0

type SetEndpointsMsg struct {
	Endpoints []*Endpoint
}

SetEndpointsMsg can be used to update the listed wishlist endpoints.

type User

type User struct {
	Name       string   `yaml:"name"`
	PublicKeys []string `yaml:"public-keys"`
}

User contains user-level configuration for a repository.

Directories

Path Synopsis
cmd
Package sshconfig can parse a SSH config file into a list of endpoints.
Package sshconfig can parse a SSH config file into a list of endpoints.

Jump to

Keyboard shortcuts

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