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

feat: Allow making a workspace for another user as an admin#427

Merged
Emyrk merged 7 commits intomainfromstevenmasley/ch13817/masqurade_party
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletionscoder-sdk/workspace.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,6 +89,10 @@ type CreateWorkspaceRequest struct {
Namespace string `json:"namespace"`
EnableAutoStart bool `json:"autostart_enabled"`

// ForUserID is an optional param to create a workspace for another user
// other than the requester. This only works for admins and site managers.
ForUserID string `json:"for_user_id,omitempty"`

// TemplateID comes from the parse template route on cemanager.
TemplateID string `json:"template_id,omitempty"`
}
Expand Down
1 change: 1 addition & 0 deletionsdocs/coder_workspaces_create.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ coder workspaces create my-new-powerful-workspace --cpu 12 --disk 100 --memory 1
-o, --org string name of the organization the workspace should be created under.
--provider string name of Workspace Provider with which to create the workspace
-t, --tag string tag of the image the workspace will be based off of. (default "latest")
--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")
```

### Options inherited from parent commands
Expand Down
26 changes: 25 additions & 1 deletioninternal/cmd/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,6 +397,7 @@ func createWorkspaceCmd() *cobra.Command {
useCVM bool
providerName string
enableAutostart bool
forUser string // Optional
)

cmd := &cobra.Command{
Expand DownExpand Up@@ -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],
Expand All@@ -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
Expand DownExpand Up@@ -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" to trail the build logs`, workspace.Name),
clog.Tipf(`run "coder workspaces watch-build %s%s" to trail the build logs`, workspace.Name, extraFlags),
)
return nil
},
Expand All@@ -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
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp