Skip to content

Commit 0e2dd46

Browse files
committed
Bumped v0.5.1
Signed-off-by: Vishal Rana <[email protected]>
1 parent 176d8bb commit 0e2dd46

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE = labstack/tunnel
2-
VERSION = 0.5.0
2+
VERSION = 0.5.1
33

44
publish:
55
git tag v$(VERSION)
@@ -8,6 +8,5 @@ publish:
88
docker build -t $(IMAGE):$(VERSION) -t $(IMAGE) .
99
docker push $(IMAGE):$(VERSION)
1010
docker push $(IMAGE):latest
11-
rm tunnel
1211

1312
.PHONY: publish

daemon/connection.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"fmt"
66
"github.com/labstack/gommon/log"
7+
"github.com/pkg/errors"
78
"github.com/spf13/viper"
89
"io"
910
"net"
@@ -33,7 +34,9 @@ type (
3334
stopChan chan bool
3435
errorChan chan error
3536
retries time.Duration
37+
ID string `json:"id"`
3638
Name string `json:"name"`
39+
Random bool `json:"random"`
3740
User string
3841
Host string
3942
TargetAddress string `json:"target_address"`
@@ -100,7 +103,7 @@ func (s *Server) newConnection(req *ConnectRequest) (c *Connection, err error) {
100103
if c.Configuration.Protocol != ProtocolHTTPS {
101104
c.RemotePort = 0
102105
}
103-
if err = c.create(); err != nil {
106+
if err = c.save(); err != nil {
104107
return
105108
}
106109
c.User += ",name=" + c.Name
@@ -285,36 +288,49 @@ func (c *Connection) stop() {
285288
}
286289
}
287290

291+
func (c *Connection) save() error {
292+
if c.ID == "" {
293+
return c.create()
294+
}
295+
return c.update()
296+
}
297+
288298
func (c *Connection) create() error {
289299
e := new(Error)
290-
_, err := c.server.resty.R().
300+
res, err := c.server.resty.R().
291301
SetBody(c).
292302
SetResult(c).
293303
SetError(e).
294304
Post("/connections")
295-
return err
305+
if err != nil {
306+
return err
307+
} else if res.IsError() {
308+
return errors.Errorf("failed to create a connection: error=%s", e.Message)
309+
}
310+
return nil
296311
}
297312

298-
func (c *Connection) update() {
313+
func (c *Connection) update() error {
299314
e := new(Error)
300315
res, err := c.server.resty.R().
301316
SetBody(c).
302317
SetResult(c).
303318
SetError(e).
304-
Put("/connections/" + c.Name)
319+
Put("/connections/" + c.ID)
305320
if err != nil {
306-
log.Error(err)
321+
return err
307322
} else if res.IsError() {
308-
log.Errorf("failed to update the connection: name=%s, error=%s", c.Name, e.Message)
323+
return errors.Errorf("failed to update the connection: name=%s, error=%s", c.Name, e.Message)
309324
}
325+
return nil
310326
}
311327

312328
func (c *Connection) delete() error {
313329
log.Warnf("removing connection %s", c.Name)
314330
e := new(Error)
315331
res, err := c.server.resty.R().
316332
SetError(e).
317-
Delete("/connections/" + c.Name)
333+
Delete("/connections/" + c.ID)
318334
if err != nil {
319335
return err
320336
} else if res.IsError() {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/mattn/go-runewidth v0.0.5 // indirect
1313
github.com/mitchellh/go-homedir v1.1.0
1414
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b
15+
github.com/pkg/errors v0.8.0
1516
github.com/spf13/cobra v0.0.5
1617
github.com/spf13/viper v1.5.0
1718
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
9898
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
9999
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
100100
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
101+
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
101102
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
102103
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
103104
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

0 commit comments

Comments
 (0)