Update documentation

This commit is contained in:
Trevor Slocum 2020-02-07 08:08:57 -08:00
parent 466b499771
commit feee3e0c3f
7 changed files with 64 additions and 27 deletions

View File

@ -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 ./...

View File

@ -1,3 +1,6 @@
0.1.3:
- Update documentation
0.1.2:
- Pass stderr from command to local terminal

View File

@ -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).

View File

@ -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)

6
go.mod
View File

@ -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
)

12
go.sum
View File

@ -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=

View File

@ -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})))
}