From 028816cc0b3d411398da6209fac048fac17ca01d Mon Sep 17 00:00:00 2001 From: Ma77C0nd0n Date: Thu, 18 May 2023 18:37:36 +0100 Subject: [PATCH 1/2] CLOUDP-172196: migrate ListCloudProviderRegions --- .../atlas/clusters/availableregions/list.go | 5 +- .../clusters/availableregions/list_test.go | 11 +++-- .../clusters/region_tier_autocomplete.go | 15 +++--- .../clusters/region_tier_autocomplete_test.go | 29 ++++++------ .../cli/atlas/quickstart/cluster_setup.go | 7 +-- internal/mocks/mock_cloud_provider_regions.go | 6 +-- internal/mocks/mock_clusters.go | 4 +- internal/search/search.go | 5 +- internal/search/search_test.go | 46 ++++++++++--------- internal/store/cloud_provider_regions.go | 14 +++--- 10 files changed, 76 insertions(+), 66 deletions(-) diff --git a/internal/cli/atlas/clusters/availableregions/list.go b/internal/cli/atlas/clusters/availableregions/list.go index 36e6e38036..6423ec3634 100644 --- a/internal/cli/atlas/clusters/availableregions/list.go +++ b/internal/cli/atlas/clusters/availableregions/list.go @@ -22,6 +22,7 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/cli/require" "github.com/mongodb/mongodb-atlas-cli/internal/config" "github.com/mongodb/mongodb-atlas-cli/internal/flag" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/mongodb/mongodb-atlas-cli/internal/store" "github.com/mongodb/mongodb-atlas-cli/internal/usage" "github.com/spf13/cobra" @@ -49,9 +50,9 @@ var listTemplate = `PROVIDER INSTANCE SIZE REGIONS{{range .Results}}{{ $provider func (opts *ListOpts) Run() error { // Set provider if existent - var provider []*string + var provider *[]string if opts.provider != "" { - provider = []*string{&opts.provider} + provider = pointer.Get([]string{opts.provider}) } r, err := opts.store.CloudProviderRegions(opts.ConfigProjectID(), opts.tier, provider) diff --git a/internal/cli/atlas/clusters/availableregions/list_test.go b/internal/cli/atlas/clusters/availableregions/list_test.go index 4d27883e30..9249bdf677 100644 --- a/internal/cli/atlas/clusters/availableregions/list_test.go +++ b/internal/cli/atlas/clusters/availableregions/list_test.go @@ -22,16 +22,17 @@ import ( "github.com/golang/mock/gomock" "github.com/mongodb/mongodb-atlas-cli/internal/flag" "github.com/mongodb/mongodb-atlas-cli/internal/mocks" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/mongodb/mongodb-atlas-cli/internal/test" - "go.mongodb.org/atlas/mongodbatlas" + atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" ) func TestList_Run_NoFlags(t *testing.T) { ctrl := gomock.NewController(t) mockStore := mocks.NewMockCloudProviderRegionsLister(ctrl) - var expected *mongodbatlas.CloudProviders - var empty []*string + var expected *atlasv2.PaginatedApiAtlasProviderRegions + var empty *[]string listOpts := &ListOpts{ store: mockStore, @@ -52,7 +53,7 @@ func TestList_Run(t *testing.T) { ctrl := gomock.NewController(t) mockStore := mocks.NewMockCloudProviderRegionsLister(ctrl) - var expected *mongodbatlas.CloudProviders + var expected *atlasv2.PaginatedApiAtlasProviderRegions listOpts := &ListOpts{ store: mockStore, @@ -62,7 +63,7 @@ func TestList_Run(t *testing.T) { mockStore. EXPECT(). - CloudProviderRegions(listOpts.ProjectID, listOpts.tier, []*string{&listOpts.provider}). + CloudProviderRegions(listOpts.ProjectID, listOpts.tier, pointer.Get([]string{listOpts.provider})). Return(expected, nil). Times(1) diff --git a/internal/cli/atlas/clusters/region_tier_autocomplete.go b/internal/cli/atlas/clusters/region_tier_autocomplete.go index d515f10908..5e36e175b1 100644 --- a/internal/cli/atlas/clusters/region_tier_autocomplete.go +++ b/internal/cli/atlas/clusters/region_tier_autocomplete.go @@ -22,6 +22,7 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/cli" "github.com/mongodb/mongodb-atlas-cli/internal/config" "github.com/mongodb/mongodb-atlas-cli/internal/flag" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/mongodb/mongodb-atlas-cli/internal/store" "github.com/mongodb/mongodb-atlas-cli/internal/validate" "github.com/spf13/cobra" @@ -31,7 +32,7 @@ type autoFunc func(cmd *cobra.Command, args []string, toComplete string) ([]stri type autoCompleteOpts struct { cli.GlobalOpts - providers []*string + providers *[]string tier string store store.CloudProviderRegionsLister } @@ -69,8 +70,8 @@ func (opts *autoCompleteOpts) tierSuggestions(toComplete string) ([]string, erro availableTiers := map[string]bool{} for _, p := range result.Results { for _, i := range p.InstanceSizes { - if _, ok := availableTiers[i.Name]; !ok && strings.HasPrefix(i.Name, strings.ToUpper(toComplete)) { - availableTiers[i.Name] = true + if _, ok := availableTiers[*i.Name]; !ok && strings.HasPrefix(*i.Name, strings.ToUpper(toComplete)) { + availableTiers[*i.Name] = true } } } @@ -117,8 +118,8 @@ func (opts *autoCompleteOpts) regionSuggestions(toComplete string) ([]string, er for _, p := range result.Results { for _, i := range p.InstanceSizes { for _, r := range i.AvailableRegions { - if _, ok := availableRegions[r.Name]; !ok && strings.HasPrefix(r.Name, strings.ToUpper(toComplete)) { - availableRegions[r.Name] = true + if _, ok := availableRegions[*r.Name]; !ok && strings.HasPrefix(*r.Name, strings.ToUpper(toComplete)) { + availableRegions[*r.Name] = true } } } @@ -151,9 +152,9 @@ func (opts *autoCompleteOpts) parseFlags(cmd *cobra.Command) { if project := cmd.Flag(flag.ProjectID).Value.String(); project != "" { opts.ProjectID = project } - opts.providers = make([]*string, 0, 1) + providers := make([]string, 0, 1) if provider := cmd.Flag(flag.Provider).Value.String(); provider != "" { - opts.providers = append(opts.providers, &provider) + opts.providers = pointer.Get(append(providers, provider)) } if tier := cmd.Flag(flag.Tier).Value.String(); tier != "" { diff --git a/internal/cli/atlas/clusters/region_tier_autocomplete_test.go b/internal/cli/atlas/clusters/region_tier_autocomplete_test.go index e1c57bb013..0321910ca6 100644 --- a/internal/cli/atlas/clusters/region_tier_autocomplete_test.go +++ b/internal/cli/atlas/clusters/region_tier_autocomplete_test.go @@ -21,8 +21,9 @@ import ( "github.com/golang/mock/gomock" "github.com/mongodb/mongodb-atlas-cli/internal/mocks" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/stretchr/testify/require" - atlas "go.mongodb.org/atlas/mongodbatlas" + atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" ) func Test_autoCompleteOpts_tierSuggestions(t *testing.T) { @@ -33,13 +34,13 @@ func Test_autoCompleteOpts_tierSuggestions(t *testing.T) { store: mockStore, } - expected := &atlas.CloudProviders{ - Results: []*atlas.CloudProvider{ + expected := &atlasv2.PaginatedApiAtlasProviderRegions{ + Results: []atlasv2.ProviderRegions{ { - Provider: "AWS", - InstanceSizes: []*atlas.InstanceSize{ + Provider: pointer.Get("AWS"), + InstanceSizes: []atlasv2.ProviderInstanceSize{ { - Name: "M0", + Name: pointer.Get("M0"), AvailableRegions: nil, }, }, @@ -65,17 +66,17 @@ func Test_autoCompleteOpts_regionSuggestions(t *testing.T) { store: mockStore, } - expected := &atlas.CloudProviders{ - Results: []*atlas.CloudProvider{ + expected := &atlasv2.PaginatedApiAtlasProviderRegions{ + Results: []atlasv2.ProviderRegions{ { - Provider: "AWS", - InstanceSizes: []*atlas.InstanceSize{ + Provider: pointer.Get("AWS"), + InstanceSizes: []atlasv2.ProviderInstanceSize{ { - Name: "M0", - AvailableRegions: []*atlas.AvailableRegion{ + Name: pointer.Get("M0"), + AvailableRegions: []atlasv2.AvailableRegion{ { - Name: "EU_EAST", - Default: false, + Name: pointer.Get("EU_EAST"), + Default: pointer.Get(false), }, }, }, diff --git a/internal/cli/atlas/quickstart/cluster_setup.go b/internal/cli/atlas/quickstart/cluster_setup.go index 90ee5ef31c..c3cfd910ed 100644 --- a/internal/cli/atlas/quickstart/cluster_setup.go +++ b/internal/cli/atlas/quickstart/cluster_setup.go @@ -22,6 +22,7 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/mongodb/mongodb-atlas-cli/internal/cli" "github.com/mongodb/mongodb-atlas-cli/internal/flag" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/mongodb/mongodb-atlas-cli/internal/search" "github.com/mongodb/mongodb-atlas-cli/internal/telemetry" "github.com/mongodb/mongodb-atlas-cli/internal/usage" @@ -182,7 +183,7 @@ func (opts *Opts) defaultRegions() ([]string, error) { cloudProviders, err := opts.store.CloudProviderRegions( opts.ConfigProjectID(), opts.Tier, - []*string{&opts.Provider}, + pointer.Get([]string{opts.Provider}), ) if err != nil { @@ -201,14 +202,14 @@ func (opts *Opts) defaultRegions() ([]string, error) { if popularRegionIndex != -1 { // the most popular region must be the first in the list popularRegion := availableRegions[popularRegionIndex] - defaultRegions = append(defaultRegions, popularRegion.Name) + defaultRegions = append(defaultRegions, *popularRegion.Name) // remove popular region from availableRegions availableRegions = append(availableRegions[:popularRegionIndex], availableRegions[popularRegionIndex+1:]...) } for _, v := range availableRegions { - defaultRegions = append(defaultRegions, v.Name) + defaultRegions = append(defaultRegions, *v.Name) } return defaultRegions, nil diff --git a/internal/mocks/mock_cloud_provider_regions.go b/internal/mocks/mock_cloud_provider_regions.go index d8e52ab9e9..513f578aa9 100644 --- a/internal/mocks/mock_cloud_provider_regions.go +++ b/internal/mocks/mock_cloud_provider_regions.go @@ -8,7 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - mongodbatlas "go.mongodb.org/atlas/mongodbatlas" + mongodbatlasv2 "go.mongodb.org/atlas/mongodbatlasv2" ) // MockCloudProviderRegionsLister is a mock of CloudProviderRegionsLister interface. @@ -35,10 +35,10 @@ func (m *MockCloudProviderRegionsLister) EXPECT() *MockCloudProviderRegionsListe } // CloudProviderRegions mocks base method. -func (m *MockCloudProviderRegionsLister) CloudProviderRegions(arg0, arg1 string, arg2 []*string) (*mongodbatlas.CloudProviders, error) { +func (m *MockCloudProviderRegionsLister) CloudProviderRegions(arg0, arg1 string, arg2 *[]string) (*mongodbatlasv2.PaginatedApiAtlasProviderRegions, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CloudProviderRegions", arg0, arg1, arg2) - ret0, _ := ret[0].(*mongodbatlas.CloudProviders) + ret0, _ := ret[0].(*mongodbatlasv2.PaginatedApiAtlasProviderRegions) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_clusters.go b/internal/mocks/mock_clusters.go index c89a7ec3f7..8faf327527 100644 --- a/internal/mocks/mock_clusters.go +++ b/internal/mocks/mock_clusters.go @@ -423,10 +423,10 @@ func (mr *MockAtlasClusterQuickStarterMockRecorder) AtlasCluster(arg0, arg1 inte } // CloudProviderRegions mocks base method. -func (m *MockAtlasClusterQuickStarter) CloudProviderRegions(arg0, arg1 string, arg2 []*string) (*mongodbatlas.CloudProviders, error) { +func (m *MockAtlasClusterQuickStarter) CloudProviderRegions(arg0, arg1 string, arg2 *[]string) (*mongodbatlasv2.PaginatedApiAtlasProviderRegions, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CloudProviderRegions", arg0, arg1, arg2) - ret0, _ := ret[0].(*mongodbatlas.CloudProviders) + ret0, _ := ret[0].(*mongodbatlasv2.PaginatedApiAtlasProviderRegions) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/search/search.go b/internal/search/search.go index a53105fe49..db5630ec36 100644 --- a/internal/search/search.go +++ b/internal/search/search.go @@ -16,6 +16,7 @@ package search import ( atlas "go.mongodb.org/atlas/mongodbatlas" + atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" "go.mongodb.org/ops-manager/opsmngr" "go.mongodb.org/ops-manager/search" ) @@ -54,9 +55,9 @@ func AtlasClusterExists(clusters []atlas.Cluster, name string) bool { } // DefaultRegion returns the index of the default region. -func DefaultRegion(regions []*atlas.AvailableRegion) int { +func DefaultRegion(regions []atlasv2.AvailableRegion) int { for i, v := range regions { - if v.Default { + if v.Default != nil && *v.Default { return i } } diff --git a/internal/search/search_test.go b/internal/search/search_test.go index eb4cd87fb3..85b832f111 100644 --- a/internal/search/search_test.go +++ b/internal/search/search_test.go @@ -19,8 +19,10 @@ package search import ( "testing" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/mongodb/mongodb-atlas-cli/internal/test/fixture" atlas "go.mongodb.org/atlas/mongodbatlas" + atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" ) func TestStringInSlice(t *testing.T) { @@ -126,61 +128,61 @@ func TestAtlasClusterExists(t *testing.T) { func TestDefaultRegion(t *testing.T) { tests := []struct { - input []*atlas.AvailableRegion + input []atlasv2.AvailableRegion want int }{ { - input: []*atlas.AvailableRegion{}, + input: []atlasv2.AvailableRegion{}, want: -1, }, { - input: []*atlas.AvailableRegion{ + input: []atlasv2.AvailableRegion{ { - Name: "test", - Default: false, + Name: pointer.Get("test"), + Default: pointer.Get(false), }, }, want: -1, }, { - input: []*atlas.AvailableRegion{ + input: []atlasv2.AvailableRegion{ { - Name: "test", - Default: true, + Name: pointer.Get("test"), + Default: pointer.Get(true), }, }, want: 0, }, { - input: []*atlas.AvailableRegion{ + input: []atlasv2.AvailableRegion{ { - Name: "test", - Default: false, + Name: pointer.Get("test"), + Default: pointer.Get(false), }, { - Name: "test2", - Default: true, + Name: pointer.Get("test2"), + Default: pointer.Get(true), }, { - Name: "test1", - Default: false, + Name: pointer.Get("test1"), + Default: pointer.Get(false), }, }, want: 1, }, { - input: []*atlas.AvailableRegion{ + input: []atlasv2.AvailableRegion{ { - Name: "test", - Default: false, + Name: pointer.Get("test"), + Default: pointer.Get(false), }, { - Name: "test2", - Default: false, + Name: pointer.Get("test2"), + Default: pointer.Get(false), }, { - Name: "test1", - Default: false, + Name: pointer.Get("test1"), + Default: pointer.Get(false), }, }, want: -1, diff --git a/internal/store/cloud_provider_regions.go b/internal/store/cloud_provider_regions.go index 32c6577059..d893366ee6 100644 --- a/internal/store/cloud_provider_regions.go +++ b/internal/store/cloud_provider_regions.go @@ -18,24 +18,26 @@ import ( "fmt" "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlas "go.mongodb.org/atlas/mongodbatlas" + atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" ) //go:generate mockgen -destination=../mocks/mock_cloud_provider_regions.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store CloudProviderRegionsLister type CloudProviderRegionsLister interface { - CloudProviderRegions(string, string, []*string) (*atlas.CloudProviders, error) + CloudProviderRegions(string, string, *[]string) (*atlasv2.PaginatedApiAtlasProviderRegions, error) } // CloudProviderRegions encapsulates the logic to manage different cloud providers. -func (s *Store) CloudProviderRegions(projectID, tier string, providerName []*string) (*atlas.CloudProviders, error) { - options := &atlas.CloudProviderRegionsOptions{ +func (s *Store) CloudProviderRegions(projectID, tier string, providerName *[]string) (*atlasv2.PaginatedApiAtlasProviderRegions, error) { + params := atlasv2.ListCloudProviderRegionsApiParams{ + GroupId: projectID, Providers: providerName, - Tier: tier, + Tier: &tier, } + switch s.service { case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Clusters.ListCloudProviderRegions(s.ctx, projectID, options) + result, _, err := s.clientv2.ClustersApi.ListCloudProviderRegionsWithParams(s.ctx, ¶ms).Execute() return result, err default: return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) From 1589ca67765c848daf4de75607e5bd3b4a7368dd Mon Sep 17 00:00:00 2001 From: Ma77C0nd0n Date: Mon, 29 May 2023 15:35:57 +0100 Subject: [PATCH 2/2] address merge changes following sdk fix --- .../atlas/clusters/availableregions/list_test.go | 2 +- .../clusters/region_tier_autocomplete_test.go | 2 +- internal/mocks/mock_cloud_provider_regions.go | 6 +++--- internal/mocks/mock_clusters.go | 4 ++-- internal/search/search.go | 4 ++-- internal/search/search_test.go | 2 +- internal/store/cloud_provider_regions.go | 6 +++--- internal/store/clusters.go | 14 +++++++------- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/cli/atlas/clusters/availableregions/list_test.go b/internal/cli/atlas/clusters/availableregions/list_test.go index 9249bdf677..891886cc31 100644 --- a/internal/cli/atlas/clusters/availableregions/list_test.go +++ b/internal/cli/atlas/clusters/availableregions/list_test.go @@ -24,7 +24,7 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/mocks" "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/mongodb/mongodb-atlas-cli/internal/test" - atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" + atlasv2 "go.mongodb.org/atlas-sdk/admin" ) func TestList_Run_NoFlags(t *testing.T) { diff --git a/internal/cli/atlas/clusters/region_tier_autocomplete_test.go b/internal/cli/atlas/clusters/region_tier_autocomplete_test.go index 0321910ca6..a8e82911da 100644 --- a/internal/cli/atlas/clusters/region_tier_autocomplete_test.go +++ b/internal/cli/atlas/clusters/region_tier_autocomplete_test.go @@ -23,7 +23,7 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/mocks" "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" + atlasv2 "go.mongodb.org/atlas-sdk/admin" ) func Test_autoCompleteOpts_tierSuggestions(t *testing.T) { diff --git a/internal/mocks/mock_cloud_provider_regions.go b/internal/mocks/mock_cloud_provider_regions.go index 513f578aa9..7e089d07f0 100644 --- a/internal/mocks/mock_cloud_provider_regions.go +++ b/internal/mocks/mock_cloud_provider_regions.go @@ -8,7 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - mongodbatlasv2 "go.mongodb.org/atlas/mongodbatlasv2" + admin "go.mongodb.org/atlas-sdk/admin" ) // MockCloudProviderRegionsLister is a mock of CloudProviderRegionsLister interface. @@ -35,10 +35,10 @@ func (m *MockCloudProviderRegionsLister) EXPECT() *MockCloudProviderRegionsListe } // CloudProviderRegions mocks base method. -func (m *MockCloudProviderRegionsLister) CloudProviderRegions(arg0, arg1 string, arg2 *[]string) (*mongodbatlasv2.PaginatedApiAtlasProviderRegions, error) { +func (m *MockCloudProviderRegionsLister) CloudProviderRegions(arg0, arg1 string, arg2 *[]string) (*admin.PaginatedApiAtlasProviderRegions, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CloudProviderRegions", arg0, arg1, arg2) - ret0, _ := ret[0].(*mongodbatlasv2.PaginatedApiAtlasProviderRegions) + ret0, _ := ret[0].(*admin.PaginatedApiAtlasProviderRegions) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_clusters.go b/internal/mocks/mock_clusters.go index 8faf327527..28582b527a 100644 --- a/internal/mocks/mock_clusters.go +++ b/internal/mocks/mock_clusters.go @@ -423,10 +423,10 @@ func (mr *MockAtlasClusterQuickStarterMockRecorder) AtlasCluster(arg0, arg1 inte } // CloudProviderRegions mocks base method. -func (m *MockAtlasClusterQuickStarter) CloudProviderRegions(arg0, arg1 string, arg2 *[]string) (*mongodbatlasv2.PaginatedApiAtlasProviderRegions, error) { +func (m *MockAtlasClusterQuickStarter) CloudProviderRegions(arg0, arg1 string, arg2 *[]string) (*admin.PaginatedApiAtlasProviderRegions, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CloudProviderRegions", arg0, arg1, arg2) - ret0, _ := ret[0].(*mongodbatlasv2.PaginatedApiAtlasProviderRegions) + ret0, _ := ret[0].(*admin.PaginatedApiAtlasProviderRegions) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/search/search.go b/internal/search/search.go index db5630ec36..76d48ea0de 100644 --- a/internal/search/search.go +++ b/internal/search/search.go @@ -15,8 +15,8 @@ package search import ( + "go.mongodb.org/atlas-sdk/admin" atlas "go.mongodb.org/atlas/mongodbatlas" - atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" "go.mongodb.org/ops-manager/opsmngr" "go.mongodb.org/ops-manager/search" ) @@ -55,7 +55,7 @@ func AtlasClusterExists(clusters []atlas.Cluster, name string) bool { } // DefaultRegion returns the index of the default region. -func DefaultRegion(regions []atlasv2.AvailableRegion) int { +func DefaultRegion(regions []admin.AvailableRegion) int { for i, v := range regions { if v.Default != nil && *v.Default { return i diff --git a/internal/search/search_test.go b/internal/search/search_test.go index 85b832f111..d98f2f8765 100644 --- a/internal/search/search_test.go +++ b/internal/search/search_test.go @@ -21,8 +21,8 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/mongodb/mongodb-atlas-cli/internal/test/fixture" + atlasv2 "go.mongodb.org/atlas-sdk/admin" atlas "go.mongodb.org/atlas/mongodbatlas" - atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" ) func TestStringInSlice(t *testing.T) { diff --git a/internal/store/cloud_provider_regions.go b/internal/store/cloud_provider_regions.go index d893366ee6..eaf4d3c4eb 100644 --- a/internal/store/cloud_provider_regions.go +++ b/internal/store/cloud_provider_regions.go @@ -18,7 +18,7 @@ import ( "fmt" "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlasv2 "go.mongodb.org/atlas/mongodbatlasv2" + atlasv2 "go.mongodb.org/atlas-sdk/admin" ) //go:generate mockgen -destination=../mocks/mock_cloud_provider_regions.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store CloudProviderRegionsLister @@ -29,7 +29,7 @@ type CloudProviderRegionsLister interface { // CloudProviderRegions encapsulates the logic to manage different cloud providers. func (s *Store) CloudProviderRegions(projectID, tier string, providerName *[]string) (*atlasv2.PaginatedApiAtlasProviderRegions, error) { - params := atlasv2.ListCloudProviderRegionsApiParams{ + params := &atlasv2.ListCloudProviderRegionsApiParams{ GroupId: projectID, Providers: providerName, Tier: &tier, @@ -37,7 +37,7 @@ func (s *Store) CloudProviderRegions(projectID, tier string, providerName *[]str switch s.service { case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.ListCloudProviderRegionsWithParams(s.ctx, ¶ms).Execute() + result, _, err := s.clientv2.ClustersApi.ListCloudProviderRegionsWithParams(s.ctx, params).Execute() return result, err default: return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) diff --git a/internal/store/clusters.go b/internal/store/clusters.go index 59ba799759..3d45fd8f88 100644 --- a/internal/store/clusters.go +++ b/internal/store/clusters.go @@ -18,7 +18,7 @@ import ( "fmt" "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlasv2 "go.mongodb.org/atlas-sdk/admin" + "go.mongodb.org/atlas-sdk/admin" atlas "go.mongodb.org/atlas/mongodbatlas" "go.mongodb.org/ops-manager/opsmngr" ) @@ -34,11 +34,11 @@ type AtlasClusterDescriber interface { } type AtlasClusterConfigurationOptionsDescriber interface { - AtlasClusterConfigurationOptions(string, string) (*atlasv2.ClusterDescriptionProcessArgs, error) + AtlasClusterConfigurationOptions(string, string) (*admin.ClusterDescriptionProcessArgs, error) } type AtlasClusterConfigurationOptionsUpdater interface { - UpdateAtlasClusterConfigurationOptions(string, string, *atlasv2.ClusterDescriptionProcessArgs) (*atlasv2.ClusterDescriptionProcessArgs, error) + UpdateAtlasClusterConfigurationOptions(string, string, *admin.ClusterDescriptionProcessArgs) (*admin.ClusterDescriptionProcessArgs, error) } type OpsManagerClusterDescriber interface { @@ -78,7 +78,7 @@ type SampleDataAdder interface { } type SampleDataStatusDescriber interface { - SampleDataStatus(string, string) (*atlasv2.SampleDatasetStatus, error) + SampleDataStatus(string, string) (*admin.SampleDatasetStatus, error) } type ClusterTester interface { @@ -119,7 +119,7 @@ func (s *Store) AddSampleData(groupID, clusterName string) (*atlas.SampleDataset } // SampleDataStatus encapsulate the logic to manage different cloud providers. -func (s *Store) SampleDataStatus(groupID, id string) (*atlasv2.SampleDatasetStatus, error) { +func (s *Store) SampleDataStatus(groupID, id string) (*admin.SampleDatasetStatus, error) { switch s.service { case config.CloudService, config.CloudGovService: result, _, err := s.clientv2.ClustersApi.GetSampleDatasetLoadStatus(s.ctx, groupID, id).Execute() @@ -254,7 +254,7 @@ func (s *Store) ListAllProjectClusters() (*opsmngr.AllClustersProjects, error) { } // AtlasClusterConfigurationOptions encapsulates the logic to manage different cloud providers. -func (s *Store) AtlasClusterConfigurationOptions(projectID, name string) (*atlasv2.ClusterDescriptionProcessArgs, error) { +func (s *Store) AtlasClusterConfigurationOptions(projectID, name string) (*admin.ClusterDescriptionProcessArgs, error) { switch s.service { case config.CloudService, config.CloudGovService: result, _, err := s.clientv2.ClustersApi.GetClusterAdvancedConfiguration(s.ctx, projectID, name).Execute() @@ -265,7 +265,7 @@ func (s *Store) AtlasClusterConfigurationOptions(projectID, name string) (*atlas } // UpdateAtlasClusterConfigurationOptions encapsulates the logic to manage different cloud providers. -func (s *Store) UpdateAtlasClusterConfigurationOptions(projectID, clusterName string, args *atlasv2.ClusterDescriptionProcessArgs) (*atlasv2.ClusterDescriptionProcessArgs, error) { +func (s *Store) UpdateAtlasClusterConfigurationOptions(projectID, clusterName string, args *admin.ClusterDescriptionProcessArgs) (*admin.ClusterDescriptionProcessArgs, error) { switch s.service { case config.CloudService, config.CloudGovService: result, _, err := s.clientv2.ClustersApi.UpdateClusterAdvancedConfiguration(s.ctx, projectID, clusterName, args).Execute()