Skip to content

Commit 99ac2be

Browse files
committed
Prevent login spam on large clusters
Added conditional to project list that will suppress project list output on login if the list is greater than 50. One last commit to correct suppressed being misspelled Bug 1542326
1 parent fa82543 commit 99ac2be

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pkg/oc/cli/cmd/login/loginoptions.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434

3535
const defaultClusterURL = "https://localhost:8443"
3636

37+
const projectsItemsSuppressThreshold = 50
38+
3739
// LoginOptions is a helper for the login and setup process, gathers all information required for a
3840
// successful login and eventual update of config files.
3941
// Depending on the Reader present it can be interactive, asking for terminal input in
@@ -316,16 +318,21 @@ func (o *LoginOptions) gatherProjectInfo() error {
316318
return err
317319
}
318320
o.Project = current.Name
319-
320-
fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project <projectname>':\n\n", o.CommandName)
321-
for _, p := range projects.List() {
322-
if o.Project == p {
323-
fmt.Fprintf(o.Out, " * %s\n", p)
324-
} else {
325-
fmt.Fprintf(o.Out, " %s\n", p)
321+
322+
// Suppress project listing if the number of projects available to the user is greater than the threshold. Prevents unnecessarily noisy logins on clusters with large numbers of projects
323+
if len(projectsItems) > projectsItemsSuppressThreshold {
324+
fmt.Fprintf(o.Out, "You have access to %d projects, the list has been suppressed. You can list all projects with '%s projects'\n\n", len(projectsItems), o.CommandName)
325+
} else {
326+
fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project <projectname>':\n\n", o.CommandName)
327+
for _, p := range projects.List() {
328+
if o.Project == p {
329+
fmt.Fprintf(o.Out, " * %s\n", p)
330+
} else {
331+
fmt.Fprintf(o.Out, " %s\n", p)
332+
}
326333
}
334+
fmt.Fprintln(o.Out)
327335
}
328-
fmt.Fprintln(o.Out)
329336
fmt.Fprintf(o.Out, "Using project %q.\n", o.Project)
330337
}
331338

0 commit comments

Comments
 (0)