Skip to content

Commit 99ed006

Browse files
committed
feat: allow setting port share protocol
1 parent 7fbca62 commit 99ed006

16 files changed

+348
-105
lines changed

coderd/database/dbauthz/dbauthz_test.go

+1
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

+1
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

+2
Original file line numberDiff line numberDiff line change
@@ -7865,6 +7865,7 @@ func (q *FakeQuerier) UpsertWorkspaceAgentPortShare(_ context.Context, arg datab
78657865
for i, share := range q.workspaceAgentPortShares {
78667866
if share.WorkspaceID == arg.WorkspaceID && share.Port == arg.Port && share.AgentName == arg.AgentName {
78677867
share.ShareLevel = arg.ShareLevel
7868+
share.Protocol = arg.Protocol
78687869
q.workspaceAgentPortShares[i] = share
78697870
return share, nil
78707871
}
@@ -7876,6 +7877,7 @@ func (q *FakeQuerier) UpsertWorkspaceAgentPortShare(_ context.Context, arg datab
78767877
AgentName: arg.AgentName,
78777878
Port: arg.Port,
78787879
ShareLevel: arg.ShareLevel,
7880+
Protocol: arg.Protocol,
78797881
}
78807882
q.workspaceAgentPortShares = append(q.workspaceAgentPortShares, psl)
78817883

coderd/database/dump.sql

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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;
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

+63-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+53-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func (api *API) postWorkspaceAgentPortShare(rw http.ResponseWriter, r *http.Requ
3636
})
3737
return
3838
}
39+
if !req.Protocol.ValidPortProtocol() {
40+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
41+
Message: "Port protocol not allowed.",
42+
})
43+
return
44+
}
3945

4046
template, err := api.Database.GetTemplateByID(ctx, workspace.TemplateID)
4147
if err != nil {
@@ -76,6 +82,7 @@ func (api *API) postWorkspaceAgentPortShare(rw http.ResponseWriter, r *http.Requ
7682
AgentName: req.AgentName,
7783
Port: req.Port,
7884
ShareLevel: database.AppSharingLevel(req.ShareLevel),
85+
Protocol: database.PortShareProtocol(req.Protocol),
7986
})
8087
if err != nil {
8188
httpapi.InternalServerError(rw, err)
@@ -169,5 +176,6 @@ func convertPortShare(share database.WorkspaceAgentPortShare) codersdk.Workspace
169176
AgentName: share.AgentName,
170177
Port: share.Port,
171178
ShareLevel: codersdk.WorkspaceAgentPortShareLevel(share.ShareLevel),
179+
Protocol: codersdk.WorkspaceAgentPortShareProtocol(share.Protocol),
172180
}
173181
}

0 commit comments

Comments
 (0)