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-74829: Update mcli ORG api calls #486

Merged
merged 4 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ require (
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
github.com/tangzero/inflector v1.0.0
go.mongodb.org/atlas v0.5.0
go.mongodb.org/ops-manager v0.10.2-0.20201006101549-1679878dc249
go.mongodb.org/atlas v0.5.1-0.20201007214134-b315fe7503d2
go.mongodb.org/ops-manager v0.10.2-0.20201012114611-29306504f77a
golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,12 @@ github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.mongodb.org/atlas v0.5.0 h1:WoeXdXSLCyquhSqSqTa0PwpjxWZbm70E1Gkbx+w3Sco=
go.mongodb.org/atlas v0.5.0/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
go.mongodb.org/ops-manager v0.10.2-0.20201006101549-1679878dc249 h1:X9EK8FUsfOWyP9o+1csMSo6aTaNu3G36ZUQYPApZg4o=
go.mongodb.org/ops-manager v0.10.2-0.20201006101549-1679878dc249/go.mod h1:l4gu8hs31sfsvJnet7nh0uEjOCXezvkzbfR6DhPRt+M=
go.mongodb.org/atlas v0.5.1-0.20201005200951-cefc31adb4ca h1:aZlmsmzOW8kYabsoBdG6BAeSOP2QShQds+6gSoMnBcg=
Copy link
Collaborator

Choose a reason for hiding this comment

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

[q] did you run go mod tidy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes I did 🤷‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤷‍♂️

go.mongodb.org/atlas v0.5.1-0.20201005200951-cefc31adb4ca/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
go.mongodb.org/atlas v0.5.1-0.20201007214134-b315fe7503d2 h1:b4Ng7d2sCSgYKwLMOetbwLcPE732SiBnJqH5rQrhZOs=
go.mongodb.org/atlas v0.5.1-0.20201007214134-b315fe7503d2/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
go.mongodb.org/ops-manager v0.10.2-0.20201012114611-29306504f77a h1:Zv7ztvzNvCcLl8c1rV85DeHio2FtGQjocJLZgbekoTQ=
go.mongodb.org/ops-manager v0.10.2-0.20201012114611-29306504f77a/go.mod h1:9NxiZOXzrBfL8E99tJPdNfrkquc31/UYZwdbO3OKZxI=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (

type ProjectOrgsLister interface {
Projects(*atlas.ListOptions) (interface{}, error)
Organizations(*atlas.ListOptions) (*atlas.Organizations, error)
Organizations(*atlas.OrganizationsListOptions) (*atlas.Organizations, error)
}

type configOpts struct {
Expand Down
23 changes: 17 additions & 6 deletions internal/cli/iam/organizations/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/mongodb/mongocli/internal/store"
"github.com/mongodb/mongocli/internal/usage"
"github.com/spf13/cobra"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const listTemplate = `ID NAME{{range .Results}}
Expand All @@ -30,7 +31,9 @@ const listTemplate = `ID NAME{{range .Results}}
type ListOpts struct {
cli.ListOpts
cli.OutputOpts
store store.OrganizationLister
store store.OrganizationLister
name string
includeDeletedOrgs bool
}

func (opts *ListOpts) init() error {
Expand All @@ -40,17 +43,22 @@ func (opts *ListOpts) init() error {
}

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

r, err := opts.store.Organizations(opts.newOrganizationListOptions())
if err != nil {
return err
}

return opts.Print(r)
}

// mongocli iam organizations(s) list
func (opts *ListOpts) newOrganizationListOptions() *atlas.OrganizationsListOptions {
return &atlas.OrganizationsListOptions{
Name: opts.name,
IncludeDeletedOrgs: &opts.includeDeletedOrgs,
ListOptions: *opts.NewListOptions(),
}
}

// mongocli iam organizations(s) list --name --includeDeletedOrgs
func ListBuilder() *cobra.Command {
opts := new(ListOpts)
opts.Template = listTemplate
Expand All @@ -67,6 +75,9 @@ func ListBuilder() *cobra.Command {
},
}

cmd.Flags().StringVar(&opts.name, flag.Name, "", usage.OrgNameFilter)
cmd.Flags().BoolVar(&opts.includeDeletedOrgs, flag.IncludeDeletedOrgs, false, usage.IncludeDeletedOrgs)

cmd.Flags().IntVar(&opts.PageNum, flag.Page, 0, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, 0, usage.Limit)

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

mockStore.
EXPECT().
Organizations(listOpts.NewListOptions()).
Organizations(listOpts.newOrganizationListOptions()).
Return(expected, nil).
Times(1)

Expand Down
1 change: 1 addition & 0 deletions internal/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,5 @@ const (
MaxCapacityGB = "maxCapacityGB" // MaxCapacityGB flag
URI = "uri" // URI flag
WriteConcern = "writeConcern" // WriteConcern flag
IncludeDeletedOrgs = "includeDeletedOrgs" // IncludeDeletedOrgs flag
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] we are in the org scope so let's rename this to includeDeleted

)
2 changes: 1 addition & 1 deletion internal/mocks/mock_organizations.go

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

4 changes: 2 additions & 2 deletions internal/store/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
//go:generate mockgen -destination=../mocks/mock_organizations.go -package=mocks github.com/mongodb/mongocli/internal/store OrganizationLister,OrganizationCreator,OrganizationDeleter,OrganizationDescriber

type OrganizationLister interface {
Organizations(*atlas.ListOptions) (*atlas.Organizations, error)
Organizations(*atlas.OrganizationsListOptions) (*atlas.Organizations, error)
}

type OrganizationDescriber interface {
Expand All @@ -42,7 +42,7 @@ type OrganizationDeleter interface {
}

// Organizations encapsulate the logic to manage different cloud providers
func (s *Store) Organizations(opts *atlas.ListOptions) (*atlas.Organizations, error) {
func (s *Store) Organizations(opts *atlas.OrganizationsListOptions) (*atlas.Organizations, error) {
switch s.service {
case config.CloudService:
result, _, err := s.client.(*atlas.Client).Organizations.List(context.Background(), opts)
Expand Down
2 changes: 2 additions & 0 deletions internal/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ const (
RoutingKey = "An optional field for your Routing Key."
IntegrationAPIToken = "Your API Token." //nolint:gosec // This is just a message not a credential
OrgName = "Your Flowdock organization name."
OrgNameFilter = "Performs a case-insensitive search for organizations which exactly match the specified name"
IncludeDeletedOrgs = "Include deleted organization."
FlowName = "Your Flowdock Flow name."
Assignment = "Flag indicating whether this blockstore can be assigned backup jobs."
EncryptedCredentials = "Flag indicating whether the username and password for this blockstore were encrypted using the credentialstool."
Expand Down