From feee3e0c3f2e833981a49e9c533010650ec07e26 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Fri, 7 Feb 2020 08:08:57 -0800 Subject: [PATCH] Update documentation --- .gitlab-ci.yml | 21 +++++++++++++++++---- CHANGELOG | 3 +++ README.md | 15 ++++++++++++--- config.go | 8 ++++---- go.mod | 6 +++--- go.sum | 12 ++++++------ pkg/gate/portal.go | 26 +++++++++++++++++++------- 7 files changed, 64 insertions(+), 27 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e66f95d..221498a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,21 @@ +image: golang:latest + stages: - - test + - validate + - build + +fmt: + stage: validate + script: + - gofmt -l -s -e . + - exit $(gofmt -l -s -e . | wc -l) + +vet: + stage: validate + script: + - go vet -composites=false ./... test: - image: golang:latest - stage: test + stage: validate script: - - go test -v ./... + - go test -race -v ./... diff --git a/CHANGELOG b/CHANGELOG index 3a8782f..9c3f510 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +0.1.3: +- Update documentation + 0.1.2: - Pass stderr from command to local terminal diff --git a/README.md b/README.md index 9d48b43..e850f18 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,19 @@ # sshtargate -[![GoDoc](https://godoc.org/gitlab.com/tslocum/sshtargate?status.svg)](https://godoc.org/gitlab.com/tslocum/sshtargate) +[![GoDoc](https://gitlab.com/tslocum/godoc-static/-/raw/master/badge.svg)](https://docs.rocketnine.space/gitlab.com/tslocum/sshtargate/pkg/gate) [![CI status](https://gitlab.com/tslocum/sshtargate/badges/master/pipeline.svg)](https://gitlab.com/tslocum/sshtargate/commits/master) [![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space) Host SSH portals to applications +## Demo + +Connect to a sshtargate portal which executes the +[cview](https://gitlab.com/tslocum/cview) [presentation demo](https://gitlab.com/tslocum/cview/blob/master/demos/presentation/main.go): + +```bash +ssh cview.rocketnine.space -p 20000 +``` + ## Install Choose one of the following methods: @@ -15,7 +24,7 @@ Choose one of the following methods: ### Compile -``` +```bash go get gitlab.com/tslocum/sshtargate ``` @@ -25,4 +34,4 @@ See [CONFIGURATION.md](https://gitlab.com/tslocum/sshtargate/blob/master/CONFIGU ## Support -Please share issues/suggestions [here](https://gitlab.com/tslocum/sshtargate/issues). +Please share issues and suggestions [here](https://gitlab.com/tslocum/sshtargate/issues). diff --git a/config.go b/config.go index b72b4a0..4f3e90d 100644 --- a/config.go +++ b/config.go @@ -8,16 +8,16 @@ import ( "gopkg.in/yaml.v2" ) -type PortalConfig struct { +type portalConfig struct { Command string Host []string `yaml:",flow"` } -type Config struct { - Portals map[string]*PortalConfig +type appConfig struct { + Portals map[string]*portalConfig } -var config = &Config{} +var config = &appConfig{} func readConfig(configPath string) error { configData, err := ioutil.ReadFile(configPath) diff --git a/go.mod b/go.mod index c3f98db..1de69be 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/creack/pty v1.1.9 github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect github.com/gliderlabs/ssh v0.2.2 - golang.org/x/crypto v0.0.0-20200117160349-530e935923ad - golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 // indirect - gopkg.in/yaml.v2 v2.2.7 + golang.org/x/crypto v0.0.0-20200206161412-a0c6ece9d31a + golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect + gopkg.in/yaml.v2 v2.2.8 ) diff --git a/go.sum b/go.sum index 0932ad6..6be282b 100644 --- a/go.sum +++ b/go.sum @@ -7,15 +7,15 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= -golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200206161412-a0c6ece9d31a h1:aczoJ0HPNE92XKa7DrIzkNN6esOKO2TBwiiYoKcINhA= +golang.org/x/crypto v0.0.0-20200206161412-a0c6ece9d31a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= -gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkg/gate/portal.go b/pkg/gate/portal.go index 948c5f0..1c8e4f1 100644 --- a/pkg/gate/portal.go +++ b/pkg/gate/portal.go @@ -1,3 +1,4 @@ +// Package gate provides SSH portals to applications. package gate import ( @@ -19,10 +20,14 @@ import ( ) const ( + // ListenTimeout is the maximum time to start listening on an address. ListenTimeout = 1 * time.Second - IdleTimeout = 1 * time.Minute + + // IdleTimeout is the maximum time for a connection to be inactive. + IdleTimeout = 1 * time.Minute ) +// Portal is an SSH portal to an application. type Portal struct { Name string Address string @@ -30,11 +35,7 @@ type Portal struct { Server *ssh.Server } -func setWinsize(f *os.File, w, h int) { - syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ), - uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0}))) -} - +// NewPortal opens an SSH portal to an application. func NewPortal(name string, address string, command []string) (*Portal, error) { if address == "" { return nil, errors.New("no address supplied") @@ -137,6 +138,17 @@ func NewPortal(name string, address string, command []string) (*Portal, error) { return &p, nil } -func (p *Portal) Shutdown() { +// Close closes the portal immediately. +func (p *Portal) Close() { p.Server.Close() } + +// Shutdown closes the portal without interrupting active connections. +func (p *Portal) Shutdown() { + p.Server.Shutdown(context.Background()) +} + +func setWinsize(f *os.File, w, h int) { + syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ), + uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0}))) +}