diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e9a550b3cc..866fea1bba 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 diff --git a/Makefile b/Makefile index 8a08d1b018..40910c28be 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,7 @@ gen-code: ## Generate code .PHONY: gen-mocks gen-mocks: ## Generate mocks @echo "==> Generating mocks" + rm -rf ./internal/mocks go generate ./internal... .PHONY: gen-docs diff --git a/build/ci/library_owners.json b/build/ci/library_owners.json index d0d8ede89f..bd6d617de9 100644 --- a/build/ci/library_owners.json +++ b/build/ci/library_owners.json @@ -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", diff --git a/go.mod b/go.mod index 481c1cf01a..48ff2901f3 100644 --- a/go.mod +++ b/go.mod @@ -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 golang.org/x/crypto v0.21.0 golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc golang.org/x/mod v0.16.0 diff --git a/go.sum b/go.sum index 8e68c69583..ddfedeeb13 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/cli/atlas/clusters/list_test.go b/internal/cli/atlas/clusters/list_test.go index 98cbd0d155..f1e9e1a235 100644 --- a/internal/cli/atlas/clusters/list_test.go +++ b/internal/cli/atlas/clusters/list_test.go @@ -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"), diff --git a/internal/cli/atlas/deployments/options/deployment_opts_pre_run.go b/internal/cli/atlas/deployments/options/deployment_opts_pre_run.go index 4684b24e12..d8d48bd36a 100644 --- a/internal/cli/atlas/deployments/options/deployment_opts_pre_run.go +++ b/internal/cli/atlas/deployments/options/deployment_opts_pre_run.go @@ -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" ) @@ -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) 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, } } diff --git a/internal/cli/atlas/projects/describe_test.go b/internal/cli/atlas/projects/describe_test.go index f692563362..3e478e7e27 100644 --- a/internal/cli/atlas/projects/describe_test.go +++ b/internal/cli/atlas/projects/describe_test.go @@ -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{ diff --git a/internal/cli/auth/login.go b/internal/cli/auth/login.go index 602af49357..77471f8ac3 100644 --- a/internal/cli/auth/login.go +++ b/internal/cli/auth/login.go @@ -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 @@ -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 } diff --git a/internal/cli/auth/login_test.go b/internal/cli/auth/login_test.go index 2c79a76e4c..f2fe4020c4 100644 --- a/internal/cli/auth/login_test.go +++ b/internal/cli/auth/login_test.go @@ -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" ) @@ -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("test@10gen.com", 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) diff --git a/internal/cli/auth/register_test.go b/internal/cli/auth/register_test.go index 02dfb67083..f0fdb4b0b2 100644 --- a/internal/cli/auth/register_test.go +++ b/internal/cli/auth/register_test.go @@ -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" ) @@ -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("test@10gen.com", 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) diff --git a/internal/cli/config/init.go b/internal/cli/config/init.go index cfe71ebfd9..9f358e87a0 100644 --- a/internal/cli/config/init.go +++ b/internal/cli/config/init.go @@ -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 } diff --git a/internal/cli/default_setter_opts.go b/internal/cli/default_setter_opts.go index a7b31a308e..c8626ed93c 100644 --- a/internal/cli/default_setter_opts.go +++ b/internal/cli/default_setter_opts.go @@ -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 { @@ -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 ( @@ -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 { @@ -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() @@ -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. @@ -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 { @@ -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 } @@ -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) @@ -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 == "" { diff --git a/internal/cli/default_setter_opts_test.go b/internal/cli/default_setter_opts_test.go index 327d263dc0..3913093ee3 100644 --- a/internal/cli/default_setter_opts_test.go +++ b/internal/cli/default_setter_opts_test.go @@ -21,8 +21,10 @@ import ( "github.com/golang/mock/gomock" "github.com/mongodb/mongodb-atlas-cli/internal/mocks" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -115,20 +117,20 @@ func TestDefaultOpts_Orgs(t *testing.T) { Store: mockStore, } t.Run("empty", func(t *testing.T) { - expectedOrgs := &atlas.Organizations{} + expectedOrgs := &admin.PaginatedOrganization{} mockStore.EXPECT().Organizations(gomock.Any()).Return(expectedOrgs, nil).Times(1) _, err := opts.orgs("") require.Error(t, err) }) t.Run("with one org", func(t *testing.T) { - expectedOrgs := &atlas.Organizations{ - Results: []*atlas.Organization{ + expectedOrgs := &admin.PaginatedOrganization{ + Results: &[]admin.AtlasOrganization{ { - ID: "1", + Id: pointer.Get("1"), Name: "Org 1", }, }, - TotalCount: 1, + TotalCount: pointer.Get(1), } mockStore.EXPECT().Organizations(gomock.Any()).Return(expectedOrgs, nil).Times(1) gotOrgs, err := opts.orgs("") @@ -137,8 +139,8 @@ func TestDefaultOpts_Orgs(t *testing.T) { }) t.Run("with no org", func(t *testing.T) { - expectedOrgs := &atlas.Organizations{ - Results: []*atlas.Organization{}, + expectedOrgs := &admin.PaginatedOrganization{ + Results: &[]admin.AtlasOrganization{}, } mockStore.EXPECT().Organizations(gomock.Any()).Return(expectedOrgs, nil).Times(1) _, err := opts.orgs("") diff --git a/internal/cli/performance_advisor_opts.go b/internal/cli/performance_advisor_opts.go index 72f4c70855..3cec38a98d 100644 --- a/internal/cli/performance_advisor_opts.go +++ b/internal/cli/performance_advisor_opts.go @@ -17,10 +17,6 @@ package cli import ( "fmt" "strings" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" - "github.com/mongodb/mongodb-atlas-cli/internal/flag" - "github.com/spf13/cobra" ) type PerformanceAdvisorOpts struct { @@ -38,20 +34,6 @@ func (opts *PerformanceAdvisorOpts) validateProcessName() error { return nil } -// MarkRequiredFlagsByService marks processName or hostId as required in accordance with the service. -// -// Atlas: processName is required -// -// OM/CM: hostId is required. -func (*PerformanceAdvisorOpts) MarkRequiredFlagsByService(cmd *cobra.Command) func() error { - return func() error { - if config.IsCloud() { - return cmd.MarkFlagRequired(flag.ProcessName) - } - return cmd.MarkFlagRequired(flag.HostID) - } -} - // Host returns the correct processName or the hostId in accordance with the service. func (opts *PerformanceAdvisorOpts) Host() (string, error) { if opts.ProcessName == "" { diff --git a/internal/cli/profile.go b/internal/cli/profile.go index 8e41194a5b..99ae771b28 100644 --- a/internal/cli/profile.go +++ b/internal/cli/profile.go @@ -15,10 +15,15 @@ package cli import ( + "errors" + "fmt" + "github.com/mongodb/mongodb-atlas-cli/internal/config" "github.com/mongodb/mongodb-atlas-cli/internal/flag" ) +var errUnsupportedService = errors.New("unsupported service") + func InitProfile(profile string) error { if profile != "" { return config.SetName(profile) @@ -28,5 +33,9 @@ func InitProfile(profile string) error { return config.SetName(availableProfiles[0]) } + if !config.IsCloud() { + return fmt.Errorf("%w: %s", errUnsupportedService, config.Service()) + } + return nil } diff --git a/internal/kubernetes/operator/config_exporter.go b/internal/kubernetes/operator/config_exporter.go index 877a8c2f7b..1b2c45343f 100644 --- a/internal/kubernetes/operator/config_exporter.go +++ b/internal/kubernetes/operator/config_exporter.go @@ -28,7 +28,6 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/resources" "github.com/mongodb/mongodb-atlas-cli/internal/store" "github.com/mongodb/mongodb-atlas-cli/internal/store/atlas" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer/json" "k8s.io/client-go/kubernetes/scheme" @@ -261,22 +260,20 @@ func (e *ConfigExporter) exportDeployments(projectName string) ([]runtime.Object func fetchClusterNames(clustersProvider atlas.AllClustersLister, projectID string) ([]string, error) { result := make([]string, 0, DefaultClustersCount) - response, err := clustersProvider.ProjectClusters(projectID, &atlas.ListOptions{ItemsPerPage: maxClusters}) + clusters, err := clustersProvider.ProjectClusters(projectID, &atlas.ListOptions{ItemsPerPage: maxClusters}) if err != nil { return nil, err } - if clusters, ok := response.(*atlasv2.PaginatedAdvancedClusterDescription); ok { - if clusters == nil { - return nil, ErrNoCloudManagerClusters - } + if clusters == nil { + return nil, ErrNoCloudManagerClusters + } - for _, cluster := range clusters.GetResults() { - if reflect.ValueOf(cluster).IsZero() { - continue - } - result = append(result, cluster.GetName()) + for _, cluster := range clusters.GetResults() { + if reflect.ValueOf(cluster).IsZero() { + continue } + result = append(result, cluster.GetName()) } serverlessInstances, err := clustersProvider.ServerlessInstances(projectID, &atlas.ListOptions{ItemsPerPage: maxClusters}) diff --git a/internal/kubernetes/operator/install.go b/internal/kubernetes/operator/install.go index f28e664916..3adf0fecdf 100644 --- a/internal/kubernetes/operator/install.go +++ b/internal/kubernetes/operator/install.go @@ -33,10 +33,8 @@ import ( ) const ( - roleOrgGroupCreator = "ORG_GROUP_CREATOR" - roleProjectOwner = "GROUP_OWNER" - atlasErrorProjectNotFound = "GROUP_NAME_NOT_FOUND" - atlasErrorNotInGroup = "NOT_IN_GROUP" + roleOrgGroupCreator = "ORG_GROUP_CREATOR" + roleProjectOwner = "GROUP_OWNER" ) type Install struct { @@ -143,13 +141,9 @@ func (i *Install) Run(ctx context.Context, orgID string) error { } func (i *Install) ensureProject(orgID, projectName string) (*admin.Group, error) { - data, err := i.atlasStore.ProjectByName(projectName) - if err == nil { - project, ok := data.(*admin.Group) - if !ok { - return nil, fmt.Errorf("failed to decode project: %w", err) - } + project, err := i.atlasStore.ProjectByName(projectName) + if err == nil { return project, nil } @@ -157,7 +151,7 @@ func (i *Install) ensureProject(orgID, projectName string) (*admin.Group, error) return nil, fmt.Errorf("failed to retrieve project: %w", err) } - data, err = i.atlasStore.CreateProject(&admin.CreateProjectApiParams{ + project, err = i.atlasStore.CreateProject(&admin.CreateProjectApiParams{ Group: &admin.Group{ Name: projectName, OrgId: orgID, @@ -169,11 +163,6 @@ func (i *Install) ensureProject(orgID, projectName string) (*admin.Group, error) return nil, fmt.Errorf("failed to create project: %w", err) } - project, ok := data.(*admin.Group) - if !ok { - return nil, fmt.Errorf("failed to decode created project: %w", err) - } - return project, nil } diff --git a/internal/kubernetes/operator/project/project.go b/internal/kubernetes/operator/project/project.go index b3b8430d90..bac41b5c33 100644 --- a/internal/kubernetes/operator/project/project.go +++ b/internal/kubernetes/operator/project/project.go @@ -15,7 +15,6 @@ package project import ( - "errors" "fmt" "strings" @@ -63,10 +62,6 @@ const ( prometheusIntegrationType = "PROMETHEUS" ) -var ( - ErrAtlasProject = errors.New("can not get 'atlas project' resource") -) - type AtlasProjectResult struct { Project *akov2.AtlasProject Secrets []*corev1.Secret @@ -74,16 +69,11 @@ type AtlasProjectResult struct { } func BuildAtlasProject(projectStore atlas.OperatorProjectStore, validator features.FeatureValidator, orgID, projectID, targetNamespace string, includeSecret bool, dictionary map[string]string, version string) (*AtlasProjectResult, error) { //nolint:gocyclo - data, err := projectStore.Project(projectID) + project, err := projectStore.Project(projectID) if err != nil { return nil, err } - project, ok := data.(*atlasv2.Group) - if !ok { - return nil, ErrAtlasProject - } - projectResult := newAtlasProject(project, dictionary, targetNamespace, version) result := &AtlasProjectResult{ diff --git a/internal/mocks/atlas/mock_atlas_generic_store.go b/internal/mocks/atlas/mock_atlas_generic_store.go index a04244bac1..6247af7137 100644 --- a/internal/mocks/atlas/mock_atlas_generic_store.go +++ b/internal/mocks/atlas/mock_atlas_generic_store.go @@ -365,10 +365,10 @@ func (mr *MockOperatorGenericStoreMockRecorder) PrivateEndpoints(arg0, arg1 inte } // Project mocks base method. -func (m *MockOperatorGenericStore) Project(arg0 string) (interface{}, error) { +func (m *MockOperatorGenericStore) Project(arg0 string) (*admin.Group, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Project", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.Group) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -380,10 +380,10 @@ func (mr *MockOperatorGenericStoreMockRecorder) Project(arg0 interface{}) *gomoc } // ProjectByName mocks base method. -func (m *MockOperatorGenericStore) ProjectByName(arg0 string) (interface{}, error) { +func (m *MockOperatorGenericStore) ProjectByName(arg0 string) (*admin.Group, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectByName", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.Group) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -395,10 +395,10 @@ func (mr *MockOperatorGenericStoreMockRecorder) ProjectByName(arg0 interface{}) } // ProjectClusters mocks base method. -func (m *MockOperatorGenericStore) ProjectClusters(arg0 string, arg1 *atlas.ListOptions) (interface{}, error) { +func (m *MockOperatorGenericStore) ProjectClusters(arg0 string, arg1 *atlas.ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectClusters", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.PaginatedAdvancedClusterDescription) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/atlas/mock_atlas_operator_cluster_store.go b/internal/mocks/atlas/mock_atlas_operator_cluster_store.go index 96a86b6fbd..9fd330f7ab 100644 --- a/internal/mocks/atlas/mock_atlas_operator_cluster_store.go +++ b/internal/mocks/atlas/mock_atlas_operator_cluster_store.go @@ -111,10 +111,10 @@ func (mr *MockOperatorClusterStoreMockRecorder) GlobalCluster(arg0, arg1 interfa } // ProjectClusters mocks base method. -func (m *MockOperatorClusterStore) ProjectClusters(arg0 string, arg1 *atlas.ListOptions) (interface{}, error) { +func (m *MockOperatorClusterStore) ProjectClusters(arg0 string, arg1 *atlas.ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectClusters", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.PaginatedAdvancedClusterDescription) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/atlas/mock_atlas_operator_project_store.go b/internal/mocks/atlas/mock_atlas_operator_project_store.go index 669a5574f3..c40948d294 100644 --- a/internal/mocks/atlas/mock_atlas_operator_project_store.go +++ b/internal/mocks/atlas/mock_atlas_operator_project_store.go @@ -216,10 +216,10 @@ func (mr *MockOperatorProjectStoreMockRecorder) PrivateEndpoints(arg0, arg1 inte } // Project mocks base method. -func (m *MockOperatorProjectStore) Project(arg0 string) (interface{}, error) { +func (m *MockOperatorProjectStore) Project(arg0 string) (*admin.Group, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Project", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.Group) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -231,10 +231,10 @@ func (mr *MockOperatorProjectStoreMockRecorder) Project(arg0 interface{}) *gomoc } // ProjectByName mocks base method. -func (m *MockOperatorProjectStore) ProjectByName(arg0 string) (interface{}, error) { +func (m *MockOperatorProjectStore) ProjectByName(arg0 string) (*admin.Group, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectByName", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.Group) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/atlas/mock_clusters.go b/internal/mocks/atlas/mock_clusters.go index 02ac998505..83d257c9d2 100644 --- a/internal/mocks/atlas/mock_clusters.go +++ b/internal/mocks/atlas/mock_clusters.go @@ -36,10 +36,10 @@ func (m *MockClusterLister) EXPECT() *MockClusterListerMockRecorder { } // ProjectClusters mocks base method. -func (m *MockClusterLister) ProjectClusters(arg0 string, arg1 *atlas.ListOptions) (interface{}, error) { +func (m *MockClusterLister) ProjectClusters(arg0 string, arg1 *atlas.ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectClusters", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.PaginatedAdvancedClusterDescription) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/atlas/mock_projects.go b/internal/mocks/atlas/mock_projects.go index dbcc2985b3..83c59a59bc 100644 --- a/internal/mocks/atlas/mock_projects.go +++ b/internal/mocks/atlas/mock_projects.go @@ -202,10 +202,10 @@ func (m *MockProjectDescriber) EXPECT() *MockProjectDescriberMockRecorder { } // Project mocks base method. -func (m *MockProjectDescriber) Project(arg0 string) (interface{}, error) { +func (m *MockProjectDescriber) Project(arg0 string) (*admin.Group, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Project", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.Group) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -217,10 +217,10 @@ func (mr *MockProjectDescriberMockRecorder) Project(arg0 interface{}) *gomock.Ca } // ProjectByName mocks base method. -func (m *MockProjectDescriber) ProjectByName(arg0 string) (interface{}, error) { +func (m *MockProjectDescriber) ProjectByName(arg0 string) (*admin.Group, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectByName", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.Group) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_clusters.go b/internal/mocks/mock_clusters.go index 1239c2af49..d4b6a10390 100644 --- a/internal/mocks/mock_clusters.go +++ b/internal/mocks/mock_clusters.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: ClusterLister,AtlasClusterDescriber,OpsManagerClusterDescriber,ClusterCreator,ClusterDeleter,ClusterUpdater,AtlasClusterGetterUpdater,ClusterPauser,ClusterStarter,AtlasClusterQuickStarter,SampleDataAdder,SampleDataStatusDescriber,AtlasClusterConfigurationOptionsDescriber,AtlasSharedClusterDescriber,ClusterUpgrader,AtlasSharedClusterGetterUpgrader,AtlasClusterConfigurationOptionsUpdater,ClusterTester) +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: ClusterLister,AtlasClusterDescriber,ClusterCreator,ClusterDeleter,ClusterUpdater,AtlasClusterGetterUpdater,ClusterPauser,ClusterStarter,AtlasClusterQuickStarter,SampleDataAdder,SampleDataStatusDescriber,AtlasClusterConfigurationOptionsDescriber,AtlasSharedClusterDescriber,ClusterUpgrader,AtlasSharedClusterGetterUpgrader,AtlasClusterConfigurationOptionsUpdater,ClusterTester) // Package mocks is a generated GoMock package. package mocks @@ -10,7 +10,6 @@ import ( gomock "github.com/golang/mock/gomock" admin "go.mongodb.org/atlas-sdk/v20231115007/admin" mongodbatlas "go.mongodb.org/atlas/mongodbatlas" - opsmngr "go.mongodb.org/ops-manager/opsmngr" ) // MockClusterLister is a mock of ClusterLister interface. @@ -37,10 +36,10 @@ func (m *MockClusterLister) EXPECT() *MockClusterListerMockRecorder { } // ProjectClusters mocks base method. -func (m *MockClusterLister) ProjectClusters(arg0 string, arg1 *mongodbatlas.ListOptions) (interface{}, error) { +func (m *MockClusterLister) ProjectClusters(arg0 string, arg1 *mongodbatlas.ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectClusters", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.PaginatedAdvancedClusterDescription) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -89,44 +88,6 @@ func (mr *MockAtlasClusterDescriberMockRecorder) AtlasCluster(arg0, arg1 interfa return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtlasCluster", reflect.TypeOf((*MockAtlasClusterDescriber)(nil).AtlasCluster), arg0, arg1) } -// MockOpsManagerClusterDescriber is a mock of OpsManagerClusterDescriber interface. -type MockOpsManagerClusterDescriber struct { - ctrl *gomock.Controller - recorder *MockOpsManagerClusterDescriberMockRecorder -} - -// MockOpsManagerClusterDescriberMockRecorder is the mock recorder for MockOpsManagerClusterDescriber. -type MockOpsManagerClusterDescriberMockRecorder struct { - mock *MockOpsManagerClusterDescriber -} - -// NewMockOpsManagerClusterDescriber creates a new mock instance. -func NewMockOpsManagerClusterDescriber(ctrl *gomock.Controller) *MockOpsManagerClusterDescriber { - mock := &MockOpsManagerClusterDescriber{ctrl: ctrl} - mock.recorder = &MockOpsManagerClusterDescriberMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOpsManagerClusterDescriber) EXPECT() *MockOpsManagerClusterDescriberMockRecorder { - return m.recorder -} - -// OpsManagerCluster mocks base method. -func (m *MockOpsManagerClusterDescriber) OpsManagerCluster(arg0, arg1 string) (*opsmngr.Cluster, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "OpsManagerCluster", arg0, arg1) - ret0, _ := ret[0].(*opsmngr.Cluster) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// OpsManagerCluster indicates an expected call of OpsManagerCluster. -func (mr *MockOpsManagerClusterDescriberMockRecorder) OpsManagerCluster(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpsManagerCluster", reflect.TypeOf((*MockOpsManagerClusterDescriber)(nil).OpsManagerCluster), arg0, arg1) -} - // MockClusterCreator is a mock of ClusterCreator interface. type MockClusterCreator struct { ctrl *gomock.Controller @@ -498,10 +459,10 @@ func (mr *MockAtlasClusterQuickStarterMockRecorder) DatabaseUser(arg0, arg1, arg } // ProjectClusters mocks base method. -func (m *MockAtlasClusterQuickStarter) ProjectClusters(arg0 string, arg1 *mongodbatlas.ListOptions) (interface{}, error) { +func (m *MockAtlasClusterQuickStarter) ProjectClusters(arg0 string, arg1 *mongodbatlas.ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectClusters", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.PaginatedAdvancedClusterDescription) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_default_opts.go b/internal/mocks/mock_default_opts.go index 40c717e8d9..bed6f50b04 100644 --- a/internal/mocks/mock_default_opts.go +++ b/internal/mocks/mock_default_opts.go @@ -8,6 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" + admin "go.mongodb.org/atlas-sdk/v20231115007/admin" mongodbatlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -35,10 +36,10 @@ func (m *MockProjectOrgsLister) EXPECT() *MockProjectOrgsListerMockRecorder { } // GetOrgProjects mocks base method. -func (m *MockProjectOrgsLister) GetOrgProjects(arg0 string, arg1 *mongodbatlas.ProjectsListOptions) (interface{}, error) { +func (m *MockProjectOrgsLister) GetOrgProjects(arg0 string, arg1 *mongodbatlas.ProjectsListOptions) (*mongodbatlas.Projects, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetOrgProjects", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Projects) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -50,10 +51,10 @@ func (mr *MockProjectOrgsListerMockRecorder) GetOrgProjects(arg0, arg1 interface } // Organization mocks base method. -func (m *MockProjectOrgsLister) Organization(arg0 string) (interface{}, error) { +func (m *MockProjectOrgsLister) Organization(arg0 string) (*admin.AtlasOrganization, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Organization", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.AtlasOrganization) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -65,10 +66,10 @@ func (mr *MockProjectOrgsListerMockRecorder) Organization(arg0 interface{}) *gom } // Organizations mocks base method. -func (m *MockProjectOrgsLister) Organizations(arg0 *mongodbatlas.OrganizationsListOptions) (interface{}, error) { +func (m *MockProjectOrgsLister) Organizations(arg0 *mongodbatlas.OrganizationsListOptions) (*admin.PaginatedOrganization, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Organizations", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.PaginatedOrganization) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -80,10 +81,10 @@ func (mr *MockProjectOrgsListerMockRecorder) Organizations(arg0 interface{}) *go } // Project mocks base method. -func (m *MockProjectOrgsLister) Project(arg0 string) (interface{}, error) { +func (m *MockProjectOrgsLister) Project(arg0 string) (*mongodbatlas.Project, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Project", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Project) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -95,10 +96,10 @@ func (mr *MockProjectOrgsListerMockRecorder) Project(arg0 interface{}) *gomock.C } // Projects mocks base method. -func (m *MockProjectOrgsLister) Projects(arg0 *mongodbatlas.ListOptions) (interface{}, error) { +func (m *MockProjectOrgsLister) Projects(arg0 *mongodbatlas.ListOptions) (*mongodbatlas.Projects, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Projects", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Projects) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_logs.go b/internal/mocks/mock_logs.go index 1adc6b2c25..4ac55dba42 100644 --- a/internal/mocks/mock_logs.go +++ b/internal/mocks/mock_logs.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: LogsDownloader,LogJobsDownloader,LogCollector,LogJobLister,LogJobDeleter) +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: LogsDownloader) // Package mocks is a generated GoMock package. package mocks @@ -10,7 +10,6 @@ import ( gomock "github.com/golang/mock/gomock" admin "go.mongodb.org/atlas-sdk/v20231115007/admin" - opsmngr "go.mongodb.org/ops-manager/opsmngr" ) // MockLogsDownloader is a mock of LogsDownloader interface. @@ -50,153 +49,3 @@ func (mr *MockLogsDownloaderMockRecorder) DownloadLog(arg0 interface{}) *gomock. mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadLog", reflect.TypeOf((*MockLogsDownloader)(nil).DownloadLog), arg0) } - -// MockLogJobsDownloader is a mock of LogJobsDownloader interface. -type MockLogJobsDownloader struct { - ctrl *gomock.Controller - recorder *MockLogJobsDownloaderMockRecorder -} - -// MockLogJobsDownloaderMockRecorder is the mock recorder for MockLogJobsDownloader. -type MockLogJobsDownloaderMockRecorder struct { - mock *MockLogJobsDownloader -} - -// NewMockLogJobsDownloader creates a new mock instance. -func NewMockLogJobsDownloader(ctrl *gomock.Controller) *MockLogJobsDownloader { - mock := &MockLogJobsDownloader{ctrl: ctrl} - mock.recorder = &MockLogJobsDownloaderMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLogJobsDownloader) EXPECT() *MockLogJobsDownloaderMockRecorder { - return m.recorder -} - -// DownloadLogJob mocks base method. -func (m *MockLogJobsDownloader) DownloadLogJob(arg0, arg1 string, arg2 io.Writer) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DownloadLogJob", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 -} - -// DownloadLogJob indicates an expected call of DownloadLogJob. -func (mr *MockLogJobsDownloaderMockRecorder) DownloadLogJob(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadLogJob", reflect.TypeOf((*MockLogJobsDownloader)(nil).DownloadLogJob), arg0, arg1, arg2) -} - -// MockLogCollector is a mock of LogCollector interface. -type MockLogCollector struct { - ctrl *gomock.Controller - recorder *MockLogCollectorMockRecorder -} - -// MockLogCollectorMockRecorder is the mock recorder for MockLogCollector. -type MockLogCollectorMockRecorder struct { - mock *MockLogCollector -} - -// NewMockLogCollector creates a new mock instance. -func NewMockLogCollector(ctrl *gomock.Controller) *MockLogCollector { - mock := &MockLogCollector{ctrl: ctrl} - mock.recorder = &MockLogCollectorMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLogCollector) EXPECT() *MockLogCollectorMockRecorder { - return m.recorder -} - -// Collect mocks base method. -func (m *MockLogCollector) Collect(arg0 string, arg1 *opsmngr.LogCollectionJob) (*opsmngr.LogCollectionJob, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Collect", arg0, arg1) - ret0, _ := ret[0].(*opsmngr.LogCollectionJob) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Collect indicates an expected call of Collect. -func (mr *MockLogCollectorMockRecorder) Collect(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Collect", reflect.TypeOf((*MockLogCollector)(nil).Collect), arg0, arg1) -} - -// MockLogJobLister is a mock of LogJobLister interface. -type MockLogJobLister struct { - ctrl *gomock.Controller - recorder *MockLogJobListerMockRecorder -} - -// MockLogJobListerMockRecorder is the mock recorder for MockLogJobLister. -type MockLogJobListerMockRecorder struct { - mock *MockLogJobLister -} - -// NewMockLogJobLister creates a new mock instance. -func NewMockLogJobLister(ctrl *gomock.Controller) *MockLogJobLister { - mock := &MockLogJobLister{ctrl: ctrl} - mock.recorder = &MockLogJobListerMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLogJobLister) EXPECT() *MockLogJobListerMockRecorder { - return m.recorder -} - -// LogCollectionJobs mocks base method. -func (m *MockLogJobLister) LogCollectionJobs(arg0 string, arg1 *opsmngr.LogListOptions) (*opsmngr.LogCollectionJobs, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "LogCollectionJobs", arg0, arg1) - ret0, _ := ret[0].(*opsmngr.LogCollectionJobs) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// LogCollectionJobs indicates an expected call of LogCollectionJobs. -func (mr *MockLogJobListerMockRecorder) LogCollectionJobs(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LogCollectionJobs", reflect.TypeOf((*MockLogJobLister)(nil).LogCollectionJobs), arg0, arg1) -} - -// MockLogJobDeleter is a mock of LogJobDeleter interface. -type MockLogJobDeleter struct { - ctrl *gomock.Controller - recorder *MockLogJobDeleterMockRecorder -} - -// MockLogJobDeleterMockRecorder is the mock recorder for MockLogJobDeleter. -type MockLogJobDeleterMockRecorder struct { - mock *MockLogJobDeleter -} - -// NewMockLogJobDeleter creates a new mock instance. -func NewMockLogJobDeleter(ctrl *gomock.Controller) *MockLogJobDeleter { - mock := &MockLogJobDeleter{ctrl: ctrl} - mock.recorder = &MockLogJobDeleterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLogJobDeleter) EXPECT() *MockLogJobDeleterMockRecorder { - return m.recorder -} - -// DeleteCollectionJob mocks base method. -func (m *MockLogJobDeleter) DeleteCollectionJob(arg0, arg1 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteCollectionJob", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteCollectionJob indicates an expected call of DeleteCollectionJob. -func (mr *MockLogJobDeleterMockRecorder) DeleteCollectionJob(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteCollectionJob", reflect.TypeOf((*MockLogJobDeleter)(nil).DeleteCollectionJob), arg0, arg1) -} diff --git a/internal/mocks/mock_maintenance.go b/internal/mocks/mock_maintenance.go index 25baa2a808..115fdbd4e3 100644 --- a/internal/mocks/mock_maintenance.go +++ b/internal/mocks/mock_maintenance.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: MaintenanceWindowUpdater,MaintenanceWindowClearer,MaintenanceWindowDeferrer,MaintenanceWindowDescriber,OpsManagerMaintenanceWindowCreator,OpsManagerMaintenanceWindowLister,OpsManagerMaintenanceWindowDeleter,OpsManagerMaintenanceWindowDescriber,OpsManagerMaintenanceWindowUpdater) +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: MaintenanceWindowUpdater,MaintenanceWindowClearer,MaintenanceWindowDeferrer,MaintenanceWindowDescriber) // Package mocks is a generated GoMock package. package mocks @@ -9,7 +9,6 @@ import ( gomock "github.com/golang/mock/gomock" admin "go.mongodb.org/atlas-sdk/v20231115007/admin" - opsmngr "go.mongodb.org/ops-manager/opsmngr" ) // MockMaintenanceWindowUpdater is a mock of MaintenanceWindowUpdater interface. @@ -160,192 +159,3 @@ func (mr *MockMaintenanceWindowDescriberMockRecorder) MaintenanceWindow(arg0 int mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MaintenanceWindow", reflect.TypeOf((*MockMaintenanceWindowDescriber)(nil).MaintenanceWindow), arg0) } - -// MockOpsManagerMaintenanceWindowCreator is a mock of OpsManagerMaintenanceWindowCreator interface. -type MockOpsManagerMaintenanceWindowCreator struct { - ctrl *gomock.Controller - recorder *MockOpsManagerMaintenanceWindowCreatorMockRecorder -} - -// MockOpsManagerMaintenanceWindowCreatorMockRecorder is the mock recorder for MockOpsManagerMaintenanceWindowCreator. -type MockOpsManagerMaintenanceWindowCreatorMockRecorder struct { - mock *MockOpsManagerMaintenanceWindowCreator -} - -// NewMockOpsManagerMaintenanceWindowCreator creates a new mock instance. -func NewMockOpsManagerMaintenanceWindowCreator(ctrl *gomock.Controller) *MockOpsManagerMaintenanceWindowCreator { - mock := &MockOpsManagerMaintenanceWindowCreator{ctrl: ctrl} - mock.recorder = &MockOpsManagerMaintenanceWindowCreatorMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOpsManagerMaintenanceWindowCreator) EXPECT() *MockOpsManagerMaintenanceWindowCreatorMockRecorder { - return m.recorder -} - -// CreateOpsManagerMaintenanceWindow mocks base method. -func (m *MockOpsManagerMaintenanceWindowCreator) CreateOpsManagerMaintenanceWindow(arg0 string, arg1 *opsmngr.MaintenanceWindow) (*opsmngr.MaintenanceWindow, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateOpsManagerMaintenanceWindow", arg0, arg1) - ret0, _ := ret[0].(*opsmngr.MaintenanceWindow) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CreateOpsManagerMaintenanceWindow indicates an expected call of CreateOpsManagerMaintenanceWindow. -func (mr *MockOpsManagerMaintenanceWindowCreatorMockRecorder) CreateOpsManagerMaintenanceWindow(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOpsManagerMaintenanceWindow", reflect.TypeOf((*MockOpsManagerMaintenanceWindowCreator)(nil).CreateOpsManagerMaintenanceWindow), arg0, arg1) -} - -// MockOpsManagerMaintenanceWindowLister is a mock of OpsManagerMaintenanceWindowLister interface. -type MockOpsManagerMaintenanceWindowLister struct { - ctrl *gomock.Controller - recorder *MockOpsManagerMaintenanceWindowListerMockRecorder -} - -// MockOpsManagerMaintenanceWindowListerMockRecorder is the mock recorder for MockOpsManagerMaintenanceWindowLister. -type MockOpsManagerMaintenanceWindowListerMockRecorder struct { - mock *MockOpsManagerMaintenanceWindowLister -} - -// NewMockOpsManagerMaintenanceWindowLister creates a new mock instance. -func NewMockOpsManagerMaintenanceWindowLister(ctrl *gomock.Controller) *MockOpsManagerMaintenanceWindowLister { - mock := &MockOpsManagerMaintenanceWindowLister{ctrl: ctrl} - mock.recorder = &MockOpsManagerMaintenanceWindowListerMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOpsManagerMaintenanceWindowLister) EXPECT() *MockOpsManagerMaintenanceWindowListerMockRecorder { - return m.recorder -} - -// OpsManagerMaintenanceWindows mocks base method. -func (m *MockOpsManagerMaintenanceWindowLister) OpsManagerMaintenanceWindows(arg0 string) (*opsmngr.MaintenanceWindows, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "OpsManagerMaintenanceWindows", arg0) - ret0, _ := ret[0].(*opsmngr.MaintenanceWindows) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// OpsManagerMaintenanceWindows indicates an expected call of OpsManagerMaintenanceWindows. -func (mr *MockOpsManagerMaintenanceWindowListerMockRecorder) OpsManagerMaintenanceWindows(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpsManagerMaintenanceWindows", reflect.TypeOf((*MockOpsManagerMaintenanceWindowLister)(nil).OpsManagerMaintenanceWindows), arg0) -} - -// MockOpsManagerMaintenanceWindowDeleter is a mock of OpsManagerMaintenanceWindowDeleter interface. -type MockOpsManagerMaintenanceWindowDeleter struct { - ctrl *gomock.Controller - recorder *MockOpsManagerMaintenanceWindowDeleterMockRecorder -} - -// MockOpsManagerMaintenanceWindowDeleterMockRecorder is the mock recorder for MockOpsManagerMaintenanceWindowDeleter. -type MockOpsManagerMaintenanceWindowDeleterMockRecorder struct { - mock *MockOpsManagerMaintenanceWindowDeleter -} - -// NewMockOpsManagerMaintenanceWindowDeleter creates a new mock instance. -func NewMockOpsManagerMaintenanceWindowDeleter(ctrl *gomock.Controller) *MockOpsManagerMaintenanceWindowDeleter { - mock := &MockOpsManagerMaintenanceWindowDeleter{ctrl: ctrl} - mock.recorder = &MockOpsManagerMaintenanceWindowDeleterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOpsManagerMaintenanceWindowDeleter) EXPECT() *MockOpsManagerMaintenanceWindowDeleterMockRecorder { - return m.recorder -} - -// DeleteOpsManagerMaintenanceWindow mocks base method. -func (m *MockOpsManagerMaintenanceWindowDeleter) DeleteOpsManagerMaintenanceWindow(arg0, arg1 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteOpsManagerMaintenanceWindow", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteOpsManagerMaintenanceWindow indicates an expected call of DeleteOpsManagerMaintenanceWindow. -func (mr *MockOpsManagerMaintenanceWindowDeleterMockRecorder) DeleteOpsManagerMaintenanceWindow(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOpsManagerMaintenanceWindow", reflect.TypeOf((*MockOpsManagerMaintenanceWindowDeleter)(nil).DeleteOpsManagerMaintenanceWindow), arg0, arg1) -} - -// MockOpsManagerMaintenanceWindowDescriber is a mock of OpsManagerMaintenanceWindowDescriber interface. -type MockOpsManagerMaintenanceWindowDescriber struct { - ctrl *gomock.Controller - recorder *MockOpsManagerMaintenanceWindowDescriberMockRecorder -} - -// MockOpsManagerMaintenanceWindowDescriberMockRecorder is the mock recorder for MockOpsManagerMaintenanceWindowDescriber. -type MockOpsManagerMaintenanceWindowDescriberMockRecorder struct { - mock *MockOpsManagerMaintenanceWindowDescriber -} - -// NewMockOpsManagerMaintenanceWindowDescriber creates a new mock instance. -func NewMockOpsManagerMaintenanceWindowDescriber(ctrl *gomock.Controller) *MockOpsManagerMaintenanceWindowDescriber { - mock := &MockOpsManagerMaintenanceWindowDescriber{ctrl: ctrl} - mock.recorder = &MockOpsManagerMaintenanceWindowDescriberMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOpsManagerMaintenanceWindowDescriber) EXPECT() *MockOpsManagerMaintenanceWindowDescriberMockRecorder { - return m.recorder -} - -// OpsManagerMaintenanceWindow mocks base method. -func (m *MockOpsManagerMaintenanceWindowDescriber) OpsManagerMaintenanceWindow(arg0, arg1 string) (*opsmngr.MaintenanceWindow, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "OpsManagerMaintenanceWindow", arg0, arg1) - ret0, _ := ret[0].(*opsmngr.MaintenanceWindow) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// OpsManagerMaintenanceWindow indicates an expected call of OpsManagerMaintenanceWindow. -func (mr *MockOpsManagerMaintenanceWindowDescriberMockRecorder) OpsManagerMaintenanceWindow(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpsManagerMaintenanceWindow", reflect.TypeOf((*MockOpsManagerMaintenanceWindowDescriber)(nil).OpsManagerMaintenanceWindow), arg0, arg1) -} - -// MockOpsManagerMaintenanceWindowUpdater is a mock of OpsManagerMaintenanceWindowUpdater interface. -type MockOpsManagerMaintenanceWindowUpdater struct { - ctrl *gomock.Controller - recorder *MockOpsManagerMaintenanceWindowUpdaterMockRecorder -} - -// MockOpsManagerMaintenanceWindowUpdaterMockRecorder is the mock recorder for MockOpsManagerMaintenanceWindowUpdater. -type MockOpsManagerMaintenanceWindowUpdaterMockRecorder struct { - mock *MockOpsManagerMaintenanceWindowUpdater -} - -// NewMockOpsManagerMaintenanceWindowUpdater creates a new mock instance. -func NewMockOpsManagerMaintenanceWindowUpdater(ctrl *gomock.Controller) *MockOpsManagerMaintenanceWindowUpdater { - mock := &MockOpsManagerMaintenanceWindowUpdater{ctrl: ctrl} - mock.recorder = &MockOpsManagerMaintenanceWindowUpdaterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOpsManagerMaintenanceWindowUpdater) EXPECT() *MockOpsManagerMaintenanceWindowUpdaterMockRecorder { - return m.recorder -} - -// UpdateOpsManagerMaintenanceWindow mocks base method. -func (m *MockOpsManagerMaintenanceWindowUpdater) UpdateOpsManagerMaintenanceWindow(arg0 string, arg1 *opsmngr.MaintenanceWindow) (*opsmngr.MaintenanceWindow, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateOpsManagerMaintenanceWindow", arg0, arg1) - ret0, _ := ret[0].(*opsmngr.MaintenanceWindow) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// UpdateOpsManagerMaintenanceWindow indicates an expected call of UpdateOpsManagerMaintenanceWindow. -func (mr *MockOpsManagerMaintenanceWindowUpdaterMockRecorder) UpdateOpsManagerMaintenanceWindow(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateOpsManagerMaintenanceWindow", reflect.TypeOf((*MockOpsManagerMaintenanceWindowUpdater)(nil).UpdateOpsManagerMaintenanceWindow), arg0, arg1) -} diff --git a/internal/mocks/mock_organizations.go b/internal/mocks/mock_organizations.go index 8b9fe9edf0..e709a5a799 100644 --- a/internal/mocks/mock_organizations.go +++ b/internal/mocks/mock_organizations.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: OrganizationLister,OrganizationCreator,OrganizationDeleter,OrganizationDescriber,AtlasOrganizationCreator) +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: OrganizationLister,OrganizationDeleter,OrganizationDescriber,AtlasOrganizationCreator) // Package mocks is a generated GoMock package. package mocks @@ -8,6 +8,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" + admin "go.mongodb.org/atlas-sdk/v20231115007/admin" mongodbatlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -35,10 +36,10 @@ func (m *MockOrganizationLister) EXPECT() *MockOrganizationListerMockRecorder { } // Organizations mocks base method. -func (m *MockOrganizationLister) Organizations(arg0 *mongodbatlas.OrganizationsListOptions) (interface{}, error) { +func (m *MockOrganizationLister) Organizations(arg0 *mongodbatlas.OrganizationsListOptions) (*admin.PaginatedOrganization, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Organizations", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.PaginatedOrganization) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -49,44 +50,6 @@ func (mr *MockOrganizationListerMockRecorder) Organizations(arg0 interface{}) *g return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Organizations", reflect.TypeOf((*MockOrganizationLister)(nil).Organizations), arg0) } -// MockOrganizationCreator is a mock of OrganizationCreator interface. -type MockOrganizationCreator struct { - ctrl *gomock.Controller - recorder *MockOrganizationCreatorMockRecorder -} - -// MockOrganizationCreatorMockRecorder is the mock recorder for MockOrganizationCreator. -type MockOrganizationCreatorMockRecorder struct { - mock *MockOrganizationCreator -} - -// NewMockOrganizationCreator creates a new mock instance. -func NewMockOrganizationCreator(ctrl *gomock.Controller) *MockOrganizationCreator { - mock := &MockOrganizationCreator{ctrl: ctrl} - mock.recorder = &MockOrganizationCreatorMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOrganizationCreator) EXPECT() *MockOrganizationCreatorMockRecorder { - return m.recorder -} - -// CreateOrganization mocks base method. -func (m *MockOrganizationCreator) CreateOrganization(arg0 string) (*mongodbatlas.Organization, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateOrganization", arg0) - ret0, _ := ret[0].(*mongodbatlas.Organization) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CreateOrganization indicates an expected call of CreateOrganization. -func (mr *MockOrganizationCreatorMockRecorder) CreateOrganization(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrganization", reflect.TypeOf((*MockOrganizationCreator)(nil).CreateOrganization), arg0) -} - // MockOrganizationDeleter is a mock of OrganizationDeleter interface. type MockOrganizationDeleter struct { ctrl *gomock.Controller @@ -148,10 +111,10 @@ func (m *MockOrganizationDescriber) EXPECT() *MockOrganizationDescriberMockRecor } // Organization mocks base method. -func (m *MockOrganizationDescriber) Organization(arg0 string) (interface{}, error) { +func (m *MockOrganizationDescriber) Organization(arg0 string) (*admin.AtlasOrganization, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Organization", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.AtlasOrganization) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_private_endpoints.go b/internal/mocks/mock_private_endpoints.go index 34c509c573..d3720e3a0e 100644 --- a/internal/mocks/mock_private_endpoints.go +++ b/internal/mocks/mock_private_endpoints.go @@ -111,10 +111,10 @@ func (m *MockPrivateEndpointCreator) EXPECT() *MockPrivateEndpointCreatorMockRec } // CreatePrivateEndpoint mocks base method. -func (m *MockPrivateEndpointCreator) CreatePrivateEndpoint(arg0 string, arg1 *admin.CloudProviderEndpointServiceRequest) (interface{}, error) { +func (m *MockPrivateEndpointCreator) CreatePrivateEndpoint(arg0 string, arg1 *admin.CloudProviderEndpointServiceRequest) (*admin.EndpointService, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreatePrivateEndpoint", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*admin.EndpointService) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_projects.go b/internal/mocks/mock_projects.go index b2950885f9..77ed1407e1 100644 --- a/internal/mocks/mock_projects.go +++ b/internal/mocks/mock_projects.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: ProjectLister,OrgProjectLister,ProjectCreator,ProjectDeleter,ProjectDescriber,ProjectUsersLister,ProjectUserDeleter,ProjectTeamLister,ProjectTeamAdder,ProjectTeamDeleter) +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: ProjectLister,ProjectCreator,ProjectDeleter,ProjectDescriber,ProjectUsersLister,ProjectUserDeleter,ProjectTeamLister,ProjectTeamAdder,ProjectTeamDeleter) // Package mocks is a generated GoMock package. package mocks @@ -35,10 +35,10 @@ func (m *MockProjectLister) EXPECT() *MockProjectListerMockRecorder { } // GetOrgProjects mocks base method. -func (m *MockProjectLister) GetOrgProjects(arg0 string, arg1 *mongodbatlas.ProjectsListOptions) (interface{}, error) { +func (m *MockProjectLister) GetOrgProjects(arg0 string, arg1 *mongodbatlas.ProjectsListOptions) (*mongodbatlas.Projects, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetOrgProjects", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Projects) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -50,10 +50,10 @@ func (mr *MockProjectListerMockRecorder) GetOrgProjects(arg0, arg1 interface{}) } // Projects mocks base method. -func (m *MockProjectLister) Projects(arg0 *mongodbatlas.ListOptions) (interface{}, error) { +func (m *MockProjectLister) Projects(arg0 *mongodbatlas.ListOptions) (*mongodbatlas.Projects, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Projects", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Projects) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -64,44 +64,6 @@ func (mr *MockProjectListerMockRecorder) Projects(arg0 interface{}) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Projects", reflect.TypeOf((*MockProjectLister)(nil).Projects), arg0) } -// MockOrgProjectLister is a mock of OrgProjectLister interface. -type MockOrgProjectLister struct { - ctrl *gomock.Controller - recorder *MockOrgProjectListerMockRecorder -} - -// MockOrgProjectListerMockRecorder is the mock recorder for MockOrgProjectLister. -type MockOrgProjectListerMockRecorder struct { - mock *MockOrgProjectLister -} - -// NewMockOrgProjectLister creates a new mock instance. -func NewMockOrgProjectLister(ctrl *gomock.Controller) *MockOrgProjectLister { - mock := &MockOrgProjectLister{ctrl: ctrl} - mock.recorder = &MockOrgProjectListerMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockOrgProjectLister) EXPECT() *MockOrgProjectListerMockRecorder { - return m.recorder -} - -// GetOrgProjects mocks base method. -func (m *MockOrgProjectLister) GetOrgProjects(arg0 string) (interface{}, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetOrgProjects", arg0) - ret0, _ := ret[0].(interface{}) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetOrgProjects indicates an expected call of GetOrgProjects. -func (mr *MockOrgProjectListerMockRecorder) GetOrgProjects(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrgProjects", reflect.TypeOf((*MockOrgProjectLister)(nil).GetOrgProjects), arg0) -} - // MockProjectCreator is a mock of ProjectCreator interface. type MockProjectCreator struct { ctrl *gomock.Controller @@ -126,10 +88,10 @@ func (m *MockProjectCreator) EXPECT() *MockProjectCreatorMockRecorder { } // CreateProject mocks base method. -func (m *MockProjectCreator) CreateProject(arg0, arg1, arg2 string, arg3 *bool, arg4 *mongodbatlas.CreateProjectOptions) (interface{}, error) { +func (m *MockProjectCreator) CreateProject(arg0, arg1, arg2 string, arg3 *bool, arg4 *mongodbatlas.CreateProjectOptions) (*mongodbatlas.Project, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateProject", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Project) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -140,21 +102,6 @@ func (mr *MockProjectCreatorMockRecorder) CreateProject(arg0, arg1, arg2, arg3, return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateProject", reflect.TypeOf((*MockProjectCreator)(nil).CreateProject), arg0, arg1, arg2, arg3, arg4) } -// ServiceVersion mocks base method. -func (m *MockProjectCreator) ServiceVersion() (*mongodbatlas.ServiceVersion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ServiceVersion") - ret0, _ := ret[0].(*mongodbatlas.ServiceVersion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ServiceVersion indicates an expected call of ServiceVersion. -func (mr *MockProjectCreatorMockRecorder) ServiceVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ServiceVersion", reflect.TypeOf((*MockProjectCreator)(nil).ServiceVersion)) -} - // MockProjectDeleter is a mock of ProjectDeleter interface. type MockProjectDeleter struct { ctrl *gomock.Controller @@ -216,10 +163,10 @@ func (m *MockProjectDescriber) EXPECT() *MockProjectDescriberMockRecorder { } // Project mocks base method. -func (m *MockProjectDescriber) Project(arg0 string) (interface{}, error) { +func (m *MockProjectDescriber) Project(arg0 string) (*mongodbatlas.Project, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Project", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Project) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -231,10 +178,10 @@ func (mr *MockProjectDescriberMockRecorder) Project(arg0 interface{}) *gomock.Ca } // ProjectByName mocks base method. -func (m *MockProjectDescriber) ProjectByName(arg0 string) (interface{}, error) { +func (m *MockProjectDescriber) ProjectByName(arg0 string) (*mongodbatlas.Project, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectByName", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.Project) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -269,10 +216,10 @@ func (m *MockProjectUsersLister) EXPECT() *MockProjectUsersListerMockRecorder { } // ProjectUsers mocks base method. -func (m *MockProjectUsersLister) ProjectUsers(arg0 string, arg1 *mongodbatlas.ListOptions) (interface{}, error) { +func (m *MockProjectUsersLister) ProjectUsers(arg0 string, arg1 *mongodbatlas.ListOptions) ([]mongodbatlas.AtlasUser, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectUsers", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].([]mongodbatlas.AtlasUser) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -344,10 +291,10 @@ func (m *MockProjectTeamLister) EXPECT() *MockProjectTeamListerMockRecorder { } // ProjectTeams mocks base method. -func (m *MockProjectTeamLister) ProjectTeams(arg0 string) (interface{}, error) { +func (m *MockProjectTeamLister) ProjectTeams(arg0 string) (*mongodbatlas.TeamsAssigned, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ProjectTeams", arg0) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(*mongodbatlas.TeamsAssigned) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/mocks/mock_service_version.go b/internal/mocks/mock_service_version.go deleted file mode 100644 index c22eecedf5..0000000000 --- a/internal/mocks/mock_service_version.go +++ /dev/null @@ -1,50 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: ServiceVersionDescriber) - -// Package mocks is a generated GoMock package. -package mocks - -import ( - reflect "reflect" - - gomock "github.com/golang/mock/gomock" - mongodbatlas "go.mongodb.org/atlas/mongodbatlas" -) - -// MockServiceVersionDescriber is a mock of ServiceVersionDescriber interface. -type MockServiceVersionDescriber struct { - ctrl *gomock.Controller - recorder *MockServiceVersionDescriberMockRecorder -} - -// MockServiceVersionDescriberMockRecorder is the mock recorder for MockServiceVersionDescriber. -type MockServiceVersionDescriberMockRecorder struct { - mock *MockServiceVersionDescriber -} - -// NewMockServiceVersionDescriber creates a new mock instance. -func NewMockServiceVersionDescriber(ctrl *gomock.Controller) *MockServiceVersionDescriber { - mock := &MockServiceVersionDescriber{ctrl: ctrl} - mock.recorder = &MockServiceVersionDescriberMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockServiceVersionDescriber) EXPECT() *MockServiceVersionDescriberMockRecorder { - return m.recorder -} - -// ServiceVersion mocks base method. -func (m *MockServiceVersionDescriber) ServiceVersion() (*mongodbatlas.ServiceVersion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ServiceVersion") - ret0, _ := ret[0].(*mongodbatlas.ServiceVersion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ServiceVersion indicates an expected call of ServiceVersion. -func (mr *MockServiceVersionDescriberMockRecorder) ServiceVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ServiceVersion", reflect.TypeOf((*MockServiceVersionDescriber)(nil).ServiceVersion)) -} diff --git a/internal/prompt/config.go b/internal/prompt/config.go index 04dea9f64b..5db1e9b41a 100644 --- a/internal/prompt/config.go +++ b/internal/prompt/config.go @@ -25,14 +25,6 @@ import ( atlas "go.mongodb.org/atlas/mongodbatlas" ) -func NewOMURLInput() survey.Prompt { - return &survey.Input{ - Message: "URL to Access Ops Manager:", - Help: "FQDN and port number of the Ops Manager Application.", - Default: config.OpsManagerURL(), - } -} - func NewOrgIDInput() survey.Prompt { return &survey.Input{ Message: "Default Org ID:", @@ -49,11 +41,8 @@ func NewProjectIDInput() survey.Prompt { } } -func AccessQuestions(isOM bool) []*survey.Question { +func AccessQuestions() []*survey.Question { helpLink := "Please provide your API keys. To create new keys, see the documentation: https://docs.atlas.mongodb.com/configure-api-access/" - if isOM { - helpLink = "Please provide your API keys. To create new keys, see the documentation: https://docs.opsmanager.mongodb.com/current/tutorial/configure-public-api-access/" - } q := []*survey.Question{ { @@ -72,16 +61,6 @@ func AccessQuestions(isOM bool) []*survey.Question { }, }, } - if isOM { - omQuestions := []*survey.Question{ - { - Name: "opsManagerURL", - Prompt: NewOMURLInput(), - Validate: validate.OptionalURL, - }, - } - q = append(omQuestions, q...) - } return q } @@ -110,9 +89,9 @@ func NewProfileReplaceConfirm(entry string) survey.Prompt { } // NewOrgSelect create a prompt to choice the organization. -func NewOrgSelect(options []atlasv2.AtlasOrganization) survey.Prompt { - opt := make([]string, len(options)) - for i, o := range options { +func NewOrgSelect(options *[]atlasv2.AtlasOrganization) survey.Prompt { + opt := make([]string, len(*options)) + for i, o := range *options { opt[i] = *o.Id } @@ -120,11 +99,11 @@ func NewOrgSelect(options []atlasv2.AtlasOrganization) survey.Prompt { Message: "Choose a default organization:", Options: opt, Description: func(_ string, i int) string { - return options[i].Name + return (*options)[i].Name }, Filter: func(filter string, _ string, i int) bool { filter = strings.ToLower(filter) - return strings.HasPrefix(strings.ToLower(options[i].Name), filter) || strings.HasPrefix(*options[i].Id, filter) + return strings.HasPrefix(strings.ToLower((*options)[i].Name), filter) || strings.HasPrefix(*(*options)[i].Id, filter) }, } } diff --git a/internal/store/access_logs.go b/internal/store/access_logs.go index 8c87166cee..bcdaf54854 100644 --- a/internal/store/access_logs.go +++ b/internal/store/access_logs.go @@ -15,10 +15,8 @@ package store import ( - "fmt" "strconv" - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -40,72 +38,62 @@ type AccessLogsLister interface { // AccessLogsByHostname encapsulates the logic to manage different cloud providers. func (s *Store) AccessLogsByHostname(groupID, hostname string, opts *atlas.AccessLogOptions) (*atlasv2.MongoDBAccessLogsList, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result := s.clientv2.AccessTrackingApi.ListAccessLogsByHostname(s.ctx, groupID, hostname) - - if opts != nil { - if opts.Start != "" { - startTime, _ := strconv.ParseInt(opts.Start, 10, 64) - result = result.Start(startTime) - } - if opts.End != "" { - endTime, _ := strconv.ParseInt(opts.End, 10, 64) - result = result.End(endTime) - } - - if opts.NLogs > 0 { - result = result.NLogs(opts.NLogs) - } - - if opts.IPAddress != "" { - result = result.IpAddress(opts.IPAddress) - } - - if opts.AuthResult != nil { - result = result.AuthResult(*opts.AuthResult) - } + result := s.clientv2.AccessTrackingApi.ListAccessLogsByHostname(s.ctx, groupID, hostname) + + if opts != nil { + if opts.Start != "" { + startTime, _ := strconv.ParseInt(opts.Start, 10, 64) + result = result.Start(startTime) + } + if opts.End != "" { + endTime, _ := strconv.ParseInt(opts.End, 10, 64) + result = result.End(endTime) + } + + if opts.NLogs > 0 { + result = result.NLogs(opts.NLogs) } - res, _, err := result.Execute() - return res, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + if opts.IPAddress != "" { + result = result.IpAddress(opts.IPAddress) + } + + if opts.AuthResult != nil { + result = result.AuthResult(*opts.AuthResult) + } } + + res, _, err := result.Execute() + return res, err } // AccessLogsByClusterName encapsulates the logic to manage different cloud providers. func (s *Store) AccessLogsByClusterName(groupID, clusterName string, opts *atlas.AccessLogOptions) (*atlasv2.MongoDBAccessLogsList, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result := s.clientv2.AccessTrackingApi.ListAccessLogsByClusterName(s.ctx, groupID, clusterName) - - if opts != nil { - if opts.Start != "" { - startTime, _ := strconv.ParseInt(opts.Start, 10, 64) - result = result.Start(startTime) - } - if opts.End != "" { - endTime, _ := strconv.ParseInt(opts.End, 10, 64) - result = result.End(endTime) - } - - if opts.NLogs > 0 { - result = result.NLogs(opts.NLogs) - } - - if opts.IPAddress != "" { - result = result.IpAddress(opts.IPAddress) - } - - if opts.AuthResult != nil { - result = result.AuthResult(*opts.AuthResult) - } + result := s.clientv2.AccessTrackingApi.ListAccessLogsByClusterName(s.ctx, groupID, clusterName) + + if opts != nil { + if opts.Start != "" { + startTime, _ := strconv.ParseInt(opts.Start, 10, 64) + result = result.Start(startTime) + } + if opts.End != "" { + endTime, _ := strconv.ParseInt(opts.End, 10, 64) + result = result.End(endTime) + } + + if opts.NLogs > 0 { + result = result.NLogs(opts.NLogs) } - res, _, err := result.Execute() - return res, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + if opts.IPAddress != "" { + result = result.IpAddress(opts.IPAddress) + } + + if opts.AuthResult != nil { + result = result.AuthResult(*opts.AuthResult) + } } + res, _, err := result.Execute() + + return res, err } diff --git a/internal/store/access_role.go b/internal/store/access_role.go index 4eb1c58078..d2b384c781 100644 --- a/internal/store/access_role.go +++ b/internal/store/access_role.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -43,51 +40,31 @@ type CloudProviderAccessRoleAuthorizer interface { // CreateCloudProviderAccessRole encapsulates the logic to manage different cloud providers. func (s *Store) CreateCloudProviderAccessRole(groupID, provider string) (*atlasv2.CloudProviderAccessRole, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - req := atlasv2.CloudProviderAccessRole{ - ProviderName: provider, - } - result, _, err := s.clientv2.CloudProviderAccessApi.CreateCloudProviderAccessRole(s.ctx, groupID, &req).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + req := atlasv2.CloudProviderAccessRole{ + ProviderName: provider, } + result, _, err := s.clientv2.CloudProviderAccessApi.CreateCloudProviderAccessRole(s.ctx, groupID, &req).Execute() + return result, err } // CloudProviderAccessRoles encapsulates the logic to manage different cloud providers. func (s *Store) CloudProviderAccessRoles(groupID string) (*atlasv2.CloudProviderAccessRoles, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudProviderAccessApi.ListCloudProviderAccessRoles(s.ctx, groupID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudProviderAccessApi.ListCloudProviderAccessRoles(s.ctx, groupID).Execute() + return result, err } // DeauthorizeCloudProviderAccessRoles encapsulates the logic to manage different cloud providers. func (s *Store) DeauthorizeCloudProviderAccessRoles(req *atlas.CloudProviderDeauthorizationRequest) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.CloudProviderAccessApi.DeauthorizeCloudProviderAccessRole(s.ctx, req.GroupID, req.ProviderName, req.RoleID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.CloudProviderAccessApi.DeauthorizeCloudProviderAccessRole(s.ctx, req.GroupID, req.ProviderName, req.RoleID).Execute() + return err } // AuthorizeCloudProviderAccessRole encapsulates the logic to manage different cloud providers. func (s *Store) AuthorizeCloudProviderAccessRole(groupID, roleID string, req *atlas.CloudProviderAccessRoleRequest) (*atlasv2.CloudProviderAccessRole, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - role := atlasv2.CloudProviderAccessRole{ - ProviderName: req.ProviderName, - IamAssumedRoleArn: req.IAMAssumedRoleARN, - } - result, _, err := s.clientv2.CloudProviderAccessApi.AuthorizeCloudProviderAccessRole(s.ctx, groupID, roleID, &role).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + role := atlasv2.CloudProviderAccessRole{ + ProviderName: req.ProviderName, + IamAssumedRoleArn: req.IAMAssumedRoleARN, } + result, _, err := s.clientv2.CloudProviderAccessApi.AuthorizeCloudProviderAccessRole(s.ctx, groupID, roleID, &role).Execute() + return result, err } diff --git a/internal/store/atlas/access_role.go b/internal/store/atlas/access_role.go index 2f766c2283..9d3e7fa50d 100644 --- a/internal/store/atlas/access_role.go +++ b/internal/store/atlas/access_role.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type CloudProviderAccessRoleLister interface { // CloudProviderAccessRoles encapsulates the logic to manage different cloud providers. func (s *Store) CloudProviderAccessRoles(groupID string) (*atlasv2.CloudProviderAccessRoles, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudProviderAccessApi.ListCloudProviderAccessRoles(s.ctx, groupID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudProviderAccessApi.ListCloudProviderAccessRoles(s.ctx, groupID).Execute() + return result, err } diff --git a/internal/store/atlas/auditing.go b/internal/store/atlas/auditing.go index 3e5e6123b9..9d3d2a998a 100644 --- a/internal/store/atlas/auditing.go +++ b/internal/store/atlas/auditing.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,11 +25,6 @@ type AuditingDescriber interface { } func (s *Store) Auditing(projectID string) (*atlasv2.AuditLog, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AuditingApi.GetAuditingConfiguration(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AuditingApi.GetAuditingConfiguration(s.ctx, projectID).Execute() + return result, err } diff --git a/internal/store/atlas/cloud_provider_backup.go b/internal/store/atlas/cloud_provider_backup.go index 50e03e40a2..2ad41bf53c 100644 --- a/internal/store/atlas/cloud_provider_backup.go +++ b/internal/store/atlas/cloud_provider_backup.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type ScheduleDescriber interface { // DescribeSchedule encapsulates the logic to manage different cloud providers. func (s *Store) DescribeSchedule(projectID, clusterName string) (*atlasv2.DiskBackupSnapshotSchedule, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.GetBackupSchedule(s.ctx, projectID, clusterName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.GetBackupSchedule(s.ctx, projectID, clusterName).Execute() + return result, err } diff --git a/internal/store/atlas/clusters.go b/internal/store/atlas/clusters.go index e15e788b86..b09da06b9c 100644 --- a/internal/store/atlas/clusters.go +++ b/internal/store/atlas/clusters.go @@ -15,16 +15,13 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" "go.mongodb.org/atlas-sdk/v20231115007/admin" ) //go:generate mockgen -destination=../../mocks/atlas/mock_clusters.go -package=atlas github.com/mongodb/mongodb-atlas-cli/internal/store/atlas ClusterLister,ClusterDescriber,ClusterConfigurationOptionsDescriber type ClusterLister interface { - ProjectClusters(string, *ListOptions) (interface{}, error) + ProjectClusters(string, *ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) } type ClusterDescriber interface { @@ -36,38 +33,23 @@ type ClusterConfigurationOptionsDescriber interface { } // ProjectClusters encapsulate the logic to manage different cloud providers. -func (s *Store) ProjectClusters(projectID string, opts *ListOptions) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.ClustersApi.ListClusters(s.ctx, projectID) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) +func (s *Store) ProjectClusters(projectID string, opts *ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) { + res := s.clientv2.ClustersApi.ListClusters(s.ctx, projectID) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } // AtlasCluster encapsulates the logic to manage different cloud providers. func (s *Store) AtlasCluster(projectID, name string) (*admin.AdvancedClusterDescription, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.GetCluster(s.ctx, projectID, name).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.GetCluster(s.ctx, projectID, name).Execute() + return result, err } // AtlasClusterConfigurationOptions encapsulates the logic to manage different cloud providers. func (s *Store) AtlasClusterConfigurationOptions(projectID, name string) (*admin.ClusterDescriptionProcessArgs, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.GetClusterAdvancedConfiguration(s.ctx, projectID, name).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.GetClusterAdvancedConfiguration(s.ctx, projectID, name).Execute() + return result, err } diff --git a/internal/store/atlas/database_roles.go b/internal/store/atlas/database_roles.go index 4051f1bbc6..db9e21bbbd 100644 --- a/internal/store/atlas/database_roles.go +++ b/internal/store/atlas/database_roles.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type DatabaseRoleLister interface { // DatabaseRoles encapsulate the logic to manage different cloud providers. func (s *Store) DatabaseRoles(projectID string) ([]atlasv2.UserCustomDBRole, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CustomDatabaseRolesApi.ListCustomDatabaseRoles(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CustomDatabaseRolesApi.ListCustomDatabaseRoles(s.ctx, projectID).Execute() + return result, err } diff --git a/internal/store/atlas/database_users.go b/internal/store/atlas/database_users.go index 8205c64c38..2f365f1acf 100644 --- a/internal/store/atlas/database_users.go +++ b/internal/store/atlas/database_users.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,15 +25,10 @@ type DatabaseUserLister interface { } func (s *Store) DatabaseUsers(projectID string, opts *ListOptions) (*atlasv2.PaginatedApiAtlasDatabaseUser, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.DatabaseUsersApi.ListDatabaseUsers(s.ctx, projectID) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.DatabaseUsersApi.ListDatabaseUsers(s.ctx, projectID) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } diff --git a/internal/store/atlas/encryption_at_rest.go b/internal/store/atlas/encryption_at_rest.go index 6d2ead81d7..5899728ffe 100644 --- a/internal/store/atlas/encryption_at_rest.go +++ b/internal/store/atlas/encryption_at_rest.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,11 +25,6 @@ type EncryptionAtRestDescriber interface { } func (s *Store) EncryptionAtRest(projectID string) (*atlasv2.EncryptionAtRest, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(s.ctx, projectID).Execute() + return result, err } diff --git a/internal/store/atlas/global_cluster.go b/internal/store/atlas/global_cluster.go index ac336e5ced..0e1dccdbc4 100644 --- a/internal/store/atlas/global_cluster.go +++ b/internal/store/atlas/global_cluster.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,11 +25,6 @@ type GlobalClusterDescriber interface { } func (s *Store) GlobalCluster(projectID, instanceName string) (*atlasv2.GeoSharding, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.GlobalClustersApi.GetManagedNamespace(s.ctx, projectID, instanceName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.GlobalClustersApi.GetManagedNamespace(s.ctx, projectID, instanceName).Execute() + return result, err } diff --git a/internal/store/atlas/integrations.go b/internal/store/atlas/integrations.go index 1cfce77d99..0bd0534201 100644 --- a/internal/store/atlas/integrations.go +++ b/internal/store/atlas/integrations.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type IntegrationLister interface { // Integrations encapsulates the logic to manage different cloud providers. func (s *Store) Integrations(projectID string) (*atlasv2.PaginatedIntegration, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(s.ctx, projectID).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(s.ctx, projectID).Execute() + return resp, err } diff --git a/internal/store/atlas/maintenance.go b/internal/store/atlas/maintenance.go index 376b41c2af..936bd586c0 100644 --- a/internal/store/atlas/maintenance.go +++ b/internal/store/atlas/maintenance.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type MaintenanceWindowDescriber interface { // MaintenanceWindow encapsulates the logic to manage different cloud providers. func (s *Store) MaintenanceWindow(projectID string) (*atlasv2.GroupMaintenanceWindow, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.MaintenanceWindowsApi.GetMaintenanceWindow(s.ctx, projectID).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.MaintenanceWindowsApi.GetMaintenanceWindow(s.ctx, projectID).Execute() + return resp, err } diff --git a/internal/store/atlas/peering_connections.go b/internal/store/atlas/peering_connections.go index 17794a2030..17f1f1b9ea 100644 --- a/internal/store/atlas/peering_connections.go +++ b/internal/store/atlas/peering_connections.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,17 +26,12 @@ type PeeringConnectionLister interface { // PeeringConnections encapsulates the logic to manage different cloud providers. func (s *Store) PeeringConnections(projectID string, opts *ContainersListOptions) ([]atlasv2.BaseNetworkPeeringConnectionSettings, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringConnections(s.ctx, projectID). - ItemsPerPage(opts.ItemsPerPage). - PageNum(opts.PageNum). - ProviderName(opts.ProviderName).Execute() - if err != nil { - return nil, err - } - return result.GetResults(), nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringConnections(s.ctx, projectID). + ItemsPerPage(opts.ItemsPerPage). + PageNum(opts.PageNum). + ProviderName(opts.ProviderName).Execute() + if err != nil { + return nil, err } + return result.GetResults(), nil } diff --git a/internal/store/atlas/private_endpoints.go b/internal/store/atlas/private_endpoints.go index 988272f8ca..44219e0603 100644 --- a/internal/store/atlas/private_endpoints.go +++ b/internal/store/atlas/private_endpoints.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type PrivateEndpointLister interface { // PrivateEndpoints encapsulates the logic to manage different cloud providers. func (s *Store) PrivateEndpoints(projectID, provider string) ([]atlasv2.EndpointService, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.PrivateEndpointServicesApi.ListPrivateEndpointServices(s.ctx, projectID, provider).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.PrivateEndpointServicesApi.ListPrivateEndpointServices(s.ctx, projectID, provider).Execute() + return result, err } diff --git a/internal/store/atlas/project_ip_access_lists.go b/internal/store/atlas/project_ip_access_lists.go index 1782b343f2..d781391e76 100644 --- a/internal/store/atlas/project_ip_access_lists.go +++ b/internal/store/atlas/project_ip_access_lists.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,15 +26,10 @@ type ProjectIPAccessListLister interface { // ProjectIPAccessLists encapsulate the logic to manage different cloud providers. func (s *Store) ProjectIPAccessLists(projectID string, opts *ListOptions) (*atlasv2.PaginatedNetworkAccess, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.ProjectIPAccessListApi.ListProjectIpAccessLists(s.ctx, projectID) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.ProjectIPAccessListApi.ListProjectIpAccessLists(s.ctx, projectID) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } diff --git a/internal/store/atlas/project_settings.go b/internal/store/atlas/project_settings.go index 2c2a5561f1..e779dca280 100644 --- a/internal/store/atlas/project_settings.go +++ b/internal/store/atlas/project_settings.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type ProjectSettingsDescriber interface { // ProjectSettings encapsulates the logic of getting settings of a particular project. func (s *Store) ProjectSettings(projectID string) (*atlasv2.GroupSettings, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ProjectsApi.GetProjectSettings(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ProjectsApi.GetProjectSettings(s.ctx, projectID).Execute() + return result, err } diff --git a/internal/store/atlas/projects.go b/internal/store/atlas/projects.go index 7824579713..02136f7ee3 100644 --- a/internal/store/atlas/projects.go +++ b/internal/store/atlas/projects.go @@ -38,8 +38,8 @@ type ProjectDeleter interface { } type ProjectDescriber interface { - Project(string) (interface{}, error) - ProjectByName(string) (interface{}, error) + Project(string) (*atlasv2.Group, error) + ProjectByName(string) (*atlasv2.Group, error) } type ProjectUsersLister interface { @@ -83,12 +83,12 @@ func (s *Store) GetOrgProjects(orgID string, opts *ListOptions) (*atlasv2.Pagina } // Project encapsulates the logic to manage different cloud providers. -func (s *Store) Project(id string) (interface{}, error) { +func (s *Store) Project(id string) (*atlasv2.Group, error) { result, _, err := s.clientv2.ProjectsApi.GetProject(s.ctx, id).Execute() return result, err } -func (s *Store) ProjectByName(name string) (interface{}, error) { +func (s *Store) ProjectByName(name string) (*atlasv2.Group, error) { result, _, err := s.clientv2.ProjectsApi.GetProjectByName(s.ctx, name).Execute() return result, err } diff --git a/internal/store/atlas/serverless_instances.go b/internal/store/atlas/serverless_instances.go index 9ea4e2f18f..88ece7e580 100644 --- a/internal/store/atlas/serverless_instances.go +++ b/internal/store/atlas/serverless_instances.go @@ -33,26 +33,22 @@ type ServerlessInstanceDescriber interface { // ServerlessInstances encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessInstances(projectID string, listOps *ListOptions) (*atlasv2.PaginatedServerlessInstanceDescription, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.ServerlessInstancesApi.ListServerlessInstances(s.ctx, projectID). - ItemsPerPage(listOps.ItemsPerPage). - PageNum(listOps.PageNum). - Execute() - - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.ServerlessInstancesApi.ListServerlessInstances(s.ctx, projectID). + ItemsPerPage(listOps.ItemsPerPage). + PageNum(listOps.PageNum). + Execute() + + return result, err } // ServerlessInstance encapsulates the logic to manage different cloud providers. func (s *Store) GetServerlessInstance(projectID, clusterName string) (*atlasv2.ServerlessInstanceDescription, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.ServerlessInstancesApi.GetServerlessInstance(s.ctx, projectID, clusterName).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.ServerlessInstancesApi.GetServerlessInstance(s.ctx, projectID, clusterName).Execute() + return result, err } diff --git a/internal/store/atlas/serverless_private_endpoints.go b/internal/store/atlas/serverless_private_endpoints.go index 352440b57b..0945eaefe3 100644 --- a/internal/store/atlas/serverless_private_endpoints.go +++ b/internal/store/atlas/serverless_private_endpoints.go @@ -15,9 +15,6 @@ package atlas import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,11 +25,6 @@ type ServerlessPrivateEndpointsLister interface { } func (s *Store) ServerlessPrivateEndpoints(projectID, instanceName string) ([]atlasv2.ServerlessTenantEndpoint, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ServerlessPrivateEndpointsApi.ListServerlessPrivateEndpoints(s.ctx, projectID, instanceName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ServerlessPrivateEndpointsApi.ListServerlessPrivateEndpoints(s.ctx, projectID, instanceName).Execute() + return result, err } diff --git a/internal/store/auditing.go b/internal/store/auditing.go index 052ddca4bc..5ba2bdbb52 100644 --- a/internal/store/auditing.go +++ b/internal/store/auditing.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -32,21 +29,11 @@ type AuditingUpdater interface { } func (s *Store) Auditing(projectID string) (*atlasv2.AuditLog, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AuditingApi.GetAuditingConfiguration(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AuditingApi.GetAuditingConfiguration(s.ctx, projectID).Execute() + return result, err } func (s *Store) UpdateAuditingConfig(projectID string, r *atlasv2.AuditLog) (*atlasv2.AuditLog, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AuditingApi.UpdateAuditingConfiguration(s.ctx, projectID, r).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AuditingApi.UpdateAuditingConfiguration(s.ctx, projectID, r).Execute() + return result, err } diff --git a/internal/store/cloud_provider_backup.go b/internal/store/cloud_provider_backup.go index c44aeb8709..1a69b98072 100644 --- a/internal/store/cloud_provider_backup.go +++ b/internal/store/cloud_provider_backup.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -95,203 +92,118 @@ type ScheduleDeleter interface { // RestoreJobs encapsulates the logic to manage different cloud providers. func (s *Store) RestoreJobs(projectID, clusterName string, opts *atlas.ListOptions) (*atlasv2.PaginatedCloudBackupRestoreJob, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.CloudBackupsApi.ListBackupRestoreJobs(s.ctx, projectID, clusterName) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.CloudBackupsApi.ListBackupRestoreJobs(s.ctx, projectID, clusterName) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } // RestoreJob encapsulates the logic to manage different cloud providers. func (s *Store) RestoreJob(projectID, clusterName, jobID string) (*atlasv2.DiskBackupSnapshotRestoreJob, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.GetBackupRestoreJob(s.ctx, projectID, clusterName, jobID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.GetBackupRestoreJob(s.ctx, projectID, clusterName, jobID).Execute() + return result, err } // CreateRestoreJobs encapsulates the logic to manage different cloud providers. func (s *Store) CreateRestoreJobs(projectID, clusterName string, request *atlasv2.DiskBackupSnapshotRestoreJob) (*atlasv2.DiskBackupSnapshotRestoreJob, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.CreateBackupRestoreJob(s.ctx, projectID, clusterName, request).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.CreateBackupRestoreJob(s.ctx, projectID, clusterName, request).Execute() + return result, err } // CreateSnapshot encapsulates the logic to manage different cloud providers. func (s *Store) CreateSnapshot(projectID, clusterName string, request *atlasv2.DiskBackupOnDemandSnapshotRequest) (*atlasv2.DiskBackupSnapshot, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.TakeSnapshot(s.ctx, projectID, clusterName, request).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.TakeSnapshot(s.ctx, projectID, clusterName, request).Execute() + return result, err } // Snapshots encapsulates the logic to manage different cloud providers. func (s *Store) Snapshots(projectID, clusterName string, opts *atlas.ListOptions) (*atlasv2.PaginatedCloudBackupReplicaSet, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.CloudBackupsApi.ListReplicaSetBackups(s.ctx, projectID, clusterName) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.CloudBackupsApi.ListReplicaSetBackups(s.ctx, projectID, clusterName) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } // Snapshot encapsulates the logic to manage different cloud providers. func (s *Store) Snapshot(projectID, clusterName, snapshotID string) (*atlasv2.DiskBackupReplicaSet, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.GetReplicaSetBackup(s.ctx, projectID, clusterName, snapshotID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.GetReplicaSetBackup(s.ctx, projectID, clusterName, snapshotID).Execute() + return result, err } // DeleteSnapshot encapsulates the logic to manage different cloud providers. func (s *Store) DeleteSnapshot(projectID, clusterName, snapshotID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.CloudBackupsApi.DeleteReplicaSetBackup(s.ctx, projectID, clusterName, snapshotID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.CloudBackupsApi.DeleteReplicaSetBackup(s.ctx, projectID, clusterName, snapshotID).Execute() + return err } // ExportJobs encapsulates the logic to manage different cloud providers. func (s *Store) ExportJobs(projectID, clusterName string, opts *atlas.ListOptions) (*atlasv2.PaginatedApiAtlasDiskBackupExportJob, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.CloudBackupsApi.ListBackupExportJobs(s.ctx, projectID, clusterName) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.CloudBackupsApi.ListBackupExportJobs(s.ctx, projectID, clusterName) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } // ExportJob encapsulates the logic to manage different cloud providers. func (s *Store) ExportJob(projectID, clusterName, bucketID string) (*atlasv2.DiskBackupExportJob, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.GetBackupExportJob(s.ctx, projectID, clusterName, bucketID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.GetBackupExportJob(s.ctx, projectID, clusterName, bucketID).Execute() + return result, err } // CreateExportJob encapsulates the logic to manage different cloud providers. func (s *Store) CreateExportJob(projectID, clusterName string, job *atlasv2.DiskBackupExportJobRequest) (*atlasv2.DiskBackupExportJob, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.CreateBackupExportJob(s.ctx, projectID, clusterName, job).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.CreateBackupExportJob(s.ctx, projectID, clusterName, job).Execute() + return result, err } // ExportBuckets encapsulates the logic to manage different cloud providers. func (s *Store) ExportBuckets(projectID string, opts *atlas.ListOptions) (*atlasv2.PaginatedBackupSnapshotExportBucket, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.CloudBackupsApi.ListExportBuckets(s.ctx, projectID) - if opts != nil { - res = res.ItemsPerPage(opts.ItemsPerPage).PageNum(opts.PageNum) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.CloudBackupsApi.ListExportBuckets(s.ctx, projectID) + if opts != nil { + res = res.ItemsPerPage(opts.ItemsPerPage).PageNum(opts.PageNum) } + result, _, err := res.Execute() + return result, err } // CreateExportBucket encapsulates the logic to manage different cloud providers. func (s *Store) CreateExportBucket(projectID string, bucket *atlasv2.DiskBackupSnapshotAWSExportBucket) (*atlasv2.DiskBackupSnapshotAWSExportBucket, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.CreateExportBucket(s.ctx, projectID, bucket).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.CreateExportBucket(s.ctx, projectID, bucket).Execute() + return result, err } // DeleteExportBucket encapsulates the logic to manage different cloud providers. func (s *Store) DeleteExportBucket(projectID, bucketID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.CloudBackupsApi.DeleteExportBucket(s.ctx, projectID, bucketID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.CloudBackupsApi.DeleteExportBucket(s.ctx, projectID, bucketID).Execute() + return err } // DescribeExportBucket encapsulates the logic to manage different cloud providers. func (s *Store) DescribeExportBucket(projectID, bucketID string) (*atlasv2.DiskBackupSnapshotAWSExportBucket, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.GetExportBucket(s.ctx, projectID, bucketID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.GetExportBucket(s.ctx, projectID, bucketID).Execute() + return result, err } // DescribeSchedule encapsulates the logic to manage different cloud providers. func (s *Store) DescribeSchedule(projectID, clusterName string) (*atlasv2.DiskBackupSnapshotSchedule, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.GetBackupSchedule(s.ctx, projectID, clusterName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.GetBackupSchedule(s.ctx, projectID, clusterName).Execute() + return result, err } // UpdateSchedule encapsulates the logic to manage different cloud providers. func (s *Store) UpdateSchedule(projectID, clusterName string, policy *atlasv2.DiskBackupSnapshotSchedule) (*atlasv2.DiskBackupSnapshotSchedule, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.UpdateBackupSchedule(s.ctx, projectID, clusterName, policy).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.UpdateBackupSchedule(s.ctx, projectID, clusterName, policy).Execute() + return result, err } // DeleteSchedule encapsulates the logic to manage different cloud providers. func (s *Store) DeleteSchedule(projectID, clusterName string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.CloudBackupsApi.DeleteAllBackupSchedules(s.ctx, projectID, clusterName).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.CloudBackupsApi.DeleteAllBackupSchedules(s.ctx, projectID, clusterName).Execute() + return err } diff --git a/internal/store/cloud_provider_backup_serverless.go b/internal/store/cloud_provider_backup_serverless.go index 4b48eae314..9c8254fb5a 100644 --- a/internal/store/cloud_provider_backup_serverless.go +++ b/internal/store/cloud_provider_backup_serverless.go @@ -46,63 +46,50 @@ type ServerlessRestoreJobsCreator interface { // ServerlessSnapshots encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessSnapshots(projectID, clusterName string, opts *atlas.ListOptions) (*atlasv2.PaginatedApiAtlasServerlessBackupSnapshot, error) { - switch s.service { - case config.CloudService: - res := s.clientv2.CloudBackupsApi.ListServerlessBackups(s.ctx, projectID, clusterName) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + res := s.clientv2.CloudBackupsApi.ListServerlessBackups(s.ctx, projectID, clusterName) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) + } + result, _, err := res.Execute() + return result, err } // ServerlessSnapshot encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessSnapshot(projectID, instanceName, snapshotID string) (*atlasv2.ServerlessBackupSnapshot, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.CloudBackupsApi.GetServerlessBackup(s.ctx, projectID, instanceName, snapshotID).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.CloudBackupsApi.GetServerlessBackup(s.ctx, projectID, instanceName, snapshotID).Execute() + return result, err } // ServerlessRestoreJobs encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessRestoreJobs(projectID, instanceName string, opts *atlas.ListOptions) (*atlasv2.PaginatedApiAtlasServerlessBackupRestoreJob, error) { - switch s.service { - case config.CloudService: - res := s.clientv2.CloudBackupsApi.ListServerlessBackupRestoreJobs(s.ctx, projectID, instanceName) - if opts != nil { - res = res.ItemsPerPage(opts.ItemsPerPage).PageNum(opts.PageNum) - } - result, _, err := res.Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + res := s.clientv2.CloudBackupsApi.ListServerlessBackupRestoreJobs(s.ctx, projectID, instanceName) + if opts != nil { + res = res.ItemsPerPage(opts.ItemsPerPage).PageNum(opts.PageNum) + } + result, _, err := res.Execute() + return result, err } // ServerlessRestoreJob encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessRestoreJob(projectID, instanceName string, jobID string) (*atlasv2.ServerlessBackupRestoreJob, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.CloudBackupsApi.GetServerlessBackupRestoreJob(s.ctx, projectID, instanceName, jobID).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.CloudBackupsApi.GetServerlessBackupRestoreJob(s.ctx, projectID, instanceName, jobID).Execute() + return result, err } // CreateRestoreJobs encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessCreateRestoreJobs(projectID, clusterName string, request *atlasv2.ServerlessBackupRestoreJob) (*atlasv2.ServerlessBackupRestoreJob, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CloudBackupsApi.CreateServerlessBackupRestoreJob(s.ctx, projectID, clusterName, request).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CloudBackupsApi.CreateServerlessBackupRestoreJob(s.ctx, projectID, clusterName, request).Execute() + return result, err } diff --git a/internal/store/cloud_provider_regions.go b/internal/store/cloud_provider_regions.go index 5b90746e34..46b10bf926 100644 --- a/internal/store/cloud_provider_regions.go +++ b/internal/store/cloud_provider_regions.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type CloudProviderRegionsLister interface { // CloudProviderRegions encapsulates the logic to manage different cloud providers. func (s *Store) CloudProviderRegions(projectID, tier string, providerName []string) (*atlasv2.PaginatedApiAtlasProviderRegions, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.ListCloudProviderRegions(s.ctx, projectID).Providers(providerName).Tier(tier).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.ListCloudProviderRegions(s.ctx, projectID).Providers(providerName).Tier(tier).Execute() + return result, err } diff --git a/internal/store/clusters.go b/internal/store/clusters.go index 4662f215c5..a0b82b388d 100644 --- a/internal/store/clusters.go +++ b/internal/store/clusters.go @@ -15,18 +15,14 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" "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_clusters.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store ClusterLister,AtlasClusterDescriber,OpsManagerClusterDescriber,ClusterCreator,ClusterDeleter,ClusterUpdater,AtlasClusterGetterUpdater,ClusterPauser,ClusterStarter,AtlasClusterQuickStarter,SampleDataAdder,SampleDataStatusDescriber,AtlasClusterConfigurationOptionsDescriber,AtlasSharedClusterDescriber,ClusterUpgrader,AtlasSharedClusterGetterUpgrader,AtlasClusterConfigurationOptionsUpdater,ClusterTester +//go:generate mockgen -destination=../mocks/mock_clusters.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store ClusterLister,AtlasClusterDescriber,ClusterCreator,ClusterDeleter,ClusterUpdater,AtlasClusterGetterUpdater,ClusterPauser,ClusterStarter,AtlasClusterQuickStarter,SampleDataAdder,SampleDataStatusDescriber,AtlasClusterConfigurationOptionsDescriber,AtlasSharedClusterDescriber,ClusterUpgrader,AtlasSharedClusterGetterUpgrader,AtlasClusterConfigurationOptionsUpdater,ClusterTester type ClusterLister interface { - ProjectClusters(string, *atlas.ListOptions) (interface{}, error) + ProjectClusters(string, *atlas.ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) } type AtlasClusterDescriber interface { @@ -41,10 +37,6 @@ type AtlasClusterConfigurationOptionsUpdater interface { UpdateAtlasClusterConfigurationOptions(string, string, *admin.ClusterDescriptionProcessArgs) (*admin.ClusterDescriptionProcessArgs, error) } -type OpsManagerClusterDescriber interface { - OpsManagerCluster(string, string) (*opsmngr.Cluster, error) -} - type AtlasSharedClusterDescriber interface { AtlasSharedCluster(string, string) (*atlas.Cluster, error) } @@ -109,46 +101,26 @@ type AtlasClusterQuickStarter interface { // AddSampleData encapsulate the logic to manage different cloud providers. func (s *Store) AddSampleData(groupID, clusterName string) (*admin.SampleDatasetStatus, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.LoadSampleDataset(s.ctx, groupID, clusterName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.LoadSampleDataset(s.ctx, groupID, clusterName).Execute() + return result, err } // SampleDataStatus encapsulate the logic to manage different cloud providers. func (s *Store) SampleDataStatus(groupID, id string) (*admin.SampleDatasetStatus, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.GetSampleDatasetLoadStatus(s.ctx, groupID, id).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.GetSampleDatasetLoadStatus(s.ctx, groupID, id).Execute() + return result, err } // CreateCluster encapsulate the logic to manage different cloud providers. func (s *Store) CreateCluster(cluster *admin.AdvancedClusterDescription) (*admin.AdvancedClusterDescription, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.CreateCluster(s.ctx, cluster.GetGroupId(), cluster).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.CreateCluster(s.ctx, cluster.GetGroupId(), cluster).Execute() + return result, err } // UpdateCluster encapsulate the logic to manage different cloud providers. func (s *Store) UpdateCluster(projectID, name string, cluster *admin.AdvancedClusterDescription) (*admin.AdvancedClusterDescription, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.UpdateCluster(s.ctx, projectID, name, cluster).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.UpdateCluster(s.ctx, projectID, name, cluster).Execute() + return result, err } // PauseCluster encapsulate the logic to manage different cloud providers. @@ -171,116 +143,51 @@ func (s *Store) StartCluster(projectID, name string) (*admin.AdvancedClusterDesc // DeleteCluster encapsulate the logic to manage different cloud providers. func (s *Store) DeleteCluster(projectID, name string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.ClustersApi.DeleteCluster(s.ctx, projectID, name).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.ClustersApi.DeleteCluster(s.ctx, projectID, name).Execute() + return err } // AtlasSharedCluster encapsulates the logic to fetch details of one shared cluster. func (s *Store) AtlasSharedCluster(projectID, name string) (*atlas.Cluster, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService, config.CloudService: - result, _, err := s.client.(*atlas.Client).Clusters.Get(s.ctx, projectID, name) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.Clusters.Get(s.ctx, projectID, name) + return result, err } // UpgradeCluster encapsulate the logic to upgrade shared clusters in a project. func (s *Store) UpgradeCluster(projectID string, cluster *atlas.Cluster) (*atlas.Cluster, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Clusters.Upgrade(s.ctx, projectID, cluster) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.Clusters.Upgrade(s.ctx, projectID, cluster) + return result, err } // ProjectClusters encapsulate the logic to manage different cloud providers. -func (s *Store) ProjectClusters(projectID string, opts *atlas.ListOptions) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.ClustersApi.ListClusters(s.ctx, projectID) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - case config.OpsManagerService, config.CloudManagerService: - result, _, err := s.client.(*opsmngr.Client).Clusters.List(s.ctx, projectID, opts) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) +func (s *Store) ProjectClusters(projectID string, opts *atlas.ListOptions) (*admin.PaginatedAdvancedClusterDescription, error) { + res := s.clientv2.ClustersApi.ListClusters(s.ctx, projectID) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } // AtlasCluster encapsulates the logic to manage different cloud providers. func (s *Store) AtlasCluster(projectID, name string) (*admin.AdvancedClusterDescription, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.GetCluster(s.ctx, projectID, name).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// OpsManagerCluster encapsulates the logic to manage different cloud providers. -func (s *Store) OpsManagerCluster(projectID, name string) (*opsmngr.Cluster, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - result, _, err := s.client.(*opsmngr.Client).Clusters.Get(s.ctx, projectID, name) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// ListAllProjectClusters encapsulate the logic to manage different cloud providers. -func (s *Store) ListAllProjectClusters() (*opsmngr.AllClustersProjects, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - result, _, err := s.client.(*opsmngr.Client).Clusters.ListAll(s.ctx) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.GetCluster(s.ctx, projectID, name).Execute() + return result, err } // AtlasClusterConfigurationOptions encapsulates the logic to manage different cloud providers. func (s *Store) AtlasClusterConfigurationOptions(projectID, name string) (*admin.ClusterDescriptionProcessArgs, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.GetClusterAdvancedConfiguration(s.ctx, projectID, name).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.GetClusterAdvancedConfiguration(s.ctx, projectID, name).Execute() + return result, err } // UpdateAtlasClusterConfigurationOptions encapsulates the logic to manage different cloud providers. func (s *Store) UpdateAtlasClusterConfigurationOptions(projectID, clusterName string, args *admin.ClusterDescriptionProcessArgs) (*admin.ClusterDescriptionProcessArgs, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ClustersApi.UpdateClusterAdvancedConfiguration(s.ctx, projectID, clusterName, args).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ClustersApi.UpdateClusterAdvancedConfiguration(s.ctx, projectID, clusterName, args).Execute() + return result, err } func (s *Store) TestClusterFailover(projectID, clusterName string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.ClustersApi.TestFailover(s.ctx, projectID, clusterName).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.ClustersApi.TestFailover(s.ctx, projectID, clusterName).Execute() + return err } diff --git a/internal/store/custom_dns.go b/internal/store/custom_dns.go index 27160c6582..45993a03c2 100644 --- a/internal/store/custom_dns.go +++ b/internal/store/custom_dns.go @@ -17,9 +17,6 @@ package store //go:generate mockgen -destination=../mocks/mock_custom_dns.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store CustomDNSEnabler,CustomDNSDisabler,CustomDNSDescriber import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -37,39 +34,24 @@ type CustomDNSDescriber interface { // EnableCustomDNS encapsulates the logic to manage different cloud providers. func (s *Store) EnableCustomDNS(projectID string) (*atlasv2.AWSCustomDNSEnabled, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - customDNSSetting := &atlasv2.AWSCustomDNSEnabled{ - Enabled: true, - } - result, _, err := s.clientv2.AWSClustersDNSApi.ToggleAWSCustomDNS(s.ctx, projectID, customDNSSetting).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + customDNSSetting := &atlasv2.AWSCustomDNSEnabled{ + Enabled: true, } + result, _, err := s.clientv2.AWSClustersDNSApi.ToggleAWSCustomDNS(s.ctx, projectID, customDNSSetting).Execute() + return result, err } // DisableCustomDNS encapsulates the logic to manage different cloud providers. func (s *Store) DisableCustomDNS(projectID string) (*atlasv2.AWSCustomDNSEnabled, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - customDNSSetting := &atlasv2.AWSCustomDNSEnabled{ - Enabled: false, - } - result, _, err := s.clientv2.AWSClustersDNSApi.ToggleAWSCustomDNS(s.ctx, projectID, customDNSSetting).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + customDNSSetting := &atlasv2.AWSCustomDNSEnabled{ + Enabled: false, } + result, _, err := s.clientv2.AWSClustersDNSApi.ToggleAWSCustomDNS(s.ctx, projectID, customDNSSetting).Execute() + return result, err } // DescribeCustomDNS encapsulates the logic to manage different cloud providers. func (s *Store) DescribeCustomDNS(projectID string) (*atlasv2.AWSCustomDNSEnabled, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AWSClustersDNSApi.GetAWSCustomDNS(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AWSClustersDNSApi.GetAWSCustomDNS(s.ctx, projectID).Execute() + return result, err } diff --git a/internal/store/data_lake.go b/internal/store/data_lake.go index c22ae936d4..19ec6dbe76 100644 --- a/internal/store/data_lake.go +++ b/internal/store/data_lake.go @@ -53,55 +53,45 @@ type DataLakeStore interface { // CreateDataLake encapsulate the logic to manage different cloud providers. func (s *Store) CreateDataLake(projectID string, dataLake *atlas.DataLakeCreateRequest) (*atlas.DataLake, error) { - switch s.service { - case config.CloudService: - result, _, err := s.client.(*atlas.Client).DataLakes.Create(s.ctx, projectID, dataLake) - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.client.DataLakes.Create(s.ctx, projectID, dataLake) + return result, err } // UpdateDataLake encapsulate the logic to manage different cloud providers. func (s *Store) UpdateDataLake(projectID, name string, dataLake *atlas.DataLakeUpdateRequest) (*atlas.DataLake, error) { - switch s.service { - case config.CloudService: - result, _, err := s.client.(*atlas.Client).DataLakes.Update(s.ctx, projectID, name, dataLake) - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.client.DataLakes.Update(s.ctx, projectID, name, dataLake) + return result, err } // DeleteDataLake encapsulate the logic to manage different cloud providers. func (s *Store) DeleteDataLake(projectID, name string) error { - switch s.service { - case config.CloudService: - _, err := s.client.(*atlas.Client).DataLakes.Delete(s.ctx, projectID, name) - return err - default: + if s.service == config.CloudGovService { return fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + _, err := s.client.DataLakes.Delete(s.ctx, projectID, name) + return err } // DataLakes encapsulate the logic to manage different cloud providers. func (s *Store) DataLakes(projectID string) ([]atlas.DataLake, error) { - switch s.service { - case config.CloudService: - result, _, err := s.client.(*atlas.Client).DataLakes.List(s.ctx, projectID) - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.client.DataLakes.List(s.ctx, projectID) + return result, err } // DataLake encapsulate the logic to manage different cloud providers. func (s *Store) DataLake(projectID, name string) (*atlas.DataLake, error) { - switch s.service { - case config.CloudService: - result, _, err := s.client.(*atlas.Client).DataLakes.Get(s.ctx, projectID, name) - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.client.DataLakes.Get(s.ctx, projectID, name) + return result, err } diff --git a/internal/store/database_roles.go b/internal/store/database_roles.go index 273902e056..717f0397b2 100644 --- a/internal/store/database_roles.go +++ b/internal/store/database_roles.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -46,59 +43,34 @@ type DatabaseRoleDescriber interface { // CreateDatabaseRole encapsulate the logic to manage different cloud providers. func (s *Store) CreateDatabaseRole(groupID string, role *atlasv2.UserCustomDBRole) (*atlasv2.UserCustomDBRole, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CustomDatabaseRolesApi.CreateCustomDatabaseRole(s.ctx, groupID, role).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CustomDatabaseRolesApi.CreateCustomDatabaseRole(s.ctx, groupID, role).Execute() + return result, err } // DeleteDatabaseRole encapsulate the logic to manage different cloud providers. func (s *Store) DeleteDatabaseRole(groupID, roleName string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.CustomDatabaseRolesApi.DeleteCustomDatabaseRole(s.ctx, groupID, roleName).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.CustomDatabaseRolesApi.DeleteCustomDatabaseRole(s.ctx, groupID, roleName).Execute() + return err } // DatabaseRoles encapsulate the logic to manage different cloud providers. func (s *Store) DatabaseRoles(projectID string) ([]atlasv2.UserCustomDBRole, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CustomDatabaseRolesApi.ListCustomDatabaseRoles(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CustomDatabaseRolesApi.ListCustomDatabaseRoles(s.ctx, projectID).Execute() + return result, err } // UpdateDatabaseRole encapsulate the logic to manage different cloud providers. func (s *Store) UpdateDatabaseRole(groupID, roleName string, role *atlasv2.UserCustomDBRole) (*atlasv2.UserCustomDBRole, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - dbRole := atlasv2.UpdateCustomDBRole{ - Actions: role.Actions, - InheritedRoles: role.InheritedRoles, - } - result, _, err := s.clientv2.CustomDatabaseRolesApi.UpdateCustomDatabaseRole(s.ctx, groupID, roleName, &dbRole).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + dbRole := atlasv2.UpdateCustomDBRole{ + Actions: role.Actions, + InheritedRoles: role.InheritedRoles, } + result, _, err := s.clientv2.CustomDatabaseRolesApi.UpdateCustomDatabaseRole(s.ctx, groupID, roleName, &dbRole).Execute() + return result, err } // DatabaseRole encapsulate the logic to manage different cloud providers. func (s *Store) DatabaseRole(groupID, roleName string) (*atlasv2.UserCustomDBRole, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.CustomDatabaseRolesApi.GetCustomDatabaseRole(s.ctx, groupID, roleName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.CustomDatabaseRolesApi.GetCustomDatabaseRole(s.ctx, groupID, roleName).Execute() + return result, err } diff --git a/internal/store/database_users.go b/internal/store/database_users.go index e6f03e0b28..867441a9ab 100644 --- a/internal/store/database_users.go +++ b/internal/store/database_users.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" "github.com/mongodb/mongodb-atlas-cli/internal/pointer" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" @@ -55,84 +52,49 @@ type DBUserCertificateCreator interface { // CreateDatabaseUser encapsulate the logic to manage different cloud providers. func (s *Store) CreateDatabaseUser(user *atlasv2.CloudDatabaseUser) (*atlasv2.CloudDatabaseUser, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.DatabaseUsersApi.CreateDatabaseUser(s.ctx, user.GroupId, user).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.DatabaseUsersApi.CreateDatabaseUser(s.ctx, user.GroupId, user).Execute() + return result, err } func (s *Store) DeleteDatabaseUser(authDB, groupID, username string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.DatabaseUsersApi.DeleteDatabaseUser(s.ctx, groupID, authDB, username).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.DatabaseUsersApi.DeleteDatabaseUser(s.ctx, groupID, authDB, username).Execute() + return err } func (s *Store) DatabaseUsers(projectID string, opts *atlas.ListOptions) (*atlasv2.PaginatedApiAtlasDatabaseUser, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.DatabaseUsersApi.ListDatabaseUsers(s.ctx, projectID) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.DatabaseUsersApi.ListDatabaseUsers(s.ctx, projectID) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } func (s *Store) UpdateDatabaseUser(params *atlasv2.UpdateDatabaseUserApiParams) (*atlasv2.CloudDatabaseUser, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.DatabaseUsersApi.UpdateDatabaseUserWithParams(s.ctx, params).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.DatabaseUsersApi.UpdateDatabaseUserWithParams(s.ctx, params).Execute() + return result, err } func (s *Store) DatabaseUser(authDB, groupID, username string) (*atlasv2.CloudDatabaseUser, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.DatabaseUsersApi.GetDatabaseUser(s.ctx, groupID, authDB, username).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.DatabaseUsersApi.GetDatabaseUser(s.ctx, groupID, authDB, username).Execute() + return result, err } // DBUserCertificates retrieves the current Atlas managed certificates for a database user. func (s *Store) DBUserCertificates(projectID, username string, opts *atlas.ListOptions) (*atlasv2.PaginatedUserCert, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.X509AuthenticationApi.ListDatabaseUserCertificates(s.ctx, projectID, username) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.X509AuthenticationApi.ListDatabaseUserCertificates(s.ctx, projectID, username) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } // CreateDBUserCertificate creates a new Atlas managed certificates for a database user. func (s *Store) CreateDBUserCertificate(projectID, username string, monthsUntilExpiration int) (string, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - userCert := &atlasv2.UserCert{ - MonthsUntilExpiration: pointer.Get(monthsUntilExpiration), - } - cert, _, err := s.clientv2.X509AuthenticationApi.CreateDatabaseUserCertificate(s.ctx, projectID, username, userCert).Execute() - return cert, err - default: - return "", fmt.Errorf("%w: %s", errUnsupportedService, s.service) + userCert := &atlasv2.UserCert{ + MonthsUntilExpiration: pointer.Get(monthsUntilExpiration), } + cert, _, err := s.clientv2.X509AuthenticationApi.CreateDatabaseUserCertificate(s.ctx, projectID, username, userCert).Execute() + return cert, err } diff --git a/internal/store/default_mongodb_version.go b/internal/store/default_mongodb_version.go index 02b733dc2c..9b8eb37de7 100644 --- a/internal/store/default_mongodb_version.go +++ b/internal/store/default_mongodb_version.go @@ -14,13 +14,6 @@ package store -import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlas "go.mongodb.org/atlas/mongodbatlas" -) - //go:generate mockgen -destination=../mocks/mock_default_mongodb_version.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store DefaultVersionGetter type DefaultVersionGetter interface { @@ -29,11 +22,6 @@ type DefaultVersionGetter interface { // CreateCloudProviderAccessRole encapsulates the logic to manage different cloud providers. func (s *Store) DefaultMongoDBVersion() (string, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).DefaultMongoDBMajorVersion.Get(s.ctx) - return result, err - default: - return "", fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.DefaultMongoDBMajorVersion.Get(s.ctx) + return result, err } diff --git a/internal/store/deprected_private_endpoints.go b/internal/store/deprected_private_endpoints.go index 8c48d1a92d..f3590587b3 100644 --- a/internal/store/deprected_private_endpoints.go +++ b/internal/store/deprected_private_endpoints.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -53,77 +50,42 @@ type InterfaceEndpointDeleterDeprecated interface { // PrivateEndpointsDeprecated encapsulates the logic to manage different cloud providers. func (s *Store) PrivateEndpointsDeprecated(projectID string, opts *atlas.ListOptions) ([]atlas.PrivateEndpointConnectionDeprecated, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).PrivateEndpointsDeprecated.List(s.ctx, projectID, opts) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.PrivateEndpointsDeprecated.List(s.ctx, projectID, opts) + return result, err } // PrivateEndpointDeprecated encapsulates the logic to manage different cloud providers. func (s *Store) PrivateEndpointDeprecated(projectID, privateLinkID string) (*atlas.PrivateEndpointConnectionDeprecated, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).PrivateEndpointsDeprecated.Get(s.ctx, projectID, privateLinkID) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.PrivateEndpointsDeprecated.Get(s.ctx, projectID, privateLinkID) + return result, err } // DeletePrivateEndpointDeprecated encapsulates the logic to manage different cloud providers. func (s *Store) DeletePrivateEndpointDeprecated(projectID, privateLinkID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.client.(*atlas.Client).PrivateEndpointsDeprecated.Delete(s.ctx, projectID, privateLinkID) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.client.PrivateEndpointsDeprecated.Delete(s.ctx, projectID, privateLinkID) + return err } // CreateInterfaceEndpointDeprecated encapsulates the logic to manage different cloud providers. func (s *Store) CreateInterfaceEndpointDeprecated(projectID, privateLinkID, interfaceEndpointID string) (*atlas.InterfaceEndpointConnectionDeprecated, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).PrivateEndpointsDeprecated.AddOneInterfaceEndpoint(s.ctx, projectID, privateLinkID, interfaceEndpointID) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.PrivateEndpointsDeprecated.AddOneInterfaceEndpoint(s.ctx, projectID, privateLinkID, interfaceEndpointID) + return result, err } // CreatePrivateEndpointDeprecated encapsulates the logic to manage different cloud providers. func (s *Store) CreatePrivateEndpointDeprecated(projectID string, r *atlas.PrivateEndpointConnectionDeprecated) (*atlas.PrivateEndpointConnectionDeprecated, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).PrivateEndpointsDeprecated.Create(s.ctx, projectID, r) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.PrivateEndpointsDeprecated.Create(s.ctx, projectID, r) + return result, err } // InterfaceEndpointDeprecated encapsulates the logic to manage different cloud providers. func (s *Store) InterfaceEndpointDeprecated(projectID, privateLinkID, interfaceEndpointID string) (*atlas.InterfaceEndpointConnectionDeprecated, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).PrivateEndpointsDeprecated.GetOneInterfaceEndpoint(s.ctx, projectID, privateLinkID, interfaceEndpointID) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.PrivateEndpointsDeprecated.GetOneInterfaceEndpoint(s.ctx, projectID, privateLinkID, interfaceEndpointID) + return result, err } // DeleteInterfaceEndpointDeprecated encapsulates the logic to manage different cloud providers. func (s *Store) DeleteInterfaceEndpointDeprecated(projectID, privateLinkID, interfaceEndpointID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.client.(*atlas.Client).PrivateEndpointsDeprecated.DeleteOneInterfaceEndpoint(s.ctx, projectID, privateLinkID, interfaceEndpointID) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.client.PrivateEndpointsDeprecated.DeleteOneInterfaceEndpoint(s.ctx, projectID, privateLinkID, interfaceEndpointID) + return err } diff --git a/internal/store/encryption_at_rest.go b/internal/store/encryption_at_rest.go index 1b5f5e16e3..ac99af3620 100644 --- a/internal/store/encryption_at_rest.go +++ b/internal/store/encryption_at_rest.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,11 +25,6 @@ type EncryptionAtRestDescriber interface { } func (s *Store) EncryptionAtRest(projectID string) (*atlasv2.EncryptionAtRest, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(s.ctx, projectID).Execute() + return result, err } diff --git a/internal/store/global_cluster.go b/internal/store/global_cluster.go index 6a38caa81b..eede78a774 100644 --- a/internal/store/global_cluster.go +++ b/internal/store/global_cluster.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,11 +25,6 @@ type GlobalClusterDescriber interface { } func (s *Store) GlobalCluster(projectID, instanceName string) (*atlasv2.GeoSharding, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.GlobalClustersApi.GetManagedNamespace(s.ctx, projectID, instanceName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.GlobalClustersApi.GetManagedNamespace(s.ctx, projectID, instanceName).Execute() + return result, err } diff --git a/internal/store/indexes.go b/internal/store/indexes.go index 467e588de5..1c9eada87d 100644 --- a/internal/store/indexes.go +++ b/internal/store/indexes.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type IndexCreator interface { // CreateIndex encapsulate the logic to manage different cloud providers. func (s *Store) CreateIndex(projectID, clusterName string, index *atlasv2.DatabaseRollingIndexRequest) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.RollingIndexApi.CreateRollingIndex(s.ctx, projectID, clusterName, index).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.RollingIndexApi.CreateRollingIndex(s.ctx, projectID, clusterName, index).Execute() + return err } diff --git a/internal/store/integrations.go b/internal/store/integrations.go index 947bf1ef79..35cecd91c0 100644 --- a/internal/store/integrations.go +++ b/internal/store/integrations.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -41,45 +38,25 @@ type IntegrationDescriber interface { // CreateIntegration encapsulates the logic to manage different cloud providers. func (s *Store) CreateIntegration(projectID, integrationType string, integration *atlasv2.ThirdPartyIntegration) (*atlasv2.PaginatedIntegration, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(s.ctx, - integrationType, projectID, integration).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(s.ctx, + integrationType, projectID, integration).Execute() + return resp, err } // Integrations encapsulates the logic to manage different cloud providers. func (s *Store) Integrations(projectID string) (*atlasv2.PaginatedIntegration, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(s.ctx, projectID).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(s.ctx, projectID).Execute() + return resp, err } // DeleteIntegration encapsulates the logic to manage different cloud providers. func (s *Store) DeleteIntegration(projectID, integrationType string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.ThirdPartyIntegrationsApi.DeleteThirdPartyIntegration(s.ctx, integrationType, projectID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.ThirdPartyIntegrationsApi.DeleteThirdPartyIntegration(s.ctx, integrationType, projectID).Execute() + return err } // Integration encapsulates the logic to manage different cloud providers. func (s *Store) Integration(projectID, integrationType string) (*atlasv2.ThirdPartyIntegration, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(s.ctx, projectID, integrationType).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(s.ctx, projectID, integrationType).Execute() + return resp, err } diff --git a/internal/store/ip_info.go b/internal/store/ip_info.go index a81374d3a6..8bf1cee005 100644 --- a/internal/store/ip_info.go +++ b/internal/store/ip_info.go @@ -15,8 +15,6 @@ package store import ( - "fmt" - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -27,13 +25,8 @@ type IPInfoDescriber interface { // IPInfo encapsulates the logic to manage different cloud providers. func (s *Store) IPInfo() (*atlas.IPInfo, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.client.(*atlas.Client).IPInfo.Get(s.ctx) - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.client.IPInfo.Get(s.ctx) + return resp, err } // IPAddress gets the client's public ip by calling the atlas private endpoint. diff --git a/internal/store/ldap_configurations.go b/internal/store/ldap_configurations.go index 8b959ff9e1..1a3580baac 100644 --- a/internal/store/ldap_configurations.go +++ b/internal/store/ldap_configurations.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -45,57 +42,32 @@ type LDAPConfigurationGetter interface { // VerifyLDAPConfiguration encapsulates the logic to manage different cloud providers. func (s *Store) VerifyLDAPConfiguration(projectID string, ldap *atlasv2.LDAPVerifyConnectivityJobRequestParams) (*atlasv2.LDAPVerifyConnectivityJobRequest, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.LDAPConfigurationApi.VerifyLDAPConfiguration(s.ctx, projectID, ldap). - Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.LDAPConfigurationApi.VerifyLDAPConfiguration(s.ctx, projectID, ldap). + Execute() + return resp, err } // GetStatusLDAPConfiguration encapsulates the logic to manage different cloud providers. func (s *Store) GetStatusLDAPConfiguration(projectID, requestID string) (*atlasv2.LDAPVerifyConnectivityJobRequest, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.LDAPConfigurationApi.GetLDAPConfigurationStatus(s.ctx, projectID, requestID).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.LDAPConfigurationApi.GetLDAPConfigurationStatus(s.ctx, projectID, requestID).Execute() + return resp, err } // SaveLDAPConfiguration encapsulates the logic to manage different cloud providers. func (s *Store) SaveLDAPConfiguration(projectID string, ldap *atlasv2.UserSecurity) (*atlasv2.UserSecurity, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.LDAPConfigurationApi.SaveLDAPConfiguration(s.ctx, projectID, ldap). - Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.LDAPConfigurationApi.SaveLDAPConfiguration(s.ctx, projectID, ldap). + Execute() + return resp, err } // DeleteLDAPConfiguration encapsulates the logic to manage different cloud providers. func (s *Store) DeleteLDAPConfiguration(projectID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.LDAPConfigurationApi.DeleteLDAPConfiguration(s.ctx, projectID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.LDAPConfigurationApi.DeleteLDAPConfiguration(s.ctx, projectID).Execute() + return err } // GetLDAPConfiguration encapsulates the logic to manage different cloud providers. func (s *Store) GetLDAPConfiguration(projectID string) (*atlasv2.UserSecurity, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.LDAPConfigurationApi.GetLDAPConfiguration(s.ctx, projectID).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.LDAPConfigurationApi.GetLDAPConfiguration(s.ctx, projectID).Execute() + return resp, err } diff --git a/internal/store/live_migration.go b/internal/store/live_migration.go index a249f44c16..57c9617dd6 100644 --- a/internal/store/live_migration.go +++ b/internal/store/live_migration.go @@ -38,33 +38,27 @@ type LiveMigrationValidationsDescriber interface { // CreateValidation encapsulate the logic to manage different cloud providers. func (s *Store) CreateValidation(groupID string, liveMigration *atlasv2.LiveMigrationRequest) (*atlasv2.LiveImportValidation, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.CloudMigrationServiceApi.ValidateMigration(s.ctx, groupID, liveMigration).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.CloudMigrationServiceApi.ValidateMigration(s.ctx, groupID, liveMigration).Execute() + return result, err } // StartLiveMigrationCutover encapsulate the logic to manage different cloud providers. func (s *Store) CreateLiveMigrationCutover(groupID, liveMigrationID string) error { - switch s.service { - case config.CloudService: - _, err := s.clientv2.CloudMigrationServiceApi.CutoverMigration(s.ctx, groupID, liveMigrationID).Execute() - return err - default: + if s.service == config.CloudGovService { return fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + _, err := s.clientv2.CloudMigrationServiceApi.CutoverMigration(s.ctx, groupID, liveMigrationID).Execute() + return err } // GetValidationStatus encapsulate the logic to manage different cloud providers. func (s *Store) GetValidationStatus(groupID, liveMigrationID string) (*atlasv2.LiveImportValidation, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.CloudMigrationServiceApi.GetValidationStatus(context.Background(), groupID, liveMigrationID).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.CloudMigrationServiceApi.GetValidationStatus(context.Background(), groupID, liveMigrationID).Execute() + return result, err } diff --git a/internal/store/live_migration_link_tokens.go b/internal/store/live_migration_link_tokens.go index a1c4d72450..68d46d106c 100644 --- a/internal/store/live_migration_link_tokens.go +++ b/internal/store/live_migration_link_tokens.go @@ -19,7 +19,6 @@ import ( "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" - "go.mongodb.org/ops-manager/opsmngr" ) //go:generate mockgen -destination=../mocks/mock_live_migration_link_tokens.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store LinkTokenCreator,LinkTokenDeleter @@ -39,25 +38,18 @@ type LinkTokenStore interface { // CreateLinkToken encapsulate the logic to manage different cloud providers. func (s *Store) CreateLinkToken(orgID string, linkToken *atlasv2.TargetOrgRequest) (*atlasv2.TargetOrg, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.CloudMigrationServiceApi.CreateLinkToken(s.ctx, orgID, linkToken).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.CloudMigrationServiceApi.CreateLinkToken(s.ctx, orgID, linkToken).Execute() + return result, err } // DeleteLinkToken encapsulate the logic to manage different cloud providers. func (s *Store) DeleteLinkToken(orgID string) error { - switch s.service { - case config.CloudService: - _, _, err := s.clientv2.CloudMigrationServiceApi.DeleteLinkToken(s.ctx, orgID).Execute() - return err - case config.OpsManagerService, config.CloudManagerService: - _, err := s.client.(*opsmngr.Client).LiveMigration.DeleteConnection(s.ctx, orgID) - return err - default: + if s.service == config.CloudGovService { return fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + _, _, err := s.clientv2.CloudMigrationServiceApi.DeleteLinkToken(s.ctx, orgID).Execute() + return err } diff --git a/internal/store/live_migrations.go b/internal/store/live_migrations.go index 8a256a3d63..47c9889b77 100644 --- a/internal/store/live_migrations.go +++ b/internal/store/live_migrations.go @@ -34,22 +34,18 @@ type LiveMigrationDescriber interface { // LiveMigrationCreate encapsulates the logic to manage different cloud providers. func (s *Store) LiveMigrationCreate(groupID string, liveMigrationRequest *atlasv2.LiveMigrationRequest) (*atlasv2.LiveMigrationResponse, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.CloudMigrationServiceApi.CreatePushMigration(context.Background(), groupID, liveMigrationRequest).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.CloudMigrationServiceApi.CreatePushMigration(context.Background(), groupID, liveMigrationRequest).Execute() + return result, err } // LiveMigrationDescribe encapsulates the logic to manage different cloud providers. func (s *Store) LiveMigrationDescribe(groupID, migrationID string) (*atlasv2.LiveMigrationResponse, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.CloudMigrationServiceApi.GetPushMigration(context.Background(), groupID, migrationID).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.CloudMigrationServiceApi.GetPushMigration(context.Background(), groupID, migrationID).Execute() + return result, err } diff --git a/internal/store/logs.go b/internal/store/logs.go index 64a04b1045..129843bec7 100644 --- a/internal/store/logs.go +++ b/internal/store/logs.go @@ -18,90 +18,23 @@ import ( "fmt" "io" - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" - "go.mongodb.org/ops-manager/opsmngr" ) -//go:generate mockgen -destination=../mocks/mock_logs.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store LogsDownloader,LogJobsDownloader,LogCollector,LogJobLister,LogJobDeleter +//go:generate mockgen -destination=../mocks/mock_logs.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store LogsDownloader type LogsDownloader interface { DownloadLog(*atlasv2.GetHostLogsApiParams) (io.ReadCloser, error) } -type LogJobsDownloader interface { - DownloadLogJob(string, string, io.Writer) error -} - -type LogCollector interface { - Collect(string, *opsmngr.LogCollectionJob) (*opsmngr.LogCollectionJob, error) -} - -type LogJobLister interface { - LogCollectionJobs(string, *opsmngr.LogListOptions) (*opsmngr.LogCollectionJobs, error) -} - -type LogJobDeleter interface { - DeleteCollectionJob(string, string) error -} - -// LogCollectionJobs encapsulate the logic to manage different cloud providers. -func (s *Store) LogCollectionJobs(groupID string, opts *opsmngr.LogListOptions) (*opsmngr.LogCollectionJobs, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - log, _, err := s.client.(*opsmngr.Client).LogCollections.List(s.ctx, groupID, opts) - return log, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// DeleteCollectionJob encapsulate the logic to manage different cloud providers. -func (s *Store) DeleteCollectionJob(groupID, logID string) error { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - _, err := s.client.(*opsmngr.Client).LogCollections.Delete(s.ctx, groupID, logID) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// Collect encapsulate the logic to manage different cloud providers. -func (s *Store) Collect(groupID string, newLog *opsmngr.LogCollectionJob) (*opsmngr.LogCollectionJob, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - log, _, err := s.client.(*opsmngr.Client).LogCollections.Create(s.ctx, groupID, newLog) - return log, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - // DownloadLog encapsulates the logic to manage different cloud providers. func (s *Store) DownloadLog(params *atlasv2.GetHostLogsApiParams) (io.ReadCloser, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.MonitoringAndLogsApi.GetHostLogsWithParams(s.ctx, params).Execute() - if err != nil { - return nil, err - } - if result == nil { - return nil, fmt.Errorf("returned file is empty") - } - return result, nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + result, _, err := s.clientv2.MonitoringAndLogsApi.GetHostLogsWithParams(s.ctx, params).Execute() + if err != nil { + return nil, err } -} - -// DownloadLogJob encapsulate the logic to manage different cloud providers. -func (s *Store) DownloadLogJob(groupID, jobID string, out io.Writer) error { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - _, err := s.client.(*opsmngr.Client).Logs.Download(s.ctx, groupID, jobID, out) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) + if result == nil { + return nil, fmt.Errorf("returned file is empty") } + return result, nil } diff --git a/internal/store/maintenance.go b/internal/store/maintenance.go index 8884917150..cb2e5b1655 100644 --- a/internal/store/maintenance.go +++ b/internal/store/maintenance.go @@ -15,14 +15,10 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" - "go.mongodb.org/ops-manager/opsmngr" ) -//go:generate mockgen -destination=../mocks/mock_maintenance.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store MaintenanceWindowUpdater,MaintenanceWindowClearer,MaintenanceWindowDeferrer,MaintenanceWindowDescriber,OpsManagerMaintenanceWindowCreator,OpsManagerMaintenanceWindowLister,OpsManagerMaintenanceWindowDeleter,OpsManagerMaintenanceWindowDescriber,OpsManagerMaintenanceWindowUpdater +//go:generate mockgen -destination=../mocks/mock_maintenance.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store MaintenanceWindowUpdater,MaintenanceWindowClearer,MaintenanceWindowDeferrer,MaintenanceWindowDescriber type MaintenanceWindowUpdater interface { UpdateMaintenanceWindow(string, *atlasv2.GroupMaintenanceWindow) error @@ -40,121 +36,26 @@ type MaintenanceWindowDescriber interface { MaintenanceWindow(string) (*atlasv2.GroupMaintenanceWindow, error) } -type OpsManagerMaintenanceWindowCreator interface { - CreateOpsManagerMaintenanceWindow(string, *opsmngr.MaintenanceWindow) (*opsmngr.MaintenanceWindow, error) -} - -type OpsManagerMaintenanceWindowLister interface { - OpsManagerMaintenanceWindows(string) (*opsmngr.MaintenanceWindows, error) -} - -type OpsManagerMaintenanceWindowDeleter interface { - DeleteOpsManagerMaintenanceWindow(string, string) error -} - -type OpsManagerMaintenanceWindowDescriber interface { - OpsManagerMaintenanceWindow(string, string) (*opsmngr.MaintenanceWindow, error) -} - -type OpsManagerMaintenanceWindowUpdater interface { - UpdateOpsManagerMaintenanceWindow(string, *opsmngr.MaintenanceWindow) (*opsmngr.MaintenanceWindow, error) -} - // UpdateMaintenanceWindow encapsulates the logic to manage different cloud providers. func (s *Store) UpdateMaintenanceWindow(projectID string, maintenanceWindow *atlasv2.GroupMaintenanceWindow) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.MaintenanceWindowsApi.UpdateMaintenanceWindow(s.ctx, projectID, maintenanceWindow).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.MaintenanceWindowsApi.UpdateMaintenanceWindow(s.ctx, projectID, maintenanceWindow).Execute() + return err } // ClearMaintenanceWindow encapsulates the logic to manage different cloud providers. func (s *Store) ClearMaintenanceWindow(projectID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.MaintenanceWindowsApi.ResetMaintenanceWindow(s.ctx, projectID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.MaintenanceWindowsApi.ResetMaintenanceWindow(s.ctx, projectID).Execute() + return err } // DeferMaintenanceWindow encapsulates the logic to manage different cloud providers. func (s *Store) DeferMaintenanceWindow(projectID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.MaintenanceWindowsApi.DeferMaintenanceWindow(s.ctx, projectID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.MaintenanceWindowsApi.DeferMaintenanceWindow(s.ctx, projectID).Execute() + return err } // MaintenanceWindow encapsulates the logic to manage different cloud providers. func (s *Store) MaintenanceWindow(projectID string) (*atlasv2.GroupMaintenanceWindow, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - resp, _, err := s.clientv2.MaintenanceWindowsApi.GetMaintenanceWindow(s.ctx, projectID).Execute() - return resp, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// CreateOpsManagerMaintenanceWindow encapsulates the logic to manage different cloud providers. -func (s *Store) CreateOpsManagerMaintenanceWindow(projectID string, maintenanceWindow *opsmngr.MaintenanceWindow) (*opsmngr.MaintenanceWindow, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - log, _, err := s.client.(*opsmngr.Client).MaintenanceWindows.Create(s.ctx, projectID, maintenanceWindow) - return log, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// OpsManagerMaintenanceWindows encapsulates the logic to manage different cloud providers. -func (s *Store) OpsManagerMaintenanceWindows(projectID string) (*opsmngr.MaintenanceWindows, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - log, _, err := s.client.(*opsmngr.Client).MaintenanceWindows.List(s.ctx, projectID) - return log, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// DeleteOpsManagerMaintenanceWindow encapsulates the logic to manage different cloud providers. -func (s *Store) DeleteOpsManagerMaintenanceWindow(projectID, maintenanceWindowID string) error { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - _, err := s.client.(*opsmngr.Client).MaintenanceWindows.Delete(s.ctx, projectID, maintenanceWindowID) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// OpsManagerMaintenanceWindow encapsulates the logic to manage different cloud providers. -func (s *Store) OpsManagerMaintenanceWindow(projectID, maintenanceWindowID string) (*opsmngr.MaintenanceWindow, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - log, _, err := s.client.(*opsmngr.Client).MaintenanceWindows.Get(s.ctx, projectID, maintenanceWindowID) - return log, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// UpdateOpsManagerMaintenanceWindow encapsulates the logic to manage different cloud providers. -func (s *Store) UpdateOpsManagerMaintenanceWindow(projectID string, maintenanceWindow *opsmngr.MaintenanceWindow) (*opsmngr.MaintenanceWindow, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - log, _, err := s.client.(*opsmngr.Client).MaintenanceWindows.Update(s.ctx, projectID, maintenanceWindow.ID, maintenanceWindow) - return log, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + resp, _, err := s.clientv2.MaintenanceWindowsApi.GetMaintenanceWindow(s.ctx, projectID).Execute() + return resp, err } diff --git a/internal/store/online_archives.go b/internal/store/online_archives.go index 387272c6e3..b447821df0 100644 --- a/internal/store/online_archives.go +++ b/internal/store/online_archives.go @@ -46,56 +46,46 @@ type OnlineArchiveDeleter interface { // OnlineArchives encapsulate the logic to manage different cloud providers. func (s *Store) OnlineArchives(projectID, clusterName string, lstOpt *atlas.ListOptions) (*atlasv2.PaginatedOnlineArchive, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.OnlineArchiveApi.ListOnlineArchives(s.ctx, projectID, clusterName). - PageNum(lstOpt.PageNum).ItemsPerPage(lstOpt.ItemsPerPage).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.OnlineArchiveApi.ListOnlineArchives(s.ctx, projectID, clusterName). + PageNum(lstOpt.PageNum).ItemsPerPage(lstOpt.ItemsPerPage).Execute() + return result, err } // OnlineArchive encapsulate the logic to manage different cloud providers. func (s *Store) OnlineArchive(projectID, clusterName, archiveID string) (*atlasv2.BackupOnlineArchive, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.OnlineArchiveApi.GetOnlineArchive(s.ctx, projectID, archiveID, clusterName).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.OnlineArchiveApi.GetOnlineArchive(s.ctx, projectID, archiveID, clusterName).Execute() + return result, err } // CreateOnlineArchive encapsulate the logic to manage different cloud providers. func (s *Store) CreateOnlineArchive(projectID, clusterName string, archive *atlasv2.BackupOnlineArchiveCreate) (*atlasv2.BackupOnlineArchive, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.OnlineArchiveApi.CreateOnlineArchive(s.ctx, projectID, clusterName, archive).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.OnlineArchiveApi.CreateOnlineArchive(s.ctx, projectID, clusterName, archive).Execute() + return result, err } // UpdateOnlineArchive encapsulate the logic to manage different cloud providers. func (s *Store) UpdateOnlineArchive(projectID, clusterName string, archive *atlasv2.BackupOnlineArchive) (*atlasv2.BackupOnlineArchive, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.OnlineArchiveApi.UpdateOnlineArchive(s.ctx, projectID, archive.GetId(), clusterName, archive).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.OnlineArchiveApi.UpdateOnlineArchive(s.ctx, projectID, archive.GetId(), clusterName, archive).Execute() + return result, err } // DeleteOnlineArchive encapsulate the logic to manage different cloud providers. func (s *Store) DeleteOnlineArchive(projectID, clusterName, archiveID string) error { - switch s.service { - case config.CloudService: - _, _, err := s.clientv2.OnlineArchiveApi.DeleteOnlineArchive(s.ctx, projectID, archiveID, clusterName).Execute() - return err - default: + if s.service == config.CloudGovService { return fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + _, _, err := s.clientv2.OnlineArchiveApi.DeleteOnlineArchive(s.ctx, projectID, archiveID, clusterName).Execute() + return err } diff --git a/internal/store/organizations.go b/internal/store/organizations.go index dcabca1335..8f83b62f95 100644 --- a/internal/store/organizations.go +++ b/internal/store/organizations.go @@ -18,22 +18,18 @@ import ( "fmt" "github.com/mongodb/mongodb-atlas-cli/internal/config" + "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_organizations.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store OrganizationLister,OrganizationCreator,OrganizationDeleter,OrganizationDescriber,AtlasOrganizationCreator +//go:generate mockgen -destination=../mocks/mock_organizations.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store OrganizationLister,OrganizationDeleter,OrganizationDescriber,AtlasOrganizationCreator type OrganizationLister interface { - Organizations(*atlas.OrganizationsListOptions) (interface{}, error) + Organizations(*atlas.OrganizationsListOptions) (*admin.PaginatedOrganization, error) } type OrganizationDescriber interface { - Organization(string) (interface{}, error) -} - -type OrganizationCreator interface { - CreateOrganization(string) (*atlas.Organization, error) + Organization(string) (*admin.AtlasOrganization, error) } type AtlasOrganizationCreator interface { @@ -45,70 +41,32 @@ type OrganizationDeleter interface { } // Organizations encapsulate the logic to manage different cloud providers. -func (s *Store) Organizations(opts *atlas.OrganizationsListOptions) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.OrganizationsApi.ListOrganizations(s.ctx) - if opts != nil { - res = res.Name(opts.Name).PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Organizations.List(s.ctx, opts) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) +func (s *Store) Organizations(opts *atlas.OrganizationsListOptions) (*admin.PaginatedOrganization, error) { + res := s.clientv2.OrganizationsApi.ListOrganizations(s.ctx) + if opts != nil { + res = res.Name(opts.Name).PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) } + result, _, err := res.Execute() + return result, err } // Organization encapsulate the logic to manage different cloud providers. -func (s *Store) Organization(id string) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.OrganizationsApi.GetOrganization(s.ctx, id).Execute() - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Organizations.Get(s.ctx, id) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// CreateOrganization encapsulate the logic to manage different cloud providers. -func (s *Store) CreateOrganization(name string) (*atlas.Organization, error) { - switch s.service { - case config.CloudManagerService, config.OpsManagerService: - org := &atlas.Organization{Name: name} - result, _, err := s.client.(*opsmngr.Client).Organizations.Create(s.ctx, org) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) Organization(id string) (*admin.AtlasOrganization, error) { + result, _, err := s.clientv2.OrganizationsApi.GetOrganization(s.ctx, id).Execute() + return result, err } // CreateAtlasOrganization encapsulate the logic to manage different cloud providers. func (s *Store) CreateAtlasOrganization(o *atlas.CreateOrganizationRequest) (*atlas.CreateOrganizationResponse, error) { - switch s.service { - case config.CloudService: - result, _, err := s.client.(*atlas.Client).Organizations.Create(s.ctx, o) - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.client.Organizations.Create(s.ctx, o) + return result, err } // DeleteOrganization encapsulate the logic to manage different cloud providers. func (s *Store) DeleteOrganization(id string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.client.(*atlas.Client).Organizations.Delete(s.ctx, id) - return err - case config.CloudManagerService, config.OpsManagerService: - _, err := s.client.(*opsmngr.Client).Organizations.Delete(s.ctx, id) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.client.Organizations.Delete(s.ctx, id) + return err } diff --git a/internal/store/peering_connections.go b/internal/store/peering_connections.go index 6ac29cee48..babda34ca3 100644 --- a/internal/store/peering_connections.go +++ b/internal/store/peering_connections.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -67,176 +64,110 @@ type ContainersDeleter interface { // PeeringConnections encapsulates the logic to manage different cloud providers. func (s *Store) PeeringConnections(projectID string, opts *atlas.ContainersListOptions) ([]atlasv2.BaseNetworkPeeringConnectionSettings, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringConnections(s.ctx, projectID). - ItemsPerPage(opts.ItemsPerPage). - PageNum(opts.PageNum). - ProviderName(opts.ProviderName).Execute() - if err != nil { - return nil, err - } - return result.GetResults(), nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringConnections(s.ctx, projectID). + ItemsPerPage(opts.ItemsPerPage). + PageNum(opts.PageNum). + ProviderName(opts.ProviderName).Execute() + if err != nil { + return nil, err } + return result.GetResults(), nil } // PeeringConnections encapsulates the logic to manage different cloud providers. func (s *Store) PeeringConnection(projectID, peerID string) (*atlasv2.BaseNetworkPeeringConnectionSettings, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.GetPeeringConnection(s.ctx, projectID, peerID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.NetworkPeeringApi.GetPeeringConnection(s.ctx, projectID, peerID).Execute() + return result, err } // DeletePrivateEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) DeletePeeringConnection(projectID, peerID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.NetworkPeeringApi.DeletePeeringConnection(s.ctx, projectID, peerID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.NetworkPeeringApi.DeletePeeringConnection(s.ctx, projectID, peerID).Execute() + return err } // CreatePeeringConnection encapsulates the logic to manage different cloud providers. func (s *Store) CreatePeeringConnection(projectID string, peer *atlasv2.BaseNetworkPeeringConnectionSettings) (*atlasv2.BaseNetworkPeeringConnectionSettings, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.CreatePeeringConnection(s.ctx, projectID, peer).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.NetworkPeeringApi.CreatePeeringConnection(s.ctx, projectID, peer).Execute() + return result, err } // ContainersByProvider encapsulates the logic to manage different cloud providers. func (s *Store) ContainersByProvider(projectID string, opts *atlas.ContainersListOptions) ([]atlasv2.CloudProviderContainer, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage).ProviderName(opts.ProviderName) - } - result, _, err := res.Execute() - if err != nil { - return nil, err - } - return result.GetResults(), nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage).ProviderName(opts.ProviderName) + } + result, _, err := res.Execute() + if err != nil { + return nil, err } + return result.GetResults(), nil } const maxPerPage = 100 // AzureContainers encapsulates the logic to manage different cloud providers. func (s *Store) AzureContainers(projectID string) ([]atlasv2.CloudProviderContainer, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID). - PageNum(0). - ItemsPerPage(maxPerPage). - ProviderName("Azure"). - Execute() - if err != nil { - return nil, err - } - return result.GetResults(), nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID). + PageNum(0). + ItemsPerPage(maxPerPage). + ProviderName("Azure"). + Execute() + if err != nil { + return nil, err } + return result.GetResults(), nil } // AWSContainers encapsulates the logic to manage different cloud providers. func (s *Store) AWSContainers(projectID string) ([]atlasv2.CloudProviderContainer, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID). - PageNum(0). - ItemsPerPage(maxPerPage). - ProviderName("AWS"). - Execute() - - if err != nil { - return nil, err - } - return result.GetResults(), nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID). + PageNum(0). + ItemsPerPage(maxPerPage). + ProviderName("AWS"). + Execute() + + if err != nil { + return nil, err } + return result.GetResults(), nil } // GCPContainers encapsulates the logic to manage different cloud providers. func (s *Store) GCPContainers(projectID string) ([]atlasv2.CloudProviderContainer, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID). - PageNum(0). - ItemsPerPage(maxPerPage). - ProviderName("GCP"). - Execute() - if err != nil { - return nil, err - } - return result.GetResults(), nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + result, _, err := s.clientv2.NetworkPeeringApi.ListPeeringContainerByCloudProvider(s.ctx, projectID). + PageNum(0). + ItemsPerPage(maxPerPage). + ProviderName("GCP"). + Execute() + if err != nil { + return nil, err } + return result.GetResults(), nil } // AllContainers encapsulates the logic to manage different cloud providers. func (s *Store) AllContainers(projectID string, opts *atlas.ListOptions) ([]atlasv2.CloudProviderContainer, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - res := s.clientv2.NetworkPeeringApi.ListPeeringContainers(s.ctx, projectID) - if opts != nil { - res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) - } - result, _, err := res.Execute() - if err != nil { - return nil, err - } - return result.GetResults(), nil - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + res := s.clientv2.NetworkPeeringApi.ListPeeringContainers(s.ctx, projectID) + if opts != nil { + res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage) + } + result, _, err := res.Execute() + if err != nil { + return nil, err } + return result.GetResults(), nil } // DeleteContainer encapsulates the logic to manage different cloud providers. func (s *Store) DeleteContainer(projectID, containerID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.NetworkPeeringApi.DeletePeeringContainer(s.ctx, projectID, containerID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -// Container encapsulates the logic to manage different cloud providers. -func (s *Store) Container(projectID, containerID string) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.GetPeeringContainer(s.ctx, projectID, containerID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.NetworkPeeringApi.DeletePeeringContainer(s.ctx, projectID, containerID).Execute() + return err } // CreateContainer encapsulates the logic to manage different cloud providers. func (s *Store) CreateContainer(projectID string, container *atlasv2.CloudProviderContainer) (*atlasv2.CloudProviderContainer, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.NetworkPeeringApi.CreatePeeringContainer(s.ctx, projectID, container).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.NetworkPeeringApi.CreatePeeringContainer(s.ctx, projectID, container).Execute() + return result, err } diff --git a/internal/store/private_endpoints.go b/internal/store/private_endpoints.go index afba6ca0b6..7c323ef461 100644 --- a/internal/store/private_endpoints.go +++ b/internal/store/private_endpoints.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -40,7 +37,7 @@ type DataLakePrivateEndpointDescriber interface { } type PrivateEndpointCreator interface { - CreatePrivateEndpoint(string, *atlasv2.CloudProviderEndpointServiceRequest) (interface{}, error) + CreatePrivateEndpoint(string, *atlasv2.CloudProviderEndpointServiceRequest) (*atlasv2.EndpointService, error) } type DataLakePrivateEndpointCreator interface { @@ -77,150 +74,85 @@ type RegionalizedPrivateEndpointSettingDescriber interface { // PrivateEndpoints encapsulates the logic to manage different cloud providers. func (s *Store) PrivateEndpoints(projectID, provider string) ([]atlasv2.EndpointService, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.PrivateEndpointServicesApi.ListPrivateEndpointServices(s.ctx, projectID, provider).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.PrivateEndpointServicesApi.ListPrivateEndpointServices(s.ctx, projectID, provider).Execute() + return result, err } // DataLakePrivateEndpoints encapsulates the logic to manage different cloud providers. func (s *Store) DataLakePrivateEndpoints(params *atlasv2.ListDataFederationPrivateEndpointsApiParams) (*atlasv2.PaginatedPrivateNetworkEndpointIdEntry, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.DataFederationApi.ListDataFederationPrivateEndpointsWithParams(s.ctx, params).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.DataFederationApi.ListDataFederationPrivateEndpointsWithParams(s.ctx, params).Execute() + return result, err } // PrivateEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) PrivateEndpoint(projectID, provider, privateLinkID string) (*atlasv2.EndpointService, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.PrivateEndpointServicesApi.GetPrivateEndpointService(s.ctx, projectID, provider, privateLinkID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.PrivateEndpointServicesApi.GetPrivateEndpointService(s.ctx, projectID, provider, privateLinkID).Execute() + return result, err } // DataLakePrivateEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) DataLakePrivateEndpoint(projectID, privateLinkID string) (*atlasv2.PrivateNetworkEndpointIdEntry, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.DataFederationApi.GetDataFederationPrivateEndpoint(s.ctx, projectID, privateLinkID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.DataFederationApi.GetDataFederationPrivateEndpoint(s.ctx, projectID, privateLinkID).Execute() + return result, err } // CreatePrivateEndpoint encapsulates the logic to manage different cloud providers. -func (s *Store) CreatePrivateEndpoint(projectID string, r *atlasv2.CloudProviderEndpointServiceRequest) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.PrivateEndpointServicesApi.CreatePrivateEndpointService(s.ctx, projectID, r). - Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) CreatePrivateEndpoint(projectID string, r *atlasv2.CloudProviderEndpointServiceRequest) (*atlasv2.EndpointService, error) { + result, _, err := s.clientv2.PrivateEndpointServicesApi.CreatePrivateEndpointService(s.ctx, projectID, r). + Execute() + return result, err } // DataLakeCreatePrivateEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) DataLakeCreatePrivateEndpoint(projectID string, r *atlasv2.PrivateNetworkEndpointIdEntry) (*atlasv2.PaginatedPrivateNetworkEndpointIdEntry, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.DataFederationApi.CreateDataFederationPrivateEndpoint(s.ctx, projectID, r). - Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.DataFederationApi.CreateDataFederationPrivateEndpoint(s.ctx, projectID, r). + Execute() + return result, err } // DeletePrivateEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) DeletePrivateEndpoint(projectID, provider, privateLinkID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.PrivateEndpointServicesApi.DeletePrivateEndpointService(s.ctx, projectID, provider, privateLinkID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.PrivateEndpointServicesApi.DeletePrivateEndpointService(s.ctx, projectID, provider, privateLinkID).Execute() + return err } // DataLakeDeletePrivateEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) DataLakeDeletePrivateEndpoint(projectID, endpointID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.DataFederationApi.DeleteDataFederationPrivateEndpoint(s.ctx, projectID, endpointID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.DataFederationApi.DeleteDataFederationPrivateEndpoint(s.ctx, projectID, endpointID).Execute() + return err } // CreateInterfaceEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) CreateInterfaceEndpoint(projectID, provider, endpointServiceID string, createRequest *atlasv2.CreateEndpointRequest) (*atlasv2.PrivateLinkEndpoint, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.PrivateEndpointServicesApi.CreatePrivateEndpoint(s.ctx, projectID, provider, - endpointServiceID, createRequest).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.PrivateEndpointServicesApi.CreatePrivateEndpoint(s.ctx, projectID, provider, + endpointServiceID, createRequest).Execute() + return result, err } // InterfaceEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) InterfaceEndpoint(projectID, cloudProvider, endpointServiceID, privateEndpointID string) (*atlasv2.PrivateLinkEndpoint, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.PrivateEndpointServicesApi.GetPrivateEndpoint(s.ctx, projectID, cloudProvider, endpointServiceID, privateEndpointID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.PrivateEndpointServicesApi.GetPrivateEndpoint(s.ctx, projectID, cloudProvider, endpointServiceID, privateEndpointID).Execute() + return result, err } // DeleteInterfaceEndpoint encapsulates the logic to manage different cloud providers. func (s *Store) DeleteInterfaceEndpoint(projectID, provider, endpointServiceID, privateEndpointID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.PrivateEndpointServicesApi.DeletePrivateEndpoint(s.ctx, projectID, provider, privateEndpointID, endpointServiceID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.PrivateEndpointServicesApi.DeletePrivateEndpoint(s.ctx, projectID, provider, privateEndpointID, endpointServiceID).Execute() + return err } // UpdateRegionalizedPrivateEndpointSetting encapsulates the logic to manage different cloud providers. func (s *Store) UpdateRegionalizedPrivateEndpointSetting(projectID string, enabled bool) (*atlasv2.ProjectSettingItem, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - setting := atlasv2.ProjectSettingItem{ - Enabled: enabled, - } - result, _, err := s.clientv2.PrivateEndpointServicesApi. - ToggleRegionalizedPrivateEndpointSetting(s.ctx, projectID, &setting).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + setting := atlasv2.ProjectSettingItem{ + Enabled: enabled, } + result, _, err := s.clientv2.PrivateEndpointServicesApi. + ToggleRegionalizedPrivateEndpointSetting(s.ctx, projectID, &setting).Execute() + return result, err } // RegionalizedPrivateEndpointSetting encapsulates the logic to manage different cloud providers. func (s *Store) RegionalizedPrivateEndpointSetting(projectID string) (*atlasv2.ProjectSettingItem, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.PrivateEndpointServicesApi.GetRegionalizedPrivateEndpointSetting(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.PrivateEndpointServicesApi.GetRegionalizedPrivateEndpointSetting(s.ctx, projectID).Execute() + return result, err } diff --git a/internal/store/process_databases.go b/internal/store/process_databases.go index 47bf9b4e60..e15a4d967b 100644 --- a/internal/store/process_databases.go +++ b/internal/store/process_databases.go @@ -15,10 +15,8 @@ package store import ( - "fmt" "strconv" - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -31,13 +29,8 @@ type ProcessDatabaseLister interface { // ProcessDatabases encapsulate the logic to manage different cloud providers. func (s *Store) ProcessDatabases(groupID, host string, port int, opts *atlas.ListOptions) (*atlasv2.PaginatedDatabase, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - process := host + ":" + strconv.Itoa(port) - result, _, err := s.clientv2.MonitoringAndLogsApi.ListDatabases(s.ctx, groupID, process). - PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + process := host + ":" + strconv.Itoa(port) + result, _, err := s.clientv2.MonitoringAndLogsApi.ListDatabases(s.ctx, groupID, process). + PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage).Execute() + return result, err } diff --git a/internal/store/process_disk_measurements.go b/internal/store/process_disk_measurements.go index dfe5aa5d86..c5adbf8c07 100644 --- a/internal/store/process_disk_measurements.go +++ b/internal/store/process_disk_measurements.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -33,22 +30,12 @@ type ProcessDatabaseMeasurementsLister interface { // ProcessDiskMeasurements encapsulate the logic to manage different cloud providers. func (s *Store) ProcessDiskMeasurements(params *atlasv2.GetDiskMeasurementsApiParams) (*atlasv2.ApiMeasurementsGeneralViewAtlas, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.MonitoringAndLogsApi.GetDiskMeasurementsWithParams(s.ctx, params).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.MonitoringAndLogsApi.GetDiskMeasurementsWithParams(s.ctx, params).Execute() + return result, err } // ProcessDatabaseMeasurements encapsulate the logic to manage different cloud providers. func (s *Store) ProcessDatabaseMeasurements(args *atlasv2.GetDatabaseMeasurementsApiParams) (*atlasv2.ApiMeasurementsGeneralViewAtlas, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.MonitoringAndLogsApi.GetDatabaseMeasurementsWithParams(s.ctx, args).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.MonitoringAndLogsApi.GetDatabaseMeasurementsWithParams(s.ctx, args).Execute() + return result, err } diff --git a/internal/store/process_disks.go b/internal/store/process_disks.go index 7dd5292495..63798e5233 100644 --- a/internal/store/process_disks.go +++ b/internal/store/process_disks.go @@ -15,10 +15,8 @@ package store import ( - "fmt" "strconv" - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -31,13 +29,8 @@ type ProcessDisksLister interface { // ProcessDisks encapsulates the logic to manage different cloud providers. func (s *Store) ProcessDisks(groupID, host string, port int, opts *atlas.ListOptions) (*atlasv2.PaginatedDiskPartition, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - processID := host + ":" + strconv.Itoa(port) - result, _, err := s.clientv2.MonitoringAndLogsApi.ListDiskPartitions(s.ctx, groupID, processID). - ItemsPerPage(opts.ItemsPerPage).PageNum(opts.PageNum).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + processID := host + ":" + strconv.Itoa(port) + result, _, err := s.clientv2.MonitoringAndLogsApi.ListDiskPartitions(s.ctx, groupID, processID). + ItemsPerPage(opts.ItemsPerPage).PageNum(opts.PageNum).Execute() + return result, err } diff --git a/internal/store/process_measurements.go b/internal/store/process_measurements.go index a6d292e4be..811259ac8c 100644 --- a/internal/store/process_measurements.go +++ b/internal/store/process_measurements.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -29,11 +26,6 @@ type ProcessMeasurementLister interface { // ProcessMeasurements encapsulate the logic to manage different cloud providers. func (s *Store) ProcessMeasurements(params *atlasv2.GetHostMeasurementsApiParams) (*atlasv2.ApiMeasurementsGeneralViewAtlas, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.MonitoringAndLogsApi.GetHostMeasurementsWithParams(s.ctx, params).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.MonitoringAndLogsApi.GetHostMeasurementsWithParams(s.ctx, params).Execute() + return result, err } diff --git a/internal/store/processes.go b/internal/store/processes.go index d395738b95..70c4289711 100644 --- a/internal/store/processes.go +++ b/internal/store/processes.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -33,22 +30,12 @@ type ProcessDescriber interface { // Process encapsulate the logic to manage different cloud providers. func (s *Store) Process(params *atlasv2.GetAtlasProcessApiParams) (*atlasv2.ApiHostViewAtlas, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.MonitoringAndLogsApi.GetAtlasProcessWithParams(s.ctx, params).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.MonitoringAndLogsApi.GetAtlasProcessWithParams(s.ctx, params).Execute() + return result, err } // Processes encapsulate the logic to manage different cloud providers. func (s *Store) Processes(params *atlasv2.ListAtlasProcessesApiParams) (*atlasv2.PaginatedHostViewAtlas, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.MonitoringAndLogsApi.ListAtlasProcessesWithParams(s.ctx, params).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.MonitoringAndLogsApi.ListAtlasProcessesWithParams(s.ctx, params).Execute() + return result, err } diff --git a/internal/store/project_ip_access_lists.go b/internal/store/project_ip_access_lists.go index 82d9dcb53b..215aee5fcc 100644 --- a/internal/store/project_ip_access_lists.go +++ b/internal/store/project_ip_access_lists.go @@ -16,9 +16,7 @@ package store import ( "errors" - "fmt" - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -45,58 +43,39 @@ func (s *Store) CreateProjectIPAccessList(entries []*atlasv2.NetworkPermissionEn if len(entries) == 0 { return nil, errors.New("no entries") } - switch s.service { - case config.CloudService, config.CloudGovService: - entry := make([]atlasv2.NetworkPermissionEntry, len(entries)) - for i, ptr := range entries { - entry[i] = *ptr - } - result, _, err := s.clientv2.ProjectIPAccessListApi.CreateProjectIpAccessList(s.ctx, entries[0].GetGroupId(), &entry).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + entry := make([]atlasv2.NetworkPermissionEntry, len(entries)) + for i, ptr := range entries { + entry[i] = *ptr } + + result, _, err := s.clientv2.ProjectIPAccessListApi.CreateProjectIpAccessList(s.ctx, entries[0].GetGroupId(), &entry).Execute() + return result, err } // DeleteProjectIPAccessList encapsulate the logic to manage different cloud providers. func (s *Store) DeleteProjectIPAccessList(projectID, entry string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.ProjectIPAccessListApi.DeleteProjectIpAccessList(s.ctx, projectID, entry).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.ProjectIPAccessListApi.DeleteProjectIpAccessList(s.ctx, projectID, entry).Execute() + return err } // ProjectIPAccessLists encapsulate the logic to manage different cloud providers. func (s *Store) ProjectIPAccessLists(projectID string, opts *atlas.ListOptions) (*atlasv2.PaginatedNetworkAccess, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - params := &atlasv2.ListProjectIpAccessListsApiParams{ - GroupId: projectID, - } - if opts != nil { - params.PageNum = &opts.PageNum - params.ItemsPerPage = &opts.ItemsPerPage - } - result, _, err := s.clientv2.ProjectIPAccessListApi. - ListProjectIpAccessListsWithParams(s.ctx, params). - Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + params := &atlasv2.ListProjectIpAccessListsApiParams{ + GroupId: projectID, } + if opts != nil { + params.PageNum = &opts.PageNum + params.ItemsPerPage = &opts.ItemsPerPage + } + result, _, err := s.clientv2.ProjectIPAccessListApi. + ListProjectIpAccessListsWithParams(s.ctx, params). + Execute() + return result, err } // IPAccessList encapsulate the logic to manage different cloud providers. func (s *Store) IPAccessList(projectID, name string) (*atlasv2.NetworkPermissionEntry, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ProjectIPAccessListApi.GetProjectIpList(s.ctx, projectID, name).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ProjectIPAccessListApi.GetProjectIpList(s.ctx, projectID, name).Execute() + return result, err } diff --git a/internal/store/project_settings.go b/internal/store/project_settings.go index b5d89e68a1..e8dbd82147 100644 --- a/internal/store/project_settings.go +++ b/internal/store/project_settings.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -34,29 +31,19 @@ type ProjectSettingsUpdater interface { // ProjectSettings encapsulates the logic of getting settings of a particular project. func (s *Store) ProjectSettings(projectID string) (*atlasv2.GroupSettings, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ProjectsApi.GetProjectSettings(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ProjectsApi.GetProjectSettings(s.ctx, projectID).Execute() + return result, err } // UpdateProjectSettings encapsulates the logic of updating settings of a particular project. func (s *Store) UpdateProjectSettings(projectID string, projectSettings *atlas.ProjectSettings) (*atlasv2.GroupSettings, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - groupSettings := atlasv2.GroupSettings{ - IsCollectDatabaseSpecificsStatisticsEnabled: projectSettings.IsCollectDatabaseSpecificsStatisticsEnabled, - IsDataExplorerEnabled: projectSettings.IsDataExplorerEnabled, - IsPerformanceAdvisorEnabled: projectSettings.IsPerformanceAdvisorEnabled, - IsRealtimePerformancePanelEnabled: projectSettings.IsRealtimePerformancePanelEnabled, - IsSchemaAdvisorEnabled: projectSettings.IsSchemaAdvisorEnabled, - } - result, _, err := s.clientv2.ProjectsApi.UpdateProjectSettings(s.ctx, projectID, &groupSettings).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + groupSettings := atlasv2.GroupSettings{ + IsCollectDatabaseSpecificsStatisticsEnabled: projectSettings.IsCollectDatabaseSpecificsStatisticsEnabled, + IsDataExplorerEnabled: projectSettings.IsDataExplorerEnabled, + IsPerformanceAdvisorEnabled: projectSettings.IsPerformanceAdvisorEnabled, + IsRealtimePerformancePanelEnabled: projectSettings.IsRealtimePerformancePanelEnabled, + IsSchemaAdvisorEnabled: projectSettings.IsSchemaAdvisorEnabled, } + result, _, err := s.clientv2.ProjectsApi.UpdateProjectSettings(s.ctx, projectID, &groupSettings).Execute() + return result, err } diff --git a/internal/store/projects.go b/internal/store/projects.go index 8cd400487e..cd45c87085 100644 --- a/internal/store/projects.go +++ b/internal/store/projects.go @@ -15,27 +15,18 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlas "go.mongodb.org/atlas/mongodbatlas" - "go.mongodb.org/ops-manager/opsmngr" ) -//go:generate mockgen -destination=../mocks/mock_projects.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store ProjectLister,OrgProjectLister,ProjectCreator,ProjectDeleter,ProjectDescriber,ProjectUsersLister,ProjectUserDeleter,ProjectTeamLister,ProjectTeamAdder,ProjectTeamDeleter +//go:generate mockgen -destination=../mocks/mock_projects.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store ProjectLister,ProjectCreator,ProjectDeleter,ProjectDescriber,ProjectUsersLister,ProjectUserDeleter,ProjectTeamLister,ProjectTeamAdder,ProjectTeamDeleter type ProjectLister interface { - Projects(*atlas.ListOptions) (interface{}, error) - GetOrgProjects(string, *atlas.ProjectsListOptions) (interface{}, error) -} - -type OrgProjectLister interface { - GetOrgProjects(string) (interface{}, error) + Projects(*atlas.ListOptions) (*atlas.Projects, error) + GetOrgProjects(string, *atlas.ProjectsListOptions) (*atlas.Projects, error) } type ProjectCreator interface { - CreateProject(string, string, string, *bool, *atlas.CreateProjectOptions) (interface{}, error) - ServiceVersionDescriber + CreateProject(string, string, string, *bool, *atlas.CreateProjectOptions) (*atlas.Project, error) } type ProjectDeleter interface { @@ -43,12 +34,12 @@ type ProjectDeleter interface { } type ProjectDescriber interface { - Project(string) (interface{}, error) - ProjectByName(string) (interface{}, error) + Project(string) (*atlas.Project, error) + ProjectByName(string) (*atlas.Project, error) } type ProjectUsersLister interface { - ProjectUsers(string, *atlas.ListOptions) (interface{}, error) + ProjectUsers(string, *atlas.ListOptions) ([]atlas.AtlasUser, error) } type ProjectUserDeleter interface { @@ -56,7 +47,7 @@ type ProjectUserDeleter interface { } type ProjectTeamLister interface { - ProjectTeams(string) (interface{}, error) + ProjectTeams(string) (*atlas.TeamsAssigned, error) } type ProjectTeamAdder interface { @@ -68,156 +59,67 @@ type ProjectTeamDeleter interface { } // Projects encapsulates the logic to manage different cloud providers. -func (s *Store) Projects(opts *atlas.ListOptions) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Projects.GetAllProjects(s.ctx, opts) - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Projects.List(s.ctx, opts) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) Projects(opts *atlas.ListOptions) (*atlas.Projects, error) { + result, _, err := s.client.Projects.GetAllProjects(s.ctx, opts) + return result, err } // GetOrgProjects encapsulates the logic to manage different cloud providers. -func (s *Store) GetOrgProjects(orgID string, opts *atlas.ProjectsListOptions) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Organizations.Projects(s.ctx, orgID, opts) - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Organizations.Projects(s.ctx, orgID, opts) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) GetOrgProjects(orgID string, opts *atlas.ProjectsListOptions) (*atlas.Projects, error) { + result, _, err := s.client.Organizations.Projects(s.ctx, orgID, opts) + return result, err } // Project encapsulates the logic to manage different cloud providers. -func (s *Store) Project(id string) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Projects.GetOneProject(s.ctx, id) - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Projects.Get(s.ctx, id) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} - -func (s *Store) ProjectByName(name string) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Projects.GetOneProjectByName(s.ctx, name) - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Projects.GetByName(s.ctx, name) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) Project(id string) (*atlas.Project, error) { + result, _, err := s.client.Projects.GetOneProject(s.ctx, id) + return result, err +} + +func (s *Store) ProjectByName(name string) (*atlas.Project, error) { + result, _, err := s.client.Projects.GetOneProjectByName(s.ctx, name) + return result, err } // CreateProject encapsulates the logic to manage different cloud providers. -func (s *Store) CreateProject(name, orgID, regionUsageRestrictions string, defaultAlertSettings *bool, opts *atlas.CreateProjectOptions) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - project := &atlas.Project{Name: name, OrgID: orgID, RegionUsageRestrictions: regionUsageRestrictions, WithDefaultAlertsSettings: defaultAlertSettings} - result, _, err := s.client.(*atlas.Client).Projects.Create(s.ctx, project, opts) - return result, err - case config.CloudManagerService, config.OpsManagerService: - project := &opsmngr.Project{Name: name, OrgID: orgID, WithDefaultAlertsSettings: defaultAlertSettings} - result, _, err := s.client.(*opsmngr.Client).Projects.Create(s.ctx, project, opts) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) CreateProject(name, orgID, regionUsageRestrictions string, defaultAlertSettings *bool, opts *atlas.CreateProjectOptions) (*atlas.Project, error) { + project := &atlas.Project{Name: name, OrgID: orgID, RegionUsageRestrictions: regionUsageRestrictions, WithDefaultAlertsSettings: defaultAlertSettings} + result, _, err := s.client.Projects.Create(s.ctx, project, opts) + return result, err } // DeleteProject encapsulates the logic to manage different cloud providers. func (s *Store) DeleteProject(projectID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.client.(*atlas.Client).Projects.Delete(s.ctx, projectID) - return err - case config.CloudManagerService, config.OpsManagerService: - _, err := s.client.(*opsmngr.Client).Projects.Delete(s.ctx, projectID) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.client.Projects.Delete(s.ctx, projectID) + return err } // ProjectUsers lists all IAM users in a project. -func (s *Store) ProjectUsers(projectID string, opts *atlas.ListOptions) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).AtlasUsers.List(s.ctx, projectID, opts) - return result, err - case config.OpsManagerService, config.CloudManagerService: - result, _, err := s.client.(*opsmngr.Client).Projects.ListUsers(s.ctx, projectID, opts) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) ProjectUsers(projectID string, opts *atlas.ListOptions) ([]atlas.AtlasUser, error) { + result, _, err := s.client.AtlasUsers.List(s.ctx, projectID, opts) + return result, err } // DeleteProject encapsulates the logic to manage different cloud providers. func (s *Store) DeleteUserFromProject(projectID, userID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.client.(*atlas.Client).Projects.RemoveUserFromProject(s.ctx, projectID, userID) - return err - case config.CloudManagerService, config.OpsManagerService: - _, err := s.client.(*opsmngr.Client).Projects.RemoveUser(s.ctx, projectID, userID) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.client.Projects.RemoveUserFromProject(s.ctx, projectID, userID) + return err } // ProjectTeams encapsulates the logic to manage different cloud providers. -func (s *Store) ProjectTeams(projectID string) (interface{}, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Projects.GetProjectTeamsAssigned(s.ctx, projectID) - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Projects.GetTeams(s.ctx, projectID, nil) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } +func (s *Store) ProjectTeams(projectID string) (*atlas.TeamsAssigned, error) { + result, _, err := s.client.Projects.GetProjectTeamsAssigned(s.ctx, projectID) + return result, err } // AddTeamsToProject encapsulates the logic to manage different cloud providers. func (s *Store) AddTeamsToProject(projectID string, teams []*atlas.ProjectTeam) (*atlas.TeamsAssigned, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).Projects.AddTeamsToProject(s.ctx, projectID, teams) - return result, err - case config.CloudManagerService, config.OpsManagerService: - result, _, err := s.client.(*opsmngr.Client).Projects.AddTeamsToProject(s.ctx, projectID, teams) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.client.Projects.AddTeamsToProject(s.ctx, projectID, teams) + return result, err } // DeleteTeamFromProject encapsulates the logic to manage different cloud providers. func (s *Store) DeleteTeamFromProject(projectID, teamID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.client.(*atlas.Client).Teams.RemoveTeamFromProject(s.ctx, projectID, teamID) - return err - case config.CloudManagerService, config.OpsManagerService: - _, err := s.client.(*opsmngr.Client).Teams.RemoveTeamFromProject(s.ctx, projectID, teamID) - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.client.Teams.RemoveTeamFromProject(s.ctx, projectID, teamID) + return err } diff --git a/internal/store/search.go b/internal/store/search.go index 12c2a5e68e..61894f9e87 100644 --- a/internal/store/search.go +++ b/internal/store/search.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -45,55 +42,30 @@ type SearchIndexDeleter interface { // SearchIndexes encapsulate the logic to manage different cloud providers. func (s *Store) SearchIndexes(projectID, clusterName, dbName, collName string) ([]atlasv2.ClusterSearchIndex, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AtlasSearchApi.ListAtlasSearchIndexes(s.ctx, projectID, clusterName, collName, dbName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AtlasSearchApi.ListAtlasSearchIndexes(s.ctx, projectID, clusterName, collName, dbName).Execute() + return result, err } // CreateSearchIndexes encapsulate the logic to manage different cloud providers. func (s *Store) CreateSearchIndexes(projectID, clusterName string, index *atlasv2.ClusterSearchIndex) (*atlasv2.ClusterSearchIndex, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AtlasSearchApi.CreateAtlasSearchIndex(s.ctx, projectID, clusterName, index).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AtlasSearchApi.CreateAtlasSearchIndex(s.ctx, projectID, clusterName, index).Execute() + return result, err } // SearchIndex encapsulate the logic to manage different cloud providers. func (s *Store) SearchIndex(projectID, clusterName, indexID string) (*atlasv2.ClusterSearchIndex, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - index, _, err := s.clientv2.AtlasSearchApi.GetAtlasSearchIndex(s.ctx, projectID, clusterName, indexID).Execute() - return index, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + index, _, err := s.clientv2.AtlasSearchApi.GetAtlasSearchIndex(s.ctx, projectID, clusterName, indexID).Execute() + return index, err } // UpdateSearchIndexes encapsulate the logic to manage different cloud providers. func (s *Store) UpdateSearchIndexes(projectID, clusterName, indexID string, index *atlasv2.ClusterSearchIndex) (*atlasv2.ClusterSearchIndex, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AtlasSearchApi.UpdateAtlasSearchIndex(s.ctx, projectID, clusterName, indexID, index).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AtlasSearchApi.UpdateAtlasSearchIndex(s.ctx, projectID, clusterName, indexID, index).Execute() + return result, err } // DeleteSearchIndex encapsulate the logic to manage different cloud providers. func (s *Store) DeleteSearchIndex(projectID, clusterName, indexID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.AtlasSearchApi.DeleteAtlasSearchIndex(s.ctx, projectID, clusterName, indexID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.AtlasSearchApi.DeleteAtlasSearchIndex(s.ctx, projectID, clusterName, indexID).Execute() + return err } diff --git a/internal/store/search_nodes.go b/internal/store/search_nodes.go index 3a3d57527f..eaa2f32bd5 100644 --- a/internal/store/search_nodes.go +++ b/internal/store/search_nodes.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -44,40 +41,20 @@ type SearchNodesDeleter interface { // SearchNodes encapsulate the logic to manage different cloud providers. func (s *Store) SearchNodes(projectID, clusterName string) (*atlasv2.ApiSearchDeploymentResponse, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AtlasSearchApi.GetAtlasSearchDeployment(s.ctx, projectID, clusterName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AtlasSearchApi.GetAtlasSearchDeployment(s.ctx, projectID, clusterName).Execute() + return result, err } func (s *Store) CreateSearchNodes(projectID, clusterName string, spec *atlasv2.ApiSearchDeploymentRequest) (*atlasv2.ApiSearchDeploymentResponse, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AtlasSearchApi.CreateAtlasSearchDeployment(s.ctx, projectID, clusterName, spec).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AtlasSearchApi.CreateAtlasSearchDeployment(s.ctx, projectID, clusterName, spec).Execute() + return result, err } func (s *Store) UpdateSearchNodes(projectID, clusterName string, spec *atlasv2.ApiSearchDeploymentRequest) (*atlasv2.ApiSearchDeploymentResponse, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.AtlasSearchApi.UpdateAtlasSearchDeployment(s.ctx, projectID, clusterName, spec).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.AtlasSearchApi.UpdateAtlasSearchDeployment(s.ctx, projectID, clusterName, spec).Execute() + return result, err } func (s *Store) DeleteSearchNodes(projectID, clusterName string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, err := s.clientv2.AtlasSearchApi.DeleteAtlasSearchDeployment(s.ctx, projectID, clusterName).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, err := s.clientv2.AtlasSearchApi.DeleteAtlasSearchDeployment(s.ctx, projectID, clusterName).Execute() + return err } diff --git a/internal/store/serverless_instances.go b/internal/store/serverless_instances.go index 03d3f9a3de..da3dfafba1 100644 --- a/internal/store/serverless_instances.go +++ b/internal/store/serverless_instances.go @@ -47,73 +47,61 @@ type ServerlessInstanceUpdater interface { // ServerlessInstances encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessInstances(projectID string, listOps *atlas.ListOptions) (*atlasv2.PaginatedServerlessInstanceDescription, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.ServerlessInstancesApi.ListServerlessInstances(s.ctx, projectID). - ItemsPerPage(listOps.ItemsPerPage). - PageNum(listOps.PageNum). - Execute() - - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.ServerlessInstancesApi.ListServerlessInstances(s.ctx, projectID). + ItemsPerPage(listOps.ItemsPerPage). + PageNum(listOps.PageNum). + Execute() + + return result, err } // ServerlessInstance encapsulates the logic to manage different cloud providers. func (s *Store) GetServerlessInstance(projectID, clusterName string) (*atlasv2.ServerlessInstanceDescription, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.ServerlessInstancesApi.GetServerlessInstance(s.ctx, projectID, clusterName).Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.ServerlessInstancesApi.GetServerlessInstance(s.ctx, projectID, clusterName).Execute() + return result, err } // Used by Kubernetes v1 ServerlessInstance encapsulates the logic to manage different cloud providers. func (s *Store) ServerlessInstance(projectID, clusterName string) (*atlas.Cluster, error) { - switch s.service { - case config.CloudService: - result, _, err := s.client.(*atlas.Client).ServerlessInstances.Get(s.ctx, projectID, clusterName) - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.client.ServerlessInstances.Get(s.ctx, projectID, clusterName) + return result, err } // DeleteServerlessInstance encapsulate the logic to manage different cloud providers. func (s *Store) DeleteServerlessInstance(projectID, name string) error { - switch s.service { - case config.CloudService: - _, _, err := s.clientv2.ServerlessInstancesApi.DeleteServerlessInstance(s.ctx, projectID, name).Execute() - return err - default: + if s.service == config.CloudGovService { return fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + _, _, err := s.clientv2.ServerlessInstancesApi.DeleteServerlessInstance(s.ctx, projectID, name).Execute() + return err } // CreateServerlessInstance encapsulate the logic to manage different cloud providers. func (s *Store) CreateServerlessInstance(projectID string, cluster *atlasv2.ServerlessInstanceDescriptionCreate) (*atlasv2.ServerlessInstanceDescription, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.ServerlessInstancesApi.CreateServerlessInstance(s.ctx, projectID, cluster). - Execute() - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.ServerlessInstancesApi.CreateServerlessInstance(s.ctx, projectID, cluster). + Execute() + return result, err } // UpdateServerlessInstance encapsulate the logic to manage different cloud providers. func (s *Store) UpdateServerlessInstance(projectID string, instanceName string, req *atlasv2.ServerlessInstanceDescriptionUpdate) (*atlasv2.ServerlessInstanceDescription, error) { - switch s.service { - case config.CloudService: - result, _, err := s.clientv2.ServerlessInstancesApi.UpdateServerlessInstance(s.ctx, projectID, instanceName, req). - Execute() - - return result, err - default: + if s.service == config.CloudGovService { return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) } + result, _, err := s.clientv2.ServerlessInstancesApi.UpdateServerlessInstance(s.ctx, projectID, instanceName, req). + Execute() + + return result, err } diff --git a/internal/store/serverless_private_endpoints.go b/internal/store/serverless_private_endpoints.go index 9a060e3e87..6a84eddb13 100644 --- a/internal/store/serverless_private_endpoints.go +++ b/internal/store/serverless_private_endpoints.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -28,11 +25,6 @@ type ServerlessPrivateEndpointsLister interface { } func (s *Store) ServerlessPrivateEndpoints(projectID, instanceName string) ([]atlasv2.ServerlessTenantEndpoint, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.ServerlessPrivateEndpointsApi.ListServerlessPrivateEndpoints(s.ctx, projectID, instanceName).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.ServerlessPrivateEndpointsApi.ListServerlessPrivateEndpoints(s.ctx, projectID, instanceName).Execute() + return result, err } diff --git a/internal/store/service_version.go b/internal/store/service_version.go deleted file mode 100644 index 21b129632c..0000000000 --- a/internal/store/service_version.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2020 MongoDB Inc -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package store - -import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlas "go.mongodb.org/atlas/mongodbatlas" - "go.mongodb.org/ops-manager/opsmngr" -) - -//go:generate mockgen -destination=../mocks/mock_service_version.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store ServiceVersionDescriber - -type ServiceVersionDescriber interface { - ServiceVersion() (*opsmngr.ServiceVersion, error) -} - -// ServiceVersion encapsulates the logic to manage different cloud providers. -func (s *Store) ServiceVersion() (*atlas.ServiceVersion, error) { - switch s.service { - case config.OpsManagerService, config.CloudManagerService: - result, _, err := s.client.(*opsmngr.Client).ServiceVersion.Get(s.ctx) - return result, err - case config.CloudService, config.CloudGovService: - result, _, err := s.client.(*atlas.Client).ServiceVersion.Get(s.ctx) - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } -} diff --git a/internal/store/store.go b/internal/store/store.go index c01cf8f1ef..e34cbeb9bf 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -31,7 +31,6 @@ import ( atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" atlasauth "go.mongodb.org/atlas/auth" atlas "go.mongodb.org/atlas/mongodbatlas" - "go.mongodb.org/ops-manager/opsmngr" ) const ( @@ -58,7 +57,7 @@ type Store struct { username string password string accessToken *atlasauth.Token - client interface{} + client *atlas.Client // Latest release of the autogenerated Atlas V2 API Client clientv2 *atlasv2.APIClient ctx context.Context @@ -277,38 +276,6 @@ func (s *Store) createV2Client(client *http.Client) error { return nil } -// setOpsManagerClient sets the internal client to use an Ops Manager client and methods. -func (s *Store) setOpsManagerClient(client *http.Client) error { - opts := []opsmngr.ClientOpt{opsmngr.SetUserAgent(config.UserAgent)} - if s.baseURL != "" { - opts = append(opts, opsmngr.SetBaseURL(s.baseURL)) - } - if log.IsDebugLevel() { - opts = append(opts, opsmngr.SetWithRaw()) - } - c, err := opsmngr.New(client, opts...) - if err != nil { - return err - } - - c.OnResponseProcessed(func(resp *atlas.Response) { - respHeaders := "" - for key, value := range resp.Header { - respHeaders += fmt.Sprintf("%v: %v\n", key, strings.Join(value, " ")) - } - - _, _ = log.Debugf(`request: -%v %v -response: -%v %v -%v -%v -`, resp.Request.Method, resp.Request.URL.String(), resp.Proto, resp.Status, respHeaders, string(resp.Raw)) - }) - s.client = c - return nil -} - // ServiceGetter is a basic interface for service and base url settings. type ServiceGetter interface { Service() string @@ -378,8 +345,6 @@ func New(opts ...Option) (*Store, error) { switch store.service { case config.CloudService, config.CloudGovService: err = store.setAtlasClient(client) - case config.CloudManagerService, config.OpsManagerService: - err = store.setOpsManagerClient(client) default: return nil, fmt.Errorf("%w: %s", errUnsupportedService, store.service) } diff --git a/internal/store/telemetry.go b/internal/store/telemetry.go index 4986167d7d..044da2840d 100644 --- a/internal/store/telemetry.go +++ b/internal/store/telemetry.go @@ -18,7 +18,6 @@ import ( "net/http" "github.com/mongodb/mongodb-atlas-cli/internal/config" - atlas "go.mongodb.org/atlas/mongodbatlas" ) //go:generate mockgen -destination=../mocks/mock_telemetry.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store EventsSender,UnauthEventsSender @@ -34,7 +33,7 @@ type UnauthEventsSender interface { func (s *Store) SendEvents(body interface{}) error { switch s.service { case config.CloudService: - client := s.client.(*atlas.Client) + client := s.client request, err := client.NewRequest(s.ctx, http.MethodPost, "api/private/v1.0/telemetry/events", body) if err != nil { return err @@ -49,7 +48,7 @@ func (s *Store) SendEvents(body interface{}) error { func (s *Store) SendUnauthEvents(body interface{}) error { switch s.service { case config.CloudService: - client := s.client.(*atlas.Client) + client := s.client request, err := client.NewRequest(s.ctx, http.MethodPost, "api/private/unauth/telemetry/events", body) if err != nil { return err diff --git a/internal/store/x509_auth_database_users.go b/internal/store/x509_auth_database_users.go index 87149218ab..a0f797aad7 100644 --- a/internal/store/x509_auth_database_users.go +++ b/internal/store/x509_auth_database_users.go @@ -15,9 +15,6 @@ package store import ( - "fmt" - - "github.com/mongodb/mongodb-atlas-cli/internal/config" atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" ) @@ -43,38 +40,23 @@ type X509CertificateStore interface { // X509Configuration retrieves the current user managed certificates for a database user. func (s *Store) X509Configuration(projectID string) (*atlasv2.UserSecurity, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - result, _, err := s.clientv2.LDAPConfigurationApi.GetLDAPConfiguration(s.ctx, projectID).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + result, _, err := s.clientv2.LDAPConfigurationApi.GetLDAPConfiguration(s.ctx, projectID).Execute() + return result, err } // SaveX509Configuration saves a customer-managed X.509 configuration for an Atlas project. func (s *Store) SaveX509Configuration(projectID, certificate string) (*atlasv2.UserSecurity, error) { - switch s.service { - case config.CloudService, config.CloudGovService: - userCertificate := atlasv2.UserSecurity{ - CustomerX509: &atlasv2.DBUserTLSX509Settings{ - Cas: &certificate, - }, - } - result, _, err := s.clientv2.LDAPConfigurationApi.SaveLDAPConfiguration(s.ctx, projectID, &userCertificate).Execute() - return result, err - default: - return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service) + userCertificate := atlasv2.UserSecurity{ + CustomerX509: &atlasv2.DBUserTLSX509Settings{ + Cas: &certificate, + }, } + result, _, err := s.clientv2.LDAPConfigurationApi.SaveLDAPConfiguration(s.ctx, projectID, &userCertificate).Execute() + return result, err } // DisableX509Configuration disables customer-managed X.509 configuration for an Atlas project. func (s *Store) DisableX509Configuration(projectID string) error { - switch s.service { - case config.CloudService, config.CloudGovService: - _, _, err := s.clientv2.X509AuthenticationApi.DisableCustomerManagedX509(s.ctx, projectID).Execute() - return err - default: - return fmt.Errorf("%w: %s", errUnsupportedService, s.service) - } + _, _, err := s.clientv2.X509AuthenticationApi.DisableCustomerManagedX509(s.ctx, projectID).Execute() + return err } diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 27b661ec71..539319c74a 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -18,9 +18,11 @@ STAGED_GO_FILES=$(git diff --cached --name-only | grep ".go$" | grep -v "mock") for FILE in ${STAGED_GO_FILES} do - gofmt -w -s "${FILE}" - goimports -w "${FILE}" - git add "${FILE}" + if [ -f "${FILE}" ]; then + gofmt -w -s "${FILE}" + goimports -w "${FILE}" + git add "${FILE}" + fi done if [[ -n "${STAGED_GO_FILES}" ]]; then