This repository was archived by the owner on Aug 30, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork18
feat: Allow making a workspace for another user as an admin#427
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
918ce66
Allow making a workspace for another user as an admin
Emyrk2f51c63
Use standard flag
Emyrk2fdb9e8
Make gendocs
Emyrk08e2e81
Adjust the output to watch the build logs
Emyrkf26d978
Fix text for user flag
Emyrk7a0b09b
Make gendocs
Emyrk48441f4
Fix forUser field
EmyrkFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionscoder-sdk/workspace.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsdocs/coder_workspaces_create.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
26 changes: 25 additions & 1 deletioninternal/cmd/workspaces.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -397,6 +397,7 @@ func createWorkspaceCmd() *cobra.Command { | ||
useCVM bool | ||
providerName string | ||
enableAutostart bool | ||
forUser string // Optional | ||
) | ||
cmd := &cobra.Command{ | ||
@@ -448,6 +449,23 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1 | ||
} | ||
} | ||
var forEmail string | ||
if forUser != "" && forUser != coder.Me { | ||
// Making a workspace for another user, do they exist? | ||
u, err := client.UserByEmail(ctx, forUser) | ||
if err != nil { | ||
// Try by ID? | ||
u, err = client.UserByID(ctx, forUser) | ||
if err != nil { | ||
return xerrors.Errorf("the user %q was not found: %w", forUser, err) | ||
} | ||
} | ||
forUser = u.ID | ||
forEmail = u.Email | ||
} else if forUser == coder.Me { | ||
forUser = "" // coder.Me means it's not for someone else, set blank | ||
} | ||
// ExactArgs(1) ensures our name value can't panic on an out of bounds. | ||
createReq := &coder.CreateWorkspaceRequest{ | ||
Name: args[0], | ||
@@ -462,6 +480,7 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1 | ||
ResourcePoolID: provider.ID, | ||
Namespace: provider.DefaultNamespace, | ||
EnableAutoStart: enableAutostart, | ||
ForUserID: forUser, | ||
} | ||
// 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 | ||
return nil | ||
} | ||
extraFlags := "" | ||
if forEmail != coder.Me && forEmail != "" { | ||
extraFlags = " --user " + forEmail | ||
} | ||
clog.LogSuccess("creating workspace...", | ||
clog.BlankLine, | ||
clog.Tipf(`run "coder workspaces watch-build %s%s" to trail the build logs`, workspace.Name, extraFlags), | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
) | ||
return nil | ||
}, | ||
@@ -507,6 +530,7 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1 | ||
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild") | ||
cmd.Flags().BoolVar(&useCVM, "container-based-vm", false, "deploy the workspace as a Container-based VM") | ||
cmd.Flags().BoolVar(&enableAutostart, "enable-autostart", false, "automatically start this workspace at your preferred time.") | ||
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.") | ||
_ = cmd.MarkFlagRequired("image") | ||
return cmd | ||
} | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.