Logs
erock
created pr with ps-34
on erockmKua
changed status
on {"status":"accepted"}
Patchsets
Diff ↕
chore(pgs): add projects.blocked col
Eric Bower <me@erock.io>
Sometimes users have sites that violate our ToS. We can delete the content but if they have a script that will reupload it will automatically recreate the site. So we need a way to prevent uploads to projects.
Makefile | 3 ++- sql/migrations/20240819_add_projects_blocked.sql | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 sql/migrations/20240819_add_projects_blocked.sql
1From a827ced4f25eb8a8dee86a09addcce1ff96c3077 Mon Sep 17 00:00:00 2001
2From: Eric Bower <me@erock.io>
3Date: Mon, 19 Aug 2024 16:33:14 -0400
4Subject: [PATCH 1/2] chore(pgs): add projects.blocked col
5
6Sometimes users have sites that violate our ToS. We can delete the
7content but if they have a script that will reupload it will
8automatically recreate the site. So we need a way to prevent uploads to
9projects.
10---
11 Makefile | 3 ++-
12 sql/migrations/20240819_add_projects_blocked.sql | 1 +
13 2 files changed, 3 insertions(+), 1 deletion(-)
14 create mode 100644 sql/migrations/20240819_add_projects_blocked.sql
15
16diff --git a/Makefile b/Makefile
17index 050b7b6..1fdba5b 100644
18--- a/Makefile
19+++ b/Makefile
20@@ -123,10 +123,11 @@ migrate:
21 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240221_add_project_acl.sql
22 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240311_add_public_key_name.sql
23 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240324_add_analytics_table.sql
24+ $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240819_add_projects_blocked.sql
25 .PHONY: migrate
26
27 latest:
28- $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240324_add_analytics_table.sql
29+ $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240819_add_projects_blocked.sql
30 .PHONY: latest
31
32 psql:
33diff --git a/sql/migrations/20240819_add_projects_blocked.sql b/sql/migrations/20240819_add_projects_blocked.sql
34new file mode 100644
35index 0000000..f3aa794
36--- /dev/null
37+++ b/sql/migrations/20240819_add_projects_blocked.sql
38@@ -0,0 +1 @@
39+ALTER TABLE projects ADD COLUMN blocked varchar(256) NOT NULL DEFAULT '';
40--
412.45.2
42
feat(pgs): block uploads for specific projects
Eric Bower <me@erock.io>
db/db.go | 1 + db/postgres/storage.go | 13 +++++++++---- filehandlers/assets/handler.go | 5 +++++ pgs/cli.go | 2 ++ pgs/wish.go | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-)
1From 7f01eb3c0a930721b95259aa73c6ab466914bcd4 Mon Sep 17 00:00:00 2001
2From: Eric Bower <me@erock.io>
3Date: Mon, 19 Aug 2024 16:48:25 -0400
4Subject: [PATCH 2/2] feat(pgs): block uploads for specific projects
5
6---
7 db/db.go | 1 +
8 db/postgres/storage.go | 13 +++++++++----
9 filehandlers/assets/handler.go | 5 +++++
10 pgs/cli.go | 2 ++
11 pgs/wish.go | 2 +-
12 5 files changed, 18 insertions(+), 5 deletions(-)
13
14diff --git a/db/db.go b/db/db.go
15index 2c82dc4..855f6fa 100644
16--- a/db/db.go
17+++ b/db/db.go
18@@ -59,6 +59,7 @@ type Project struct {
19 ProjectDir string `json:"project_dir"`
20 Username string `json:"username"`
21 Acl ProjectAcl `json:"acl"`
22+ Blocked string `json:"blocked"`
23 CreatedAt *time.Time `json:"created_at"`
24 UpdatedAt *time.Time `json:"updated_at"`
25 }
26diff --git a/db/postgres/storage.go b/db/postgres/storage.go
27index 1b98756..0aec6c7 100644
28--- a/db/postgres/storage.go
29+++ b/db/postgres/storage.go
30@@ -251,11 +251,11 @@ const (
31 sqlInsertProject = `INSERT INTO projects (user_id, name, project_dir) VALUES ($1, $2, $3) RETURNING id;`
32 sqlUpdateProject = `UPDATE projects SET updated_at = $3 WHERE user_id = $1 AND name = $2;`
33 sqlUpdateProjectAcl = `UPDATE projects SET acl = $3, updated_at = $4 WHERE user_id = $1 AND name = $2;`
34- sqlFindProjectByName = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
35+ sqlFindProjectByName = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
36 sqlSelectProjectCount = `SELECT count(id) FROM projects`
37- sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 ORDER BY name ASC, updated_at DESC;`
38- sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
39- sqlFindProjectLinks = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
40+ sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 ORDER BY name ASC, updated_at DESC;`
41+ sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
42+ sqlFindProjectLinks = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
43 sqlLinkToProject = `UPDATE projects SET project_dir = $1, updated_at = $2 WHERE id = $3;`
44 sqlRemoveProject = `DELETE FROM projects WHERE id = $1;`
45 )
46@@ -1632,6 +1632,7 @@ func (me *PsqlDB) FindProjectByName(userID, name string) (*db.Project, error) {
47 &project.Name,
48 &project.ProjectDir,
49 &project.Acl,
50+ &project.Blocked,
51 &project.CreatedAt,
52 &project.UpdatedAt,
53 )
54@@ -1656,6 +1657,7 @@ func (me *PsqlDB) FindProjectLinks(userID, name string) ([]*db.Project, error) {
55 &project.Name,
56 &project.ProjectDir,
57 &project.Acl,
58+ &project.Blocked,
59 &project.CreatedAt,
60 &project.UpdatedAt,
61 )
62@@ -1687,6 +1689,7 @@ func (me *PsqlDB) FindProjectsByPrefix(userID, prefix string) ([]*db.Project, er
63 &project.Name,
64 &project.ProjectDir,
65 &project.Acl,
66+ &project.Blocked,
67 &project.CreatedAt,
68 &project.UpdatedAt,
69 )
70@@ -1718,6 +1721,7 @@ func (me *PsqlDB) FindProjectsByUser(userID string) ([]*db.Project, error) {
71 &project.Name,
72 &project.ProjectDir,
73 &project.Acl,
74+ &project.Blocked,
75 &project.CreatedAt,
76 &project.UpdatedAt,
77 )
78@@ -1756,6 +1760,7 @@ func (me *PsqlDB) FindAllProjects(page *db.Pager, by string) (*db.Paginate[*db.P
79 &project.Name,
80 &project.ProjectDir,
81 &project.Acl,
82+ &project.Blocked,
83 &project.CreatedAt,
84 &project.UpdatedAt,
85 )
86diff --git a/filehandlers/assets/handler.go b/filehandlers/assets/handler.go
87index 22edce6..7332d35 100644
88--- a/filehandlers/assets/handler.go
89+++ b/filehandlers/assets/handler.go
90@@ -294,6 +294,11 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (strin
91 setProject(s, project)
92 }
93
94+ if project.Blocked != "" {
95+ msg := "project has been blocked and cannot upload files: %s"
96+ return "", fmt.Errorf(msg, project.Blocked)
97+ }
98+
99 if entry.Mode.IsDir() {
100 _, _, err := h.Storage.PutObject(
101 bucket,
102diff --git a/pgs/cli.go b/pgs/cli.go
103index 0af5802..faeef45 100644
104--- a/pgs/cli.go
105+++ b/pgs/cli.go
106@@ -24,6 +24,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
107 "Links To",
108 "ACL Type",
109 "ACL",
110+ "Blocked",
111 }
112 data := [][]string{}
113 for _, project := range projects {
114@@ -40,6 +41,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
115 project.Acl.Type,
116 strings.Join(project.Acl.Data, " "),
117 )
118+ row = append(row, project.Blocked)
119 data = append(data, row)
120 }
121
122diff --git a/pgs/wish.go b/pgs/wish.go
123index cef389b..c32f6ae 100644
124--- a/pgs/wish.go
125+++ b/pgs/wish.go
126@@ -78,7 +78,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
127 }
128
129 // default width and height when no pty
130- width := 80
131+ width := 100
132 height := 24
133 pty, _, ok := sesh.Pty()
134 if ok {
135--
1362.45.2
137
ps-34
by
erock
on chore(pgs): add projects.blocked col
Eric Bower <me@erock.io>
Sometimes users have sites that violate our ToS. We can delete the content but if they have a script that will reupload it will automatically recreate the site. So we need a way to prevent uploads to projects.
Makefile | 3 ++- sql/migrations/20240819_add_projects_blocked.sql | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 sql/migrations/20240819_add_projects_blocked.sql
1From a827ced4f25eb8a8dee86a09addcce1ff96c3077 Mon Sep 17 00:00:00 2001
2From: Eric Bower <me@erock.io>
3Date: Mon, 19 Aug 2024 16:33:14 -0400
4Subject: [PATCH 1/2] chore(pgs): add projects.blocked col
5
6Sometimes users have sites that violate our ToS. We can delete the
7content but if they have a script that will reupload it will
8automatically recreate the site. So we need a way to prevent uploads to
9projects.
10---
11 Makefile | 3 ++-
12 sql/migrations/20240819_add_projects_blocked.sql | 1 +
13 2 files changed, 3 insertions(+), 1 deletion(-)
14 create mode 100644 sql/migrations/20240819_add_projects_blocked.sql
15
16diff --git a/Makefile b/Makefile
17index 050b7b6..1fdba5b 100644
18--- a/Makefile
19+++ b/Makefile
20@@ -123,10 +123,11 @@ migrate:
21 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240221_add_project_acl.sql
22 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240311_add_public_key_name.sql
23 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240324_add_analytics_table.sql
24+ $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240819_add_projects_blocked.sql
25 .PHONY: migrate
26
27 latest:
28- $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240324_add_analytics_table.sql
29+ $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240819_add_projects_blocked.sql
30 .PHONY: latest
31
32 psql:
33diff --git a/sql/migrations/20240819_add_projects_blocked.sql b/sql/migrations/20240819_add_projects_blocked.sql
34new file mode 100644
35index 0000000..f3aa794
36--- /dev/null
37+++ b/sql/migrations/20240819_add_projects_blocked.sql
38@@ -0,0 +1 @@
39+ALTER TABLE projects ADD COLUMN blocked varchar(256) NOT NULL DEFAULT '';
40--
412.45.2
42
feat(pgs): block uploads for specific projects
Eric Bower <me@erock.io>
db/db.go | 1 + db/postgres/storage.go | 13 +++++++++---- filehandlers/assets/handler.go | 5 +++++ pgs/cli.go | 2 ++ pgs/wish.go | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-)
1From 7f01eb3c0a930721b95259aa73c6ab466914bcd4 Mon Sep 17 00:00:00 2001
2From: Eric Bower <me@erock.io>
3Date: Mon, 19 Aug 2024 16:48:25 -0400
4Subject: [PATCH 2/2] feat(pgs): block uploads for specific projects
5
6---
7 db/db.go | 1 +
8 db/postgres/storage.go | 13 +++++++++----
9 filehandlers/assets/handler.go | 5 +++++
10 pgs/cli.go | 2 ++
11 pgs/wish.go | 2 +-
12 5 files changed, 18 insertions(+), 5 deletions(-)
13
14diff --git a/db/db.go b/db/db.go
15index 2c82dc4..855f6fa 100644
16--- a/db/db.go
17+++ b/db/db.go
18@@ -59,6 +59,7 @@ type Project struct {
19 ProjectDir string `json:"project_dir"`
20 Username string `json:"username"`
21 Acl ProjectAcl `json:"acl"`
22+ Blocked string `json:"blocked"`
23 CreatedAt *time.Time `json:"created_at"`
24 UpdatedAt *time.Time `json:"updated_at"`
25 }
26diff --git a/db/postgres/storage.go b/db/postgres/storage.go
27index 1b98756..0aec6c7 100644
28--- a/db/postgres/storage.go
29+++ b/db/postgres/storage.go
30@@ -251,11 +251,11 @@ const (
31 sqlInsertProject = `INSERT INTO projects (user_id, name, project_dir) VALUES ($1, $2, $3) RETURNING id;`
32 sqlUpdateProject = `UPDATE projects SET updated_at = $3 WHERE user_id = $1 AND name = $2;`
33 sqlUpdateProjectAcl = `UPDATE projects SET acl = $3, updated_at = $4 WHERE user_id = $1 AND name = $2;`
34- sqlFindProjectByName = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
35+ sqlFindProjectByName = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
36 sqlSelectProjectCount = `SELECT count(id) FROM projects`
37- sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 ORDER BY name ASC, updated_at DESC;`
38- sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
39- sqlFindProjectLinks = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
40+ sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 ORDER BY name ASC, updated_at DESC;`
41+ sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
42+ sqlFindProjectLinks = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
43 sqlLinkToProject = `UPDATE projects SET project_dir = $1, updated_at = $2 WHERE id = $3;`
44 sqlRemoveProject = `DELETE FROM projects WHERE id = $1;`
45 )
46@@ -1632,6 +1632,7 @@ func (me *PsqlDB) FindProjectByName(userID, name string) (*db.Project, error) {
47 &project.Name,
48 &project.ProjectDir,
49 &project.Acl,
50+ &project.Blocked,
51 &project.CreatedAt,
52 &project.UpdatedAt,
53 )
54@@ -1656,6 +1657,7 @@ func (me *PsqlDB) FindProjectLinks(userID, name string) ([]*db.Project, error) {
55 &project.Name,
56 &project.ProjectDir,
57 &project.Acl,
58+ &project.Blocked,
59 &project.CreatedAt,
60 &project.UpdatedAt,
61 )
62@@ -1687,6 +1689,7 @@ func (me *PsqlDB) FindProjectsByPrefix(userID, prefix string) ([]*db.Project, er
63 &project.Name,
64 &project.ProjectDir,
65 &project.Acl,
66+ &project.Blocked,
67 &project.CreatedAt,
68 &project.UpdatedAt,
69 )
70@@ -1718,6 +1721,7 @@ func (me *PsqlDB) FindProjectsByUser(userID string) ([]*db.Project, error) {
71 &project.Name,
72 &project.ProjectDir,
73 &project.Acl,
74+ &project.Blocked,
75 &project.CreatedAt,
76 &project.UpdatedAt,
77 )
78@@ -1756,6 +1760,7 @@ func (me *PsqlDB) FindAllProjects(page *db.Pager, by string) (*db.Paginate[*db.P
79 &project.Name,
80 &project.ProjectDir,
81 &project.Acl,
82+ &project.Blocked,
83 &project.CreatedAt,
84 &project.UpdatedAt,
85 )
86diff --git a/filehandlers/assets/handler.go b/filehandlers/assets/handler.go
87index 22edce6..7332d35 100644
88--- a/filehandlers/assets/handler.go
89+++ b/filehandlers/assets/handler.go
90@@ -294,6 +294,11 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (strin
91 setProject(s, project)
92 }
93
94+ if project.Blocked != "" {
95+ msg := "project has been blocked and cannot upload files: %s"
96+ return "", fmt.Errorf(msg, project.Blocked)
97+ }
98+
99 if entry.Mode.IsDir() {
100 _, _, err := h.Storage.PutObject(
101 bucket,
102diff --git a/pgs/cli.go b/pgs/cli.go
103index 0af5802..faeef45 100644
104--- a/pgs/cli.go
105+++ b/pgs/cli.go
106@@ -24,6 +24,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
107 "Links To",
108 "ACL Type",
109 "ACL",
110+ "Blocked",
111 }
112 data := [][]string{}
113 for _, project := range projects {
114@@ -40,6 +41,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
115 project.Acl.Type,
116 strings.Join(project.Acl.Data, " "),
117 )
118+ row = append(row, project.Blocked)
119 data = append(data, row)
120 }
121
122diff --git a/pgs/wish.go b/pgs/wish.go
123index cef389b..c32f6ae 100644
124--- a/pgs/wish.go
125+++ b/pgs/wish.go
126@@ -78,7 +78,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
127 }
128
129 // default width and height when no pty
130- width := 80
131+ width := 100
132 height := 24
133 pty, _, ok := sesh.Pty()
134 if ok {
135--
1362.45.2
137