Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix lint errors
  • Loading branch information
dwahler committed May 9, 2022
commit 781fab9ce13c26748e554b406affb4efa3bd43c5
19 changes: 13 additions & 6 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cli
import (
"context"
"io"
"math/rand"
"net"
"os"
"strings"
Expand All @@ -20,6 +19,7 @@ import (
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/cryptorand"
)

func ssh() *cobra.Command {
Expand Down Expand Up @@ -52,7 +52,11 @@ func ssh() *cobra.Command {
return xerrors.New("no workspaces to shuffle")
}

workspace = workspaces[rand.Intn(len(workspaces))]
idx, err := cryptorand.Intn(len(workspaces))
if err != nil {
return err
}
workspace = workspaces[idx]
} else {
err := cobra.MinimumNArgs(1)(cmd, args)
if err != nil {
Expand Down Expand Up @@ -108,11 +112,14 @@ func ssh() *cobra.Command {
}
if agent.ID == uuid.Nil {
if len(agents) > 1 {
if shuffle {
agent = agents[rand.Intn(len(agents))]
} else {
if !shuffle {
return xerrors.New("you must specify the name of an agent")
}
idx, err := cryptorand.Intn(len(agents))
if err != nil {
return err
}
agent = agents[idx]
} else {
agent = agents[0]
}
Expand Down Expand Up @@ -191,7 +198,7 @@ func ssh() *cobra.Command {
}
cliflag.BoolVarP(cmd.Flags(), &stdio, "stdio", "", "CODER_SSH_STDIO", false, "Specifies whether to emit SSH output over stdin/stdout.")
cliflag.BoolVarP(cmd.Flags(), &shuffle, "shuffle", "", "CODER_SSH_SHUFFLE", false, "Specifies whether to choose a random workspace")
cmd.Flags().MarkHidden("shuffle")
_ = cmd.Flags().MarkHidden("shuffle")

return cmd
}
Expand Down