summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2023-08-19 19:10:51 -0700
committerMike Crute <mike@crute.us>2023-08-19 22:17:50 -0700
commitd49a29a4015026a012a03a2ebb3f8f845decb2d4 (patch)
tree98bbe15f11e092184df7044fb99cd7921aebb5a6
parent7655a82ee0bff121aec08edcbaa3f799d34453b2 (diff)
downloadwebsocket_proxy-d49a29a4015026a012a03a2ebb3f8f845decb2d4.tar.bz2
websocket_proxy-d49a29a4015026a012a03a2ebb3f8f845decb2d4.tar.xz
websocket_proxy-d49a29a4015026a012a03a2ebb3f8f845decb2d4.zip
WIP upgrade
-rw-r--r--TODO.txt4
-rw-r--r--cmd/client/autoupdate.go28
-rw-r--r--cmd/client/client.go8
3 files changed, 38 insertions, 2 deletions
diff --git a/TODO.txt b/TODO.txt
index f0dba8d..e8b167f 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,3 +1,7 @@
1[ ] Add metrics 1[ ] Add metrics
2[ ] Log sessions to DB table 2[ ] Log sessions to DB table
3[ ] Email on new session (maybe?) 3[ ] Email on new session (maybe?)
4[ ] Automatically upgrade client
5[ ] Server driven session max TTL
6[ ] Rate limit tokens
7[ ] Rate limit CA
diff --git a/cmd/client/autoupdate.go b/cmd/client/autoupdate.go
new file mode 100644
index 0000000..feb272e
--- /dev/null
+++ b/cmd/client/autoupdate.go
@@ -0,0 +1,28 @@
1package client
2
3import (
4 "context"
5 "log"
6 "os"
7)
8
9// TODO:
10// Check the Server header from the host and if the second part does not match
11// - Use HEAD, ignore 404
12// Download the latest client for this os/arch (remap GOARCH=amd64 to x86_64)
13// Re-execute the client in the same process so the latest client is used
14// Log some output to let the user know this happened
15// Verify SHA256 based on server ETag
16func upgradeAndRestartClient(ctx context.Context, version, host string) error {
17 // Download, chmod, verify, unlink original, rename old to new, exec new
18 exec, err := os.Executable()
19 if err != nil {
20 return err
21 }
22
23 // Refuse if any path segment starts with go-build.*
24
25 log.Printf("Executable is %s", exec)
26
27 return nil
28}
diff --git a/cmd/client/client.go b/cmd/client/client.go
index b72003d..afc7a1d 100644
--- a/cmd/client/client.go
+++ b/cmd/client/client.go
@@ -37,7 +37,7 @@ func NewClientCommand(appVersion string) *cobra.Command {
37 Run: func(c *cobra.Command, args []string) { 37 Run: func(c *cobra.Command, args []string) {
38 cfg := app.Config{} 38 cfg := app.Config{}
39 cli.MustGetConfig(c, &cfg) 39 cli.MustGetConfig(c, &cfg)
40 clientMain(cfg, args[0], args[1], args[2]) 40 clientMain(cfg, appVersion, args[0], args[1], args[2])
41 }, 41 },
42 } 42 }
43 cli.AddFlags(clientCmd, &app.Config{}, app.DefaultConfig, "client") 43 cli.AddFlags(clientCmd, &app.Config{}, app.DefaultConfig, "client")
@@ -202,12 +202,16 @@ func fetchOauthToken(ctx context.Context, clientId, proxyHost string) (string, e
202 return tokenResponse.AccessToken, nil 202 return tokenResponse.AccessToken, nil
203} 203}
204 204
205func clientMain(cfg app.Config, host, port, username string) { 205func clientMain(cfg app.Config, appVersion, host, port, username string) {
206 log.SetOutput(os.Stderr) 206 log.SetOutput(os.Stderr)
207 207
208 ctx, cancel := context.WithCancel(context.Background()) 208 ctx, cancel := context.WithCancel(context.Background())
209 defer cancel() 209 defer cancel()
210 210
211 if err := upgradeAndRestartClient(ctx, appVersion, cfg.ClientHost); err != nil {
212 log.Fatalf("Error attempting to upgrade client: %s", err)
213 }
214
211 agentConn, err := connectToAgent() 215 agentConn, err := connectToAgent()
212 if err != nil { 216 if err != nil {
213 log.Fatalf("Error connecting to agent, is it started?") 217 log.Fatalf("Error connecting to agent, is it started?")