Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea91c1b

Browse files
committed
use port sharer
1 parentf8e7094 commitea91c1b

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

‎coderd/portsharing/portsharing.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package portsharing
22

3+
import (
4+
"github.com/google/uuid"
5+
6+
"github.com/coder/coder/v2/codersdk"
7+
)
8+
39
typePortSharerinterface {
4-
CanRestrictShareLevel()bool
10+
ShareLevelAllowed(workspaceID uuid.UUID,level codersdk.WorkspacePortSharingLevel)bool
511
}
612

713
typeAGPLPortSharerstruct{}
814

9-
func (AGPLPortSharer)CanRestrictShareLevel()bool {
10-
returnfalse
15+
func (AGPLPortSharer)ShareLevelAllowed(_ uuid.UUID,_ codersdk.WorkspacePortSharingLevel)bool {
16+
returntrue
1117
}
1218

1319
varDefaultPortSharerPortSharer=AGPLPortSharer{}

‎coderd/workspaceportsharing.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ import (
2323
func (api*API)postWorkspacePortShareLevel(rw http.ResponseWriter,r*http.Request) {
2424
ctx:=r.Context()
2525
workspace:=httpmw.WorkspaceParam(r)
26+
portSharer:=*api.PortSharer.Load()
2627
varreq codersdk.UpdateWorkspaceAgentPortSharingLevelRequest
2728
if!httpapi.Read(ctx,rw,r,&req) {
2829
return
2930
}
3031

32+
shareLevelAllowed:=portSharer.ShareLevelAllowed(workspace.ID,codersdk.WorkspacePortSharingLevel(req.ShareLevel))
33+
if!shareLevelAllowed {
34+
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
35+
Message:"Port sharing level not allowed.",
36+
})
37+
return
38+
}
39+
3140
agents,err:=api.Database.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx,workspace.ID)
3241
iferr!=nil {
3342
httpapi.InternalServerError(rw,err)
@@ -59,7 +68,12 @@ func (api *API) postWorkspacePortShareLevel(rw http.ResponseWriter, r *http.Requ
5968
return
6069
}
6170

62-
if (req.ShareLevel==codersdk.Shar)
71+
ifreq.ShareLevel==int(codersdk.WorkspaceAgentPortSharingLevelOwner) {
72+
// If the port is not shared, and the user is trying to set it to owner,
73+
// we don't need to do anything.
74+
rw.WriteHeader(http.StatusOK)
75+
return
76+
}
6377

6478
err=api.Database.CreateWorkspacePortShareLevel(ctx, database.CreateWorkspacePortShareLevelParams{
6579
WorkspaceID:workspace.ID,
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package portsharing
22

3+
import (
4+
"github.com/google/uuid"
5+
6+
"github.com/coder/coder/v2/codersdk"
7+
)
8+
39
typeEnterprisePortSharerstruct{}
410

511
funcNewEnterprisePortSharer()*EnterprisePortSharer {
612
return&EnterprisePortSharer{}
713
}
814

9-
func (EnterprisePortSharer)CanRestrictShareLevel()bool {
10-
returntrue
15+
func (EnterprisePortSharer)ShareLevelAllowed(_ uuid.UUID,_ codersdk.WorkspacePortSharingLevel)bool {
16+
returnfalse
1117
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp