fix: use provided username when fetching workspaces (#12955)

This commit is contained in:
Kyle Carberry 2024-04-13 14:39:57 -04:00 committed by GitHub
parent 00fcf36999
commit d3790bb5be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 11 additions and 9 deletions

View File

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

View File

@ -42,7 +42,7 @@ func (r *RootCmd) ping() *serpent.Command {
_, workspaceAgent, err := getWorkspaceAndAgent( _, workspaceAgent, err := getWorkspaceAndAgent(
ctx, inv, client, ctx, inv, client,
false, // Do not autostart for a ping. false, // Do not autostart for a ping.
codersdk.Me, workspaceName, workspaceName,
) )
if err != nil { if err != nil {
return err return err

View File

@ -73,7 +73,7 @@ func (r *RootCmd) portForward() *serpent.Command {
return xerrors.New("no port-forwards requested") return xerrors.New("no port-forwards requested")
} }
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, codersdk.Me, inv.Args[0]) workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, inv.Args[0])
if err != nil { if err != nil {
return err return err
} }

View File

@ -39,7 +39,7 @@ func (r *RootCmd) speedtest() *serpent.Command {
ctx, cancel := context.WithCancel(inv.Context()) ctx, cancel := context.WithCancel(inv.Context())
defer cancel() defer cancel()
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, false, codersdk.Me, inv.Args[0]) _, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, false, inv.Args[0])
if err != nil { if err != nil {
return err return err
} }

View File

@ -157,7 +157,7 @@ func (r *RootCmd) ssh() *serpent.Command {
} }
} }
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, codersdk.Me, inv.Args[0]) workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, inv.Args[0])
if err != nil { if err != nil {
return err return err
} }
@ -551,10 +551,12 @@ startWatchLoop:
// getWorkspaceAgent returns the workspace and agent selected using either the // getWorkspaceAgent returns the workspace and agent selected using either the
// `<workspace>[.<agent>]` syntax via `in`. // `<workspace>[.<agent>]` syntax via `in`.
// If autoStart is true, the workspace will be started if it is not already running. // If autoStart is true, the workspace will be started if it is not already running.
func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *codersdk.Client, autostart bool, userID string, in string) (codersdk.Workspace, codersdk.WorkspaceAgent, error) { //nolint:revive func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *codersdk.Client, autostart bool, input string) (codersdk.Workspace, codersdk.WorkspaceAgent, error) { //nolint:revive
var ( var (
workspace codersdk.Workspace workspace codersdk.Workspace
workspaceParts = strings.Split(in, ".") // The input will be `owner/name.agent`
// The agent is optional.
workspaceParts = strings.Split(input, ".")
err error err error
) )

View File

@ -110,7 +110,7 @@ func (r *RootCmd) vscodeSSH() *serpent.Command {
// will call this command after the workspace is started. // will call this command after the workspace is started.
autostart := false autostart := false
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, autostart, owner, name) _, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, autostart, fmt.Sprintf("%s/%s", owner, name))
if err != nil { if err != nil {
return xerrors.Errorf("find workspace and agent: %w", err) return xerrors.Errorf("find workspace and agent: %w", err)
} }