Skip to content

Commit

Permalink
Prevent login spam on large clusters
Browse files Browse the repository at this point in the history
Added conditional to project list that will suppress project
list output on login if the list is greater than 50.

Bug 1542326
  • Loading branch information
Oats87 committed Feb 21, 2018
1 parent fa82543 commit 769bdfd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pkg/oc/cli/cmd/login/loginoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <projectname>':\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 <projectname>':\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)
}

Expand Down

0 comments on commit 769bdfd

Please sign in to comment.