diff --git a/cmd/ocm/list/rhRegion/cmd.go b/cmd/ocm/list/rhRegion/cmd.go index 13c97b0b..14a6eec4 100644 --- a/cmd/ocm/list/rhRegion/cmd.go +++ b/cmd/ocm/list/rhRegion/cmd.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/openshift-online/ocm-cli/pkg/config" - "github.com/openshift-online/ocm-cli/pkg/ocm" "github.com/openshift-online/ocm-cli/pkg/rhRegion" "github.com/spf13/cobra" ) @@ -27,27 +26,14 @@ func run(cmd *cobra.Command, argv []string) error { return fmt.Errorf("Not logged in, run the 'login' command") } - connection, err := ocm.NewConnection().Build() + regions, err := rhRegion.GetRhRegions(cfg.URL) if err != nil { - return err + return fmt.Errorf("Failed to get OCM regions: %w", err) } - defer connection.Close() - // Check that the configuration has credentials or tokens that don't have expired: - armed, reason, err := cfg.Armed() - if err != nil { - return err - } - if !armed { - return fmt.Errorf("Not logged in, %s, run the 'login' command", reason) - } - - regions, err := rhRegion.GetRhRegions(connection.URL()) - if err != nil { - return fmt.Errorf("Failed to get OCM regions: %v", err) - } for regionName := range regions { fmt.Println(regionName) } return nil + } diff --git a/cmd/ocm/login/cmd.go b/cmd/ocm/login/cmd.go index f5c8c28f..6267fd9b 100644 --- a/cmd/ocm/login/cmd.go +++ b/cmd/ocm/login/cmd.go @@ -247,7 +247,6 @@ func run(cmd *cobra.Command, argv []string) error { // Update the configuration with the values given in the command line: cfg.TokenURL = tokenURL - cfg.RhRegion = args.rhRegion cfg.ClientID = clientID cfg.ClientSecret = args.clientSecret cfg.Scopes = args.scopes @@ -276,10 +275,10 @@ func run(cmd *cobra.Command, argv []string) error { } // If an OCM region is provided, update the config URL with the SDK generated URL - if cfg.RhRegion != "" { + if args.rhRegion != "" { regValue, err := rhRegion.GetRhRegion(connection.URL(), args.rhRegion) if err != nil { - return fmt.Errorf("Can't find region: %v", err) + return fmt.Errorf("Can't find region: %w", err) } cfg.URL = regValue.URL } diff --git a/go.mod b/go.mod index 91a04916..66770e40 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a - golang.org/x/net v0.10.0 golang.org/x/term v0.10.0 golang.org/x/text v0.11.0 gopkg.in/yaml.v3 v3.0.1 @@ -73,10 +72,9 @@ require ( github.com/sirupsen/logrus v1.9.0 // indirect github.com/zgalor/weberr v0.7.0 // indirect golang.org/x/crypto v0.1.0 // indirect + golang.org/x/net v0.10.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/tools v0.9.3 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) - -replace github.com/openshift-online/ocm-sdk-go v0.1.388 => ../ocm-sdk-go diff --git a/go.sum b/go.sum index 8e4d3309..a8307aaa 100644 --- a/go.sum +++ b/go.sum @@ -312,6 +312,8 @@ github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ= +github.com/openshift-online/ocm-sdk-go v0.1.388 h1:c8yPCUQwJm3QhcVmnyMPFpeDtxPBaPeYh5hLv1vg9YQ= +github.com/openshift-online/ocm-sdk-go v0.1.388/go.mod h1:/+VFIw1iW2H0jEkFH4GnbL/liWareyzsL0w7mDIudB4= github.com/openshift/rosa v1.2.24 h1:vv0yYnWHx6CCPEAau/0rS54P2ksaf+uWXb1TQPWxiYE= github.com/openshift/rosa v1.2.24/go.mod h1:MVXB27O3PF8WoOic23I03mmq6/9kVxpFx6FKyLMCyrQ= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= diff --git a/pkg/config/config.go b/pkg/config/config.go index 09dbda2d..8284af97 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -48,10 +48,9 @@ type Config struct { RefreshToken string `json:"refresh_token,omitempty" doc:"Offline or refresh token."` Scopes []string `json:"scopes,omitempty" doc:"OpenID scope. If this option is used it will replace completely the default scopes. Can be repeated multiple times to specify multiple scopes."` TokenURL string `json:"token_url,omitempty" doc:"OpenID token URL."` - RhRegion string - URL string `json:"url,omitempty" doc:"URL of the API gateway. The value can be the complete URL or an alias. The valid aliases are 'production', 'staging' and 'integration'."` - User string `json:"user,omitempty" doc:"User name."` - Pager string `json:"pager,omitempty" doc:"Pager command, for example 'less'. If empty no pager will be used."` + URL string `json:"url,omitempty" doc:"URL of the API gateway. The value can be the complete URL or an alias. The valid aliases are 'production', 'staging' and 'integration'."` + User string `json:"user,omitempty" doc:"User name."` + Pager string `json:"pager,omitempty" doc:"Pager command, for example 'less'. If empty no pager will be used."` } // Load loads the configuration from the configuration file. If the configuration file doesn't exist @@ -271,10 +270,6 @@ func (c *Config) Connection() (connection *sdk.Connection, err error) { } builder.Insecure(c.Insecure) - if c.RhRegion != "" { - builder.RhRegion(c.RhRegion) - } - // Create the connection: connection, err = builder.Build() if err != nil { diff --git a/pkg/rhRegion/rhRegion.go b/pkg/rhRegion/rhRegion.go index b6e9bbb9..432ca8ce 100644 --- a/pkg/rhRegion/rhRegion.go +++ b/pkg/rhRegion/rhRegion.go @@ -23,11 +23,11 @@ func GetRhRegions(ocmServiceUrl string) (map[string]Region, error) { // Adding nolint here in order to prevent linter from failing due to variable http get resp, err := http.Get(url) //nolint if err != nil { - return regions, fmt.Errorf("Can't retrieve shards: %s\n", err) + return regions, fmt.Errorf("Can't retrieve shards: %s", err) } err = json2.NewDecoder(resp.Body).Decode(®ions) if err != nil { - return regions, fmt.Errorf("Can't decode shards: %s\n", err) + return regions, fmt.Errorf("Can't decode shards: %s", err) } return regions, nil } @@ -40,7 +40,7 @@ func GetRhRegion(ocmServiceUrl string, regionName string) (Region, error) { regionName = fmt.Sprintf("rh-%s", regionName) regVal, ok := regions[regionName] if !ok { - return Region{}, fmt.Errorf("Can't find region %s\n", regionName) + return Region{}, fmt.Errorf("Can't find region %s", regionName) } return regVal, nil } @@ -54,7 +54,7 @@ func DetermineRegionDiscoveryUrl(ocmServiceUrl string) (string, error) { //TODO: Remove the OR condition from this if statement before the MR merge if strings.HasSuffix(baseUrl.Hostname(), "integration.openshift.com") || true { regionDiscoveryHost = "api.integration.openshift.com" - } else if strings.HasSuffix(baseUrl.Hostname(), "integration.openshift.com") { + } else if strings.HasSuffix(baseUrl.Hostname(), "stage.openshift.com") { regionDiscoveryHost = "api.stage.openshift.com" } return fmt.Sprintf("https://%s/static/ocm-shards.json", regionDiscoveryHost), nil