Skip to content

Commit

Permalink
task: clean some references to the old atlas client (#2377)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn authored Oct 17, 2023
1 parent d674614 commit 811c672
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 268 deletions.
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/iam/organizations/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/parse_service_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions internal/cli/parse_service_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
9 changes: 4 additions & 5 deletions internal/store/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion internal/store/alert_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 5 additions & 14 deletions internal/store/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/store/api_keys_access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions internal/store/backup_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
112 changes: 0 additions & 112 deletions internal/test/fixture/all_clusters.go

This file was deleted.

Loading

0 comments on commit 811c672

Please sign in to comment.