Skip to content

Commit

Permalink
task: clean some usages of the old sdk (#2711)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn authored Mar 6, 2024
1 parent be8aaae commit c94d94d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 32 deletions.
6 changes: 3 additions & 3 deletions internal/cli/atlas/projects/settings/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
)

const updateTemplate = "Project settings updated.\n"
Expand Down Expand Up @@ -61,8 +61,8 @@ func (opts *UpdateOpts) Run() error {
return opts.Print(r)
}

func (opts *UpdateOpts) newProjectSettings() *atlas.ProjectSettings {
return &atlas.ProjectSettings{
func (opts *UpdateOpts) newProjectSettings() *atlasv2.GroupSettings {
return &atlasv2.GroupSettings{
IsCollectDatabaseSpecificsStatisticsEnabled: cli.ReturnValueForSetting(opts.enableCollectDatabaseSpecificsStatistics, opts.disableCollectDatabaseSpecificsStatistics),
IsDataExplorerEnabled: cli.ReturnValueForSetting(opts.enableDataExplorer, opts.disableDataExplorer),
IsPerformanceAdvisorEnabled: cli.ReturnValueForSetting(opts.enablePerformanceAdvisor, opts.disablePerformanceAdvisor),
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/require/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ExactArgs(n int) cobra.PositionalArgs {
}
}

// ExactArgsObjectID returns an error if there are not exactly n args and
// ExactObjectIDArgs returns an error if there are not exactly n args and
// any of those args is not an ObjectID.
func ExactObjectIDArgs(n int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
Expand Down
3 changes: 1 addition & 2 deletions internal/mocks/mock_project_settings.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions internal/store/project_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package store

import (
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

//go:generate mockgen -destination=../mocks/mock_project_settings.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store ProjectSettingsDescriber,ProjectSettingsUpdater
Expand All @@ -26,7 +25,7 @@ type ProjectSettingsDescriber interface {
}

type ProjectSettingsUpdater interface {
UpdateProjectSettings(string, *atlas.ProjectSettings) (*atlasv2.GroupSettings, error)
UpdateProjectSettings(string, *atlasv2.GroupSettings) (*atlasv2.GroupSettings, error)
}

// ProjectSettings encapsulates the logic of getting settings of a particular project.
Expand All @@ -36,14 +35,7 @@ func (s *Store) ProjectSettings(projectID string) (*atlasv2.GroupSettings, error
}

// UpdateProjectSettings encapsulates the logic of updating settings of a particular project.
func (s *Store) UpdateProjectSettings(projectID string, projectSettings *atlas.ProjectSettings) (*atlasv2.GroupSettings, error) {
groupSettings := atlasv2.GroupSettings{
IsCollectDatabaseSpecificsStatisticsEnabled: projectSettings.IsCollectDatabaseSpecificsStatisticsEnabled,
IsDataExplorerEnabled: projectSettings.IsDataExplorerEnabled,
IsPerformanceAdvisorEnabled: projectSettings.IsPerformanceAdvisorEnabled,
IsRealtimePerformancePanelEnabled: projectSettings.IsRealtimePerformancePanelEnabled,
IsSchemaAdvisorEnabled: projectSettings.IsSchemaAdvisorEnabled,
}
result, _, err := s.clientv2.ProjectsApi.UpdateProjectSettings(s.ctx, projectID, &groupSettings).Execute()
func (s *Store) UpdateProjectSettings(projectID string, projectSettings *atlasv2.GroupSettings) (*atlasv2.GroupSettings, error) {
result, _, err := s.clientv2.ProjectsApi.UpdateProjectSettings(s.ctx, projectID, projectSettings).Execute()
return result, err
}
4 changes: 2 additions & 2 deletions test/e2e/atlas/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,12 @@ func createProjectWithoutAlertSettings(projectName string) (string, error) {
return "", fmt.Errorf("%s (%w)", string(resp), err)
}

var project mongodbatlas.Project
var project atlasv2.Group
if err := json.Unmarshal(resp, &project); err != nil {
return "", fmt.Errorf("invalid response: %s (%w)", string(resp), err)
}

return project.ID, nil
return project.GetId(), nil
}

func listClustersForProject(t *testing.T, cliPath, projectID string) atlasv2.PaginatedAdvancedClusterDescription {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"
"time"

"go.mongodb.org/atlas/mongodbatlas"
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
)

const (
Expand All @@ -45,12 +45,12 @@ func CreateProject(projectName string) (string, error) {
return "", fmt.Errorf("%w: %s", err, string(resp))
}

var project mongodbatlas.Project
var project atlasv2.Group
if err := json.Unmarshal(resp, &project); err != nil {
return "", fmt.Errorf("%w: %s", err, resp)
}

return project.ID, nil
return project.GetId(), nil
}

func deleteProject(projectID string) error {
Expand Down
20 changes: 10 additions & 10 deletions test/e2e/iam/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strconv"

"github.com/mongodb/mongodb-atlas-cli/test/e2e"
"go.mongodb.org/atlas/mongodbatlas"
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
)

const (
Expand Down Expand Up @@ -65,13 +65,13 @@ func createOrgAPIKey() (string, error) {
return "", fmt.Errorf("%w: %s", err, string(resp))
}

var key mongodbatlas.APIKey
var key atlasv2.ApiKeyUserDetails
if err := json.Unmarshal(resp, &key); err != nil {
return "", err
}

if key.ID != "" {
return key.ID, nil
if key.GetId() != "" {
return key.GetId(), nil
}

return "", errNoAPIKey
Expand Down Expand Up @@ -115,12 +115,12 @@ func createTeam(teamName string) (string, error) {
return "", fmt.Errorf("%w: %s", err, string(resp))
}

var team mongodbatlas.Team
var team atlasv2.Team
if err := json.Unmarshal(resp, &team); err != nil {
return "", err
}

return team.ID, nil
return team.GetId(), nil
}

func deleteTeam(teamID string) error {
Expand Down Expand Up @@ -160,14 +160,14 @@ func OrgNUser(n int) (username, userID string, err error) {
return "", "", fmt.Errorf("error loading org users: %w (%s)", err, string(resp))
}

var users mongodbatlas.AtlasUsersResponse
var users atlasv2.PaginatedAppUser
if err := json.Unmarshal(resp, &users); err != nil {
return "", "", err
}

if len(users.Results) <= n {
return "", "", fmt.Errorf("%w: %d for %d users", errInvalidIndex, n, len(users.Results))
if len(users.GetResults()) <= n {
return "", "", fmt.Errorf("%w: %d for %d users", errInvalidIndex, n, len(users.GetResults()))
}

return users.Results[n].Username, users.Results[n].ID, nil
return users.GetResults()[n].Username, users.GetResults()[n].GetId(), nil
}

0 comments on commit c94d94d

Please sign in to comment.