mirror of
https://github.com/coder/coder.git
synced 2026-10-28 02:42:54 +08:00
feat: add ability to make workspace for other user from cli (#8481)
* feat: add ability to make workspace for other user from cli * Add example to show functionality
This commit is contained in:
+19
-13
@@ -626,24 +626,30 @@ func CurrentOrganization(inv *clibase.Invocation, client *codersdk.Client) (code
|
||||
return orgs[0], nil
|
||||
}
|
||||
|
||||
func splitNamedWorkspace(identifier string) (owner string, workspaceName string, err error) {
|
||||
parts := strings.Split(identifier, "/")
|
||||
|
||||
switch len(parts) {
|
||||
case 1:
|
||||
owner = codersdk.Me
|
||||
workspaceName = parts[0]
|
||||
case 2:
|
||||
owner = parts[0]
|
||||
workspaceName = parts[1]
|
||||
default:
|
||||
return "", "", xerrors.Errorf("invalid workspace name: %q", identifier)
|
||||
}
|
||||
return owner, workspaceName, nil
|
||||
}
|
||||
|
||||
// namedWorkspace fetches and returns a workspace by an identifier, which may be either
|
||||
// a bare name (for a workspace owned by the current user) or a "user/workspace" combination,
|
||||
// where user is either a username or UUID.
|
||||
func namedWorkspace(ctx context.Context, client *codersdk.Client, identifier string) (codersdk.Workspace, error) {
|
||||
parts := strings.Split(identifier, "/")
|
||||
|
||||
var owner, name string
|
||||
switch len(parts) {
|
||||
case 1:
|
||||
owner = codersdk.Me
|
||||
name = parts[0]
|
||||
case 2:
|
||||
owner = parts[0]
|
||||
name = parts[1]
|
||||
default:
|
||||
return codersdk.Workspace{}, xerrors.Errorf("invalid workspace name: %q", identifier)
|
||||
owner, name, err := splitNamedWorkspace(identifier)
|
||||
if err != nil {
|
||||
return codersdk.Workspace{}, err
|
||||
}
|
||||
|
||||
return client.WorkspaceByOwnerAndName(ctx, owner, name, codersdk.WorkspaceOptions{})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user