repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
bd272f7
parent
8d29755
author
Eric Bower
date
2024-02-18 15:20:48 +0000 UTC
chore: use slog wish middleware logger
5 files changed,  +52, -8
M feeds/ssh.go
+2, -2
 1@@ -12,11 +12,11 @@ import (
 2 	"github.com/charmbracelet/ssh"
 3 	"github.com/charmbracelet/wish"
 4 	bm "github.com/charmbracelet/wish/bubbletea"
 5-	lm "github.com/charmbracelet/wish/logging"
 6 	"github.com/picosh/pico/db/postgres"
 7 	"github.com/picosh/pico/filehandlers"
 8 	"github.com/picosh/pico/shared"
 9 	"github.com/picosh/pico/shared/storage"
10+	wsh "github.com/picosh/pico/wish"
11 	"github.com/picosh/pico/wish/cms"
12 	"github.com/picosh/send/list"
13 	"github.com/picosh/send/pipe"
14@@ -42,7 +42,7 @@ func createRouter(handler *filehandlers.FileHandlerRouter) proxy.Router {
15 			wishrsync.Middleware(handler),
16 			auth.Middleware(handler),
17 			bm.Middleware(cms.Middleware(&handler.Cfg.ConfigCms, handler.Cfg)),
18-			lm.Middleware(),
19+			wsh.LogMiddleware(handler.GetLogger()),
20 		}
21 	}
22 }
M pastes/ssh.go
+2, -2
 1@@ -12,11 +12,11 @@ import (
 2 	"github.com/charmbracelet/ssh"
 3 	"github.com/charmbracelet/wish"
 4 	bm "github.com/charmbracelet/wish/bubbletea"
 5-	lm "github.com/charmbracelet/wish/logging"
 6 	"github.com/picosh/pico/db/postgres"
 7 	"github.com/picosh/pico/filehandlers"
 8 	"github.com/picosh/pico/shared"
 9 	"github.com/picosh/pico/shared/storage"
10+	wsh "github.com/picosh/pico/wish"
11 	"github.com/picosh/pico/wish/cms"
12 	"github.com/picosh/send/list"
13 	"github.com/picosh/send/pipe"
14@@ -42,7 +42,7 @@ func createRouter(handler *filehandlers.FileHandlerRouter) proxy.Router {
15 			wishrsync.Middleware(handler),
16 			auth.Middleware(handler),
17 			bm.Middleware(cms.Middleware(&handler.Cfg.ConfigCms, handler.Cfg)),
18-			lm.Middleware(),
19+			wsh.LogMiddleware(handler.GetLogger()),
20 		}
21 	}
22 }
M pgs/ssh.go
+2, -2
 1@@ -12,11 +12,11 @@ import (
 2 	"github.com/charmbracelet/ssh"
 3 	"github.com/charmbracelet/wish"
 4 	bm "github.com/charmbracelet/wish/bubbletea"
 5-	lm "github.com/charmbracelet/wish/logging"
 6 	"github.com/picosh/pico/db/postgres"
 7 	uploadassets "github.com/picosh/pico/filehandlers/assets"
 8 	"github.com/picosh/pico/shared"
 9 	"github.com/picosh/pico/shared/storage"
10+	wsh "github.com/picosh/pico/wish"
11 	"github.com/picosh/send/list"
12 	"github.com/picosh/send/pipe"
13 	"github.com/picosh/send/proxy"
14@@ -42,7 +42,7 @@ func createRouter(cfg *shared.ConfigSite, handler *uploadassets.UploadAssetHandl
15 			wishrsync.Middleware(handler),
16 			auth.Middleware(handler),
17 			bm.Middleware(CmsMiddleware(&cfg.ConfigCms, cfg)),
18-			lm.Middleware(),
19+			wsh.LogMiddleware(handler.GetLogger()),
20 		}
21 	}
22 }
M prose/ssh.go
+2, -2
 1@@ -12,12 +12,12 @@ import (
 2 	"github.com/charmbracelet/ssh"
 3 	"github.com/charmbracelet/wish"
 4 	bm "github.com/charmbracelet/wish/bubbletea"
 5-	lm "github.com/charmbracelet/wish/logging"
 6 	"github.com/picosh/pico/db/postgres"
 7 	"github.com/picosh/pico/filehandlers"
 8 	uploadimgs "github.com/picosh/pico/filehandlers/imgs"
 9 	"github.com/picosh/pico/shared"
10 	"github.com/picosh/pico/shared/storage"
11+	wsh "github.com/picosh/pico/wish"
12 	"github.com/picosh/pico/wish/cms"
13 	"github.com/picosh/send/list"
14 	"github.com/picosh/send/pipe"
15@@ -43,7 +43,7 @@ func createRouter(handler *filehandlers.FileHandlerRouter) proxy.Router {
16 			wishrsync.Middleware(handler),
17 			auth.Middleware(handler),
18 			bm.Middleware(cms.Middleware(&handler.Cfg.ConfigCms, handler.Cfg)),
19-			lm.Middleware(),
20+			wsh.LogMiddleware(handler.GetLogger()),
21 		}
22 	}
23 }
A wish/logger.go
+44, -0
 1@@ -0,0 +1,44 @@
 2+package wish
 3+
 4+import (
 5+	"log/slog"
 6+	"time"
 7+
 8+	"github.com/charmbracelet/ssh"
 9+	"github.com/charmbracelet/wish"
10+)
11+
12+func LogMiddleware(logger *slog.Logger) wish.Middleware {
13+	return func(sh ssh.Handler) ssh.Handler {
14+		return func(s ssh.Session) {
15+			ct := time.Now()
16+			pty, _, ok := s.Pty()
17+
18+			logger.Info(
19+				"connect",
20+				"user",
21+				s.User(),
22+				"ip",
23+				s.RemoteAddr().String(),
24+				"pty",
25+				ok,
26+				"term",
27+				pty.Term,
28+				"windowWidth",
29+				pty.Window.Width,
30+				"windowHeight",
31+				pty.Window.Height,
32+			)
33+
34+			sh(s)
35+
36+			logger.Info(
37+				"disconnect",
38+				"ip",
39+				s.RemoteAddr().String(),
40+				"duration",
41+				time.Since(ct),
42+			)
43+		}
44+	}
45+}