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
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitedf70b9

Browse files
authored
feat: Allow making a workspace for another user as an admin (#427)
* Allow making a workspace for another user as an admin
1 parent3582a0d commitedf70b9

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

‎coder-sdk/workspace.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ type CreateWorkspaceRequest struct {
8989
Namespacestring`json:"namespace"`
9090
EnableAutoStartbool`json:"autostart_enabled"`
9191

92+
// ForUserID is an optional param to create a workspace for another user
93+
// other than the requester. This only works for admins and site managers.
94+
ForUserIDstring`json:"for_user_id,omitempty"`
95+
9296
// TemplateID comes from the parse template route on cemanager.
9397
TemplateIDstring`json:"template_id,omitempty"`
9498
}

‎docs/coder_workspaces_create.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1
3333
-o, --org string name of the organization the workspace should be created under.
3434
--provider string name of Workspace Provider with which to create the workspace
3535
-t, --tag string tag of the image the workspace will be based off of. (default "latest")
36+
--user string Specify the user whose resources to target. This flag can only be used by admins and managers. Input an email or user id. (default "me")
3637
```
3738

3839
###Options inherited from parent commands

‎internal/cmd/workspaces.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ func createWorkspaceCmd() *cobra.Command {
397397
useCVMbool
398398
providerNamestring
399399
enableAutostartbool
400+
forUserstring// Optional
400401
)
401402

402403
cmd:=&cobra.Command{
@@ -448,6 +449,23 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1
448449
}
449450
}
450451

452+
varforEmailstring
453+
ifforUser!=""&&forUser!=coder.Me {
454+
// Making a workspace for another user, do they exist?
455+
u,err:=client.UserByEmail(ctx,forUser)
456+
iferr!=nil {
457+
// Try by ID?
458+
u,err=client.UserByID(ctx,forUser)
459+
iferr!=nil {
460+
returnxerrors.Errorf("the user %q was not found: %w",forUser,err)
461+
}
462+
}
463+
forUser=u.ID
464+
forEmail=u.Email
465+
}elseifforUser==coder.Me {
466+
forUser=""// coder.Me means it's not for someone else, set blank
467+
}
468+
451469
// ExactArgs(1) ensures our name value can't panic on an out of bounds.
452470
createReq:=&coder.CreateWorkspaceRequest{
453471
Name:args[0],
@@ -462,6 +480,7 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1
462480
ResourcePoolID:provider.ID,
463481
Namespace:provider.DefaultNamespace,
464482
EnableAutoStart:enableAutostart,
483+
ForUserID:forUser,
465484
}
466485

467486
// if any of these defaulted to their zero value we provision
@@ -489,9 +508,13 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1
489508
returnnil
490509
}
491510

511+
extraFlags:=""
512+
ifforEmail!=coder.Me&&forEmail!="" {
513+
extraFlags=" --user "+forEmail
514+
}
492515
clog.LogSuccess("creating workspace...",
493516
clog.BlankLine,
494-
clog.Tipf(`run "coder workspaces watch-build %s" to trail the build logs`,workspace.Name),
517+
clog.Tipf(`run "coder workspaces watch-build %s%s" to trail the build logs`,workspace.Name,extraFlags),
495518
)
496519
returnnil
497520
},
@@ -507,6 +530,7 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1
507530
cmd.Flags().BoolVar(&follow,"follow",false,"follow buildlog after initiating rebuild")
508531
cmd.Flags().BoolVar(&useCVM,"container-based-vm",false,"deploy the workspace as a Container-based VM")
509532
cmd.Flags().BoolVar(&enableAutostart,"enable-autostart",false,"automatically start this workspace at your preferred time.")
533+
cmd.Flags().StringVar(&forUser,"user",coder.Me,"Specify the user whose resources to target. This flag can only be used by admins and managers. Input an email or user id.")
510534
_=cmd.MarkFlagRequired("image")
511535
returncmd
512536
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp