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

Commit6776c03

Browse files
committed
fix: Remove unused workspace routes in favor of list with filter (#2038)
* fix: Remove unused workspace routes in favor of list with filterThis consolidates the workspace routes into a single place.It allows users to fetch a workspace by their username andworkspace name, which will be used by the frontend for routing.* Fix RBAC* Fix CLI usages
1 parent7a6665f commit6776c03

26 files changed

+72
-424
lines changed

‎cli/autostart.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ func autostartShow() *cobra.Command {
4141
iferr!=nil {
4242
returnerr
4343
}
44-
organization,err:=currentOrganization(cmd,client)
45-
iferr!=nil {
46-
returnerr
47-
}
4844

49-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
45+
workspace,err:=namedWorkspace(cmd,client,args[0])
5046
iferr!=nil {
5147
returnerr
5248
}
@@ -93,18 +89,14 @@ func autostartEnable() *cobra.Command {
9389
iferr!=nil {
9490
returnerr
9591
}
96-
organization,err:=currentOrganization(cmd,client)
97-
iferr!=nil {
98-
returnerr
99-
}
10092

10193
spec:=fmt.Sprintf("CRON_TZ=%s %s %s * * %s",autostartTimezone,autostartMinute,autostartHour,autostartDayOfWeek)
10294
validSchedule,err:=schedule.Weekly(spec)
10395
iferr!=nil {
10496
returnerr
10597
}
10698

107-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
99+
workspace,err:=namedWorkspace(cmd,client,args[0])
108100
iferr!=nil {
109101
returnerr
110102
}
@@ -142,12 +134,8 @@ func autostartDisable() *cobra.Command {
142134
iferr!=nil {
143135
returnerr
144136
}
145-
organization,err:=currentOrganization(cmd,client)
146-
iferr!=nil {
147-
returnerr
148-
}
149137

150-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
138+
workspace,err:=namedWorkspace(cmd,client,args[0])
151139
iferr!=nil {
152140
returnerr
153141
}

‎cli/bump.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ func bump() *cobra.Command {
4343
iferr!=nil {
4444
returnxerrors.Errorf("create client: %w",err)
4545
}
46-
organization,err:=currentOrganization(cmd,client)
47-
iferr!=nil {
48-
returnxerrors.Errorf("get current org: %w",err)
49-
}
50-
51-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
46+
workspace,err:=namedWorkspace(cmd,client,args[0])
5247
iferr!=nil {
5348
returnxerrors.Errorf("get workspace: %w",err)
5449
}

‎cli/configssh.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ func configSSH() *cobra.Command {
4848
iferr!=nil {
4949
returnerr
5050
}
51-
organization,err:=currentOrganization(cmd,client)
52-
iferr!=nil {
53-
returnerr
54-
}
5551
ifstrings.HasPrefix(sshConfigFile,"~/") {
5652
dirname,_:=os.UserHomeDir()
5753
sshConfigFile=filepath.Join(dirname,sshConfigFile[2:])
@@ -65,7 +61,9 @@ func configSSH() *cobra.Command {
6561
sshConfigContent=sshConfigContent[:startIndex-1]+sshConfigContent[endIndex+len(sshEndToken):]
6662
}
6763

68-
workspaces,err:=client.WorkspacesByOwner(cmd.Context(),organization.ID,codersdk.Me)
64+
workspaces,err:=client.Workspaces(cmd.Context(), codersdk.WorkspaceFilter{
65+
Owner:codersdk.Me,
66+
})
6967
iferr!=nil {
7068
returnerr
7169
}

‎cli/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func create() *cobra.Command {
4949
workspaceName,err=cliui.Prompt(cmd, cliui.PromptOptions{
5050
Text:"Specify a name for your workspace:",
5151
Validate:func(workspaceNamestring)error {
52-
_,err=client.WorkspaceByOwnerAndName(cmd.Context(),organization.ID,codersdk.Me,workspaceName)
52+
_,err=client.WorkspaceByOwnerAndName(cmd.Context(),codersdk.Me,workspaceName)
5353
iferr==nil {
5454
returnxerrors.Errorf("A workspace already exists named %q!",workspaceName)
5555
}
@@ -75,7 +75,7 @@ func create() *cobra.Command {
7575
returnxerrors.Errorf("TTL must be at least 1 minute")
7676
}
7777

78-
_,err=client.WorkspaceByOwnerAndName(cmd.Context(),organization.ID,codersdk.Me,workspaceName)
78+
_,err=client.WorkspaceByOwnerAndName(cmd.Context(),codersdk.Me,workspaceName)
7979
iferr==nil {
8080
returnxerrors.Errorf("A workspace already exists named %q!",workspaceName)
8181
}

‎cli/delete.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ func delete() *cobra.Command {
3030
iferr!=nil {
3131
returnerr
3232
}
33-
organization,err:=currentOrganization(cmd,client)
34-
iferr!=nil {
35-
returnerr
36-
}
37-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
33+
workspace,err:=namedWorkspace(cmd,client,args[0])
3834
iferr!=nil {
3935
returnerr
4036
}

‎cli/portforward.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ func portForward() *cobra.Command {
7070
iferr!=nil {
7171
returnerr
7272
}
73-
organization,err:=currentOrganization(cmd,client)
74-
iferr!=nil {
75-
returnerr
76-
}
7773

78-
workspace,agent,err:=getWorkspaceAndAgent(cmd,client,organization.ID,codersdk.Me,args[0],false)
74+
workspace,agent,err:=getWorkspaceAndAgent(cmd,client,codersdk.Me,args[0],false)
7975
iferr!=nil {
8076
returnerr
8177
}

‎cli/root.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"golang.org/x/xerrors"
1111

12-
"github.com/google/uuid"
1312
"github.com/kirsle/configdir"
1413
"github.com/mattn/go-isatty"
1514
"github.com/spf13/cobra"
@@ -180,7 +179,7 @@ func currentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.
180179
// namedWorkspace fetches and returns a workspace by an identifier, which may be either
181180
// a bare name (for a workspace owned by the current user) or a "user/workspace" combination,
182181
// where user is either a username or UUID.
183-
funcnamedWorkspace(cmd*cobra.Command,client*codersdk.Client,orgID uuid.UUID,identifierstring) (codersdk.Workspace,error) {
182+
funcnamedWorkspace(cmd*cobra.Command,client*codersdk.Client,identifierstring) (codersdk.Workspace,error) {
184183
parts:=strings.Split(identifier,"/")
185184

186185
varowner,namestring
@@ -195,7 +194,7 @@ func namedWorkspace(cmd *cobra.Command, client *codersdk.Client, orgID uuid.UUID
195194
return codersdk.Workspace{},xerrors.Errorf("invalid workspace name: %q",identifier)
196195
}
197196

198-
returnclient.WorkspaceByOwnerAndName(cmd.Context(),orgID,owner,name)
197+
returnclient.WorkspaceByOwnerAndName(cmd.Context(),owner,name)
199198
}
200199

201200
// createConfig consumes the global configuration flag to produce a config root.

‎cli/server.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,9 @@ func server() *cobra.Command {
412412
"Interrupt caught, gracefully exiting. Use ctrl+\\ to force quit"))
413413

414414
ifdev {
415-
organizations,err:=client.OrganizationsByUser(cmd.Context(),codersdk.Me)
416-
iferr!=nil {
417-
returnxerrors.Errorf("get organizations: %w",err)
418-
}
419-
workspaces,err:=client.WorkspacesByOwner(cmd.Context(),organizations[0].ID,codersdk.Me)
415+
workspaces,err:=client.Workspaces(cmd.Context(), codersdk.WorkspaceFilter{
416+
Owner:codersdk.Me,
417+
})
420418
iferr!=nil {
421419
returnxerrors.Errorf("get workspaces: %w",err)
422420
}

‎cli/show.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ func show() *cobra.Command {
1818
iferr!=nil {
1919
returnerr
2020
}
21-
organization,err:=currentOrganization(cmd,client)
22-
iferr!=nil {
23-
returnerr
24-
}
25-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
21+
workspace,err:=namedWorkspace(cmd,client,args[0])
2622
iferr!=nil {
2723
returnxerrors.Errorf("get workspace: %w",err)
2824
}

‎cli/ssh.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ func ssh() *cobra.Command {
4848
iferr!=nil {
4949
returnerr
5050
}
51-
organization,err:=currentOrganization(cmd,client)
52-
iferr!=nil {
53-
returnerr
54-
}
5551

5652
ifshuffle {
5753
err:=cobra.ExactArgs(0)(cmd,args)
@@ -65,7 +61,7 @@ func ssh() *cobra.Command {
6561
}
6662
}
6763

68-
workspace,agent,err:=getWorkspaceAndAgent(cmd,client,organization.ID,codersdk.Me,args[0],shuffle)
64+
workspace,agent,err:=getWorkspaceAndAgent(cmd,client,codersdk.Me,args[0],shuffle)
6965
iferr!=nil {
7066
returnerr
7167
}
@@ -185,7 +181,7 @@ func ssh() *cobra.Command {
185181
// getWorkspaceAgent returns the workspace and agent selected using either the
186182
// `<workspace>[.<agent>]` syntax via `in` or picks a random workspace and agent
187183
// if `shuffle` is true.
188-
funcgetWorkspaceAndAgent(cmd*cobra.Command,client*codersdk.Client,orgID uuid.UUID,userIDstring,instring,shufflebool) (codersdk.Workspace, codersdk.WorkspaceAgent,error) {//nolint:revive
184+
funcgetWorkspaceAndAgent(cmd*cobra.Command,client*codersdk.Client,userIDstring,instring,shufflebool) (codersdk.Workspace, codersdk.WorkspaceAgent,error) {//nolint:revive
189185
ctx:=cmd.Context()
190186

191187
var (
@@ -194,7 +190,9 @@ func getWorkspaceAndAgent(cmd *cobra.Command, client *codersdk.Client, orgID uui
194190
errerror
195191
)
196192
ifshuffle {
197-
workspaces,err:=client.WorkspacesByOwner(cmd.Context(),orgID,userID)
193+
workspaces,err:=client.Workspaces(cmd.Context(), codersdk.WorkspaceFilter{
194+
Owner:codersdk.Me,
195+
})
198196
iferr!=nil {
199197
return codersdk.Workspace{}, codersdk.WorkspaceAgent{},err
200198
}
@@ -207,7 +205,7 @@ func getWorkspaceAndAgent(cmd *cobra.Command, client *codersdk.Client, orgID uui
207205
return codersdk.Workspace{}, codersdk.WorkspaceAgent{},err
208206
}
209207
}else {
210-
workspace,err=namedWorkspace(cmd,client,orgID,workspaceParts[0])
208+
workspace,err=namedWorkspace(cmd,client,workspaceParts[0])
211209
iferr!=nil {
212210
return codersdk.Workspace{}, codersdk.WorkspaceAgent{},err
213211
}

‎cli/start.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ func start() *cobra.Command {
2828
iferr!=nil {
2929
returnerr
3030
}
31-
organization,err:=currentOrganization(cmd,client)
32-
iferr!=nil {
33-
returnerr
34-
}
35-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
31+
workspace,err:=namedWorkspace(cmd,client,args[0])
3632
iferr!=nil {
3733
returnerr
3834
}

‎cli/state.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ func statePull() *cobra.Command {
3030
iferr!=nil {
3131
returnerr
3232
}
33-
organization,err:=currentOrganization(cmd,client)
34-
iferr!=nil {
35-
returnerr
36-
}
37-
38-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
33+
workspace,err:=namedWorkspace(cmd,client,args[0])
3934
iferr!=nil {
4035
returnerr
4136
}
@@ -76,12 +71,7 @@ func statePush() *cobra.Command {
7671
iferr!=nil {
7772
returnerr
7873
}
79-
organization,err:=currentOrganization(cmd,client)
80-
iferr!=nil {
81-
returnerr
82-
}
83-
84-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
74+
workspace,err:=namedWorkspace(cmd,client,args[0])
8575
iferr!=nil {
8676
returnerr
8777
}

‎cli/stop.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ func stop() *cobra.Command {
2828
iferr!=nil {
2929
returnerr
3030
}
31-
organization,err:=currentOrganization(cmd,client)
32-
iferr!=nil {
33-
returnerr
34-
}
35-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
31+
workspace,err:=namedWorkspace(cmd,client,args[0])
3632
iferr!=nil {
3733
returnerr
3834
}

‎cli/ttl.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ func ttlShow() *cobra.Command {
3939
iferr!=nil {
4040
returnxerrors.Errorf("create client: %w",err)
4141
}
42-
organization,err:=currentOrganization(cmd,client)
43-
iferr!=nil {
44-
returnxerrors.Errorf("get current org: %w",err)
45-
}
4642

47-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
43+
workspace,err:=namedWorkspace(cmd,client,args[0])
4844
iferr!=nil {
4945
returnxerrors.Errorf("get workspace: %w",err)
5046
}
@@ -72,12 +68,8 @@ func ttlset() *cobra.Command {
7268
iferr!=nil {
7369
returnxerrors.Errorf("create client: %w",err)
7470
}
75-
organization,err:=currentOrganization(cmd,client)
76-
iferr!=nil {
77-
returnxerrors.Errorf("get current org: %w",err)
78-
}
7971

80-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
72+
workspace,err:=namedWorkspace(cmd,client,args[0])
8173
iferr!=nil {
8274
returnxerrors.Errorf("get workspace: %w",err)
8375
}
@@ -120,12 +112,8 @@ func ttlunset() *cobra.Command {
120112
iferr!=nil {
121113
returnxerrors.Errorf("create client: %w",err)
122114
}
123-
organization,err:=currentOrganization(cmd,client)
124-
iferr!=nil {
125-
returnxerrors.Errorf("get current org: %w",err)
126-
}
127115

128-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
116+
workspace,err:=namedWorkspace(cmd,client,args[0])
129117
iferr!=nil {
130118
returnxerrors.Errorf("get workspace: %w",err)
131119
}

‎cli/update.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ func update() *cobra.Command {
1919
iferr!=nil {
2020
returnerr
2121
}
22-
organization,err:=currentOrganization(cmd,client)
23-
iferr!=nil {
24-
returnerr
25-
}
26-
workspace,err:=namedWorkspace(cmd,client,organization.ID,args[0])
22+
workspace,err:=namedWorkspace(cmd,client,args[0])
2723
iferr!=nil {
2824
returnerr
2925
}

‎coderd/coderd.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,7 @@ func New(options *Options) *API {
152152
r.Get("/",api.templatesByOrganization)
153153
r.Get("/{templatename}",api.templateByOrganizationAndName)
154154
})
155-
r.Route("/workspaces",func(r chi.Router) {
156-
r.Post("/",api.postWorkspacesByOrganization)
157-
r.Get("/",api.workspacesByOrganization)
158-
r.Route("/{user}",func(r chi.Router) {
159-
r.Use(httpmw.ExtractUserParam(options.Database))
160-
r.Get("/{workspacename}",api.workspaceByOwnerAndName)
161-
r.Get("/",api.workspacesByOwner)
162-
})
163-
})
155+
r.Post("/workspaces",api.postWorkspacesByOrganization)
164156
r.Route("/members",func(r chi.Router) {
165157
r.Get("/roles",api.assignableOrgRoles)
166158
r.Route("/{user}",func(r chi.Router) {
@@ -259,6 +251,7 @@ func New(options *Options) *API {
259251
r.Get("/",api.organizationsByUser)
260252
r.Get("/{organizationname}",api.organizationByUserAndName)
261253
})
254+
r.Get("/workspace/{workspacename}",api.workspaceByOwnerAndName)
262255
r.Get("/gitsshkey",api.gitSSHKey)
263256
r.Put("/gitsshkey",api.regenerateGitSSHKey)
264257
})

‎coderd/coderd_test.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,16 @@ func TestAuthorizeAllEndpoints(t *testing.T) {
147147
"GET:/api/v2/workspaceagents/{workspaceagent}/turn": {NoAuthorize:true},
148148

149149
// These endpoints have more assertions. This is good, add more endpoints to assert if you can!
150-
"GET:/api/v2/organizations/{organization}": {AssertObject:rbac.ResourceOrganization.InOrg(admin.OrganizationID)},
151-
"GET:/api/v2/users/{user}/organizations": {StatusCode:http.StatusOK,AssertObject:rbac.ResourceOrganization},
152-
"GET:/api/v2/users/{user}/workspaces": {StatusCode:http.StatusOK,AssertObject:rbac.ResourceWorkspace},
153-
"GET:/api/v2/organizations/{organization}/workspaces/{user}": {StatusCode:http.StatusOK,AssertObject:rbac.ResourceWorkspace},
154-
"GET:/api/v2/organizations/{organization}/workspaces/{user}/{workspace}": {
155-
AssertObject:rbac.ResourceWorkspace.InOrg(organization.ID).WithID(workspace.ID.String()).WithOwner(workspace.OwnerID.String()),
156-
},
157-
"GET:/api/v2/workspaces/{workspace}/builds/{workspacebuildname}": {
150+
"GET:/api/v2/organizations/{organization}": {AssertObject:rbac.ResourceOrganization.InOrg(admin.OrganizationID)},
151+
"GET:/api/v2/users/{user}/organizations": {StatusCode:http.StatusOK,AssertObject:rbac.ResourceOrganization},
152+
"GET:/api/v2/users/{user}/workspace/{workspacename}": {
153+
AssertObject:rbac.ResourceWorkspace,
158154
AssertAction:rbac.ActionRead,
159-
AssertObject:workspaceRBACObj,
160155
},
161-
"GET:/api/v2/organizations/{organization}/workspaces/{user}/{workspacename}": {
156+
"GET:/api/v2/workspaces/{workspace}/builds/{workspacebuildname}": {
162157
AssertAction:rbac.ActionRead,
163158
AssertObject:workspaceRBACObj,
164159
},
165-
"GET:/api/v2/organizations/{organization}/workspaces": {StatusCode:http.StatusOK,AssertObject:rbac.ResourceWorkspace},
166160
"GET:/api/v2/workspacebuilds/{workspacebuild}": {
167161
AssertAction:rbac.ActionRead,
168162
AssertObject:workspaceRBACObj,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp