Skip to content

Commit

Permalink
[BUG] Fix user being unable to delete their tunnel (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewScibek authored Jul 19, 2019
1 parent e9fd880 commit 7e74899
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
14 changes: 14 additions & 0 deletions Manual_testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Steps

1) punch login
2) punch setup
3) punch generate-key
4) punch reserve <testdomain>
5) punch http 4000
6) punch http 4000 <testdomain>
7) punch http 4000 <testdomain>
8) punch https 4001
9) punch tcp 2701
10) punch it http:4000 tcp:2701
11) punch it http:4000 tcp:2701 <testdomain>
12) punch release <testdomain>
2 changes: 1 addition & 1 deletion backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type Clock interface {

// Default values for ExponentialBackOff.
const (
DefaultInitialInterval = 1000 * time.Millisecond
DefaultInitialInterval = 250 * time.Millisecond
DefaultRandomizationFactor = 0.25
DefaultMultiplier = 1.5
DefaultMaxInterval = 7 * time.Second
Expand Down
12 changes: 10 additions & 2 deletions restapi/restclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"net/http"
)

var apiVersion = "2019.4.19.1"
var apiVersion = "2019.7.16.1"

//RestClient A stuct to hold persistent data that is used between rest calls
type RestClient struct {
URL string
RefreshToken string
APIKey string
Client http.Client
}

Expand All @@ -43,9 +44,16 @@ func NewRestClient(apiEndpoint string, refreshToken string) RestClient {
return restAPI
}

func (restClient *RestClient) SetRefreshToken(refreshToken string) {
rt := WithHeader(nil)
rt.Set("Authorization", "Bearer "+restClient.RefreshToken)
restClient.Client.Transport = rt
}

//SetAPIKey set api key header
func (restClient *RestClient) SetAPIKey(apiKey string) {
rt := WithHeader(restClient.Client.Transport)
restClient.APIKey = apiKey
rt := WithHeader(nil)
rt.Set("Authorization", "Bearer "+apiKey)
restClient.Client.Transport = rt
}
Expand Down
3 changes: 2 additions & 1 deletion tunnel/ssh_jump.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ func createTunnel(jumpConn *ssh.Client, tunnelConfig *Config, semaphore *Semapho
// Connect to SSH remote server using serverEndpoint
var serverConn net.Conn
for {
serverConn, err = jumpConn.Dial("tcp", serverEndpoint.String())
log.Debugf("Dial into SSHD Container %s", serverEndpoint.String())
serverConn, err = jumpConn.Dial("tcp", serverEndpoint.String())
if err == nil {
tunnelCreating.state = tunnelDone
break
}
log.Debugf("Dial into SSHD Container %s Failed: %s", serverEndpoint.String(), err.Error())
wait := exponentialBackoff.NextBackOff()
log.Debugf("Backoff Tick %s", wait.String())
time.Sleep(wait)
Expand Down
7 changes: 3 additions & 4 deletions tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ func StartReverseTunnel(tunnelConfig ...Config) {

func startReverseTunnel(jumpConn *ssh.Client, tunnelConfig *Config, wg *sync.WaitGroup, semaphore *Semaphore, tcpPort string) {
defer cleanup(tunnelConfig)

if wg != nil {
defer wg.Done()
}
defer wg.Done()
sClient, err := createTunnel(jumpConn, tunnelConfig, semaphore)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
Expand Down Expand Up @@ -132,7 +129,9 @@ func startReverseTunnel(jumpConn *ssh.Client, tunnelConfig *Config, wg *sync.Wai
}
func cleanup(config *Config) {
fmt.Println("\nClosing tunnel")
config.RestAPI.SetRefreshToken(config.RestAPI.RefreshToken)
errSession := config.RestAPI.StartSession(config.RestAPI.RefreshToken)
config.RestAPI.SetAPIKey(config.RestAPI.APIKey)
errDelete := config.RestAPI.DeleteTunnelAPI(config.Subdomain)
if errSession != nil || errDelete != nil {
fmt.Fprintf(os.Stderr,
Expand Down

0 comments on commit 7e74899

Please sign in to comment.