Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions cmd/list/accessrequests/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package accessrequests

import (
"context"
"fmt"
"os"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -38,6 +37,7 @@ func NewListAccessRequestsCommand() *cobra.Command {
}

output.AddFlag(cmd)
output.AddHideEmptyColumnsFlag(cmd)
ocm.AddOptionalClusterFlag(cmd)
return cmd
}
Expand Down Expand Up @@ -67,12 +67,34 @@ func ListAccessRequestsRunner() rosa.CommandRunner {
}
return nil
}

headers := []string{"STATE", "ID", "CLUSTER ID", "UPDATED AT"}

var tableData [][]string
for _, accessRequest := range accessRequests {
row := []string{
string(accessRequest.Status().State()),
accessRequest.ID(),
accessRequest.ClusterId(),
accessRequest.UpdatedAt().UTC().Format(time.UnixDate),
}
tableData = append(tableData, row)
}

if output.ShouldHideEmptyColumns() {
tableData = output.RemoveEmptyColumns(headers, tableData)
} else {
tableData = append([][]string{headers}, tableData...)
}

writer := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
output, hasPending, pendingId := getAccessRequestsOutput(clusterId, accessRequests)
fmt.Fprint(writer, output)
output.BuildTable(writer, "\t", tableData)
if err := writer.Flush(); err != nil {
return err
}

hasPending, pendingId := checkForPendingRequests(clusterId, accessRequests)

if hasPending {
r.Reporter.Infof("Run the following command to approve or deny the Access Request:\n\n"+
" rosa create decision --access-request %s --decision Approved\n"+
Expand All @@ -84,23 +106,22 @@ func ListAccessRequestsRunner() rosa.CommandRunner {
}
}

func getAccessRequestsOutput(clusterId string, accessRequests []*v1.AccessRequest) (string, bool, string) {
output := "STATE\tID\tCLUSTER ID\tUPDATED AT\n"
func checkForPendingRequests(clusterId string, accessRequests []*v1.AccessRequest) (bool, string) {
hasPending := false
id := "<ID>"
for _, accessRequest := range accessRequests {
if accessRequest.Status().State() == v1.AccessRequestStatePending {
if accessRequest.Status().State() == v1.AccessRequestStatePending ||
accessRequest.Status().State() == v1.AccessRequestStateApproved {
hasPending = true
if clusterId != "" {
id = accessRequest.ID()
}
// Once we find the first pending/approved request for the cluster, we can break
// since we only need one ID for the suggestion message
if clusterId != "" && hasPending {
break
}
}
output += fmt.Sprintf("%s\t%s\t%s\t%s\n",
accessRequest.Status().State(),
accessRequest.ID(),
accessRequest.ClusterId(),
accessRequest.UpdatedAt().Format(time.UnixDate))
}

return output, hasPending, id
return hasPending, id
Comment on lines +109 to +126
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command has been altered pretty heavily in terms of how it gathers data and im worried it will have different a different table for certain clusters after these changes. Could you provide some output from it to show that it works the same?

}
2 changes: 0 additions & 2 deletions cmd/list/accessrequests/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package accessrequests

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -126,7 +125,6 @@ var _ = Describe("rosa attach policy", func() {
Expect(err).NotTo(HaveOccurred())

stdOut, _ := t.StdOutReader.Read()
fmt.Println(stdOut)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change

Expect(stdOut).To(Equal(accessRequestsOutput))
})

Expand Down
30 changes: 21 additions & 9 deletions cmd/list/accountroles/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package accountroles

import (
"fmt"
"os"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -55,6 +54,7 @@ func init() {
"List only account-roles that are associated with the given version.",
)
output.AddFlag(Cmd)
output.AddHideEmptyColumnsFlag(Cmd)
}

func run(_ *cobra.Command, _ []string) {
Expand Down Expand Up @@ -108,23 +108,35 @@ func run(_ *cobra.Command, _ []string) {
os.Exit(0)
}

// Create the writer that will be used to print the tabulated results:
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(writer, "ROLE NAME\tROLE TYPE\tROLE ARN\tOPENSHIFT VERSION\tAWS Managed\n")
headers := []string{"ROLE NAME", "ROLE TYPE", "ROLE ARN", "OPENSHIFT VERSION", "AWS Managed"}

var tableData [][]string
for _, accountRole := range accountRoles {
awsManaged := "No"
if accountRole.ManagedPolicy {
awsManaged = "Yes"
}
fmt.Fprintf(
writer,
"%s\t%s\t%s\t%s\t%s\n",
row := []string{
accountRole.RoleName,
accountRole.RoleType,
accountRole.RoleARN,
accountRole.Version,
awsManaged,
)
}
tableData = append(tableData, row)
Comment on lines -120 to +126
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified:

tableData = append(tableData, []string{
    accountRole.RoleName,
    ...
    ...
})

}

if output.ShouldHideEmptyColumns() {
tableData = output.RemoveEmptyColumns(headers, tableData)
} else {
tableData = append([][]string{headers}, tableData...)
}
writer.Flush()

writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
output.BuildTable(writer, "\t", tableData)
if err := writer.Flush(); err != nil {
_ = r.Reporter.Errorf("Failed to flush output: %v", err)
os.Exit(1)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file looks great


}
56 changes: 45 additions & 11 deletions cmd/list/addon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package addon

import (
"fmt"
"os"
"text/tabwriter"

Expand Down Expand Up @@ -56,6 +55,7 @@ func init() {
)

output.AddFlag(Cmd)
output.AddHideEmptyColumnsFlag(Cmd)
}

// When no specific cluster id is provided by the user, this function lists all available AddOns
Expand All @@ -81,18 +81,34 @@ func listAllAddOns(r *rosa.Runtime) {
os.Exit(0)
}

// Create the writer that will be used to print the tabulated results:
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(writer, "ID\t\tNAME\t\tAVAILABILITY\n")
headers := []string{"ID", "NAME", "AVAILABILITY"}
var tableData [][]string
for _, addOnResource := range addOnResources {
availability := "unavailable"
if addOnResource.Available {
availability = "available"
}
fmt.Fprintf(writer, "%s\t\t%s\t\t%s\n", addOnResource.AddOn.ID(), addOnResource.AddOn.Name(), availability)
row := []string{
addOnResource.AddOn.ID(),
addOnResource.AddOn.Name(),
availability,
}
tableData = append(tableData, row)
}

if output.ShouldHideEmptyColumns() {
tableData = output.RemoveEmptyColumns(headers, tableData)
} else {
tableData = append([][]string{headers}, tableData...)
}
writer.Flush()

writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
output.BuildTable(writer, "\t\t", tableData)

if err := writer.Flush(); err != nil {
_ = r.Reporter.Errorf("Failed to flush output: %v", err)
os.Exit(1)
}
os.Exit(0)
}

Expand Down Expand Up @@ -142,13 +158,31 @@ func listClusterAddOns(clusterKey string, r *rosa.Runtime) {
os.Exit(0)
}

// Create the writer that will be used to print the tabulated results:
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(writer, "ID\t\tNAME\t\tSTATE\n")
headers := []string{"ID", "NAME", "STATE"}

var tableData [][]string
for _, clusterAddOn := range clusterAddOns {
fmt.Fprintf(writer, "%s\t\t%s\t\t%s\n", clusterAddOn.ID, clusterAddOn.Name, clusterAddOn.State)
row := []string{
clusterAddOn.ID,
clusterAddOn.Name,
clusterAddOn.State,
}
tableData = append(tableData, row)
}

if output.ShouldHideEmptyColumns() {
tableData = output.RemoveEmptyColumns(headers, tableData)
} else {
tableData = append([][]string{headers}, tableData...)
}

writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
output.BuildTable(writer, "\t\t", tableData)

if err := writer.Flush(); err != nil {
_ = r.Reporter.Errorf("Failed to flush output: %v", err)
os.Exit(1)
}
writer.Flush()
}

func run(_ *cobra.Command, _ []string) {
Expand Down
27 changes: 19 additions & 8 deletions cmd/list/breakglasscredential/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var Cmd = &cobra.Command{
func init() {
ocm.AddClusterFlag(Cmd)
output.AddFlag(Cmd)
output.AddHideEmptyColumnsFlag(Cmd)
}

func run(cmd *cobra.Command, _ []string) {
Expand Down Expand Up @@ -69,18 +70,28 @@ func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command) error {
return nil
}

// Create the writer that will be used to print the tabulated results:
writer := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)

fmt.Fprintf(writer, "ID\tUSERNAME\tSTATUS\n")
headers := []string{"ID", "USERNAME", "STATUS"}
var tableData [][]string
for _, credential := range breakGlassCredentials {
fmt.Fprintf(writer, "%s\t%s\t%s\n",
row := []string{
credential.ID(),
credential.Username(),
credential.Status(),
)
string(credential.Status()),
}
tableData = append(tableData, row)
}

if output.ShouldHideEmptyColumns() {
tableData = output.RemoveEmptyColumns(headers, tableData)
} else {
tableData = append([][]string{headers}, tableData...)
}
writer.Flush()

writer := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
output.BuildTable(writer, "\t", tableData)

if err := writer.Flush(); err != nil {
return err
}
return nil
}
34 changes: 23 additions & 11 deletions cmd/list/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package cluster

import (
"fmt"
"os"
"text/tabwriter"

Expand Down Expand Up @@ -52,6 +51,7 @@ func init() {
flags.SortFlags = false

output.AddFlag(Cmd)
output.AddHideEmptyColumnsFlag(Cmd)
flags.BoolVarP(&args.listAll, "all", "a", false, "List all clusters across different AWS "+
"accounts under the same Red Hat organization")
flags.StringVar(&args.accountRoleArn, "account-role-arn", "", "List all clusters "+
Expand Down Expand Up @@ -107,25 +107,37 @@ func run(_ *cobra.Command, _ []string) {
os.Exit(0)
}

// Create the writer that will be used to print the tabulated results:
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(writer, "ID\tNAME\tSTATE\tTOPOLOGY\n")
headers := []string{"ID", "NAME", "STATE", "TOPOLOGY"}
var tableData [][]string
for _, cluster := range clusters {
typeOutput := "Classic"
typeOutput := ""
if cluster.AWS() != nil && cluster.AWS().STS() != nil && cluster.AWS().STS().Enabled() {
typeOutput = "Classic (STS)"
}
if cluster.Hypershift().Enabled() {
typeOutput = "Hosted CP"
}
fmt.Fprintf(
writer,
"%s\t%s\t%s\t%s\n",

row := []string{
cluster.ID(),
cluster.Name(),
cluster.State(),
string(cluster.State()),
typeOutput,
)
}
tableData = append(tableData, row)
}

if output.ShouldHideEmptyColumns() {
tableData = output.RemoveEmptyColumns(headers, tableData)
} else {
tableData = append([][]string{headers}, tableData...)
}

writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
output.BuildTable(writer, "\t", tableData)

if err := writer.Flush(); err != nil {
_ = r.Reporter.Errorf("Failed to flush output: %v", err)
os.Exit(1)
}
writer.Flush()
}
Loading