Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control sockets manager #152

Merged
merged 17 commits into from
Jul 8, 2016
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ GODIR ?= github.com/moul/advanced-ssh-config
PKG_BASE_DIR ?= ./pkg
CONVEY_PORT ?= 9042
SOURCES := $(shell find . -type f -name "*.go")
GOLIST := $(shell go list ./...)
COMMANDS := $(shell go list ./... | grep -v /vendor/ | grep /cmd/)
PACKAGES := $(shell go list ./... | grep -v /vendor/ | grep -v /cmd/)
REL_COMMANDS := $(subst $(GODIR),./,$(COMMANDS))
Expand All @@ -13,7 +14,6 @@ GO ?= $(GOENV) go
USER ?= $(shell whoami)



all: build


Expand Down
103 changes: 88 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,26 +307,38 @@ AUTHOR(S):
Manfred Touron <https://github.com/moul/advanced-ssh-config>

COMMANDS:
proxy Connect to host SSH socket, used by ProxyCommand
build Build .ssh/config
info Display system-wide information
list List all hosts from assh config
search Search entries by given search text
wrapper Initialize assh, then run ssh/scp/rsync...
config Manage ssh and assh configuration
sockets Manage control sockets
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--config, -c "~/.ssh/assh.yml" Location of config file [$ASSH_CONFIG]
--debug, -D Enable debug mode [$ASSH_DEBUG]
--verbose, -V Enable verbose mode
--help, -h show help
--generate-bash-completion
--version, -v print the version
--config value, -c value Location of config file (default: "~/.ssh/assh.yml") [$ASSH_CONFIG]
--debug, -D Enable debug mode [$ASSH_DEBUG]
--verbose, -V Enable verbose mode
--help, -h show help
--version, -v print the version
```

### Usage examples

##### `assh config build`

Rewrites and replaces the existing ~/.ssh/config file.

This action is automatically done by assh when detecting configuration changes.
Running this command manually is useful to setup assh.

```console
$ assh config build > ~/.ssh/config
```

##### `assh config list`

List hosts and options.

```console
$ assh list
$ assh config list
Listing entries

*.scw -> root@[hostname_not_specified]:22
Expand Down Expand Up @@ -370,13 +382,71 @@ Listing entries
User: bob
```

##### `assh config search <keyword>`

Search for `<keyword>` in hosts and host options.

```console
$ assh search bart
$ assh config search bart
Listing results for bart:
bart -> [email protected]:22
bart-access -> moul@[hostname_not_specified]:22
```

##### `assh info`

Display system-wide information.

```console
$ assh info
Debug mode (client): false
CLI Path: /path/to/assh
Go version: go1.6.2
OS/Arch: darwin/amd64

RC files:
- ~/.ssh/assh.yml
- ~/.ssh/assh.d/hosts.yml
- ~/.ssh/assh.d/moul.yml
- ~/.ssh/assh.d/test.yml

Statistics:
- 299 hosts
- 2 templates
- 4 included files
```

##### `assh sockets list`

List active control sockets.

```console
$ assh sockets list
4 active control sockets in "~/.ssh/cm/":

- bart/homer/lisa-22-root.sock (14 minutes)
- bart/homer-22-root.sock (14 minutes)
- bart-22-root.sock (14 minutes)
- marge-22-bart.sock (1 hour)
```

##### `assh sockets flush`

Close active control sockets.

```console
$ assh sockets flush
Closed 4 control sockets.
```

##### `assh sockets master`

Create a master control sockets.

```console
$ assh sockets master
```

## Install

Get the latest version using GO (recommended way):
Expand Down Expand Up @@ -428,16 +498,19 @@ With the wrapper, `ssh` will *always* be called with an updated `~/.ssh/config`

1. Backup your old `~/.ssh/config`: `cp ~/.ssh/config ~/.ssh/config.backup`
2. Create a new `~/.ssh/assh.yml` file
3. Run `assh build > ~/.ssh/config` to validate the syntax of your `~/.ssh/assh.yml` file and automatically build your `~/.ssh/config` file
3. Run `assh config build > ~/.ssh/config` to validate the syntax of your `~/.ssh/assh.yml` file and automatically build your `~/.ssh/config` file
4. You are ready!

## Changelog

### master (unreleased)

* Add a control socket manager `assh sockets {list,flush,master}` ([#152](https://github.com/moul/advanced-ssh-config/pull/152))
* Add a `assh --config=/path/to/assh.yml` option
* Add storm-like `assh list` and `assh search {keyword}` commands ([#151](https://github.com/moul/advanced-ssh-config/pull/151))
* Add storm-like `assh config list` and `assh config search {keyword}` commands ([#151](https://github.com/moul/advanced-ssh-config/pull/151))
* Add an optional `ASSHBinaryPath` variable in the `assh.yml` file ([#148](https://github.com/moul/advanced-ssh-config/issues/148))
* Rename `assh proxy -> assh connect`
* Hide `assh connect` and `assh wrapper` from the help

[Full commits list](https://github.com/moul/advanced-ssh-config/compare/v2.3.0...master)

Expand Down
2 changes: 1 addition & 1 deletion cmd/assh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func BashComplete(c *cli.Context) {
for _, option := range []string{"--debug", "--verbose", "--help", "--version"} {
fmt.Println(option)
}
for _, command := range []string{"proxy", "build", "info", "help"} {
for _, command := range []string{"connect", "config", "info", "sockets", "help"} {
fmt.Println(command)
}
}
Expand Down
12 changes: 8 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ import:
- package: golang.org/x/crypto
subpackages:
- ssh/terminal
- package: github.com/mattn/go-zglob
- package: github.com/docker/go-units
4 changes: 3 additions & 1 deletion pkg/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
. "github.com/moul/advanced-ssh-config/pkg/logger"
)

func cmdBuild(c *cli.Context) {
func cmdBuild(c *cli.Context) error {
conf, err := config.Open(c.GlobalString("config"))
if err != nil {
Logger.Fatalf("Cannot open configuration file: %v", err)
}

conf.WriteSSHConfigTo(os.Stdout)

return nil
}
57 changes: 43 additions & 14 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ func init() {
// Commands is the list of cli commands
var Commands = []cli.Command{
{
Name: "proxy",
Name: "connect",
Usage: "Connect to host SSH socket, used by ProxyCommand",
Description: "Argument is a host.",
Action: cmdProxy,
Hidden: true,
Flags: []cli.Flag{
cli.IntFlag{
Name: "port, p",
Expand Down Expand Up @@ -48,11 +49,6 @@ var Commands = []cli.Command{
Action: cmdInit,
},
*/
{
Name: "build",
Usage: "Build .ssh/config",
Action: cmdBuild,
},
/*
{
Name: "etc-hosts",
Expand All @@ -67,19 +63,52 @@ var Commands = []cli.Command{
Action: cmdInfo,
},
{
Name: "list",
Usage: "List all hosts from assh config",
Action: cmdList,
Name: "config",
Usage: "Manage ssh and assh configuration",
Subcommands: []cli.Command{
{
Name: "build",
Usage: "Build .ssh/config",
Action: cmdBuild,
},
{
Name: "list",
Usage: "List all hosts from assh config",
Action: cmdList,
},
{
Name: "search",
Usage: "Search entries by given search text",
Action: cmdSearch,
},
},
},
{
Name: "search",
Usage: "Search entries by given search text",
Action: cmdSearch,
Name: "sockets",
Usage: "Manage control sockets",
Subcommands: []cli.Command{
{
Name: "list",
Action: cmdCsList,
Usage: "List active control sockets",
},
{
Name: "flush",
Action: cmdCsFlush,
Usage: "Close control sockets",
},
{
Name: "master",
Action: cmdCsMaster,
Usage: "Open a master control socket",
},
},
},
// FIXME: tree
{
Name: "wrapper",
Usage: "Initialize assh, then run ssh/scp/rsync...",
Name: "wrapper",
Usage: "Initialize assh, then run ssh/scp/rsync...",
Hidden: true,
Subcommands: []cli.Command{
{
Name: "ssh",
Expand Down
Loading