From 769bdfdd9a780b75b73f599f0b95973ded6224bf Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Wed, 21 Feb 2018 15:56:13 -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. 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..a9886502f3e2 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 projectsItemsSurpressThreshold = 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) + + // Surpress 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) > projectsItemsSurpressThreshold { + fmt.Fprintf(o.Out, "You have access to %d projects, the list has been surpressed. You can list all projects with '%s projects'\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) }