From 811c672ba8e9ed250b64da5eba5f50f03ebf2dbe Mon Sep 17 00:00:00 2001 From: Gustavo Bazan Date: Tue, 17 Oct 2023 17:16:37 +0100 Subject: [PATCH] task: clean some references to the old atlas client (#2377) --- internal/cli/iam/organizations/create_test.go | 4 +- .../cli/iam/organizations/describe_test.go | 4 +- internal/cli/iam/organizations/list.go | 3 +- internal/cli/parse_service_version.go | 4 +- internal/cli/parse_service_version_test.go | 14 +-- internal/store/agents.go | 9 +- internal/store/alert_configuration.go | 2 +- internal/store/alerts.go | 19 +-- internal/store/api_keys_access_list.go | 2 +- internal/store/backup_configs.go | 5 +- internal/test/fixture/all_clusters.go | 112 ------------------ internal/test/fixture/continuous_snapshots.go | 67 ----------- internal/test/fixture/global_alerts.go | 51 -------- 13 files changed, 28 insertions(+), 268 deletions(-) delete mode 100644 internal/test/fixture/all_clusters.go delete mode 100644 internal/test/fixture/continuous_snapshots.go delete mode 100644 internal/test/fixture/global_alerts.go diff --git a/internal/cli/iam/organizations/create_test.go b/internal/cli/iam/organizations/create_test.go index df7e421544..8d29f19f00 100644 --- a/internal/cli/iam/organizations/create_test.go +++ b/internal/cli/iam/organizations/create_test.go @@ -23,14 +23,14 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/flag" "github.com/mongodb/mongodb-atlas-cli/internal/mocks" "github.com/mongodb/mongodb-atlas-cli/internal/test" - "go.mongodb.org/atlas/mongodbatlas" + "go.mongodb.org/ops-manager/opsmngr" ) func TestCreate_Run(t *testing.T) { ctrl := gomock.NewController(t) mockStore := mocks.NewMockOrganizationCreator(ctrl) - expected := &mongodbatlas.Organization{} + expected := &opsmngr.Organization{} mockStore. EXPECT(). diff --git a/internal/cli/iam/organizations/describe_test.go b/internal/cli/iam/organizations/describe_test.go index 1369d1e593..2be61562af 100644 --- a/internal/cli/iam/organizations/describe_test.go +++ b/internal/cli/iam/organizations/describe_test.go @@ -25,14 +25,14 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/mocks" "github.com/mongodb/mongodb-atlas-cli/internal/test" "github.com/stretchr/testify/assert" - atlas "go.mongodb.org/atlas/mongodbatlas" + "go.mongodb.org/ops-manager/opsmngr" ) func TestDescribe_Run(t *testing.T) { ctrl := gomock.NewController(t) mockStore := mocks.NewMockOrganizationDescriber(ctrl) stringVal := "test" - expected := &atlas.Organization{ + expected := &opsmngr.Organization{ Links: nil, ID: stringVal, Name: stringVal, diff --git a/internal/cli/iam/organizations/list.go b/internal/cli/iam/organizations/list.go index 1cce635463..1674f820b3 100644 --- a/internal/cli/iam/organizations/list.go +++ b/internal/cli/iam/organizations/list.go @@ -26,6 +26,7 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/usage" "github.com/spf13/cobra" atlas "go.mongodb.org/atlas/mongodbatlas" + "go.mongodb.org/ops-manager/opsmngr" ) const listTemplate = `ID NAME{{range .Results}} @@ -57,7 +58,7 @@ func (opts *ListOpts) Run() error { return opts.Print(r) } -func (opts *ListOpts) newOrganizationListOptions() *atlas.OrganizationsListOptions { +func (opts *ListOpts) newOrganizationListOptions() *opsmngr.OrganizationsListOptions { return &atlas.OrganizationsListOptions{ Name: opts.name, IncludeDeletedOrgs: &opts.includeDeletedOrgs, diff --git a/internal/cli/parse_service_version.go b/internal/cli/parse_service_version.go index ddd120d194..0737c29aa0 100644 --- a/internal/cli/parse_service_version.go +++ b/internal/cli/parse_service_version.go @@ -18,11 +18,11 @@ import ( "strings" "github.com/Masterminds/semver/v3" - atlas "go.mongodb.org/atlas/mongodbatlas" + "go.mongodb.org/ops-manager/opsmngr" ) // ParseServiceVersion parses service version into semver.Version. -func ParseServiceVersion(v *atlas.ServiceVersion) (*semver.Version, error) { +func ParseServiceVersion(v *opsmngr.ServiceVersion) (*semver.Version, error) { versionParts := strings.Split(v.Version, ".") const maxVersionParts = 2 diff --git a/internal/cli/parse_service_version_test.go b/internal/cli/parse_service_version_test.go index 2b7236b552..74e1c000f2 100644 --- a/internal/cli/parse_service_version_test.go +++ b/internal/cli/parse_service_version_test.go @@ -19,43 +19,43 @@ package cli import ( "testing" - "go.mongodb.org/atlas/mongodbatlas" + "go.mongodb.org/ops-manager/opsmngr" ) func TestParseServiceVersion(t *testing.T) { tests := []struct { name string - serviceVersion *mongodbatlas.ServiceVersion + serviceVersion *opsmngr.ServiceVersion expected string wantErr bool }{ { name: "OM 5.0", - serviceVersion: &mongodbatlas.ServiceVersion{Version: "5.0.0.100.20210101T0000Z"}, + serviceVersion: &opsmngr.ServiceVersion{Version: "5.0.0.100.20210101T0000Z"}, expected: "5.0.0", wantErr: false, }, { name: "OM 5.0-rc1", - serviceVersion: &mongodbatlas.ServiceVersion{Version: "5.0.0-rc1.100.20210101T0000Z"}, + serviceVersion: &opsmngr.ServiceVersion{Version: "5.0.0-rc1.100.20210101T0000Z"}, expected: "5.0.0", wantErr: false, }, { name: "OM 5.0.1", - serviceVersion: &mongodbatlas.ServiceVersion{Version: "5.0.1.100.20210101T0000Z"}, + serviceVersion: &opsmngr.ServiceVersion{Version: "5.0.1.100.20210101T0000Z"}, expected: "5.0.0", wantErr: false, }, { name: "master", - serviceVersion: &mongodbatlas.ServiceVersion{Version: "master"}, + serviceVersion: &opsmngr.ServiceVersion{Version: "master"}, expected: "", wantErr: true, }, { name: "v20210101", - serviceVersion: &mongodbatlas.ServiceVersion{Version: "v20210101"}, + serviceVersion: &opsmngr.ServiceVersion{Version: "v20210101"}, expected: "20210101.0.0", wantErr: false, }, diff --git a/internal/store/agents.go b/internal/store/agents.go index 7ed936226b..a293f78003 100644 --- a/internal/store/agents.go +++ b/internal/store/agents.go @@ -18,14 +18,13 @@ import ( "fmt" "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlas "go.mongodb.org/atlas/mongodbatlas" "go.mongodb.org/ops-manager/opsmngr" ) //go:generate mockgen -destination=../mocks/mock_agents.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AgentLister,AgentUpgrader,AgentAPIKeyLister,AgentAPIKeyCreator,AgentAPIKeyDeleter,AgentGlobalVersionsLister,AgentProjectVersionsLister type AgentLister interface { - Agents(string, string, *atlas.ListOptions) (*opsmngr.Agents, error) + Agents(string, string, *opsmngr.ListOptions) (*opsmngr.Agents, error) } type AgentGlobalVersionsLister interface { @@ -53,7 +52,7 @@ type AgentAPIKeyDeleter interface { } // Agents encapsulates the logic to manage different cloud providers. -func (s *Store) Agents(projectID, agentType string, opts *atlas.ListOptions) (*opsmngr.Agents, error) { +func (s *Store) Agents(projectID, agentType string, opts *opsmngr.ListOptions) (*opsmngr.Agents, error) { switch s.service { case config.OpsManagerService, config.CloudManagerService: result, _, err := s.client.(*opsmngr.Client).Agents.ListAgentsByType(s.ctx, projectID, agentType, opts) @@ -107,7 +106,7 @@ func (s *Store) DeleteAgentAPIKey(projectID, keyID string) error { } } -// Agents encapsulates the logic to manage different cloud providers. +// AgentGlobalVersions encapsulates the logic to manage different cloud providers. func (s *Store) AgentGlobalVersions() (*opsmngr.SoftwareVersions, error) { switch s.service { case config.OpsManagerService: @@ -118,7 +117,7 @@ func (s *Store) AgentGlobalVersions() (*opsmngr.SoftwareVersions, error) { } } -// Agents encapsulates the logic to manage different cloud providers. +// AgentProjectVersions encapsulates the logic to manage different cloud providers. func (s *Store) AgentProjectVersions(projectID string) (*opsmngr.AgentVersions, error) { switch s.service { case config.OpsManagerService, config.CloudManagerService: diff --git a/internal/store/alert_configuration.go b/internal/store/alert_configuration.go index 274994eab8..c1282d5168 100644 --- a/internal/store/alert_configuration.go +++ b/internal/store/alert_configuration.go @@ -26,7 +26,7 @@ import ( //go:generate mockgen -destination=../mocks/mock_alert_configuration.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AlertConfigurationLister,AlertConfigurationCreator,AlertConfigurationDeleter,AlertConfigurationUpdater,MatcherFieldsLister,AlertConfigurationEnabler,AlertConfigurationDisabler type AlertConfigurationLister interface { - AlertConfigurations(string, *atlas.ListOptions) ([]atlas.AlertConfiguration, error) + AlertConfigurations(string, *opsmngr.ListOptions) ([]atlas.AlertConfiguration, error) } type AlertConfigurationCreator interface { diff --git a/internal/store/alerts.go b/internal/store/alerts.go index 5b9d7a3895..4c81072e0b 100644 --- a/internal/store/alerts.go +++ b/internal/store/alerts.go @@ -25,23 +25,20 @@ import ( //go:generate mockgen -destination=../mocks/mock_alerts.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AlertDescriber,AlertLister,AlertAcknowledger type AlertDescriber interface { - Alert(string, string) (*atlas.Alert, error) + Alert(string, string) (*opsmngr.Alert, error) } type AlertLister interface { - Alerts(string, *atlas.AlertsListOptions) (*atlas.AlertsResponse, error) + Alerts(string, *opsmngr.AlertsListOptions) (*atlas.AlertsResponse, error) } type AlertAcknowledger interface { - AcknowledgeAlert(string, string, *atlas.AcknowledgeRequest) (*atlas.Alert, error) + AcknowledgeAlert(string, string, *opsmngr.AcknowledgeRequest) (*atlas.Alert, error) } // Alert encapsulate the logic to manage different cloud providers. func (s *Store) Alert(projectID, alertID string) (*atlas.Alert, error) { switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Alerts.Get(s.ctx, projectID, alertID) - return result, err case config.OpsManagerService, config.CloudManagerService: result, _, err := s.client.(*opsmngr.Client).Alerts.Get(s.ctx, projectID, alertID) return result, err @@ -51,11 +48,8 @@ func (s *Store) Alert(projectID, alertID string) (*atlas.Alert, error) { } // Alerts encapsulate the logic to manage different cloud providers. -func (s *Store) Alerts(projectID string, opts *atlas.AlertsListOptions) (*atlas.AlertsResponse, error) { +func (s *Store) Alerts(projectID string, opts *opsmngr.AlertsListOptions) (*opsmngr.AlertsResponse, error) { switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Alerts.List(s.ctx, projectID, opts) - return result, err case config.OpsManagerService, config.CloudManagerService: result, _, err := s.client.(*opsmngr.Client).Alerts.List(s.ctx, projectID, opts) return result, err @@ -65,11 +59,8 @@ func (s *Store) Alerts(projectID string, opts *atlas.AlertsListOptions) (*atlas. } // Acknowledge encapsulate the logic to manage different cloud providers. -func (s *Store) AcknowledgeAlert(projectID, alertID string, body *atlas.AcknowledgeRequest) (*atlas.Alert, error) { +func (s *Store) AcknowledgeAlert(projectID, alertID string, body *opsmngr.AcknowledgeRequest) (*atlas.Alert, error) { switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Alerts.Acknowledge(s.ctx, projectID, alertID, body) - return result, err case config.OpsManagerService, config.CloudManagerService: result, _, err := s.client.(*opsmngr.Client).Alerts.Acknowledge(s.ctx, projectID, alertID, body) return result, err diff --git a/internal/store/api_keys_access_list.go b/internal/store/api_keys_access_list.go index 8274ff07c5..d9da5dd09c 100644 --- a/internal/store/api_keys_access_list.go +++ b/internal/store/api_keys_access_list.go @@ -25,7 +25,7 @@ import ( //go:generate mockgen -destination=../mocks/mock_api_keys_access_list.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store OrganizationAPIKeyAccessListCreator,OrganizationAPIKeyAccessListDeleter,OrganizationAPIKeyAccessListLister type OrganizationAPIKeyAccessListLister interface { - OrganizationAPIKeyAccessLists(string, string, *atlas.ListOptions) (*atlas.AccessListAPIKeys, error) + OrganizationAPIKeyAccessLists(string, string, *opsmngr.ListOptions) (*atlas.AccessListAPIKeys, error) } type OrganizationAPIKeyAccessListDeleter interface { diff --git a/internal/store/backup_configs.go b/internal/store/backup_configs.go index d9d133075d..cee3613aa6 100644 --- a/internal/store/backup_configs.go +++ b/internal/store/backup_configs.go @@ -18,7 +18,6 @@ import ( "fmt" "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlas "go.mongodb.org/atlas/mongodbatlas" "go.mongodb.org/ops-manager/opsmngr" ) @@ -29,7 +28,7 @@ type BackupConfigGetter interface { } type BackupConfigLister interface { - ListBackupConfigs(string, *atlas.ListOptions) (*opsmngr.BackupConfigs, error) + ListBackupConfigs(string, *opsmngr.ListOptions) (*opsmngr.BackupConfigs, error) } type BackupConfigUpdater interface { @@ -48,7 +47,7 @@ func (s *Store) GetBackupConfig(projectID, clusterID string) (*opsmngr.BackupCon } // ListBackupConfigs encapsulates the logic to manage different cloud providers. -func (s *Store) ListBackupConfigs(projectID string, options *atlas.ListOptions) (*opsmngr.BackupConfigs, error) { +func (s *Store) ListBackupConfigs(projectID string, options *opsmngr.ListOptions) (*opsmngr.BackupConfigs, error) { switch s.service { case config.CloudManagerService, config.OpsManagerService: result, _, err := s.client.(*opsmngr.Client).BackupConfigs.List(s.ctx, projectID, options) diff --git a/internal/test/fixture/all_clusters.go b/internal/test/fixture/all_clusters.go deleted file mode 100644 index d569629d64..0000000000 --- a/internal/test/fixture/all_clusters.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2020 MongoDB Inc -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package fixture - -import ( - atlas "go.mongodb.org/atlas/mongodbatlas" - "go.mongodb.org/ops-manager/opsmngr" -) - -func AllClusters() *opsmngr.AllClustersProjects { - return &opsmngr.AllClustersProjects{ - Links: []*atlas.Link{}, - Results: []*opsmngr.AllClustersProject{ - { - GroupName: "AtlasGroup1", - OrgName: "TestAtlasOrg1", - PlanType: "Atlas", - GroupID: "5e5fbc29e76c9a4be2ed3d39", - OrgID: "5e5fbc29e76c9a4be2ed3d36", - Clusters: []opsmngr.AllClustersCluster{ - { - ClusterID: "5e5fbc29e76c9a4be2ed3d4d", - Name: "AtlasCluster1", - Type: "sharded cluster", - Availability: "unavailable", - Versions: []string{"3.4.2"}, - BackupEnabled: true, - AuthEnabled: true, - SSLEnabled: true, - AlertCount: 0, - DataSizeBytes: 1000000, - NodeCount: 7, - }, - { - ClusterID: "5e5fbc29e76c9a4be2ed3d4f", - Name: "AtlasReplSet1", - Type: "replica set", - Availability: "dead", - Versions: []string{"3.4.1"}, - BackupEnabled: false, - AuthEnabled: true, - SSLEnabled: true, - AlertCount: 0, - DataSizeBytes: 1300000, - NodeCount: 2, - }, - }, - }, - { - GroupName: "CloudGroup1", - OrgName: "TestCloudOrg1", - PlanType: "Cloud Manager", - GroupID: "5e5fbc29e76c9a4be2ed3d38", - OrgID: "5e5fbc29e76c9a4be2ed3d34", - Tags: []string{"some tag 1", "some tag 2"}, - Clusters: []opsmngr.AllClustersCluster{ - { - ClusterID: "5e5fbc29e76c9a4be2ed3d42", - Name: "cluster1", - Type: "sharded cluster", - Availability: "warning", - Versions: []string{"3.4.1", "2.4.3"}, - BackupEnabled: true, - AuthEnabled: false, - SSLEnabled: false, - AlertCount: 0, - DataSizeBytes: 1000000, - NodeCount: 6, - }, - { - ClusterID: "5e5fbc29e76c9a4be2ed3d3c", - Name: "replica_set", - Type: "replica set", - Availability: "available", - Versions: []string{"3.4.1"}, - BackupEnabled: true, - AuthEnabled: true, - SSLEnabled: true, - AlertCount: 0, - DataSizeBytes: 500000, - NodeCount: 2, - }, - { - ClusterID: "da303f3fec69b2100bacf10dd9e6d5e0", - Name: "standalone:27017", - Type: "standalone", - Availability: "unavailable", - Versions: []string{"2.4.3"}, - BackupEnabled: false, - AuthEnabled: false, - SSLEnabled: true, - AlertCount: 0, - DataSizeBytes: 2000000, - NodeCount: 1, - }, - }, - }, - }, - TotalCount: 2, - } -} diff --git a/internal/test/fixture/continuous_snapshots.go b/internal/test/fixture/continuous_snapshots.go deleted file mode 100644 index 9efb3216a9..0000000000 --- a/internal/test/fixture/continuous_snapshots.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2020 MongoDB Inc -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fixture - -import atlas "go.mongodb.org/atlas/mongodbatlas" - -func ContinuousSnapshots() *atlas.ContinuousSnapshots { - doNotDelete := false - part := new(atlas.Part) - - part.ClusterID = "7c2487d833e9e75286093696" - part.CompressionSetting = "GZIP" - part.DataSizeBytes = 4502 - part.EncryptionEnabled = false - part.FileSizeBytes = 324760 - part.MongodVersion = "3.6.10" - part.ReplicaSetName = "Cluster0-shard-0" - part.StorageSizeBytes = 53248 - part.TypeName = "REPLICA_SET" - - return &atlas.ContinuousSnapshots{ - Links: []*atlas.Link{ - { - Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/6c7498dg87d9e6526801572b/clusters/Cluster0/snapshots?pageNum=1&itemsPerPage=100", - Rel: "self", - }, - }, - Results: []*atlas.ContinuousSnapshot{ - { - ClusterID: "7c2487d833e9e75286093696", - Complete: true, - Created: &atlas.SnapshotTimestamp{ - Date: "2017-12-26T16:32:16Z", - Increment: 1, - }, - DoNotDelete: &doNotDelete, - Expires: "2018-12-25T16:32:16Z", - GroupID: "6c7498dg87d9e6526801572b", - ID: "5a4279d4fcc178500596745a", - LastOplogAppliedTimestamp: &atlas.SnapshotTimestamp{ - Date: "2017-12-26T16:32:15Z", - Increment: 1, - }, - Links: []*atlas.Link{ - { - Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/6c7498dg87d9e6526801572b/clusters/Cluster0/snapshots/5a4279d4fcc178500596745a", - Rel: "self", - }, - }, - Parts: []*atlas.Part{part}, - }, - }, - TotalCount: 1, - } -} diff --git a/internal/test/fixture/global_alerts.go b/internal/test/fixture/global_alerts.go deleted file mode 100644 index 3334457842..0000000000 --- a/internal/test/fixture/global_alerts.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2020 MongoDB Inc -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fixture - -import ( - atlas "go.mongodb.org/atlas/mongodbatlas" - "go.mongodb.org/ops-manager/opsmngr" -) - -func GlobalAlert() *opsmngr.GlobalAlert { - return &opsmngr.GlobalAlert{ - Alert: atlas.Alert{ - ID: "3b7d2de0a4b02fd2c98146de", - GroupID: "1", - AlertConfigID: "5730f5e1e4b030a9634a3f69", - EventTypeName: "OPLOG_BEHIND", - Created: "2016-10-09T06:16:36Z", - Updated: "2016-10-10T22:03:11Z", - Status: "OPEN", - LastNotified: "2016-10-10T20:42:32Z", - ReplicaSetName: "shardedCluster-shard-0", - ClusterName: "shardedCluster", - AcknowledgedUntil: "2016-11-01T00:00:00Z", - AcknowledgingUsername: "admin@example.com", - }, - Tags: []string{}, - Links: []*atlas.Link{}, - SourceTypeName: "REPLICA_SET", - ClusterID: "572a00f2e4b051814b144e90", - } -} - -func GlobalAlerts() *opsmngr.GlobalAlerts { - return &opsmngr.GlobalAlerts{ - Links: []*atlas.Link{}, - Results: []*opsmngr.GlobalAlert{GlobalAlert()}, - TotalCount: 1, - } -}