Skip to content

Commit

Permalink
Merge pull request #671 from Mhodesty/OSD-24997
Browse files Browse the repository at this point in the history
OSD-24997: Show if a user is banned when using osdctl cluster context
  • Loading branch information
openshift-merge-bot[bot] authored Feb 24, 2025
2 parents b89b070 + 0d81288 commit 12e4598
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/cluster/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ type contextData struct {

// OCM Cluster description
Description string

// User Banned Information
UserBanned bool
BanCode string
BanDescription string
}

// newCmdContext implements the context command to show the current context of a cluster
Expand Down Expand Up @@ -241,6 +246,9 @@ func (o *contextOptions) printLongOutput(data *contextData) {

// Print Dynatrace URL
printDynatraceResources(data)

// Print User Banned Details
printUserBannedStatus(data)
}

func (o *contextOptions) printShortOutput(data *contextData) {
Expand Down Expand Up @@ -378,6 +386,22 @@ func (o *contextOptions) generateContextData() (*contextData, []error) {
}
}

GetBannedUser := func() {
defer wg.Done()
defer utils.StartDelayTracker(o.verbose, "Check Banned User").End()
subscription, err := utils.GetSubscription(ocmClient, data.ClusterID)
if err != nil {
errors = append(errors, fmt.Errorf("error while getting subscripton %v", err))
}
creator, err := utils.GetAccount(ocmClient, subscription.Creator().ID())
if err != nil {
errors = append(errors, fmt.Errorf("error while checking if user is banned %v", err))
}
data.UserBanned = creator.Banned()
data.BanCode = creator.BanCode()
data.BanDescription = creator.BanDescription()
}

GetJiraIssues := func() {
defer wg.Done()
defer utils.StartDelayTracker(o.verbose, "Jira Issues").End()
Expand Down Expand Up @@ -457,6 +481,7 @@ func (o *contextOptions) generateContextData() (*contextData, []error) {
GetSupportExceptions,
GetPagerDutyAlerts,
GetDynatraceDetails,
GetBannedUser,
)

if o.output == longOutputConfigValue {
Expand Down Expand Up @@ -734,6 +759,21 @@ func printDynatraceResources(data *contextData) {
}
}

func printUserBannedStatus(data *contextData) {
var name string = "User Ban Details"
fmt.Println("\n" + delimiter + name)
if data.UserBanned {
fmt.Println("User is banned")
fmt.Printf("Ban code = %v\n", data.BanCode)
fmt.Printf("Ban description = %v\n", data.BanDescription)
if data.BanCode == BanCodeExportControlCompliance {
fmt.Println("User banned due to export control compliance.\nPlease follow the steps detailed here: https://github.com/openshift/ops-sop/blob/master/v4/alerts/UpgradeConfigSyncFailureOver4HrSRE.md#user-banneddisabled-due-to-export-control-compliance .")
}
} else {
fmt.Println("User is not banned")
}
}

func (data *contextData) printClusterHeader() {
clusterHeader := fmt.Sprintf("%s -- %s", data.ClusterName, data.ClusterID)
fmt.Println(strings.Repeat("=", len(clusterHeader)))
Expand Down

0 comments on commit 12e4598

Please sign in to comment.