Logs
erock
created pr with ps-33
on Patchsets
Diff ↕
feat(pgs): tunnel default to requester username if no username provided
Eric Bower <me@erock.io>
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 feat(pgs): tunnel default to requester username if no username provided
Eric Bower <me@erock.io>
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