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

Skip to content

Commit 5d6e386

Browse files
committed
fix lint errors
1 parent e130409 commit 5d6e386

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cli/ssh.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cli
33
import (
44
"context"
55
"io"
6-
"math/rand"
76
"net"
87
"os"
98
"strings"
@@ -20,6 +19,7 @@ import (
2019
"github.com/coder/coder/cli/cliui"
2120
"github.com/coder/coder/coderd/database"
2221
"github.com/coder/coder/codersdk"
22+
"github.com/coder/coder/cryptorand"
2323
)
2424

2525
func ssh() *cobra.Command {
@@ -52,7 +52,11 @@ func ssh() *cobra.Command {
5252
return xerrors.New("no workspaces to shuffle")
5353
}
5454

55-
workspace = workspaces[rand.Intn(len(workspaces))]
55+
idx, err := cryptorand.Intn(len(workspaces))
56+
if err != nil {
57+
return err
58+
}
59+
workspace = workspaces[idx]
5660
} else {
5761
err := cobra.MinimumNArgs(1)(cmd, args)
5862
if err != nil {
@@ -108,11 +112,14 @@ func ssh() *cobra.Command {
108112
}
109113
if agent.ID == uuid.Nil {
110114
if len(agents) > 1 {
111-
if shuffle {
112-
agent = agents[rand.Intn(len(agents))]
113-
} else {
115+
if !shuffle {
114116
return xerrors.New("you must specify the name of an agent")
115117
}
118+
idx, err := cryptorand.Intn(len(agents))
119+
if err != nil {
120+
return err
121+
}
122+
agent = agents[idx]
116123
} else {
117124
agent = agents[0]
118125
}
@@ -191,7 +198,7 @@ func ssh() *cobra.Command {
191198
}
192199
cliflag.BoolVarP(cmd.Flags(), &stdio, "stdio", "", "CODER_SSH_STDIO", false, "Specifies whether to emit SSH output over stdin/stdout.")
193200
cliflag.BoolVarP(cmd.Flags(), &shuffle, "shuffle", "", "CODER_SSH_SHUFFLE", false, "Specifies whether to choose a random workspace")
194-
cmd.Flags().MarkHidden("shuffle")
201+
_ = cmd.Flags().MarkHidden("shuffle")
195202

196203
return cmd
197204
}

0 commit comments

Comments
 (0)