From 99ac2be764aa30a247ea6a3382d1db13861bef2b Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Wed, 21 Feb 2018 17:15:41 -0800 Subject: [PATCH] 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 --- pkg/oc/cli/cmd/login/loginoptions.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/oc/cli/cmd/login/loginoptions.go b/pkg/oc/cli/cmd/login/loginoptions.go index b8ed0c4582ac..47ddbf2bf624 100644 --- a/pkg/oc/cli/cmd/login/loginoptions.go +++ b/pkg/oc/cli/cmd/login/loginoptions.go @@ -34,6 +34,8 @@ import ( const defaultClusterURL = "https://localhost:8443" +const projectsItemsSuppressThreshold = 50 + // LoginOptions is a helper for the login and setup process, gathers all information required for a // successful login and eventual update of config files. // Depending on the Reader present it can be interactive, asking for terminal input in @@ -316,16 +318,21 @@ func (o *LoginOptions) gatherProjectInfo() error { return err } o.Project = current.Name - - fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project ':\n\n", o.CommandName) - for _, p := range projects.List() { - if o.Project == p { - fmt.Fprintf(o.Out, " * %s\n", p) - } else { - fmt.Fprintf(o.Out, " %s\n", p) + + // 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 + if len(projectsItems) > projectsItemsSuppressThreshold { + 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) + } else { + fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project ':\n\n", o.CommandName) + for _, p := range projects.List() { + if o.Project == p { + fmt.Fprintf(o.Out, " * %s\n", p) + } else { + fmt.Fprintf(o.Out, " %s\n", p) + } } + fmt.Fprintln(o.Out) } - fmt.Fprintln(o.Out) fmt.Fprintf(o.Out, "Using project %q.\n", o.Project) }