Skip to content

Commit

Permalink
task: remove more atlas references from the code base (#2765)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn committed Mar 13, 2024
1 parent 6ede93f commit 711d3cb
Show file tree
Hide file tree
Showing 64 changed files with 203 additions and 263 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -29,7 +29,7 @@ require (
github.com/tangzero/inflector v1.0.0
go.mongodb.org/atlas v0.36.0
go.mongodb.org/mongo-driver v1.14.0
go.mongodb.org/ops-manager v0.55.3
go.mongodb.org/ops-manager v0.55.5
golang.org/x/crypto v0.21.0
golang.org/x/mod v0.16.0
golang.org/x/tools v0.19.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -212,8 +212,8 @@ go.mongodb.org/atlas v0.36.0 h1:m05S3AO7zkl+bcG1qaNsEKBnAqnKx2FDwLooHpIG3j4=
go.mongodb.org/atlas v0.36.0/go.mod h1:nfPldE9dSama6G2IbIzmEza02Ly7yFZjMMVscaM0uEc=
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.mongodb.org/ops-manager v0.55.5 h1:MA6ATGRPg6SYzX7IzmiBcTEVISxmEvrIFTlKMy1y4SQ=
go.mongodb.org/ops-manager v0.55.5/go.mod h1:cckwuzkMX8+bKLnXOb5IO1uhDZzC0B3vPQURXLjoc18=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/invitations/describe_test.go
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"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestDescribe_Run(t *testing.T) {
Expand All @@ -38,7 +38,7 @@ func TestDescribe_Run(t *testing.T) {
mockStore.
EXPECT().
OrganizationInvitation(opts.ConfigOrgID(), opts.id).
Return(&mongodbatlas.Invitation{}, nil).
Return(&opsmngr.Invitation{}, nil).
Times(1)

if err := opts.Run(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/organizations/invitations/invite.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 = "User '{{.Username}}' invited.\n"
Expand Down Expand Up @@ -57,8 +57,8 @@ func (opts *InviteOpts) Run() error {
return opts.Print(r)
}

func (opts *InviteOpts) newInvitation() *atlas.Invitation {
return &atlas.Invitation{
func (opts *InviteOpts) newInvitation() *opsmngr.Invitation {
return &opsmngr.Invitation{
Username: opts.username,
Roles: opts.roles,
TeamIDs: opts.teamIDs,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/invitations/invite_test.go
Expand Up @@ -23,14 +23,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 TestCreate_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockOrganizationInviter(ctrl)

expected := &mongodbatlas.Invitation{}
expected := &opsmngr.Invitation{}
opts := &InviteOpts{
store: mockStore,
username: "test",
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/organizations/invitations/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"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

const listTemplate = `ID USERNAME CREATED AT EXPIRES AT{{range valueOrEmptySlice .}}
Expand Down Expand Up @@ -55,8 +55,8 @@ func (opts *ListOpts) Run() error {
return opts.Print(r)
}

func (opts *ListOpts) newInvitationOptions() *atlas.InvitationOptions {
return &atlas.InvitationOptions{
func (opts *ListOpts) newInvitationOptions() *opsmngr.InvitationOptions {
return &opsmngr.InvitationOptions{
Username: opts.username,
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/invitations/list_test.go
Expand Up @@ -23,14 +23,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.NewMockOrganizationInvitationLister(ctrl)

var expected []*mongodbatlas.Invitation
var expected []*opsmngr.Invitation

listOpts := &ListOpts{store: mockStore}

Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/organizations/invitations/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"
)

const updateTemplate = "Invitation {{.ID}} updated.\n"
Expand Down Expand Up @@ -56,8 +56,8 @@ func (opts *UpdateOpts) Run() error {
return opts.Print(r)
}

func (opts *UpdateOpts) newInvitation() *atlas.Invitation {
return &atlas.Invitation{
func (opts *UpdateOpts) newInvitation() *opsmngr.Invitation {
return &opsmngr.Invitation{
Username: opts.username,
Roles: opts.roles,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/organizations/invitations/update_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"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

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

expected := &atlas.Invitation{}
expected := &opsmngr.Invitation{}

updateOpts := &UpdateOpts{
roles: []string{"test"},
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/projects/apikeys/assign.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 AssignOpts struct {
Expand All @@ -44,8 +44,8 @@ func (opts *AssignOpts) initStore(ctx context.Context) func() error {
}
}

func (opts *AssignOpts) newAssignAPIKey() *atlas.AssignAPIKey {
return &atlas.AssignAPIKey{
func (opts *AssignOpts) newAssignAPIKey() *opsmngr.AssignAPIKey {
return &opsmngr.AssignAPIKey{
Roles: opts.roles,
}
}
Expand Down
62 changes: 4 additions & 58 deletions internal/cli/iam/projects/create.go
Expand Up @@ -18,15 +18,14 @@ import (
"context"
"fmt"

"github.com/Masterminds/semver/v3"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/cli"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/cli/require"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/config"
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/flag"
"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 (
Expand All @@ -39,7 +38,6 @@ type CreateOpts struct {
name string
projectOwnerID string
withoutDefaultAlertSettings bool
serviceVersion *semver.Version
store store.ProjectCreator
}

Expand Down Expand Up @@ -71,60 +69,8 @@ func (opts *CreateOpts) Run() error {
return opts.Print(r)
}

func (opts *CreateOpts) newCreateProjectOptions() *atlas.CreateProjectOptions {
return &atlas.CreateProjectOptions{ProjectOwnerID: opts.projectOwnerID}
}

func (opts *CreateOpts) validateOwnerID() error {
if opts.projectOwnerID == "" || opts.serviceVersion == nil {
return nil
}

constrain, err := semver.NewConstraint(">= 6.0")
if err != nil {
return err
}

if !constrain.Check(opts.serviceVersion) {
return fmt.Errorf("%s is available only for Atlas, Cloud Manager and Ops Manager >= 6.0", flag.OwnerID)
}

return nil
}

func (opts *CreateOpts) validateWithoutDefaultAlertSettings() error {
if !opts.withoutDefaultAlertSettings || opts.serviceVersion == nil {
return nil
}

constrain, err := semver.NewConstraint(">= 6.0")
if err != nil {
return err
}

if !constrain.Check(opts.serviceVersion) {
return fmt.Errorf("%s is available only for Atlas, Cloud Manager and Ops Manager >= 6.0", flag.WithoutDefaultAlertSettings)
}

return nil
}

func (opts *CreateOpts) initServiceVersion() error {
if config.Service() != config.OpsManagerService {
return nil
}
v, err := opts.store.ServiceVersion()
if err != nil {
return err
}

sv, err := cli.ParseServiceVersion(v)
if err != nil {
return err
}

opts.serviceVersion = sv
return nil
func (opts *CreateOpts) newCreateProjectOptions() *opsmngr.CreateProjectOptions {
return &opsmngr.CreateProjectOptions{ProjectOwnerID: opts.projectOwnerID}
}

// mongocli iam project(s) create <name> [--orgId orgId] [--ownerID ownerID] [--withoutDefaultAlertSettings].
Expand All @@ -149,7 +95,7 @@ func CreateBuilder() *cobra.Command {
if !config.IsCloud() {
opts.Template += "Agent API Key: '{{.AgentAPIKey}}'\n"
}
return opts.PreRunE(opts.initStore(cmd.Context()), opts.initServiceVersion, opts.validateOwnerID, opts.validateWithoutDefaultAlertSettings)
return opts.PreRunE(opts.initStore(cmd.Context()))
},
RunE: func(_ *cobra.Command, args []string) error {
opts.name = args[0]
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/projects/invitations/describe_test.go
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"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestDescribe_Run(t *testing.T) {
Expand All @@ -38,7 +38,7 @@ func TestDescribe_Run(t *testing.T) {
mockStore.
EXPECT().
ProjectInvitation(opts.ConfigProjectID(), opts.id).
Return(&mongodbatlas.Invitation{}, nil).
Return(&opsmngr.Invitation{}, nil).
Times(1)

if err := opts.Run(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/projects/invitations/invite.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 = "User '{{.Username}}' invited.\n"
Expand Down Expand Up @@ -57,8 +57,8 @@ func (opts *InviteOpts) Run() error {
return opts.Print(r)
}

func (opts *InviteOpts) newInvitation() *atlas.Invitation {
return &atlas.Invitation{
func (opts *InviteOpts) newInvitation() *opsmngr.Invitation {
return &opsmngr.Invitation{
Username: opts.username,
Roles: opts.roles,
TeamIDs: opts.teamIDs,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/projects/invitations/invite_test.go
Expand Up @@ -23,14 +23,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 TestCreate_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockProjectInviter(ctrl)

expected := &mongodbatlas.Invitation{}
expected := &opsmngr.Invitation{}
opts := &InviteOpts{
store: mockStore,
username: "test",
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/projects/invitations/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"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

const listTemplate = `ID USERNAME CREATED AT EXPIRES AT{{range valueOrEmptySlice .}}
Expand Down Expand Up @@ -55,8 +55,8 @@ func (opts *ListOpts) Run() error {
return opts.Print(r)
}

func (opts *ListOpts) newInvitationOptions() *atlas.InvitationOptions {
return &atlas.InvitationOptions{
func (opts *ListOpts) newInvitationOptions() *opsmngr.InvitationOptions {
return &opsmngr.InvitationOptions{
Username: opts.username,
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/projects/invitations/list_test.go
Expand Up @@ -23,14 +23,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.NewMockProjectInvitationLister(ctrl)

var expected []*mongodbatlas.Invitation
var expected []*opsmngr.Invitation

listOpts := &ListOpts{store: mockStore}

Expand Down
6 changes: 3 additions & 3 deletions internal/cli/iam/projects/invitations/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"
)

const updateTemplate = "Invitation {{.ID}} updated.\n"
Expand Down Expand Up @@ -56,8 +56,8 @@ func (opts *UpdateOpts) Run() error {
return opts.Print(r)
}

func (opts *UpdateOpts) newInvitation() *atlas.Invitation {
return &atlas.Invitation{
func (opts *UpdateOpts) newInvitation() *opsmngr.Invitation {
return &opsmngr.Invitation{
Username: opts.username,
Roles: opts.roles,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/iam/projects/invitations/update_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"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)

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

expected := &atlas.Invitation{}
expected := &opsmngr.Invitation{}

updateOpts := &UpdateOpts{
roles: []string{"test"},
Expand Down

0 comments on commit 711d3cb

Please sign in to comment.