Skip to content

task: reduce usage of "go.mongodb.org/atlas/mongodbatlas" #3764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
github.com/yuin/goldmark v1.7.10
go.mongodb.org/atlas v0.38.0
go.mongodb.org/atlas-sdk/v20240530005 v20240530005.0.0
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0
go.mongodb.org/mongo-driver v1.17.3
go.opentelemetry.io/otel v1.35.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0
Expand All @@ -61,10 +62,6 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0

require github.com/minio/minlz v1.0.0 // indirect

require (
cloud.google.com/go v0.120.0 // indirect
cloud.google.com/go/auth v0.16.0 // indirect
Expand Down Expand Up @@ -127,6 +124,7 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/minio/minlz v1.0.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/nwaples/rardecode/v2 v2.1.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions internal/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package api
import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"go.mongodb.org/atlas/mongodbatlas"
)

type AuthenticatedConfigWrapper struct {
Expand Down Expand Up @@ -51,5 +50,5 @@ func (c *AuthenticatedConfigWrapper) GetBaseURL() (string, error) {
}

// By default, return the default base URL
return mongodbatlas.CloudURL, nil
return store.CloudServiceURL, nil
}
2 changes: 1 addition & 1 deletion internal/cli/backup/exports/buckets/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var listTemplate = `ID BUCKET NAME CLOUD PROVIDER IAM ROLE ID{{range valueOrEmpt
`

func (opts *ListOpts) Run() error {
listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()
r, err := opts.store.ExportBuckets(opts.ConfigProjectID(), listOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/backup/exports/buckets/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestListOpts_Run(t *testing.T) {

mockStore.
EXPECT().
ExportBuckets(listOpts.ProjectID, listOpts.NewListOptions()).
ExportBuckets(listOpts.ProjectID, listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/backup/exports/jobs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var listTemplate = `ID EXPORT BUCKET ID STATE SNAPSHOT ID{{range valueOrEmptySli
`

func (opts *ListOpts) Run() error {
listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()
r, err := opts.store.ExportJobs(opts.ConfigProjectID(), opts.clusterName, listOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/backup/exports/jobs/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestListOpts_Run(t *testing.T) {

mockStore.
EXPECT().
ExportJobs(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
ExportJobs(listOpts.ProjectID, "Cluster0", listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/backup/restores/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (opts *ListOpts) Run() error {
return err
}

listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()
restoreJobs, err := opts.store.RestoreJobs(opts.ConfigProjectID(), opts.clusterName, listOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/backup/restores/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestListOpts_Run(t *testing.T) {

mockStore.
EXPECT().
RestoreJobs(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
RestoreJobs(listOpts.ProjectID, "Cluster0", listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/backup/snapshots/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (opts *ListOpts) Run() error {
return err
}

listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()
snapshotsList, err := opts.store.Snapshots(opts.ConfigProjectID(), opts.clusterName, listOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/backup/snapshots/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestList_Run(t *testing.T) {

mockStore.
EXPECT().
Snapshots(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
Snapshots(listOpts.ProjectID, "Cluster0", listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
8 changes: 4 additions & 4 deletions internal/cli/cloudproviders/accessroles/aws/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
atlasv2 "go.mongodb.org/atlas-sdk/v20250312002/admin"
)

const authorizeTemplate = "AWS IAM role '{{.RoleId}} successfully authorized.\n"
Expand Down Expand Up @@ -54,10 +54,10 @@ func (opts *AuthorizeOpts) Run() error {
return opts.Print(r)
}

func (opts *AuthorizeOpts) newCloudProviderAuthorizationRequest() *atlas.CloudProviderAccessRoleRequest {
return &atlas.CloudProviderAccessRoleRequest{
func (opts *AuthorizeOpts) newCloudProviderAuthorizationRequest() *atlasv2.CloudProviderAccessRoleRequestUpdate {
return &atlasv2.CloudProviderAccessRoleRequestUpdate{
ProviderName: provider,
IAMAssumedRoleARN: &opts.IAMAssumedRoleARN,
IamAssumedRoleArn: &opts.IAMAssumedRoleARN,
}
}

Expand Down
11 changes: 1 addition & 10 deletions internal/cli/cloudproviders/accessroles/aws/deauthorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const (
Expand Down Expand Up @@ -54,22 +53,14 @@ func (opts *DeauthorizeOpts) Run() error {
return opts.Print(deauthorizeFail)
}

err := opts.store.DeauthorizeCloudProviderAccessRoles(opts.newCloudProviderDeauthorizationRequest())
err := opts.store.DeauthorizeCloudProviderAccessRoles(opts.ConfigProjectID(), provider, opts.Entry)
if err != nil {
return err
}

return opts.Print(deauthorizeSuccess)
}

func (opts *DeauthorizeOpts) newCloudProviderDeauthorizationRequest() *atlas.CloudProviderDeauthorizationRequest {
return &atlas.CloudProviderDeauthorizationRequest{
ProviderName: provider,
GroupID: opts.ConfigProjectID(),
RoleID: opts.Entry,
}
}

// atlas cloudProvider aws accessRoles deauthorize <roleId> [--projectId projectId].
func DeauthorizeBuilder() *cobra.Command {
opts := &DeauthorizeOpts{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestDeauthorizeOpts_Run(t *testing.T) {

mockStore.
EXPECT().
DeauthorizeCloudProviderAccessRoles(opts.newCloudProviderDeauthorizationRequest()).
DeauthorizeCloudProviderAccessRoles(opts.ProjectID, provider, opts.Entry).
Return(nil).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/clusters/onlinearchive/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var listTemplate = `ID DATABASE COLLECTION STATE{{range valueOrEmptySlice .Resul
`

func (opts *ListOpts) Run() error {
lst := opts.NewListOptions()
lst := opts.NewAtlasListOptions()
r, err := opts.store.OnlineArchives(opts.ConfigProjectID(), opts.clusterName, lst)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/clusters/onlinearchive/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestList_Run(t *testing.T) {

mockStore.
EXPECT().
OnlineArchives(listOpts.ProjectID, listOpts.clusterName, listOpts.NewListOptions()).
OnlineArchives(listOpts.ProjectID, listOpts.clusterName, listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (opts *ListOpts) validate() error {
}

func (opts *ListOpts) Run() error {
r, err := opts.store.PipelineAvailableSnapshots(opts.ConfigProjectID(), opts.pipelineName, convertTime(opts.completedAfter), opts.NewListOptions())
r, err := opts.store.PipelineAvailableSnapshots(opts.ConfigProjectID(), opts.pipelineName, convertTime(opts.completedAfter), opts.NewAtlasListOptions())
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestListOpts_Run(t *testing.T) {

mockStore.
EXPECT().
PipelineAvailableSnapshots(listOpts.ProjectID, listOpts.pipelineName, convertTime(listOpts.completedAfter), listOpts.NewListOptions()).
PipelineAvailableSnapshots(listOpts.ProjectID, listOpts.pipelineName, convertTime(listOpts.completedAfter), listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
6 changes: 2 additions & 4 deletions internal/cli/default_setter_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ func (opts *DefaultSetterOpts) projects() (ids, names []string, err error) {
}
if err != nil {
err = commonerrors.Check(err)
var atlasErr *atlas.ErrorResponse
if errors.As(err, &atlasErr) && atlasErr.HTTPCode == 404 {
if atlasErr, ok := atlasv2.AsError(err); ok && atlasErr.GetError() == 404 {
return nil, nil, errNoResults
}
return nil, nil, err
Expand All @@ -118,8 +117,7 @@ func (opts *DefaultSetterOpts) orgs(filter string) (results []atlasv2.AtlasOrgan
pagination := &atlasv2.ListOrganizationsApiParams{Name: &filter, ItemsPerPage: pointer.Get(resultsLimit)}
orgs, err := opts.Store.Organizations(pagination)
if err != nil {
var atlasErr *atlas.ErrorResponse
if errors.As(err, &atlasErr) && atlasErr.HTTPCode == 404 {
if atlasErr, ok := atlasv2.AsError(err); ok && atlasErr.GetError() == 404 {
return nil, errNoResults
}
return nil, commonerrors.Check(err)
Expand Down
9 changes: 0 additions & 9 deletions internal/cli/list_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
"github.com/spf13/cobra"
"go.mongodb.org/atlas/mongodbatlas"
)

const (
Expand All @@ -33,14 +32,6 @@ type ListOpts struct {
OmitCount bool
}

func (opts *ListOpts) NewListOptions() *mongodbatlas.ListOptions {
return &mongodbatlas.ListOptions{
PageNum: opts.PageNum,
ItemsPerPage: opts.ItemsPerPage,
IncludeCount: !opts.OmitCount,
}
}

func (opts *ListOpts) NewAtlasListOptions() *store.ListOptions {
return &store.ListOptions{
PageNum: opts.PageNum,
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics/databases/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var databasesListTemplate = `DATABASE NAME{{range valueOrEmptySlice .Results}}
`

func (opts *ListsOpts) Run() error {
listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()
r, err := opts.store.ProcessDatabases(opts.ConfigProjectID(), opts.host, opts.port, listOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics/databases/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestDatabasesListsOpts_Run(t *testing.T) {
store: mockStore,
}

opts := listOpts.NewListOptions()
opts := listOpts.NewAtlasListOptions()
mockStore.
EXPECT().ProcessDatabases(listOpts.ProjectID, listOpts.host, listOpts.port, opts).
Return(expected, nil).
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics/disks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (opts *ListsOpts) initStore(ctx context.Context) func() error {
}

func (opts *ListsOpts) Run() error {
listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()
r, err := opts.store.ProcessDisks(opts.ConfigProjectID(), opts.host, opts.port, listOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics/disks/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestDisksListsOpts_Run(t *testing.T) {
store: mockStore,
}

opts := listOpts.NewListOptions()
opts := listOpts.NewAtlasListOptions()
mockStore.
EXPECT().ProcessDisks(listOpts.ProjectID, listOpts.host, listOpts.port, opts).
Return(expected, nil).
Expand Down
9 changes: 7 additions & 2 deletions internal/cli/networking/containers/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (opts *ListOpts) Run() error {
var r []atlasv2.CloudProviderContainer
var err error
if opts.provider == "" {
r, err = opts.store.AllContainers(opts.ConfigProjectID(), opts.NewListOptions())
r, err = opts.store.AllContainers(opts.ConfigProjectID(), opts.NewAtlasListOptions())
} else {
listOpts := opts.newContainerListOptions()
r, err = opts.store.ContainersByProvider(opts.ConfigProjectID(), listOpts)
Expand All @@ -66,9 +66,14 @@ func (opts *ListOpts) Run() error {
}

func (opts *ListOpts) newContainerListOptions() *atlas.ContainersListOptions {
lst := opts.NewAtlasListOptions()
return &atlas.ContainersListOptions{
ProviderName: opts.provider,
ListOptions: *opts.NewListOptions(),
ListOptions: atlas.ListOptions{
PageNum: lst.PageNum,
ItemsPerPage: lst.ItemsPerPage,
IncludeCount: lst.IncludeCount,
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/networking/containers/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestList_Run(t *testing.T) {

mockStore.
EXPECT().
AllContainers(listOpts.ProjectID, listOpts.NewListOptions()).
AllContainers(listOpts.ProjectID, listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
9 changes: 4 additions & 5 deletions internal/cli/organizations/apikeys/accesslists/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -49,13 +48,13 @@ func (opts *ListOpts) initStore(ctx context.Context) func() error {
}

func (opts *ListOpts) Run() error {
listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()
params := &admin.ListApiKeyAccessListsEntriesApiParams{
OrgId: opts.ConfigOrgID(),
ApiUserId: opts.id,
PageNum: pointer.Get(listOpts.PageNum),
ItemsPerPage: pointer.Get(listOpts.ItemsPerPage),
IncludeCount: pointer.Get(listOpts.IncludeCount),
PageNum: &listOpts.PageNum,
ItemsPerPage: &listOpts.ItemsPerPage,
IncludeCount: &listOpts.IncludeCount,
}
result, err := opts.store.OrganizationAPIKeyAccessLists(params)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestListOpts_Run(t *testing.T) {
opts := &ListOpts{
store: mockStore,
}
listOpts := opts.NewListOptions()
listOpts := opts.NewAtlasListOptions()

params := &admin.ListApiKeyAccessListsEntriesApiParams{
OrgId: opts.OrgID,
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/organizations/apikeys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (opts *ListOpts) initStore(ctx context.Context) func() error {
}

func (opts *ListOpts) Run() error {
r, err := opts.store.OrganizationAPIKeys(opts.ConfigOrgID(), opts.NewListOptions())
r, err := opts.store.OrganizationAPIKeys(opts.ConfigOrgID(), opts.NewAtlasListOptions())

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/organizations/apikeys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestListOpts_Run(t *testing.T) {

mockStore.
EXPECT().
OrganizationAPIKeys(opts.OrgID, opts.NewListOptions()).
OrganizationAPIKeys(opts.OrgID, opts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/organizations/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (opts *ListOpts) newOrganizationListOptions() *atlasv2.ListOrganizationsApi
params := &atlasv2.ListOrganizationsApiParams{
Name: &opts.name,
}
if listOpt := opts.NewListOptions(); listOpt != nil {
if listOpt := opts.NewAtlasListOptions(); listOpt != nil {
params.PageNum = &listOpt.PageNum
params.ItemsPerPage = &listOpt.ItemsPerPage
params.IncludeCount = &listOpt.IncludeCount
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/organizations/users/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (opts *ListOpts) initStore(ctx context.Context) func() error {
}

func (opts *ListOpts) Run() error {
listOptions := opts.NewListOptions()
listOptions := opts.NewAtlasListOptions()
r, err := opts.store.OrganizationUsers(opts.ConfigOrgID(), listOptions)

if err != nil {
Expand Down
Loading
Loading