Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3790bb

Browse files
authored
fix: use provided username when fetching workspaces (coder#12955)
1 parent 00fcf36 commit d3790bb

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

cli/open.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (r *RootCmd) openVSCode() *serpent.Command {
6464
// need to wait for the agent to start.
6565
workspaceQuery := inv.Args[0]
6666
autostart := true
67-
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, autostart, codersdk.Me, workspaceQuery)
67+
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, autostart, workspaceQuery)
6868
if err != nil {
6969
return xerrors.Errorf("get workspace and agent: %w", err)
7070
}

cli/ping.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (r *RootCmd) ping() *serpent.Command {
4242
_, workspaceAgent, err := getWorkspaceAndAgent(
4343
ctx, inv, client,
4444
false, // Do not autostart for a ping.
45-
codersdk.Me, workspaceName,
45+
workspaceName,
4646
)
4747
if err != nil {
4848
return err

cli/portforward.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (r *RootCmd) portForward() *serpent.Command {
7373
return xerrors.New("no port-forwards requested")
7474
}
7575

76-
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, codersdk.Me, inv.Args[0])
76+
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, inv.Args[0])
7777
if err != nil {
7878
return err
7979
}

cli/speedtest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (r *RootCmd) speedtest() *serpent.Command {
3939
ctx, cancel := context.WithCancel(inv.Context())
4040
defer cancel()
4141

42-
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, false, codersdk.Me, inv.Args[0])
42+
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, false, inv.Args[0])
4343
if err != nil {
4444
return err
4545
}

cli/ssh.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (r *RootCmd) ssh() *serpent.Command {
157157
}
158158
}
159159

160-
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, codersdk.Me, inv.Args[0])
160+
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, inv.Args[0])
161161
if err != nil {
162162
return err
163163
}
@@ -551,10 +551,12 @@ startWatchLoop:
551551
// getWorkspaceAgent returns the workspace and agent selected using either the
552552
// `<workspace>[.<agent>]` syntax via `in`.
553553
// If autoStart is true, the workspace will be started if it is not already running.
554-
func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *codersdk.Client, autostart bool, userID string, in string) (codersdk.Workspace, codersdk.WorkspaceAgent, error) { //nolint:revive
554+
func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *codersdk.Client, autostart bool, input string) (codersdk.Workspace, codersdk.WorkspaceAgent, error) { //nolint:revive
555555
var (
556-
workspace codersdk.Workspace
557-
workspaceParts = strings.Split(in, ".")
556+
workspace codersdk.Workspace
557+
// The input will be `owner/name.agent`
558+
// The agent is optional.
559+
workspaceParts = strings.Split(input, ".")
558560
err error
559561
)
560562

cli/vscodessh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (r *RootCmd) vscodeSSH() *serpent.Command {
110110
// will call this command after the workspace is started.
111111
autostart := false
112112

113-
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, autostart, owner, name)
113+
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, autostart, fmt.Sprintf("%s/%s", owner, name))
114114
if err != nil {
115115
return xerrors.Errorf("find workspace and agent: %w", err)
116116
}

0 commit comments

Comments
 (0)