9
9
"time"
10
10
11
11
"github.com/google/uuid"
12
- "golang.org/x/sync/errgroup"
13
12
"golang.org/x/xerrors"
14
13
15
14
"github.com/coder/coder/v2/apiversion"
@@ -244,8 +243,6 @@ func (r *dynamicRenderer) getWorkspaceOwnerData(ctx context.Context, ownerID uui
244
243
return nil // already fetched
245
244
}
246
245
247
- var g errgroup.Group
248
-
249
246
// You only need to be able to read the organization member to get the owner
250
247
// data. Only the terraform files can therefore leak more information than the
251
248
// caller should have access to. All this info should be public assuming you can
@@ -266,72 +263,54 @@ func (r *dynamicRenderer) getWorkspaceOwnerData(ctx context.Context, ownerID uui
266
263
return xerrors .Errorf ("fetch user: %w" ,err )
267
264
}
268
265
269
- var ownerRoles []previewtypes.WorkspaceOwnerRBACRole
270
- g .Go (func ()error {
271
- // nolint:gocritic // This is kind of the wrong query to use here, but it
272
- // matches how the provisioner currently works. We should figure out
273
- // something that needs less escalation but has the correct behavior.
274
- row ,err := r .db .GetAuthorizationUserRoles (dbauthz .AsProvisionerd (ctx ),ownerID )
275
- if err != nil {
276
- return err
277
- }
278
- roles ,err := row .RoleNames ()
279
- if err != nil {
280
- return err
266
+ // nolint:gocritic // This is kind of the wrong query to use here, but it
267
+ // matches how the provisioner currently works. We should figure out
268
+ // something that needs less escalation but has the correct behavior.
269
+ row ,err := r .db .GetAuthorizationUserRoles (dbauthz .AsProvisionerd (ctx ),ownerID )
270
+ if err != nil {
271
+ return xerrors .Errorf ("user roles: %w" ,err )
272
+ }
273
+ roles ,err := row .RoleNames ()
274
+ if err != nil {
275
+ return xerrors .Errorf ("expand roles: %w" ,err )
276
+ }
277
+ ownerRoles := make ([]previewtypes.WorkspaceOwnerRBACRole ,0 ,len (roles ))
278
+ for _ ,it := range roles {
279
+ if it .OrganizationID != uuid .Nil && it .OrganizationID != r .data .templateVersion .OrganizationID {
280
+ continue
281
281
}
282
- ownerRoles = make ([]previewtypes.WorkspaceOwnerRBACRole ,0 ,len (roles ))
283
- for _ ,it := range roles {
284
- if it .OrganizationID != uuid .Nil && it .OrganizationID != r .data .templateVersion .OrganizationID {
285
- continue
286
- }
287
- var orgID string
288
- if it .OrganizationID != uuid .Nil {
289
- orgID = it .OrganizationID .String ()
290
- }
291
- ownerRoles = append (ownerRoles , previewtypes.WorkspaceOwnerRBACRole {
292
- Name :it .Name ,
293
- OrgID :orgID ,
294
- })
282
+ var orgID string
283
+ if it .OrganizationID != uuid .Nil {
284
+ orgID = it .OrganizationID .String ()
295
285
}
296
- return nil
297
- })
286
+ ownerRoles = append (ownerRoles , previewtypes.WorkspaceOwnerRBACRole {
287
+ Name :it .Name ,
288
+ OrgID :orgID ,
289
+ })
290
+ }
298
291
299
- var publicKey string
300
- g .Go (func ()error {
301
- // The correct public key has to be sent. This will not be leaked
302
- // unless the template leaks it.
303
- // nolint:gocritic
304
- key ,err := r .db .GetGitSSHKey (dbauthz .AsProvisionerd (ctx ),ownerID )
305
- if err != nil {
306
- return err
307
- }
308
- publicKey = key .PublicKey
309
- return nil
310
- })
292
+ // The correct public key has to be sent. This will not be leaked
293
+ // unless the template leaks it.
294
+ // nolint:gocritic
295
+ key ,err := r .db .GetGitSSHKey (dbauthz .AsProvisionerd (ctx ),ownerID )
296
+ if err != nil {
297
+ return xerrors .Errorf ("ssh key: %w" ,err )
298
+ }
311
299
312
- var groupNames []string
313
- g .Go (func ()error {
314
- // The groups need to be sent to preview. These groups are not exposed to the
315
- // user, unless the template does it through the parameters. Regardless, we need
316
- // the correct groups, and a user might not have read access.
317
- // nolint:gocritic
318
- groups ,err := r .db .GetGroups (dbauthz .AsProvisionerd (ctx ), database.GetGroupsParams {
319
- OrganizationID :r .data .templateVersion .OrganizationID ,
320
- HasMemberID :ownerID ,
321
- })
322
- if err != nil {
323
- return err
324
- }
325
- groupNames = make ([]string ,0 ,len (groups ))
326
- for _ ,it := range groups {
327
- groupNames = append (groupNames ,it .Group .Name )
328
- }
329
- return nil
300
+ // The groups need to be sent to preview. These groups are not exposed to the
301
+ // user, unless the template does it through the parameters. Regardless, we need
302
+ // the correct groups, and a user might not have read access.
303
+ // nolint:gocritic
304
+ groups ,err := r .db .GetGroups (dbauthz .AsProvisionerd (ctx ), database.GetGroupsParams {
305
+ OrganizationID :r .data .templateVersion .OrganizationID ,
306
+ HasMemberID :ownerID ,
330
307
})
331
-
332
- err = g .Wait ()
333
308
if err != nil {
334
- return err
309
+ return xerrors .Errorf ("groups: %w" ,err )
310
+ }
311
+ groupNames := make ([]string ,0 ,len (groups ))
312
+ for _ ,it := range groups {
313
+ groupNames = append (groupNames ,it .Group .Name )
335
314
}
336
315
337
316
r .currentOwner = & previewtypes.WorkspaceOwner {
@@ -341,7 +320,7 @@ func (r *dynamicRenderer) getWorkspaceOwnerData(ctx context.Context, ownerID uui
341
320
Email :mem .Email ,
342
321
LoginType :string (user .LoginType ),
343
322
RBACRoles :ownerRoles ,
344
- SSHPublicKey :publicKey ,
323
+ SSHPublicKey :key . PublicKey ,
345
324
Groups :groupNames ,
346
325
}
347
326
return nil