Skip to content
Closed
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
38 changes: 24 additions & 14 deletions cmd/ocm-backplane/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package config

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/openshift/backplane-cli/pkg/cli/config"
)
Expand All @@ -21,33 +24,40 @@ func newGetCmd() *cobra.Command {
}

func getConfig(cmd *cobra.Command, args []string) error {
config, err := config.GetBackplaneConfiguration()
configPath, err := config.GetConfigFilePath()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may overwrite environment configuration settings. For example : GitHub - backplane-cli config.

if err != nil {
return err
}

proxyURL := ""
if config.ProxyURL != nil {
proxyURL = *config.ProxyURL
if _, err = os.Stat(configPath); err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("unable to access config file %s: %w", configPath, err)
}
} else {
viper.SetConfigFile(configPath)
viper.SetConfigType("json")
if err := viper.ReadInConfig(); err != nil {
return err
}
}

switch args[0] {
case URLConfigVar:
fmt.Printf("%s: %s\n", URLConfigVar, config.URL)
fmt.Printf("%s: %s\n", URLConfigVar, viper.GetString(URLConfigVar))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this changes config get url from reporting the effective URL to reading only the raw value stored in the config file?

The exist implementation has the effective URL is resolved from BACKPLANE_URL or the current OCM
env, while the file-backed url field is already deprecated and may not be present. (e.g with BACKPLANE_URL set and no url in the config file).

case ProxyURLConfigVar:
fmt.Printf("%s: %s\n", ProxyURLConfigVar, proxyURL)
fmt.Printf("%s: %s\n", ProxyURLConfigVar, strings.Join(viper.GetStringSlice(ProxyURLConfigVar), ", "))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this bypasses the existing HTTPS_PROXY binding and the first-working-proxy selection, so the output changes from the effective proxy to the raw list stored in the file?

case SessionConfigVar:
fmt.Printf("%s: %s\n", SessionConfigVar, config.SessionDirectory)
fmt.Printf("%s: %s\n", SessionConfigVar, viper.GetString(SessionConfigVar))
case PagerDutyAPIConfigVar:
fmt.Printf("%s: %s\n", PagerDutyAPIConfigVar, config.PagerDutyAPIKey)
fmt.Printf("%s: %s\n", PagerDutyAPIConfigVar, viper.GetString(PagerDutyAPIConfigVar))
case GovcloudVar:
fmt.Printf("%s: %t\n", GovcloudVar, config.Govcloud)
fmt.Printf("%s: %t\n", GovcloudVar, viper.GetBool(GovcloudVar))
case "all":
fmt.Printf("%s: %s\n", URLConfigVar, config.URL)
fmt.Printf("%s: %s\n", ProxyURLConfigVar, proxyURL)
fmt.Printf("%s: %s\n", SessionConfigVar, config.SessionDirectory)
fmt.Printf("%s: %s\n", PagerDutyAPIConfigVar, config.PagerDutyAPIKey)
fmt.Printf("%s: %t\n", GovcloudVar, config.Govcloud)
fmt.Printf("%s: %s\n", URLConfigVar, viper.GetString(URLConfigVar))
fmt.Printf("%s: %s\n", ProxyURLConfigVar, strings.Join(viper.GetStringSlice(ProxyURLConfigVar), ", "))
fmt.Printf("%s: %s\n", SessionConfigVar, viper.GetString(SessionConfigVar))
fmt.Printf("%s: %s\n", PagerDutyAPIConfigVar, viper.GetString(PagerDutyAPIConfigVar))
fmt.Printf("%s: %t\n", GovcloudVar, viper.GetBool(GovcloudVar))
default:
return fmt.Errorf("supported config variables are %s, %s, %s, %s, & %s", URLConfigVar, ProxyURLConfigVar, SessionConfigVar, PagerDutyAPIConfigVar, GovcloudVar)
}
Expand Down