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

CLOUDP-234527: Remove MongoCLI 3rd followup #2716

Merged
merged 8 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Docs maintained by Docs Cloud Team
/docs/ @mongodb/docs-cloud-team

/internal/kubernetes/operator/ @mongodb/atlas_kubernetes_team
/internal/cli/atlas/kubernetes/ @mongodb/atlas_kubernetes_team
1 change: 0 additions & 1 deletion build/ci/library_owners.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"go.mongodb.org/atlas": "mongocli",
"go.mongodb.org/atlas-sdk/v20231115007": "mongocli",
"go.mongodb.org/mongo-driver": "mongocli",
"go.mongodb.org/ops-manager": "mongocli",
"golang.org/x/crypto": "mongocli",
"golang.org/x/tools": "mongocli",
"google.golang.org/api": "mongocli",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
go.mongodb.org/atlas v0.36.0
go.mongodb.org/atlas-sdk/v20231115007 v20231115007.1.0
go.mongodb.org/mongo-driver v1.14.0
go.mongodb.org/ops-manager v0.55.3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/mod v0.16.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ go.mongodb.org/atlas-sdk/v20231115007 v20231115007.1.0 h1:RAnP53qeTT32iySa4sjfl1
go.mongodb.org/atlas-sdk/v20231115007 v20231115007.1.0/go.mod h1:JU7JOUGcv7pfDzbRTwIr8hGy2R1lehdrdfGj9fDjSVY=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.mongodb.org/ops-manager v0.55.3 h1:ZckNLra9XfvUxWgRfdCVOr7QkeCPi7S4VNbcK5di/2A=
go.mongodb.org/ops-manager v0.55.3/go.mod h1:3KAtjSrHt4KB0mWLDRDlQpiyZypB+4EX9XXjx3gN5PA=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg=
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/atlas/clusters/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestList_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockClusterLister(ctrl)

expected := admin.PaginatedAdvancedClusterDescription{
expected := &admin.PaginatedAdvancedClusterDescription{
Results: &[]admin.AdvancedClusterDescription{
{
Name: pointer.Get("test"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/cli"
"github.com/mongodb/mongodb-atlas-cli/internal/log"
"github.com/shirou/gopsutil/v3/host"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
"go.mongodb.org/atlas/mongodbatlas"
)

Expand Down Expand Up @@ -108,23 +107,22 @@ func (opts *DeploymentOpts) AtlasDeployments(projectID string) ([]Deployment, er
ItemsPerPage: MaxItemsPerPage,
}

projectClusters, err := opts.AtlasClusterListStore.ProjectClusters(projectID, listOpts)
atlasClusters, err := opts.AtlasClusterListStore.ProjectClusters(projectID, listOpts)
if err != nil {
return nil, err
}
atlasClusters := projectClusters.(*admin.PaginatedAdvancedClusterDescription)
gssbzn marked this conversation as resolved.
Show resolved Hide resolved

deployments := make([]Deployment, len(atlasClusters.GetResults()))
for i, c := range atlasClusters.GetResults() {
stateName := *c.StateName
if *c.Paused {
stateName := c.GetStateName()
if c.GetPaused() {
// for paused clusters, Atlas returns stateName IDLE and Paused=true
stateName = PausedState
}
deployments[i] = Deployment{
Type: "ATLAS",
Name: *c.Name,
MongoDBVersion: *c.MongoDBVersion,
Name: c.GetName(),
MongoDBVersion: c.GetMongoDBVersion(),
StateName: stateName,
}
}
Expand Down
9 changes: 5 additions & 4 deletions internal/cli/atlas/projects/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ import (

"github.com/golang/mock/gomock"
mocks "github.com/mongodb/mongodb-atlas-cli/internal/mocks/atlas"
"go.mongodb.org/ops-manager/opsmngr"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
)

func TestDescribe_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockProjectDescriber(ctrl)
expected := opsmngr.Project{
expected := &admin.Group{
Name: "test",
ID: "5a0a1e7e0f2912c554080adc",
Id: pointer.Get("5a0a1e7e0f2912c554080adc"),
}
mockStore.
EXPECT().
Project(gomock.Eq("5a0a1e7e0f2912c554080adc")).
Return(&expected, nil).
Return(expected, nil).
Times(1)

opts := &DescribeOpts{
Expand Down
15 changes: 6 additions & 9 deletions internal/cli/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ var (
type LoginOpts struct {
cli.DefaultSetterOpts
cli.RefresherOpts
AccessToken string
RefreshToken string
IsGov bool
isCloudManager bool
NoBrowser bool
SkipConfig bool
config LoginConfig
AccessToken string
RefreshToken string
IsGov bool
NoBrowser bool
SkipConfig bool
config LoginConfig
}

// SyncWithOAuthAccessProfile returns a function that is synchronizing the oauth settings
Expand All @@ -67,8 +66,6 @@ func (opts *LoginOpts) SyncWithOAuthAccessProfile(c LoginConfig) func() error {
switch {
case opts.IsGov:
opts.Service = config.CloudGovService
case opts.isCloudManager:
opts.Service = config.CloudManagerService
default:
opts.Service = config.CloudService
}
Expand Down
10 changes: 6 additions & 4 deletions internal/cli/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
"go.mongodb.org/atlas/auth"
atlas "go.mongodb.org/atlas/mongodbatlas"
)
Expand Down Expand Up @@ -134,10 +136,10 @@ func Test_loginOpts_Run(t *testing.T) {
mockConfig.EXPECT().Set("ops_manager_url", gomock.Any()).Times(0)
mockConfig.EXPECT().AccessTokenSubject().Return("[email protected]", nil).Times(1)
mockConfig.EXPECT().Save().Return(nil).Times(2)
expectedOrgs := &atlas.Organizations{
TotalCount: 1,
Results: []*atlas.Organization{
{ID: "o1", Name: "Org1"},
expectedOrgs := &admin.PaginatedOrganization{
TotalCount: pointer.Get(1),
Results: &[]admin.AtlasOrganization{
{Id: pointer.Get("o1"), Name: "Org1"},
},
}
mockStore.EXPECT().Organizations(gomock.Any()).Return(expectedOrgs, nil).Times(1)
Expand Down
10 changes: 6 additions & 4 deletions internal/cli/auth/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
"go.mongodb.org/atlas/auth"
atlas "go.mongodb.org/atlas/mongodbatlas"
)
Expand Down Expand Up @@ -97,10 +99,10 @@ func Test_registerOpts_Run(t *testing.T) {
mockConfig.EXPECT().Set("ops_manager_url", gomock.Any()).Times(0)
mockConfig.EXPECT().AccessTokenSubject().Return("[email protected]", nil).Times(1)
mockConfig.EXPECT().Save().Return(nil).Times(2)
expectedOrgs := &atlas.Organizations{
TotalCount: 1,
Results: []*atlas.Organization{
{ID: "o1", Name: "Org1"},
expectedOrgs := &admin.PaginatedOrganization{
TotalCount: pointer.Get(1),
Results: &[]admin.AtlasOrganization{
{Id: pointer.Get("o1"), Name: "Org1"},
},
}
mockStore.EXPECT().Organizations(gomock.Any()).Return(expectedOrgs, nil).Times(1)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Enter [?] on any option to get help.

`, atlas)

q := prompt.AccessQuestions(false)
q := prompt.AccessQuestions()
if err := telemetry.TrackAsk(q, opts); err != nil {
return err
}
Expand Down
113 changes: 23 additions & 90 deletions internal/cli/default_setter_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/validate"
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

//go:generate mockgen -destination=../mocks/mock_default_opts.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/cli ProjectOrgsLister

type ProjectOrgsLister interface {
Project(id string) (interface{}, error)
Projects(*atlas.ListOptions) (interface{}, error)
Organization(id string) (interface{}, error)
Organizations(*atlas.OrganizationsListOptions) (interface{}, error)
GetOrgProjects(string, *atlas.ProjectsListOptions) (interface{}, error)
Project(id string) (*atlas.Project, error)
Projects(*atlas.ListOptions) (*atlas.Projects, error)
Organization(id string) (*atlasv2.AtlasOrganization, error)
Organizations(*atlas.OrganizationsListOptions) (*atlasv2.PaginatedOrganization, error)
GetOrgProjects(string, *atlas.ProjectsListOptions) (*atlas.Projects, error)
}

type DefaultSetterOpts struct {
Expand All @@ -66,14 +65,6 @@ func (opts *DefaultSetterOpts) InitStore(ctx context.Context) error {
return err
}

func (opts *DefaultSetterOpts) IsCloud() bool {
return opts.Service == config.CloudService || opts.Service == config.CloudGovService
}

func (opts *DefaultSetterOpts) IsOpsManager() bool {
return opts.Service == config.OpsManagerService
}

const resultsLimit = 500

var (
Expand All @@ -92,7 +83,7 @@ func (opts *DefaultSetterOpts) projects() (ids, names []string, err error) {
spin.Start()
defer spin.Stop()

var projects interface{}
var projects *atlas.Projects
if opts.OrgID == "" {
projects, err = opts.Store.Projects(&atlas.ListOptions{ItemsPerPage: resultsLimit})
} else {
Expand All @@ -108,30 +99,19 @@ func (opts *DefaultSetterOpts) projects() (ids, names []string, err error) {
}
return nil, nil, err
}
switch r := projects.(type) {
case *atlas.Projects:
if r.TotalCount == 0 {
return nil, nil, errNoResults
}
if r.TotalCount > resultsLimit {
return nil, nil, errTooManyResults
}
ids, names = atlasProjects(r.Results)
case *opsmngr.Projects:
if r.TotalCount == 0 {
return nil, nil, errNoResults
}
if r.TotalCount > resultsLimit {
return nil, nil, errTooManyResults
}
ids, names = omProjects(r.Results)
if projects.TotalCount == 0 {
return nil, nil, errNoResults
}
if projects.TotalCount > resultsLimit {
return nil, nil, errTooManyResults
}
ids, names = atlasProjects(projects.Results)

return ids, names, nil
}

// Orgs fetches organizations, filtering by name.
func (opts *DefaultSetterOpts) orgs(filter string) (results interface{}, err error) {
func (opts *DefaultSetterOpts) orgs(filter string) (results *[]atlasv2.AtlasOrganization, err error) {
spin := newSpinner()
spin.Start()
defer spin.Stop()
Expand All @@ -149,27 +129,14 @@ func (opts *DefaultSetterOpts) orgs(filter string) (results interface{}, err err
if orgs == nil {
return nil, errNoResults
}
switch r := orgs.(type) {
case *atlasv2.PaginatedOrganization:
if r.GetTotalCount() == 0 {
return nil, errNoResults
}
if r.GetTotalCount() > resultsLimit {
return nil, errTooManyResults
}
results = *r.Results
case *atlas.Organizations:
if r.TotalCount == 0 {
return nil, errNoResults
}
if r.TotalCount > resultsLimit {
return nil, errTooManyResults
}
results = r.Results
default:

if orgs.GetTotalCount() == 0 {
return nil, errNoResults
}
return results, nil
if orgs.GetTotalCount() > resultsLimit {
return nil, errTooManyResults
}
return orgs.Results, nil
}

// ProjectExists checks if the project exists and the current user has access to it.
Expand Down Expand Up @@ -289,13 +256,7 @@ func (opts *DefaultSetterOpts) askOrgWithFilter(filter string) error {
return opts.manualOrgID()
}

switch o := orgs.(type) {
case []atlasv2.AtlasOrganization:
return opts.selectOrg(o)
case []*atlas.Organization:
return opts.selectOnPremOrg(o)
}
return nil
return opts.selectOrg(orgs)
}

func (opts *DefaultSetterOpts) manualOrgID() error {
Expand All @@ -315,9 +276,9 @@ func (opts *DefaultSetterOpts) manualOrgID() error {
return nil
}

func (opts *DefaultSetterOpts) selectOrg(orgs []atlasv2.AtlasOrganization) error {
if len(orgs) == 1 {
opts.OrgID = *orgs[0].Id
func (opts *DefaultSetterOpts) selectOrg(orgs *[]atlasv2.AtlasOrganization) error {
if orgs != nil && len(*orgs) == 1 {
opts.OrgID = *(*orgs)[0].Id
return nil
}

Expand All @@ -332,23 +293,6 @@ func (opts *DefaultSetterOpts) selectOrg(orgs []atlasv2.AtlasOrganization) error
return nil
}

func (opts *DefaultSetterOpts) selectOnPremOrg(orgs []*atlas.Organization) error {
if len(orgs) == 1 {
opts.OrgID = orgs[0].ID
return nil
}

opts.runOnMultipleOrgsOrProjects()

p := prompt.NewOnPremOrgSelect(orgs)
if err := telemetry.TrackAskOne(p, &opts.OrgID); err != nil {
return err
}
opts.AskedOrgsOrProjects = true

return nil
}

func (opts *DefaultSetterOpts) SetUpProject() {
if opts.ProjectID != "" {
config.SetProjectID(opts.ProjectID)
Expand Down Expand Up @@ -376,17 +320,6 @@ func atlasProjects(projects []*atlas.Project) (ids, names []string) {
return ids, names
}

// omProjects transform []*opsmngr.Project to a []string of ids and another for names.
func omProjects(projects []*opsmngr.Project) (ids, names []string) {
names = make([]string, len(projects))
ids = make([]string, len(projects))
for i, p := range projects {
ids[i] = p.ID
names[i] = p.Name
}
return ids, names
}

func (*DefaultSetterOpts) DefaultQuestions() []*survey.Question {
defaultOutput := config.Output()
if defaultOutput == "" {
Expand Down
Loading