Skip to content

Commit 6f8835b

Browse files
authored
task: reduce usage of "go.mongodb.org/atlas/mongodbatlas" (#3764)
1 parent 1703924 commit 6f8835b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+133
-160
lines changed

go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ require (
4545
github.com/yuin/goldmark v1.7.10
4646
go.mongodb.org/atlas v0.38.0
4747
go.mongodb.org/atlas-sdk/v20240530005 v20240530005.0.0
48+
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0
4849
go.mongodb.org/mongo-driver v1.17.3
4950
go.opentelemetry.io/otel v1.35.0
5051
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0
@@ -61,10 +62,6 @@ require (
6162
gopkg.in/yaml.v3 v3.0.1
6263
)
6364

64-
require go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0
65-
66-
require github.com/minio/minlz v1.0.0 // indirect
67-
6865
require (
6966
cloud.google.com/go v0.120.0 // indirect
7067
cloud.google.com/go/auth v0.16.0 // indirect
@@ -127,6 +124,7 @@ require (
127124
github.com/mailru/easyjson v0.7.7 // indirect
128125
github.com/mattn/go-colorable v0.1.13 // indirect
129126
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
127+
github.com/minio/minlz v1.0.0 // indirect
130128
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
131129
github.com/montanaflynn/stats v0.7.1 // indirect
132130
github.com/nwaples/rardecode/v2 v2.1.0 // indirect

internal/api/config.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package api
1717
import (
1818
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
1919
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
20-
"go.mongodb.org/atlas/mongodbatlas"
2120
)
2221

2322
type AuthenticatedConfigWrapper struct {
@@ -51,5 +50,5 @@ func (c *AuthenticatedConfigWrapper) GetBaseURL() (string, error) {
5150
}
5251

5352
// By default, return the default base URL
54-
return mongodbatlas.CloudURL, nil
53+
return store.CloudServiceURL, nil
5554
}

internal/cli/backup/exports/buckets/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var listTemplate = `ID BUCKET NAME CLOUD PROVIDER IAM ROLE ID{{range valueOrEmpt
4646
`
4747

4848
func (opts *ListOpts) Run() error {
49-
listOpts := opts.NewListOptions()
49+
listOpts := opts.NewAtlasListOptions()
5050
r, err := opts.store.ExportBuckets(opts.ConfigProjectID(), listOpts)
5151
if err != nil {
5252
return err

internal/cli/backup/exports/buckets/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestListOpts_Run(t *testing.T) {
5151

5252
mockStore.
5353
EXPECT().
54-
ExportBuckets(listOpts.ProjectID, listOpts.NewListOptions()).
54+
ExportBuckets(listOpts.ProjectID, listOpts.NewAtlasListOptions()).
5555
Return(expected, nil).
5656
Times(1)
5757

internal/cli/backup/exports/jobs/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var listTemplate = `ID EXPORT BUCKET ID STATE SNAPSHOT ID{{range valueOrEmptySli
4747
`
4848

4949
func (opts *ListOpts) Run() error {
50-
listOpts := opts.NewListOptions()
50+
listOpts := opts.NewAtlasListOptions()
5151
r, err := opts.store.ExportJobs(opts.ConfigProjectID(), opts.clusterName, listOpts)
5252
if err != nil {
5353
return err

internal/cli/backup/exports/jobs/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestListOpts_Run(t *testing.T) {
3838

3939
mockStore.
4040
EXPECT().
41-
ExportJobs(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
41+
ExportJobs(listOpts.ProjectID, "Cluster0", listOpts.NewAtlasListOptions()).
4242
Return(expected, nil).
4343
Times(1)
4444

internal/cli/backup/restores/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (opts *ListOpts) Run() error {
6666
return err
6767
}
6868

69-
listOpts := opts.NewListOptions()
69+
listOpts := opts.NewAtlasListOptions()
7070
restoreJobs, err := opts.store.RestoreJobs(opts.ConfigProjectID(), opts.clusterName, listOpts)
7171
if err != nil {
7272
return err

internal/cli/backup/restores/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestListOpts_Run(t *testing.T) {
4848

4949
mockStore.
5050
EXPECT().
51-
RestoreJobs(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
51+
RestoreJobs(listOpts.ProjectID, "Cluster0", listOpts.NewAtlasListOptions()).
5252
Return(expected, nil).
5353
Times(1)
5454

internal/cli/backup/snapshots/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (opts *ListOpts) Run() error {
6666
return err
6767
}
6868

69-
listOpts := opts.NewListOptions()
69+
listOpts := opts.NewAtlasListOptions()
7070
snapshotsList, err := opts.store.Snapshots(opts.ConfigProjectID(), opts.clusterName, listOpts)
7171
if err != nil {
7272
return err

internal/cli/backup/snapshots/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestList_Run(t *testing.T) {
6464

6565
mockStore.
6666
EXPECT().
67-
Snapshots(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
67+
Snapshots(listOpts.ProjectID, "Cluster0", listOpts.NewAtlasListOptions()).
6868
Return(expected, nil).
6969
Times(1)
7070

internal/cli/cloudproviders/accessroles/aws/authorize.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
2525
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2626
"github.com/spf13/cobra"
27-
atlas "go.mongodb.org/atlas/mongodbatlas"
27+
atlasv2 "go.mongodb.org/atlas-sdk/v20250312002/admin"
2828
)
2929

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

57-
func (opts *AuthorizeOpts) newCloudProviderAuthorizationRequest() *atlas.CloudProviderAccessRoleRequest {
58-
return &atlas.CloudProviderAccessRoleRequest{
57+
func (opts *AuthorizeOpts) newCloudProviderAuthorizationRequest() *atlasv2.CloudProviderAccessRoleRequestUpdate {
58+
return &atlasv2.CloudProviderAccessRoleRequestUpdate{
5959
ProviderName: provider,
60-
IAMAssumedRoleARN: &opts.IAMAssumedRoleARN,
60+
IamAssumedRoleArn: &opts.IAMAssumedRoleARN,
6161
}
6262
}
6363

internal/cli/cloudproviders/accessroles/aws/deauthorize.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
2626
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2727
"github.com/spf13/cobra"
28-
atlas "go.mongodb.org/atlas/mongodbatlas"
2928
)
3029

3130
const (
@@ -54,22 +53,14 @@ func (opts *DeauthorizeOpts) Run() error {
5453
return opts.Print(deauthorizeFail)
5554
}
5655

57-
err := opts.store.DeauthorizeCloudProviderAccessRoles(opts.newCloudProviderDeauthorizationRequest())
56+
err := opts.store.DeauthorizeCloudProviderAccessRoles(opts.ConfigProjectID(), provider, opts.Entry)
5857
if err != nil {
5958
return err
6059
}
6160

6261
return opts.Print(deauthorizeSuccess)
6362
}
6463

65-
func (opts *DeauthorizeOpts) newCloudProviderDeauthorizationRequest() *atlas.CloudProviderDeauthorizationRequest {
66-
return &atlas.CloudProviderDeauthorizationRequest{
67-
ProviderName: provider,
68-
GroupID: opts.ConfigProjectID(),
69-
RoleID: opts.Entry,
70-
}
71-
}
72-
7364
// atlas cloudProvider aws accessRoles deauthorize <roleId> [--projectId projectId].
7465
func DeauthorizeBuilder() *cobra.Command {
7566
opts := &DeauthorizeOpts{

internal/cli/cloudproviders/accessroles/aws/deauthorize_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestDeauthorizeOpts_Run(t *testing.T) {
5050

5151
mockStore.
5252
EXPECT().
53-
DeauthorizeCloudProviderAccessRoles(opts.newCloudProviderDeauthorizationRequest()).
53+
DeauthorizeCloudProviderAccessRoles(opts.ProjectID, provider, opts.Entry).
5454
Return(nil).
5555
Times(1)
5656

internal/cli/clusters/onlinearchive/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var listTemplate = `ID DATABASE COLLECTION STATE{{range valueOrEmptySlice .Resul
4848
`
4949

5050
func (opts *ListOpts) Run() error {
51-
lst := opts.NewListOptions()
51+
lst := opts.NewAtlasListOptions()
5252
r, err := opts.store.OnlineArchives(opts.ConfigProjectID(), opts.clusterName, lst)
5353
if err != nil {
5454
return err

internal/cli/clusters/onlinearchive/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestList_Run(t *testing.T) {
4444

4545
mockStore.
4646
EXPECT().
47-
OnlineArchives(listOpts.ProjectID, listOpts.clusterName, listOpts.NewListOptions()).
47+
OnlineArchives(listOpts.ProjectID, listOpts.clusterName, listOpts.NewAtlasListOptions()).
4848
Return(expected, nil).
4949
Times(1)
5050

internal/cli/datalakepipelines/availablesnapshots/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (opts *ListOpts) validate() error {
7171
}
7272

7373
func (opts *ListOpts) Run() error {
74-
r, err := opts.store.PipelineAvailableSnapshots(opts.ConfigProjectID(), opts.pipelineName, convertTime(opts.completedAfter), opts.NewListOptions())
74+
r, err := opts.store.PipelineAvailableSnapshots(opts.ConfigProjectID(), opts.pipelineName, convertTime(opts.completedAfter), opts.NewAtlasListOptions())
7575
if err != nil {
7676
return err
7777
}

internal/cli/datalakepipelines/availablesnapshots/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestListOpts_Run(t *testing.T) {
6767

6868
mockStore.
6969
EXPECT().
70-
PipelineAvailableSnapshots(listOpts.ProjectID, listOpts.pipelineName, convertTime(listOpts.completedAfter), listOpts.NewListOptions()).
70+
PipelineAvailableSnapshots(listOpts.ProjectID, listOpts.pipelineName, convertTime(listOpts.completedAfter), listOpts.NewAtlasListOptions()).
7171
Return(expected, nil).
7272
Times(1)
7373

internal/cli/default_setter_opts.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ func (opts *DefaultSetterOpts) projects() (ids, names []string, err error) {
9393
}
9494
if err != nil {
9595
err = commonerrors.Check(err)
96-
var atlasErr *atlas.ErrorResponse
97-
if errors.As(err, &atlasErr) && atlasErr.HTTPCode == 404 {
96+
if atlasErr, ok := atlasv2.AsError(err); ok && atlasErr.GetError() == 404 {
9897
return nil, nil, errNoResults
9998
}
10099
return nil, nil, err
@@ -118,8 +117,7 @@ func (opts *DefaultSetterOpts) orgs(filter string) (results []atlasv2.AtlasOrgan
118117
pagination := &atlasv2.ListOrganizationsApiParams{Name: &filter, ItemsPerPage: pointer.Get(resultsLimit)}
119118
orgs, err := opts.Store.Organizations(pagination)
120119
if err != nil {
121-
var atlasErr *atlas.ErrorResponse
122-
if errors.As(err, &atlasErr) && atlasErr.HTTPCode == 404 {
120+
if atlasErr, ok := atlasv2.AsError(err); ok && atlasErr.GetError() == 404 {
123121
return nil, errNoResults
124122
}
125123
return nil, commonerrors.Check(err)

internal/cli/list_opts.go

-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
2020
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2121
"github.com/spf13/cobra"
22-
"go.mongodb.org/atlas/mongodbatlas"
2322
)
2423

2524
const (
@@ -33,14 +32,6 @@ type ListOpts struct {
3332
OmitCount bool
3433
}
3534

36-
func (opts *ListOpts) NewListOptions() *mongodbatlas.ListOptions {
37-
return &mongodbatlas.ListOptions{
38-
PageNum: opts.PageNum,
39-
ItemsPerPage: opts.ItemsPerPage,
40-
IncludeCount: !opts.OmitCount,
41-
}
42-
}
43-
4435
func (opts *ListOpts) NewAtlasListOptions() *store.ListOptions {
4536
return &store.ListOptions{
4637
PageNum: opts.PageNum,

internal/cli/metrics/databases/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var databasesListTemplate = `DATABASE NAME{{range valueOrEmptySlice .Results}}
4848
`
4949

5050
func (opts *ListsOpts) Run() error {
51-
listOpts := opts.NewListOptions()
51+
listOpts := opts.NewAtlasListOptions()
5252
r, err := opts.store.ProcessDatabases(opts.ConfigProjectID(), opts.host, opts.port, listOpts)
5353
if err != nil {
5454
return err

internal/cli/metrics/databases/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestDatabasesListsOpts_Run(t *testing.T) {
4444
store: mockStore,
4545
}
4646

47-
opts := listOpts.NewListOptions()
47+
opts := listOpts.NewAtlasListOptions()
4848
mockStore.
4949
EXPECT().ProcessDatabases(listOpts.ProjectID, listOpts.host, listOpts.port, opts).
5050
Return(expected, nil).

internal/cli/metrics/disks/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (opts *ListsOpts) initStore(ctx context.Context) func() error {
4444
}
4545

4646
func (opts *ListsOpts) Run() error {
47-
listOpts := opts.NewListOptions()
47+
listOpts := opts.NewAtlasListOptions()
4848
r, err := opts.store.ProcessDisks(opts.ConfigProjectID(), opts.host, opts.port, listOpts)
4949
if err != nil {
5050
return err

internal/cli/metrics/disks/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestDisksListsOpts_Run(t *testing.T) {
4444
store: mockStore,
4545
}
4646

47-
opts := listOpts.NewListOptions()
47+
opts := listOpts.NewAtlasListOptions()
4848
mockStore.
4949
EXPECT().ProcessDisks(listOpts.ProjectID, listOpts.host, listOpts.port, opts).
5050
Return(expected, nil).

internal/cli/networking/containers/list.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (opts *ListOpts) Run() error {
5353
var r []atlasv2.CloudProviderContainer
5454
var err error
5555
if opts.provider == "" {
56-
r, err = opts.store.AllContainers(opts.ConfigProjectID(), opts.NewListOptions())
56+
r, err = opts.store.AllContainers(opts.ConfigProjectID(), opts.NewAtlasListOptions())
5757
} else {
5858
listOpts := opts.newContainerListOptions()
5959
r, err = opts.store.ContainersByProvider(opts.ConfigProjectID(), listOpts)
@@ -66,9 +66,14 @@ func (opts *ListOpts) Run() error {
6666
}
6767

6868
func (opts *ListOpts) newContainerListOptions() *atlas.ContainersListOptions {
69+
lst := opts.NewAtlasListOptions()
6970
return &atlas.ContainersListOptions{
7071
ProviderName: opts.provider,
71-
ListOptions: *opts.NewListOptions(),
72+
ListOptions: atlas.ListOptions{
73+
PageNum: lst.PageNum,
74+
ItemsPerPage: lst.ItemsPerPage,
75+
IncludeCount: lst.IncludeCount,
76+
},
7277
}
7378
}
7479

internal/cli/networking/containers/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestList_Run(t *testing.T) {
5252

5353
mockStore.
5454
EXPECT().
55-
AllContainers(listOpts.ProjectID, listOpts.NewListOptions()).
55+
AllContainers(listOpts.ProjectID, listOpts.NewAtlasListOptions()).
5656
Return(expected, nil).
5757
Times(1)
5858

internal/cli/organizations/apikeys/accesslists/list.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
2222
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
2323
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
24-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer"
2524
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
2625
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2726
"github.com/spf13/cobra"
@@ -49,13 +48,13 @@ func (opts *ListOpts) initStore(ctx context.Context) func() error {
4948
}
5049

5150
func (opts *ListOpts) Run() error {
52-
listOpts := opts.NewListOptions()
51+
listOpts := opts.NewAtlasListOptions()
5352
params := &admin.ListApiKeyAccessListsEntriesApiParams{
5453
OrgId: opts.ConfigOrgID(),
5554
ApiUserId: opts.id,
56-
PageNum: pointer.Get(listOpts.PageNum),
57-
ItemsPerPage: pointer.Get(listOpts.ItemsPerPage),
58-
IncludeCount: pointer.Get(listOpts.IncludeCount),
55+
PageNum: &listOpts.PageNum,
56+
ItemsPerPage: &listOpts.ItemsPerPage,
57+
IncludeCount: &listOpts.IncludeCount,
5958
}
6059
result, err := opts.store.OrganizationAPIKeyAccessLists(params)
6160
if err != nil {

internal/cli/organizations/apikeys/accesslists/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestListOpts_Run(t *testing.T) {
3333
opts := &ListOpts{
3434
store: mockStore,
3535
}
36-
listOpts := opts.NewListOptions()
36+
listOpts := opts.NewAtlasListOptions()
3737

3838
params := &admin.ListApiKeyAccessListsEntriesApiParams{
3939
OrgId: opts.OrgID,

internal/cli/organizations/apikeys/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (opts *ListOpts) initStore(ctx context.Context) func() error {
4848
}
4949

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

5353
if err != nil {
5454
return err

internal/cli/organizations/apikeys/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestListOpts_Run(t *testing.T) {
3737

3838
mockStore.
3939
EXPECT().
40-
OrganizationAPIKeys(opts.OrgID, opts.NewListOptions()).
40+
OrganizationAPIKeys(opts.OrgID, opts.NewAtlasListOptions()).
4141
Return(expected, nil).
4242
Times(1)
4343

internal/cli/organizations/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (opts *ListOpts) newOrganizationListOptions() *atlasv2.ListOrganizationsApi
6161
params := &atlasv2.ListOrganizationsApiParams{
6262
Name: &opts.name,
6363
}
64-
if listOpt := opts.NewListOptions(); listOpt != nil {
64+
if listOpt := opts.NewAtlasListOptions(); listOpt != nil {
6565
params.PageNum = &listOpt.PageNum
6666
params.ItemsPerPage = &listOpt.ItemsPerPage
6767
params.IncludeCount = &listOpt.IncludeCount

internal/cli/organizations/users/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (opts *ListOpts) initStore(ctx context.Context) func() error {
4646
}
4747

4848
func (opts *ListOpts) Run() error {
49-
listOptions := opts.NewListOptions()
49+
listOptions := opts.NewAtlasListOptions()
5050
r, err := opts.store.OrganizationUsers(opts.ConfigOrgID(), listOptions)
5151

5252
if err != nil {

0 commit comments

Comments
 (0)