Skip to content

Commit

Permalink
Fixed lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Boivie committed Sep 14, 2017
1 parent 4f2a5fe commit e6c902f
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 157 deletions.
50 changes: 25 additions & 25 deletions app/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ type Backend interface {
IsReady() bool
Connect() net.Conn
GetInfo() PathInfo
Subscribe(chan ProgressCmd)
Subscribe(chan progressCmd)
GetLogger() *logrus.Entry
}

type backendStruct struct {
id int
info PathInfo
log *logrus.Entry
subscribeProgress chan chan ProgressCmd
subscribeProgress chan chan progressCmd
getConn chan chan net.Conn
progress chan ProgressCmd
progress chan progressCmd
start chan bool
isReady bool
sshConfig *ssh.ClientConfig
Expand All @@ -53,7 +53,7 @@ func (b *backendStruct) Connect() net.Conn {
return <-reply
}

func (b *backendStruct) Subscribe(sub chan ProgressCmd) {
func (b *backendStruct) Subscribe(sub chan progressCmd) {
b.subscribeProgress <- sub
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func (b *backendStruct) isProvisioned() bool {

func (b *backendStruct) waitProvisioned() error {
if !b.isProvisioned() {
b.progress <- ProgressCmd{"wait_provisioning_start", nil}
b.progress <- progressCmd{"wait_provisioning_start", nil}
for {
newInfo := doLookup(b.info.Host, b.info.Prefix)
if newInfo == nil {
Expand All @@ -103,7 +103,7 @@ func (b *backendStruct) waitProvisioned() error {
time.Sleep(5 * time.Second)
}
b.log.Info("Provisioning completed")
b.progress <- ProgressCmd{"wait_provisioning_end", nil}
b.progress <- progressCmd{"wait_provisioning_end", nil}
}
return nil
}
Expand All @@ -118,7 +118,7 @@ func (b *backendStruct) failed(reason string, err error) {
}
}

func dialSSH(info *SSHTunnel, config *ssh.ClientConfig, proxyCommand string) (*ssh.Client, error) {
func dialSSH(info *configSSHTunnel, config *ssh.ClientConfig, proxyCommand string) (*ssh.Client, error) {
var conn net.Conn
var err error

Expand All @@ -139,40 +139,40 @@ func dialSSH(info *SSHTunnel, config *ssh.ClientConfig, proxyCommand string) (*s
}

func (b *backendStruct) connectSSH() (client *ssh.Client, err error) {
b.progress <- ProgressCmd{"connection_start", nil}
b.progress <- progressCmd{"connection_start", nil}
b.log.Info("Connecting to SSH server")
for retry := 0; retry < maxRetriesServer; retry++ {
b.progress <- ProgressCmd{"connection_try", nil}
b.progress <- progressCmd{"connection_try", nil}
client, err = dialSSH(b.info.SSHTunnel, b.sshConfig, proxyCommand)
if err == nil {
b.log.Infof("Connected to SSH server: %v, err %v", client, err)
go generateKeepalive(client)
b.progress <- ProgressCmd{"connection_established", nil}
b.progress <- progressCmd{"connection_established", nil}
return
}

b.log.Warnf("SSH Connection failed: %v - retrying", err)
b.progress <- ProgressCmd{"connection_retry", nil}
b.progress <- progressCmd{"connection_retry", nil}
time.Sleep(1 * time.Second)
}
b.log.Warnf("SSH Connection retry limit reached")
b.progress <- ProgressCmd{"connection_failed", "Connection retry limit reached"}
b.progress <- progressCmd{"connection_failed", "Connection retry limit reached"}
return nil, errors.New("SSH Connection retry limit reached")
}

func (b *backendStruct) reconnectSSH() (client *ssh.Client, err error) {
b.progress <- ProgressCmd{"reconnection_start", nil}
b.progress <- progressCmd{"reconnection_start", nil}
b.log.Info("Re-connecting to SSH server")
client, err = dialSSH(b.info.SSHTunnel, b.sshConfig, proxyCommand)
if err == nil {
b.log.Infof("Re-connected to SSH server: %v, err %v", client, err)
go generateKeepalive(client)
b.progress <- ProgressCmd{"reconnection_established", nil}
b.progress <- progressCmd{"reconnection_established", nil}
return
}

b.log.Warnf("SSH Re-connection failed. Assuming host is down.")
b.progress <- ProgressCmd{"reconnection_failed", "Re-connection failed"}
b.progress <- progressCmd{"reconnection_failed", "Re-connection failed"}
return nil, err
}

Expand All @@ -193,7 +193,7 @@ func (b *backendStruct) bootstrap(client *ssh.Client) (err error) {
for idx, cmd := range b.info.SSHTunnel.Bootstrap {
b.log.Infof("Started running bootstrap '%s'", cmd.Command)
status.Steps[idx].Status = "started"
b.progress <- ProgressCmd{"bootstrap_status", status}
b.progress <- progressCmd{"bootstrap_status", status}
if session, err = client.NewSession(); err != nil {
return
}
Expand All @@ -202,7 +202,7 @@ func (b *backendStruct) bootstrap(client *ssh.Client) (err error) {
session.Stderr = os.Stderr
session.Run(cmd.Command)
status.Steps[idx].Status = "done"
b.progress <- ProgressCmd{"bootstrap_status", status}
b.progress <- progressCmd{"bootstrap_status", status}
b.log.Infof("Finished running bootstrap '%s'", cmd.Command)
}

Expand Down Expand Up @@ -236,14 +236,14 @@ func (b *backendStruct) prepareSSH() (err error) {
if b.info.SSHTunnel.SSHKeyFileName != "" {
sshKey, err = ioutil.ReadFile(b.info.SSHTunnel.SSHKeyFileName)
if err != nil {
b.progress <- ProgressCmd{"connection_failed", "Failed to read SSH key"}
b.progress <- progressCmd{"connection_failed", "Failed to read SSH key"}
return
}
}

key, err := ssh.ParsePrivateKey(sshKey)
if err != nil {
b.progress <- ProgressCmd{"connection_failed", "Failed to parse SSH key"}
b.progress <- progressCmd{"connection_failed", "Failed to parse SSH key"}
return
}

Expand Down Expand Up @@ -288,14 +288,14 @@ func (b *backendStruct) connectionCreator(client *ssh.Client, onError chan error
}

func (b *backendStruct) waitBackend(client *ssh.Client) (err error) {
b.progress <- ProgressCmd{"waiting_backend", nil}
b.progress <- progressCmd{"waiting_backend", nil}
for retries := 0; retries < maxRetriesClient; retries++ {
b.log.Info("Waiting for backend to be ready...")
var conn net.Conn
if conn, err = client.Dial("tcp", b.info.Backend.Address); err == nil {
defer conn.Close()
b.log.Info("Backend is ready.")
b.progress <- ProgressCmd{"connection_success", nil}
b.progress <- progressCmd{"connection_success", nil}
return
} else if err == io.EOF {
b.log.Warnf("Disconnected from SSH server while connecting to %s: %v - re-connecting SSH", b.info.Backend.Address, err)
Expand All @@ -306,11 +306,11 @@ func (b *backendStruct) waitBackend(client *ssh.Client) (err error) {
}

b.log.Warnf("Backend not ready yet. (%v)", err)
b.progress <- ProgressCmd{"waiting_backend_retry", nil}
b.progress <- progressCmd{"waiting_backend_retry", nil}
time.Sleep(5 * time.Second)
}
b.log.Warn("Waiting backend retry limit reached. Aborting.")
b.progress <- ProgressCmd{"waiting_backend_timeout", "Connection retry limit reached"}
b.progress <- progressCmd{"waiting_backend_timeout", "Connection retry limit reached"}
err = errors.New("Backend retry limit reached")
return
}
Expand Down Expand Up @@ -383,9 +383,9 @@ func NewBackend(id int, info PathInfo) Backend {
id,
info,
log,
make(chan chan ProgressCmd),
make(chan chan progressCmd),
make(chan chan net.Conn, 1000),
make(chan ProgressCmd),
make(chan progressCmd),
make(chan bool),
false,
nil,
Expand Down
49 changes: 25 additions & 24 deletions app/config.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package app

type Command struct {
type configCommand struct {
Description string `json:"description"`
Command string `json:"command"`
}

type SSHTunnel struct {
type configSSHTunnel struct {
Address string `json:"address"`
Username string `json:"username"`
SSHKeyContents string `json:"ssh_key_contents"`
SSHKeyFileName string `json:"ssh_key_filename"`

Bootstrap []Command `json:"bootstrap"`
Run *Command `json:"run"`
Bootstrap []configCommand `json:"bootstrap"`
Run *configCommand `json:"run"`
}

type ConfigBackend struct {
type configBackend struct {
Address string `json:"address"`
BasePath string `json:"base_path"`
}

type Provisioning struct {
type configProvisioning struct {
// If this is 'started', undergang will periodically poll the /path endpoint every 5 seconds
// until it is 'done', 'failed' or the Provisioning field is missing.
Status string `json:"status"`
}

type BasicAuth struct {
type configBasicAuth struct {
Username string `json:"username"`
Password string `json:"password"`
}
Expand All @@ -36,34 +36,35 @@ type BasicAuth struct {
// redirected back to $original_url/__ug_auth?code=$code. UG will then do a HTTP POST to ValidateUrl
// with the code, and if correct, it will return 200 and UG will set a cookie limited to the domain
// and redirect the user back to $original_url.
type ServerAuth struct {
AuthUrl string `json:"auth_url"`
ValidateUrl string `json:"validate_url"`
type configServerAuth struct {
AuthURL string `json:"auth_url"`
ValidateURL string `json:"validate_url"`
}

type Style struct {
type configStyle struct {
BackgroundColor string `json:"background_color"`
}

type ProgressPage struct {
Style *Style `json:"style"`
Filename string `json:"filename"`
Url string `json:"url"`
Hostname string `json:"hostname"`
type configProgressPage struct {
Style *configStyle `json:"style"`
Filename string `json:"filename"`
URL string `json:"url"`
Hostname string `json:"hostname"`
}

// PathInfo represents the configuration of a backend
type PathInfo struct {
Host string `json:"host"`
Prefix string `json:"prefix"`
Provisioning *Provisioning `json:"provisioning"`
SSHTunnel *SSHTunnel `json:"ssh_tunnel"`
Host string `json:"host"`
Prefix string `json:"prefix"`
Provisioning *configProvisioning `json:"provisioning"`
SSHTunnel *configSSHTunnel `json:"ssh_tunnel"`

Backend *ConfigBackend `json:"backend"`
Backend *configBackend `json:"backend"`
StaticOverrides map[string]string `json:"static_overrides"`

ProgressPage *ProgressPage `json:"progress_page"`
ProgressPage *configProgressPage `json:"progress_page"`

BasicAuth *BasicAuth `json:"basic_auth"`
BasicAuth *configBasicAuth `json:"basic_auth"`

ServerAuth *ServerAuth `json:"server_auth"`
ServerAuth *configServerAuth `json:"server_auth"`
}
2 changes: 1 addition & 1 deletion app/external_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func doLookup(host string, path string) *PathInfo {
log.Logger = logrus.StandardLogger()

log.Info("Asking about pathinfo")
uri := externalLookupUrl + "?host=" + url.QueryEscape(host) + "&path=" + url.QueryEscape(path)
uri := externalLookupURL + "?host=" + url.QueryEscape(host) + "&path=" + url.QueryEscape(path)
req := goreq.Request{
Uri: uri,
Accept: "application/json",
Expand Down
2 changes: 1 addition & 1 deletion app/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func forward(w http.ResponseWriter, req *http.Request) {

var revProxy http.Handler
if isWebsocket(req) {
revProxy = &WebsocketReverseProxy{
revProxy = &websocketReverseProxy{
Backend: backend,
Director: director,
Dial: func(network, addr string) (net.Conn, error) {
Expand Down
9 changes: 5 additions & 4 deletions app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"runtime"
)

var externalLookupUrl string
var externalLookupURL string
var proxyCommand string

func dumpHandler(w http.ResponseWriter, req *http.Request) {
Expand All @@ -20,9 +20,10 @@ func healthHandler(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "OK\n")
}

func Init(externalPathLookupUrl_ string, accessLookupUrl string, proxyCommand_ string) {
proxyCommand = proxyCommand_
externalLookupUrl = externalPathLookupUrl_
// Init initializes the application
func Init(extPathLookupURL string, proxyCmd string) {
proxyCommand = proxyCmd
externalLookupURL = extPathLookupURL
go backendManager()

http.HandleFunc("/__ug__dump", dumpHandler)
Expand Down
Loading

0 comments on commit e6c902f

Please sign in to comment.