Skip to content

Commit 4297f0d

Browse files
deansheatherf0ssel
authored andcommitted
feat: allow setting port share protocol
1 parent 3e99c03 commit 4297f0d

16 files changed

+348
-105
lines changed

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,7 @@ func (s *MethodTestSuite) TestWorkspacePortSharing() {
16071607
AgentName: ps.AgentName,
16081608
Port: ps.Port,
16091609
ShareLevel: ps.ShareLevel,
1610+
Protocol: ps.Protocol,
16101611
}).Asserts(ws, rbac.ActionUpdate).Returns(ps)
16111612
}))
16121613
s.Run("GetWorkspaceAgentPortShare", s.Subtest(func(db database.Store, check *expects) {

coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func WorkspaceAgentPortShare(t testing.TB, db database.Store, orig database.Work
140140
AgentName: takeFirst(orig.AgentName, namesgenerator.GetRandomName(1)),
141141
Port: takeFirst(orig.Port, 8080),
142142
ShareLevel: takeFirst(orig.ShareLevel, database.AppSharingLevelPublic),
143+
Protocol: takeFirst(orig.Protocol, database.PortShareProtocolHttp),
143144
})
144145
require.NoError(t, err, "insert workspace agent")
145146
return ps

coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7871,6 +7871,7 @@ func (q *FakeQuerier) UpsertWorkspaceAgentPortShare(_ context.Context, arg datab
78717871
for i, share := range q.workspaceAgentPortShares {
78727872
if share.WorkspaceID == arg.WorkspaceID && share.Port == arg.Port && share.AgentName == arg.AgentName {
78737873
share.ShareLevel = arg.ShareLevel
7874+
share.Protocol = arg.Protocol
78747875
q.workspaceAgentPortShares[i] = share
78757876
return share, nil
78767877
}
@@ -7882,6 +7883,7 @@ func (q *FakeQuerier) UpsertWorkspaceAgentPortShare(_ context.Context, arg datab
78827883
AgentName: arg.AgentName,
78837884
Port: arg.Port,
78847885
ShareLevel: arg.ShareLevel,
7886+
Protocol: arg.Protocol,
78857887
}
78867888
q.workspaceAgentPortShares = append(q.workspaceAgentPortShares, psl)
78877889

coderd/database/dump.sql

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE workspace_agent_port_share DROP COLUMN protocol;
2+
3+
DROP TYPE port_share_protocol;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TYPE port_share_protocol AS ENUM ('http', 'https');
2+
3+
ALTER TABLE workspace_agent_port_share
4+
ADD COLUMN protocol port_share_protocol NOT NULL DEFAULT 'http'::port_share_protocol;

coderd/database/models.go

Lines changed: 63 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 53 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,51 @@
11
-- name: GetWorkspaceAgentPortShare :one
2-
SELECT * FROM workspace_agent_port_share WHERE workspace_id = $1 AND agent_name = $2 AND port = $3;
2+
SELECT
3+
*
4+
FROM
5+
workspace_agent_port_share
6+
WHERE
7+
workspace_id = $1
8+
AND agent_name = $2
9+
AND port = $3;
310

411
-- name: ListWorkspaceAgentPortShares :many
5-
SELECT * FROM workspace_agent_port_share WHERE workspace_id = $1;
12+
SELECT
13+
*
14+
FROM
15+
workspace_agent_port_share
16+
WHERE
17+
workspace_id = $1;
618

719
-- name: DeleteWorkspaceAgentPortShare :exec
8-
DELETE FROM workspace_agent_port_share WHERE workspace_id = $1 AND agent_name = $2 AND port = $3;
20+
DELETE FROM
21+
workspace_agent_port_share
22+
WHERE
23+
workspace_id = $1
24+
AND agent_name = $2
25+
AND port = $3;
926

1027
-- name: UpsertWorkspaceAgentPortShare :one
11-
INSERT INTO workspace_agent_port_share (workspace_id, agent_name, port, share_level)
12-
VALUES ($1, $2, $3, $4)
13-
ON CONFLICT (workspace_id, agent_name, port) DO UPDATE SET share_level = $4 RETURNING *;
28+
INSERT INTO
29+
workspace_agent_port_share (
30+
workspace_id,
31+
agent_name,
32+
port,
33+
share_level,
34+
protocol
35+
)
36+
VALUES (
37+
$1,
38+
$2,
39+
$3,
40+
$4,
41+
$5
42+
)
43+
ON CONFLICT (
44+
workspace_id,
45+
agent_name,
46+
port
47+
)
48+
DO UPDATE SET
49+
share_level = $4,
50+
protocol = $5
51+
RETURNING *;

coderd/workspaceagentportshare.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func (api *API) postWorkspaceAgentPortShare(rw http.ResponseWriter, r *http.Requ
5555
})
5656
return
5757
}
58+
if !req.Protocol.ValidPortProtocol() {
59+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
60+
Message: "Port protocol not allowed.",
61+
})
62+
return
63+
}
5864

5965
template, err := api.Database.GetTemplateByID(ctx, workspace.TemplateID)
6066
if err != nil {
@@ -95,6 +101,7 @@ func (api *API) postWorkspaceAgentPortShare(rw http.ResponseWriter, r *http.Requ
95101
AgentName: req.AgentName,
96102
Port: req.Port,
97103
ShareLevel: database.AppSharingLevel(req.ShareLevel),
104+
Protocol: database.PortShareProtocol(req.Protocol),
98105
})
99106
if err != nil {
100107
httpapi.InternalServerError(rw, err)
@@ -188,5 +195,6 @@ func convertPortShare(share database.WorkspaceAgentPortShare) codersdk.Workspace
188195
AgentName: share.AgentName,
189196
Port: share.Port,
190197
ShareLevel: codersdk.WorkspaceAgentPortShareLevel(share.ShareLevel),
198+
Protocol: codersdk.WorkspaceAgentPortShareProtocol(share.Protocol),
191199
}
192200
}

0 commit comments

Comments
 (0)