pico / feat(pgs): tunnel default to requester username if no username provided #17

open · opened on 2024-08-19T13:48:20Z by erock
Help
# add changes to patch request
git format-patch main --stdout | ssh pr.pico.sh pr add 17
# add review to patch request
git format-patch main --stdout | ssh pr.pico.sh pr add --review 17
# remove patchset
ssh pr.pico.sh ps rm ps-x
# checkout all patches
ssh pr.pico.sh pr print 17 | git am -3
# print a diff between the last two patches in a patch request
ssh pr.pico.sh pr diff 17
# accept PR
ssh pr.pico.sh pr accept 17
# close PR
ssh pr.pico.sh pr close 17

Logs

erock created pr with ps-33 on 2024-08-19T13:48:20Z

Patchsets

Diff ↕
 pgs/api.go    |  3 +++
 pgs/tunnel.go | 19 ++++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)
 1From 259da7a5f62e987bd40b1e84255c5e44472c14ad Mon Sep 17 00:00:00 2001
 2From: Eric Bower <me@erock.io>
 3Date: Mon, 19 Aug 2024 09:47:46 -0400
 4Subject: [PATCH] feat(pgs): tunnel default to requester username if no
 5 username provided
 6
 7---
 8 pgs/api.go    |  3 +++
 9 pgs/tunnel.go | 19 ++++++++++++-------
10 2 files changed, 15 insertions(+), 7 deletions(-)
11
12diff --git a/pgs/api.go b/pgs/api.go
13index f73c5eb..d3c39df 100644
14--- a/pgs/api.go
15+++ b/pgs/api.go
16@@ -372,6 +372,9 @@ func ServeAsset(fname string, opts *storage.ImgProcessOpts, fromImgs bool, hasPe
17 	st := shared.GetStorage(r)
18 	logger := shared.GetLogger(r)
19 
20+	fmt.Println("===")
21+	fmt.Println(subdomain)
22+	fmt.Println("===")
23 	props, err := getProjectFromSubdomain(subdomain)
24 	if err != nil {
25 		logger.Info(err.Error(), "subdomain", subdomain, "filename", fname)
26diff --git a/pgs/tunnel.go b/pgs/tunnel.go
27index e9bf24a..694fa5a 100644
28--- a/pgs/tunnel.go
29+++ b/pgs/tunnel.go
30@@ -57,6 +57,18 @@ func createHttpHandler(apiConfig *shared.ApiConfig) CtxHttpBridge {
31 			return http.HandlerFunc(shared.UnauthorizedHandler)
32 		}
33 
34+		requester, _ := dbh.FindUserForKey("", pubkeyStr)
35+		if requester != nil {
36+			log = log.With(
37+				"requester", requester.Name,
38+			)
39+		}
40+
41+		// assume no username provided
42+		if props.Username == props.ProjectName {
43+			props.Username = requester.Name
44+		}
45+
46 		owner, err := dbh.FindUserForName(props.Username)
47 		if err != nil {
48 			log.Error(err.Error())
49@@ -72,13 +84,6 @@ func createHttpHandler(apiConfig *shared.ApiConfig) CtxHttpBridge {
50 			return http.HandlerFunc(shared.UnauthorizedHandler)
51 		}
52 
53-		requester, _ := dbh.FindUserForKey("", pubkeyStr)
54-		if requester != nil {
55-			log = log.With(
56-				"requester", requester.Name,
57-			)
58-		}
59-
60 		// impersonation logic
61 		if asUser != "" {
62 			isAdmin := dbh.HasFeatureForUser(requester.ID, "admin")
63-- 
642.45.2
65
ps-33 by erock on 2024-08-19T13:48:20Z

feat(pgs): tunnel default to requester username if no username provided

Eric Bower <me@erock.io> 2024-08-19T13:47:46Z
 pgs/api.go    |  3 +++
 pgs/tunnel.go | 19 ++++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)
 1From 259da7a5f62e987bd40b1e84255c5e44472c14ad Mon Sep 17 00:00:00 2001
 2From: Eric Bower <me@erock.io>
 3Date: Mon, 19 Aug 2024 09:47:46 -0400
 4Subject: [PATCH] feat(pgs): tunnel default to requester username if no
 5 username provided
 6
 7---
 8 pgs/api.go    |  3 +++
 9 pgs/tunnel.go | 19 ++++++++++++-------
10 2 files changed, 15 insertions(+), 7 deletions(-)
11
12diff --git a/pgs/api.go b/pgs/api.go
13index f73c5eb..d3c39df 100644
14--- a/pgs/api.go
15+++ b/pgs/api.go
16@@ -372,6 +372,9 @@ func ServeAsset(fname string, opts *storage.ImgProcessOpts, fromImgs bool, hasPe
17 	st := shared.GetStorage(r)
18 	logger := shared.GetLogger(r)
19 
20+	fmt.Println("===")
21+	fmt.Println(subdomain)
22+	fmt.Println("===")
23 	props, err := getProjectFromSubdomain(subdomain)
24 	if err != nil {
25 		logger.Info(err.Error(), "subdomain", subdomain, "filename", fname)
26diff --git a/pgs/tunnel.go b/pgs/tunnel.go
27index e9bf24a..694fa5a 100644
28--- a/pgs/tunnel.go
29+++ b/pgs/tunnel.go
30@@ -57,6 +57,18 @@ func createHttpHandler(apiConfig *shared.ApiConfig) CtxHttpBridge {
31 			return http.HandlerFunc(shared.UnauthorizedHandler)
32 		}
33 
34+		requester, _ := dbh.FindUserForKey("", pubkeyStr)
35+		if requester != nil {
36+			log = log.With(
37+				"requester", requester.Name,
38+			)
39+		}
40+
41+		// assume no username provided
42+		if props.Username == props.ProjectName {
43+			props.Username = requester.Name
44+		}
45+
46 		owner, err := dbh.FindUserForName(props.Username)
47 		if err != nil {
48 			log.Error(err.Error())
49@@ -72,13 +84,6 @@ func createHttpHandler(apiConfig *shared.ApiConfig) CtxHttpBridge {
50 			return http.HandlerFunc(shared.UnauthorizedHandler)
51 		}
52 
53-		requester, _ := dbh.FindUserForKey("", pubkeyStr)
54-		if requester != nil {
55-			log = log.With(
56-				"requester", requester.Name,
57-			)
58-		}
59-
60 		// impersonation logic
61 		if asUser != "" {
62 			isAdmin := dbh.HasFeatureForUser(requester.ID, "admin")
63-- 
642.45.2
65