Skip to content
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

task: reduce usages of the old atlas client #2760

Merged
merged 3 commits into from Mar 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/cli/auth/logout.go
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/oauth"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

type logoutOpts struct {
Expand All @@ -44,7 +44,7 @@ type ConfigDeleter interface {
}

type Revoker interface {
RevokeToken(context.Context, string, string) (*atlas.Response, error)
RevokeToken(context.Context, string, string) (*opsmngr.Response, error)
}

func (opts *logoutOpts) initFlow() error {
Expand Down
17 changes: 8 additions & 9 deletions internal/cli/default_setter_opts.go
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/prompt"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/store"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/validate"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

Expand Down Expand Up @@ -87,14 +86,14 @@ func (opts *DefaultSetterOpts) projects() (ids, names []string, err error) {

var projects *opsmngr.Projects
if opts.OrgID == "" {
projects, err = opts.Store.Projects(&atlas.ListOptions{ItemsPerPage: resultsLimit})
projects, err = opts.Store.Projects(&opsmngr.ListOptions{ItemsPerPage: resultsLimit})
} else {
list := &atlas.ProjectsListOptions{}
list := &opsmngr.ProjectsListOptions{}
list.ItemsPerPage = resultsLimit
projects, err = opts.Store.GetOrgProjects(opts.OrgID, list)
}
if err != nil {
var atlasErr *atlas.ErrorResponse
var atlasErr *opsmngr.ErrorResponse
if errors.As(err, &atlasErr) && atlasErr.HTTPCode == 404 {
return nil, nil, errNoResults
}
Expand All @@ -116,11 +115,11 @@ func (opts *DefaultSetterOpts) orgs(filter string) (organizations []*opsmngr.Org
spin.Start()
defer spin.Stop()
includeDeleted := false
pagination := &atlas.OrganizationsListOptions{IncludeDeletedOrgs: &includeDeleted, Name: filter}
pagination := &opsmngr.OrganizationsListOptions{IncludeDeletedOrgs: &includeDeleted, Name: filter}
pagination.ItemsPerPage = resultsLimit
orgs, err := opts.Store.Organizations(pagination)
if err != nil {
var atlasErr *atlas.ErrorResponse
var atlasErr *opsmngr.ErrorResponse
if errors.As(err, &atlasErr) && atlasErr.HTTPCode == 404 {
return nil, errNoResults
}
Expand Down Expand Up @@ -150,7 +149,7 @@ func (opts *DefaultSetterOpts) ProjectExists(id string) bool {
func (opts *DefaultSetterOpts) AskProject() error {
ids, names, err := opts.projects()
if err != nil {
var target *atlas.ErrorResponse
var target *opsmngr.ErrorResponse
switch {
case errors.Is(err, errNoResults):
_, _ = fmt.Fprintln(opts.OutWriter, "You don't seem to have access to any project")
Expand Down Expand Up @@ -212,7 +211,7 @@ func (opts *DefaultSetterOpts) askOrgWithFilter(filter string) error {
orgs, err := opts.orgs(filter)
if err != nil {
applyFilter := false
var target *atlas.ErrorResponse
var target *opsmngr.ErrorResponse
switch {
case errors.Is(err, errNoResults):
if filter == "" {
Expand Down Expand Up @@ -271,7 +270,7 @@ func (opts *DefaultSetterOpts) manualOrgID() error {
return nil
}

func (opts *DefaultSetterOpts) selectOnPremOrg(orgs []*atlas.Organization) error {
func (opts *DefaultSetterOpts) selectOnPremOrg(orgs []*opsmngr.Organization) error {
if len(orgs) == 1 {
opts.OrgID = orgs[0].ID
return nil
Expand Down
12 changes: 6 additions & 6 deletions internal/cli/iam/organizations/apikeys/accesslists/create.go
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/store"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

const createTemplate = "Created new access list entry(s).\n"
Expand All @@ -46,20 +46,20 @@ func (opts *CreateOpts) initStore(ctx context.Context) func() error {
}
}

func (opts *CreateOpts) newAccessListAPIKeysReq() ([]*atlas.AccessListAPIKeysReq, error) {
req := make([]*atlas.AccessListAPIKeysReq, 0, len(opts.ips)+len(opts.cidrs))
func (opts *CreateOpts) newAccessListAPIKeysReq() ([]*opsmngr.AccessListAPIKeysReq, error) {
req := make([]*opsmngr.AccessListAPIKeysReq, 0, len(opts.ips)+len(opts.cidrs))
if len(opts.ips) == 0 && len(opts.cidrs) == 0 {
return nil, fmt.Errorf("either --%s, --%s must be set", flag.IP, flag.CIDR)
}
for _, v := range opts.ips {
entry := &atlas.AccessListAPIKeysReq{
entry := &opsmngr.AccessListAPIKeysReq{
IPAddress: v,
}
req = append(req, entry)
}

for _, v := range opts.cidrs {
entry := &atlas.AccessListAPIKeysReq{
entry := &opsmngr.AccessListAPIKeysReq{
CidrBlock: v,
}
req = append(req, entry)
Expand All @@ -74,7 +74,7 @@ func (opts *CreateOpts) Run() error {
return err
}

var result *atlas.AccessListAPIKeys
var result *opsmngr.AccessListAPIKeys

result, err = opts.store.CreateOrganizationAPIKeyAccessList(opts.ConfigOrgID(), opts.apyKey, req)
if err != nil {
Expand Down
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/test"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestCreate_Run(t *testing.T) {
Expand All @@ -44,7 +44,7 @@ func TestCreate_Run(t *testing.T) {
mockStore.
EXPECT().
CreateOrganizationAPIKeyAccessList(createOpts.OrgID, createOpts.apyKey, r).
Return(&atlas.AccessListAPIKeys{}, nil).
Return(&opsmngr.AccessListAPIKeys{}, nil).
Times(1)

if err = createOpts.Run(); err != nil {
Expand Down
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/test"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestListOpts_Run(t *testing.T) {
Expand All @@ -37,8 +37,8 @@ func TestListOpts_Run(t *testing.T) {
mockStore.
EXPECT().
OrganizationAPIKeyAccessLists(opts.OrgID, opts.id, opts.NewListOptions()).
Return(&atlas.AccessListAPIKeys{
Results: []*atlas.AccessListAPIKey{},
Return(&opsmngr.AccessListAPIKeys{
Results: []*opsmngr.AccessListAPIKey{},
}, nil).
Times(1)

Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/organizations/apikeys/create.go
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/store"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

const createTemplate = `API Key '{{.ID}}' created.
Expand All @@ -49,8 +49,8 @@ func (opts *CreateOpts) initStore(ctx context.Context) func() error {
}
}

func (opts *CreateOpts) newAPIKeyInput() *atlas.APIKeyInput {
return &atlas.APIKeyInput{
func (opts *CreateOpts) newAPIKeyInput() *opsmngr.APIKeyInput {
return &opsmngr.APIKeyInput{
Desc: opts.desc,
Roles: opts.roles,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/apikeys/create_test.go
Expand Up @@ -21,14 +21,14 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestCreate_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockOrganizationAPIKeyCreator(ctrl)

expected := &mongodbatlas.APIKey{
expected := &opsmngr.APIKey{
ID: "1",
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/apikeys/describe_test.go
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestDescribeOpts_Run(t *testing.T) {
Expand All @@ -36,7 +36,7 @@ func TestDescribeOpts_Run(t *testing.T) {
mockStore.
EXPECT().
OrganizationAPIKey(opts.OrgID, opts.id).
Return(&mongodbatlas.APIKey{}, nil).
Return(&opsmngr.APIKey{}, nil).
Times(1)

if err := opts.Run(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/apikeys/list_test.go
Expand Up @@ -22,14 +22,14 @@ import (
"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/test"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestListOpts_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockOrganizationAPIKeyLister(ctrl)

var expected []mongodbatlas.APIKey
var expected []opsmngr.APIKey

opts := &ListOpts{
store: mockStore,
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/organizations/apikeys/update.go
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/store"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

type UpdateOpts struct {
Expand All @@ -45,8 +45,8 @@ func (opts *UpdateOpts) initStore(ctx context.Context) func() error {
}
}

func (opts *UpdateOpts) newAPIKeyInput() *atlas.APIKeyInput {
return &atlas.APIKeyInput{
func (opts *UpdateOpts) newAPIKeyInput() *opsmngr.APIKeyInput {
return &opsmngr.APIKeyInput{
Desc: opts.desc,
Roles: opts.roles,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/apikeys/update_test.go
Expand Up @@ -21,14 +21,14 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestUpdateOpts_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockOrganizationAPIKeyUpdater(ctrl)

expected := &mongodbatlas.APIKey{
expected := &opsmngr.APIKey{
ID: "1",
}

Expand Down
3 changes: 1 addition & 2 deletions internal/cli/iam/organizations/list.go
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/store"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

Expand Down Expand Up @@ -59,7 +58,7 @@ func (opts *ListOpts) Run() error {
}

func (opts *ListOpts) newOrganizationListOptions() *opsmngr.OrganizationsListOptions {
return &atlas.OrganizationsListOptions{
return &opsmngr.OrganizationsListOptions{
Name: opts.name,
IncludeDeletedOrgs: &opts.includeDeletedOrgs,
ListOptions: *opts.NewListOptions(),
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/users/list_test.go
Expand Up @@ -24,14 +24,14 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/test"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestList_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockUserLister(ctrl)

expected := &mongodbatlas.AtlasUsersResponse{}
expected := &opsmngr.UsersResponse{}

listOpts := &ListOpts{
GlobalOpts: cli.GlobalOpts{
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/projects/apikeys/create.go
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/store"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/usage"
"github.com/spf13/cobra"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

var createTemplate = `API Key '{{.ID}}' created.
Expand All @@ -50,7 +50,7 @@ func (opts *CreateOpts) initStore(ctx context.Context) func() error {
}

func (opts *CreateOpts) Run() error {
apiKeyInput := &mongodbatlas.APIKeyInput{
apiKeyInput := &opsmngr.APIKeyInput{
Desc: opts.description,
Roles: opts.roles,
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/projects/apikeys/create_test.go
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestCreate_Run(t *testing.T) {
Expand All @@ -36,11 +36,11 @@ func TestCreate_Run(t *testing.T) {

createOpts.ProjectID = "5a0a1e7e0f2912c554080adc"

apiKey := &mongodbatlas.APIKeyInput{
apiKey := &opsmngr.APIKeyInput{
Desc: createOpts.description,
Roles: []string{},
}
expected := &mongodbatlas.APIKey{}
expected := &opsmngr.APIKey{}

mockStore.
EXPECT().
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/projects/apikeys/list_test.go
Expand Up @@ -21,14 +21,14 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/mocks"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestList_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockProjectAPIKeyLister(ctrl)

var expected []mongodbatlas.APIKey
var expected []opsmngr.APIKey

listOpts := &ListOpts{
store: mockStore,
Expand Down
1 change: 0 additions & 1 deletion internal/cli/iam/projects/create.go
Expand Up @@ -31,7 +31,6 @@ import (

const (
atlasCreateTemplate = "Project '{{.ID}}' created.\n"
govRegionOnly = "GOV_REGIONS_ONLY"
)

type CreateOpts struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/projects/list.go
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/store"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/usage"
"github.com/spf13/cobra"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

const listTemplate = `ID NAME{{range valueOrEmptySlice .Results}}
Expand All @@ -52,7 +52,7 @@ func (opts *ListOpts) Run() error {
var err error
listOptions := opts.NewListOptions()
if opts.ConfigOrgID() != "" && config.Service() == config.OpsManagerService {
l := &mongodbatlas.ProjectsListOptions{ListOptions: *listOptions}
l := &opsmngr.ProjectsListOptions{ListOptions: *listOptions}
r, err = opts.store.GetOrgProjects(opts.ConfigOrgID(), l)
} else {
r, err = opts.store.Projects(listOptions)
Expand Down