diff --git a/docs/atlascli/command/atlas-kubernetes-config-generate.txt b/docs/atlascli/command/atlas-kubernetes-config-generate.txt index 13b41407fd..b967e1d166 100644 --- a/docs/atlascli/command/atlas-kubernetes-config-generate.txt +++ b/docs/atlascli/command/atlas-kubernetes-config-generate.txt @@ -41,6 +41,10 @@ Options - strings - false - One or more comma separated cluster names to import + * - --dataFederationName + - strings + - false + - One or more comma separated data federation names to import * - -h, --help - - false @@ -105,7 +109,7 @@ Examples .. code-block:: - # Export Project, DatabaseUsers, and specific Deployment resources for a specific project including connection and integration secrets to a specific namespace: + # Export Project, DatabaseUsers, DataFederations and specific Deployment resources for a specific project including connection and integration secrets to a specific namespace: atlas kubernetes config generate --projectId= --clusterName= --includeSecrets --targetNamespace= @@ -113,3 +117,9 @@ Examples # Export resources for a specific version of the Atlas Kubernetes Operator: atlas kubernetes config generate --projectId= --targetNamespace= --operatorVersion=1.5.1 + + +.. code-block:: + + # Export Project, DatabaseUsers, Clusters and specific DataFederation resources for a specific project to a specific namespace: + atlas kubernetes config generate --projectId= --dataFederationName= --targetNamespace= diff --git a/internal/cli/atlas/kubernetes/config/generate.go b/internal/cli/atlas/kubernetes/config/generate.go index 229251fffa..f6b5a17cae 100644 --- a/internal/cli/atlas/kubernetes/config/generate.go +++ b/internal/cli/atlas/kubernetes/config/generate.go @@ -36,13 +36,14 @@ var ErrUnsupportedOperatorVersionFmt = "version %q is not supported. Supported v type GenerateOpts struct { cli.GlobalOpts cli.OutputOpts - clusterName []string - includeSecrets bool - targetNamespace string - operatorVersion string - store store.AtlasOperatorGenericStore - credsStore store.CredentialsGetter - crdsProvider crds.AtlasOperatorCRDProvider + clusterName []string + dataFederationName []string + includeSecrets bool + targetNamespace string + operatorVersion string + store store.AtlasOperatorGenericStore + credsStore store.CredentialsGetter + crdsProvider crds.AtlasOperatorCRDProvider } func (opts *GenerateOpts) ValidateTargetNamespace() error { @@ -87,6 +88,7 @@ func (opts *GenerateOpts) Run() error { WithSecretsData(opts.includeSecrets). WithTargetOperatorVersion(opts.operatorVersion). WithFeatureValidator(featureValidator). + WithDataFederationNames(opts.dataFederationName). Run() if err != nil { return err @@ -115,11 +117,14 @@ func GenerateBuilder() *cobra.Command { # Export Project, DatabaseUsers, Deployments resources for a specific project including connection and integration secrets to a specific namespace: atlas kubernetes config generate --projectId= --includeSecrets --targetNamespace= - # Export Project, DatabaseUsers, and specific Deployment resources for a specific project including connection and integration secrets to a specific namespace: + # Export Project, DatabaseUsers, DataFederations and specific Deployment resources for a specific project including connection and integration secrets to a specific namespace: atlas kubernetes config generate --projectId= --clusterName= --includeSecrets --targetNamespace= # Export resources for a specific version of the Atlas Kubernetes Operator: - atlas kubernetes config generate --projectId= --targetNamespace= --operatorVersion=1.5.1`, + atlas kubernetes config generate --projectId= --targetNamespace= --operatorVersion=1.5.1 + + # Export Project, DatabaseUsers, Clusters and specific DataFederation resources for a specific project to a specific namespace: + atlas kubernetes config generate --projectId= --dataFederationName= --targetNamespace=`, PreRunE: func(cmd *cobra.Command, args []string) error { return opts.PreRunE( opts.ValidateProjectID, @@ -140,6 +145,7 @@ func GenerateBuilder() *cobra.Command { cmd.Flags().BoolVar(&opts.includeSecrets, flag.OperatorIncludeSecrets, false, usage.OperatorIncludeSecrets) cmd.Flags().StringVar(&opts.targetNamespace, flag.OperatorTargetNamespace, "", usage.OperatorTargetNamespace) cmd.Flags().StringVar(&opts.operatorVersion, flag.OperatorVersion, features.LatestOperatorMajorVersion, usage.OperatorVersion) + cmd.Flags().StringSliceVar(&opts.dataFederationName, flag.DataFederationName, []string{}, usage.ExporterDataFederationName) return cmd } diff --git a/internal/flag/flags.go b/internal/flag/flags.go index 44374df032..552a5fc057 100644 --- a/internal/flag/flags.go +++ b/internal/flag/flags.go @@ -357,6 +357,7 @@ const ( AWSRoleID = "awsRoleId" // AWSRoleID flag AWSTestS3Bucket = "awsTestS3Bucket" // AWSTestS3Bucket flag DataFederation = "dataFederation" // DataFederation flag + DataFederationName = "dataFederationName" // DataFederationName flag Value = "value" // Value flag OverrunPolicy = "overrunPolicy" // OverrunPolicy flag AuthorizedEmail = "authorizedEmail" // authorizedEmail flag diff --git a/internal/kubernetes/operator/config_exporter.go b/internal/kubernetes/operator/config_exporter.go index 23fb19da82..562671d279 100644 --- a/internal/kubernetes/operator/config_exporter.go +++ b/internal/kubernetes/operator/config_exporter.go @@ -20,6 +20,7 @@ import ( "fmt" "reflect" + "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/datafederation" "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/dbusers" "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/deployment" "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/features" @@ -44,12 +45,13 @@ type ConfigExporter struct { dataProvider store.AtlasOperatorGenericStore credsProvider store.CredentialsGetter projectID string - clusters []string + clusterNames []string targetNamespace string operatorVersion string includeSecretsData bool orgID string dictionaryForAtlasNames map[string]string + dataFederationNames []string } var ( @@ -62,7 +64,8 @@ func NewConfigExporter(dataProvider store.AtlasOperatorGenericStore, credsProvid dataProvider: dataProvider, credsProvider: credsProvider, projectID: projectID, - clusters: []string{}, + clusterNames: []string{}, + dataFederationNames: []string{}, targetNamespace: "", includeSecretsData: false, orgID: orgID, @@ -71,7 +74,7 @@ func NewConfigExporter(dataProvider store.AtlasOperatorGenericStore, credsProvid } func (e *ConfigExporter) WithClustersNames(clusters []string) *ConfigExporter { - e.clusters = clusters + e.clusterNames = clusters return e } @@ -95,6 +98,11 @@ func (e *ConfigExporter) WithFeatureValidator(validator features.FeatureValidato return e } +func (e *ConfigExporter) WithDataFederationNames(dataFederations []string) *ConfigExporter { + e.dataFederationNames = dataFederations + return e +} + func (e *ConfigExporter) Run() (string, error) { // TODO: Add REST to OPERATOR entities matcher @@ -116,6 +124,12 @@ func (e *ConfigExporter) Run() (string, error) { } resources = append(resources, deploymentsResources...) + dataFederationResource, err := e.exportDataFederation(projectName) + if err != nil { + return "", err + } + resources = append(resources, dataFederationResource...) + for _, res := range resources { err = serializer.Encode(res, output) if err != nil { @@ -168,15 +182,15 @@ func (e *ConfigExporter) exportProject() ([]runtime.Object, string, error) { func (e *ConfigExporter) exportDeployments(projectName string) ([]runtime.Object, error) { var result []runtime.Object - if len(e.clusters) == 0 { + if len(e.clusterNames) == 0 { clusters, err := fetchClusterNames(e.dataProvider, e.projectID) if err != nil { return nil, err } - e.clusters = clusters + e.clusterNames = clusters } - for _, deploymentName := range e.clusters { + for _, deploymentName := range e.clusterNames { // Try advanced cluster first if advancedCluster, err := deployment.BuildAtlasAdvancedDeployment(e.dataProvider, e.featureValidator, e.projectID, projectName, deploymentName, e.targetNamespace, e.dictionaryForAtlasNames, e.operatorVersion); err == nil { if advancedCluster != nil { @@ -245,3 +259,39 @@ func fetchClusterNames(clustersProvider store.AtlasAllClustersLister, projectID return result, nil } + +func (e *ConfigExporter) exportDataFederation(projectName string) ([]runtime.Object, error) { + var result []runtime.Object + nameList := e.dataFederationNames + if len(nameList) == 0 { + dataFederations, err := e.fetchDataFederationNames() + if err != nil { + return nil, err + } + nameList = dataFederations + } + for _, name := range nameList { + atlasDataFederations, err := datafederation.BuildAtlasDataFederation(e.dataProvider, name, e.projectID, projectName, e.operatorVersion, e.targetNamespace, e.dictionaryForAtlasNames) + if err != nil { + return nil, err + } + result = append(result, atlasDataFederations) + } + return result, nil +} + +func (e *ConfigExporter) fetchDataFederationNames() ([]string, error) { + var result []string + dataFederations, err := e.dataProvider.DataFederationList(e.projectID) + if err != nil { + return nil, err + } + for _, obj := range dataFederations { + name := obj.GetName() + if reflect.ValueOf(name).IsZero() { + continue + } + result = append(result, name) + } + return result, nil +} diff --git a/internal/kubernetes/operator/config_exporter_test.go b/internal/kubernetes/operator/config_exporter_test.go new file mode 100644 index 0000000000..04ab9d8d11 --- /dev/null +++ b/internal/kubernetes/operator/config_exporter_test.go @@ -0,0 +1,91 @@ +// Copyright 2023 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. + +//go:build unit + +package operator + +import ( + "testing" + + "github.com/go-test/deep" + "github.com/golang/mock/gomock" + "github.com/mongodb/mongodb-atlas-cli/internal/mocks" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" + "go.mongodb.org/atlas-sdk/v20230201004/admin" +) + +const projectID = "TestProjectID" + +func Test_fetchDataFederationNames(t *testing.T) { + ctl := gomock.NewController(t) + atlasOperatorGenericStore := mocks.NewMockAtlasOperatorGenericStore(ctl) + + t.Run("Can fetch Data Federation Instance names", func(t *testing.T) { + dataFederations := []admin.DataLakeTenant{ + { + DataProcessRegion: &admin.DataLakeDataProcessRegion{ + CloudProvider: "TestProvider", + Region: "TestRegion", + }, + Name: pointer.Get("DataFederationInstance0"), + State: pointer.Get("TestState"), + Storage: &admin.DataLakeStorage{ + Databases: nil, + Stores: nil, + }, + }, + { + DataProcessRegion: &admin.DataLakeDataProcessRegion{ + CloudProvider: "TestProvider", + Region: "TestRegion", + }, + Name: pointer.Get("DataFederationInstance1"), + State: pointer.Get("TestState"), + Storage: &admin.DataLakeStorage{ + Databases: nil, + Stores: nil, + }, + }, + { + DataProcessRegion: &admin.DataLakeDataProcessRegion{ + CloudProvider: "TestProvider", + Region: "TestRegion", + }, + Name: pointer.Get("DataFederationInstance2"), + State: pointer.Get("TestState"), + Storage: &admin.DataLakeStorage{ + Databases: nil, + Stores: nil, + }, + }, + } + + atlasOperatorGenericStore.EXPECT().DataFederationList(projectID).Return(dataFederations, nil) + expected := []string{"DataFederationInstance0", "DataFederationInstance1", "DataFederationInstance2"} + ce := NewConfigExporter( + atlasOperatorGenericStore, + nil, // credsProvider (not used) + projectID, "", // orgID (not used) + ) + got, err := ce.fetchDataFederationNames() + if err != nil { + t.Fatalf("%v", err) + } + + if diff := deep.Equal(got, expected); diff != nil { + t.Error(diff) + } + }) +} diff --git a/internal/kubernetes/operator/datafederation/datafederation.go b/internal/kubernetes/operator/datafederation/datafederation.go new file mode 100644 index 0000000000..d21201b73e --- /dev/null +++ b/internal/kubernetes/operator/datafederation/datafederation.go @@ -0,0 +1,203 @@ +// Copyright 2023 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 datafederation + +import ( + "fmt" + + "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/features" + "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/resources" + "github.com/mongodb/mongodb-atlas-cli/internal/store" + atlasV1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/common" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" + "go.mongodb.org/atlas-sdk/v20230201004/admin" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + DeletingState = "DELETING" + DeletedState = "DELETED" +) + +func BuildAtlasDataFederation(dataFederationStore store.DataFederationStore, dataFederationName, projectID, projectName, operatorVersion, targetNamespace string, dictionary map[string]string) (*atlasV1.AtlasDataFederation, error) { + dataFederation, err := dataFederationStore.DataFederation(projectID, dataFederationName) + if err != nil { + return nil, err + } + if !isDataFederationExportable(dataFederation) { + return nil, nil + } + atlasDataFederation := &atlasV1.AtlasDataFederation{ + TypeMeta: v1.TypeMeta{ + APIVersion: "atlas.mongodb.com/v1", + Kind: "AtlasDataFederation", + }, + ObjectMeta: v1.ObjectMeta{ + Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, dataFederation.GetName()), dictionary), + Namespace: targetNamespace, + Labels: map[string]string{ + features.ResourceVersion: operatorVersion, + }, + }, + Spec: getDataFederationSpec(dataFederation, targetNamespace, projectName), + Status: status.DataFederationStatus{ + Common: status.Common{ + Conditions: []status.Condition{}, + }, + }, + } + return atlasDataFederation, nil +} + +func isDataFederationExportable(dataFederation *admin.DataLakeTenant) bool { + state := dataFederation.GetState() + return state != DeletingState && state != DeletedState +} + +func getDataFederationSpec(dataFederationSpec *admin.DataLakeTenant, targetNamespace, projectName string) atlasV1.DataFederationSpec { + return atlasV1.DataFederationSpec{ + Project: common.ResourceRefNamespaced{Name: projectName, Namespace: targetNamespace}, + Name: dataFederationSpec.GetName(), + CloudProviderConfig: getCloudProviderConfig(dataFederationSpec.CloudProviderConfig), + DataProcessRegion: getDataProcessRegion(dataFederationSpec.DataProcessRegion), + Storage: getStorage(dataFederationSpec.Storage), + } +} + +func getCloudProviderConfig(cloudProviderConfig *admin.DataLakeCloudProviderConfig) *atlasV1.CloudProviderConfig { + if cloudProviderConfig == nil { + return &atlasV1.CloudProviderConfig{} + } + return &atlasV1.CloudProviderConfig{ + AWS: &atlasV1.AWSProviderConfig{ + RoleID: cloudProviderConfig.Aws.RoleId, + TestS3Bucket: cloudProviderConfig.Aws.TestS3Bucket, + }, + } +} + +func getDataProcessRegion(dataProcessRegion *admin.DataLakeDataProcessRegion) *atlasV1.DataProcessRegion { + if dataProcessRegion == nil { + return &atlasV1.DataProcessRegion{} + } + return &atlasV1.DataProcessRegion{ + CloudProvider: dataProcessRegion.CloudProvider, + Region: dataProcessRegion.Region, + } +} + +func getStorage(storage *admin.DataLakeStorage) *atlasV1.Storage { + if storage == nil { + return &atlasV1.Storage{} + } + return &atlasV1.Storage{ + Databases: getDatabases(storage.Databases), + Stores: getStores(storage.Stores), + } +} + +func getDatabases(database []admin.DataLakeDatabaseInstance) []atlasV1.Database { + if database == nil { + return []atlasV1.Database{} + } + result := make([]atlasV1.Database, 0, len(database)) + + for _, obj := range database { + result = append(result, atlasV1.Database{ + Collections: getCollection(obj.GetCollections()), + MaxWildcardCollections: obj.GetMaxWildcardCollections(), + Name: obj.GetName(), + Views: getViews(obj.GetViews()), + }) + } + return result +} + +func getCollection(collections []admin.DataLakeDatabaseCollection) []atlasV1.Collection { + if collections == nil { + return []atlasV1.Collection{} + } + result := make([]atlasV1.Collection, 0, len(collections)) + + for _, obj := range collections { + result = append(result, atlasV1.Collection{ + DataSources: getDataSources(obj.GetDataSources()), + Name: obj.GetName(), + }) + } + return result +} + +func getDataSources(dataSources []admin.DataLakeDatabaseDataSourceSettings) []atlasV1.DataSource { + if dataSources == nil { + return []atlasV1.DataSource{} + } + result := make([]atlasV1.DataSource, 0, len(dataSources)) + + for _, obj := range dataSources { + result = append(result, atlasV1.DataSource{ + AllowInsecure: obj.GetAllowInsecure(), + Collection: obj.GetCollection(), + CollectionRegex: obj.GetCollectionRegex(), + Database: obj.GetDatabase(), + DatabaseRegex: obj.GetDatabaseRegex(), + DefaultFormat: obj.GetDefaultFormat(), + Path: obj.GetPath(), + ProvenanceFieldName: obj.GetProvenanceFieldName(), + StoreName: obj.GetStoreName(), + Urls: obj.GetUrls(), + }) + } + return result +} + +func getViews(views []admin.DataLakeApiBase) []atlasV1.View { + if views == nil { + return []atlasV1.View{} + } + result := make([]atlasV1.View, 0, len(views)) + + for _, obj := range views { + result = append(result, atlasV1.View{ + Name: obj.GetName(), + Pipeline: obj.GetPipeline(), + Source: obj.GetSource(), + }) + } + return result +} + +func getStores(stores []admin.DataLakeStoreSettings) []atlasV1.Store { + if stores == nil { + return []atlasV1.Store{} + } + result := make([]atlasV1.Store, 0, len(stores)) + + for _, obj := range stores { + result = append(result, atlasV1.Store{ + Name: obj.GetName(), + Provider: obj.Provider, + AdditionalStorageClasses: obj.GetAdditionalStorageClasses(), + Bucket: obj.GetBucket(), + Delimiter: obj.GetDelimiter(), + IncludeTags: obj.GetIncludeTags(), + Prefix: obj.GetPrefix(), + Public: obj.GetPublic(), + Region: obj.GetRegion(), + }) + } + return result +} diff --git a/internal/kubernetes/operator/datafederation/datafederation_test.go b/internal/kubernetes/operator/datafederation/datafederation_test.go new file mode 100644 index 0000000000..8493303cd7 --- /dev/null +++ b/internal/kubernetes/operator/datafederation/datafederation_test.go @@ -0,0 +1,207 @@ +// Copyright 2023 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. + +///go:build unit + +package datafederation + +import ( + "fmt" + "testing" + + "github.com/go-test/deep" + "github.com/golang/mock/gomock" + "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/features" + "github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/resources" + "github.com/mongodb/mongodb-atlas-cli/internal/mocks" + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" + atlasV1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/common" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" + "go.mongodb.org/atlas-sdk/v20230201004/admin" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + projectName = "testProject-1" + dataFederationName = "testDataFederation-1" + targetNamespace = "test-namespace-1" + resourceVersion = "x.y.z" + projectID = "test-project-id" +) + +func Test_BuildAtlasDataFederation(t *testing.T) { + ctl := gomock.NewController(t) + dataFederationStore := mocks.NewMockDataFederationStore(ctl) + dictionary := resources.AtlasNameToKubernetesName() + + t.Run("Can import Data Federations", func(t *testing.T) { + dataFederation := &admin.DataLakeTenant{ + CloudProviderConfig: &admin.DataLakeCloudProviderConfig{ + Aws: admin.DataLakeAWSCloudProviderConfig{ + RoleId: "TestRoleID", + TestS3Bucket: "TestBucket", + }, + }, + DataProcessRegion: &admin.DataLakeDataProcessRegion{ + CloudProvider: "TestProvider", + Region: "TestRegion", + }, + Hostnames: []string{"TestHostname"}, + Name: pointer.Get(dataFederationName), + State: pointer.Get("TestState"), + Storage: &admin.DataLakeStorage{ + Databases: []admin.DataLakeDatabaseInstance{ + { + Collections: []admin.DataLakeDatabaseCollection{ + { + DataSources: []admin.DataLakeDatabaseDataSourceSettings{ + { + AllowInsecure: pointer.Get(true), + Collection: pointer.Get("TestCollection"), + CollectionRegex: pointer.Get("TestCollectionRegex"), + Database: pointer.Get("TestDatabase"), + DatabaseRegex: pointer.Get("TestDatabaseRegex"), + DefaultFormat: pointer.Get("TestFormat"), + Path: pointer.Get("TestPath"), + ProvenanceFieldName: pointer.Get("TestFieldName"), + StoreName: pointer.Get("TestStoreName"), + Urls: []string{"TestUrl"}, + }, + }, + Name: pointer.Get("TestName"), + }, + }, + MaxWildcardCollections: pointer.Get(10), + Name: pointer.Get("TestName"), + Views: []admin.DataLakeApiBase{ + { + Name: pointer.Get("TestName"), + Pipeline: pointer.Get("TestPipeline"), + Source: pointer.Get("TestSource"), + }, + }, + }, + }, + Stores: []admin.DataLakeStoreSettings{ + { + Name: pointer.Get("TestName"), + Provider: "TestProvider", + AdditionalStorageClasses: []string{"TestClasses"}, + Bucket: pointer.Get("TestBucket"), + Delimiter: pointer.Get("TestDelimiter"), + IncludeTags: pointer.Get(true), + Prefix: pointer.Get("TestPrefix"), + Public: pointer.Get(true), + Region: pointer.Get("TestRegion"), + }, + }, + }, + } + + dataFederationStore.EXPECT().DataFederation(projectID, dataFederationName).Return(dataFederation, nil) + + expected := &atlasV1.AtlasDataFederation{ + TypeMeta: v1.TypeMeta{ + Kind: "AtlasDataFederation", + APIVersion: "atlas.mongodb.com/v1", + }, + ObjectMeta: v1.ObjectMeta{ + Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, dataFederation.GetName()), dictionary), + Namespace: targetNamespace, + Labels: map[string]string{ + features.ResourceVersion: resourceVersion, + }, + }, + Spec: atlasV1.DataFederationSpec{ + Project: common.ResourceRefNamespaced{ + Name: projectName, + Namespace: targetNamespace, + }, + Name: dataFederationName, + CloudProviderConfig: &atlasV1.CloudProviderConfig{ + AWS: &atlasV1.AWSProviderConfig{ + RoleID: dataFederation.CloudProviderConfig.Aws.RoleId, + TestS3Bucket: dataFederation.CloudProviderConfig.Aws.TestS3Bucket, + }, + }, + DataProcessRegion: &atlasV1.DataProcessRegion{ + CloudProvider: dataFederation.DataProcessRegion.CloudProvider, + Region: dataFederation.DataProcessRegion.Region, + }, + Storage: &atlasV1.Storage{ + Databases: []atlasV1.Database{ + { + Collections: []atlasV1.Collection{ + { + DataSources: []atlasV1.DataSource{ + { + AllowInsecure: true, + Collection: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].Collection, + CollectionRegex: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].CollectionRegex, + Database: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].Database, + DatabaseRegex: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].DatabaseRegex, + DefaultFormat: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].DefaultFormat, + Path: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].Path, + ProvenanceFieldName: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].ProvenanceFieldName, + StoreName: *dataFederation.Storage.Databases[0].Collections[0].DataSources[0].StoreName, + Urls: []string{dataFederation.Storage.Databases[0].Collections[0].DataSources[0].Urls[0]}, + }, + }, + Name: *dataFederation.Storage.Databases[0].Collections[0].Name, + }, + }, + MaxWildcardCollections: *dataFederation.Storage.Databases[0].MaxWildcardCollections, + Name: *dataFederation.Storage.Databases[0].Name, + Views: []atlasV1.View{ + { + Name: *dataFederation.Storage.Databases[0].Views[0].Name, + Pipeline: *dataFederation.Storage.Databases[0].Views[0].Pipeline, + Source: *dataFederation.Storage.Databases[0].Views[0].Source, + }, + }, + }, + }, + Stores: []atlasV1.Store{ + { + Name: *dataFederation.Storage.Stores[0].Name, + Provider: dataFederation.Storage.Stores[0].Provider, + AdditionalStorageClasses: []string{dataFederation.Storage.Stores[0].AdditionalStorageClasses[0]}, + Bucket: *dataFederation.Storage.Stores[0].Bucket, + Delimiter: *dataFederation.Storage.Stores[0].Delimiter, + IncludeTags: *dataFederation.Storage.Stores[0].IncludeTags, + Prefix: *dataFederation.Storage.Stores[0].Prefix, + Public: *dataFederation.Storage.Stores[0].Public, + Region: *dataFederation.Storage.Stores[0].Region, + }, + }, + }, + }, + Status: status.DataFederationStatus{ + Common: status.Common{ + Conditions: []status.Condition{}, + }, + }, + } + + got, err := BuildAtlasDataFederation(dataFederationStore, dataFederationName, projectID, projectName, resourceVersion, targetNamespace, dictionary) + if err != nil { + t.Fatalf("%v", err) + } + + if diff := deep.Equal(got, expected); diff != nil { + t.Error(diff) + } + }) +} diff --git a/internal/mocks/mock_atlas_generic_store.go b/internal/mocks/mock_atlas_generic_store.go new file mode 100644 index 0000000000..f48138d6f9 --- /dev/null +++ b/internal/mocks/mock_atlas_generic_store.go @@ -0,0 +1,575 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: AtlasOperatorGenericStore) + +// Package mocks is a generated GoMock package. +package mocks + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + admin "go.mongodb.org/atlas-sdk/v20230201004/admin" + mongodbatlas "go.mongodb.org/atlas/mongodbatlas" +) + +// MockAtlasOperatorGenericStore is a mock of AtlasOperatorGenericStore interface. +type MockAtlasOperatorGenericStore struct { + ctrl *gomock.Controller + recorder *MockAtlasOperatorGenericStoreMockRecorder +} + +// MockAtlasOperatorGenericStoreMockRecorder is the mock recorder for MockAtlasOperatorGenericStore. +type MockAtlasOperatorGenericStoreMockRecorder struct { + mock *MockAtlasOperatorGenericStore +} + +// NewMockAtlasOperatorGenericStore creates a new mock instance. +func NewMockAtlasOperatorGenericStore(ctrl *gomock.Controller) *MockAtlasOperatorGenericStore { + mock := &MockAtlasOperatorGenericStore{ctrl: ctrl} + mock.recorder = &MockAtlasOperatorGenericStoreMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAtlasOperatorGenericStore) EXPECT() *MockAtlasOperatorGenericStoreMockRecorder { + return m.recorder +} + +// AlertConfigurations mocks base method. +func (m *MockAtlasOperatorGenericStore) AlertConfigurations(arg0 string, arg1 *mongodbatlas.ListOptions) ([]mongodbatlas.AlertConfiguration, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AlertConfigurations", arg0, arg1) + ret0, _ := ret[0].([]mongodbatlas.AlertConfiguration) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AlertConfigurations indicates an expected call of AlertConfigurations. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) AlertConfigurations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AlertConfigurations", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).AlertConfigurations), arg0, arg1) +} + +// AssignProjectAPIKey mocks base method. +func (m *MockAtlasOperatorGenericStore) AssignProjectAPIKey(arg0, arg1 string, arg2 *mongodbatlas.AssignAPIKey) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AssignProjectAPIKey", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// AssignProjectAPIKey indicates an expected call of AssignProjectAPIKey. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) AssignProjectAPIKey(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssignProjectAPIKey", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).AssignProjectAPIKey), arg0, arg1, arg2) +} + +// AtlasCluster mocks base method. +func (m *MockAtlasOperatorGenericStore) AtlasCluster(arg0, arg1 string) (*admin.AdvancedClusterDescription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtlasCluster", arg0, arg1) + ret0, _ := ret[0].(*admin.AdvancedClusterDescription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AtlasCluster indicates an expected call of AtlasCluster. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) AtlasCluster(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtlasCluster", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).AtlasCluster), arg0, arg1) +} + +// AtlasClusterConfigurationOptions mocks base method. +func (m *MockAtlasOperatorGenericStore) AtlasClusterConfigurationOptions(arg0, arg1 string) (*admin.ClusterDescriptionProcessArgs, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AtlasClusterConfigurationOptions", arg0, arg1) + ret0, _ := ret[0].(*admin.ClusterDescriptionProcessArgs) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AtlasClusterConfigurationOptions indicates an expected call of AtlasClusterConfigurationOptions. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) AtlasClusterConfigurationOptions(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AtlasClusterConfigurationOptions", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).AtlasClusterConfigurationOptions), arg0, arg1) +} + +// Auditing mocks base method. +func (m *MockAtlasOperatorGenericStore) Auditing(arg0 string) (*admin.AuditLog, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Auditing", arg0) + ret0, _ := ret[0].(*admin.AuditLog) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Auditing indicates an expected call of Auditing. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) Auditing(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Auditing", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).Auditing), arg0) +} + +// CloudProviderAccessRoles mocks base method. +func (m *MockAtlasOperatorGenericStore) CloudProviderAccessRoles(arg0 string) (*admin.CloudProviderAccessRoles, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CloudProviderAccessRoles", arg0) + ret0, _ := ret[0].(*admin.CloudProviderAccessRoles) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CloudProviderAccessRoles indicates an expected call of CloudProviderAccessRoles. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) CloudProviderAccessRoles(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloudProviderAccessRoles", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).CloudProviderAccessRoles), arg0) +} + +// CreateOrganizationAPIKey mocks base method. +func (m *MockAtlasOperatorGenericStore) CreateOrganizationAPIKey(arg0 string, arg1 *mongodbatlas.APIKeyInput) (*mongodbatlas.APIKey, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateOrganizationAPIKey", arg0, arg1) + ret0, _ := ret[0].(*mongodbatlas.APIKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateOrganizationAPIKey indicates an expected call of CreateOrganizationAPIKey. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) CreateOrganizationAPIKey(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrganizationAPIKey", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).CreateOrganizationAPIKey), arg0, arg1) +} + +// CreateProject mocks base method. +func (m *MockAtlasOperatorGenericStore) CreateProject(arg0, arg1, arg2 string, arg3 *bool, arg4 *mongodbatlas.CreateProjectOptions) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateProject", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateProject indicates an expected call of CreateProject. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) CreateProject(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateProject", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).CreateProject), arg0, arg1, arg2, arg3, arg4) +} + +// CreateProjectAPIKey mocks base method. +func (m *MockAtlasOperatorGenericStore) CreateProjectAPIKey(arg0 string, arg1 *mongodbatlas.APIKeyInput) (*mongodbatlas.APIKey, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateProjectAPIKey", arg0, arg1) + ret0, _ := ret[0].(*mongodbatlas.APIKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateProjectAPIKey indicates an expected call of CreateProjectAPIKey. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) CreateProjectAPIKey(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateProjectAPIKey", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).CreateProjectAPIKey), arg0, arg1) +} + +// DataFederation mocks base method. +func (m *MockAtlasOperatorGenericStore) DataFederation(arg0, arg1 string) (*admin.DataLakeTenant, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DataFederation", arg0, arg1) + ret0, _ := ret[0].(*admin.DataLakeTenant) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DataFederation indicates an expected call of DataFederation. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) DataFederation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DataFederation", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).DataFederation), arg0, arg1) +} + +// DataFederationList mocks base method. +func (m *MockAtlasOperatorGenericStore) DataFederationList(arg0 string) ([]admin.DataLakeTenant, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DataFederationList", arg0) + ret0, _ := ret[0].([]admin.DataLakeTenant) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DataFederationList indicates an expected call of DataFederationList. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) DataFederationList(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DataFederationList", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).DataFederationList), arg0) +} + +// DatabaseRoles mocks base method. +func (m *MockAtlasOperatorGenericStore) DatabaseRoles(arg0 string) ([]admin.UserCustomDBRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DatabaseRoles", arg0) + ret0, _ := ret[0].([]admin.UserCustomDBRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DatabaseRoles indicates an expected call of DatabaseRoles. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) DatabaseRoles(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DatabaseRoles", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).DatabaseRoles), arg0) +} + +// DatabaseUsers mocks base method. +func (m *MockAtlasOperatorGenericStore) DatabaseUsers(arg0 string, arg1 *mongodbatlas.ListOptions) (*admin.PaginatedApiAtlasDatabaseUser, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DatabaseUsers", arg0, arg1) + ret0, _ := ret[0].(*admin.PaginatedApiAtlasDatabaseUser) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DatabaseUsers indicates an expected call of DatabaseUsers. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) DatabaseUsers(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DatabaseUsers", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).DatabaseUsers), arg0, arg1) +} + +// DescribeSchedule mocks base method. +func (m *MockAtlasOperatorGenericStore) DescribeSchedule(arg0, arg1 string) (*admin.DiskBackupSnapshotSchedule, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DescribeSchedule", arg0, arg1) + ret0, _ := ret[0].(*admin.DiskBackupSnapshotSchedule) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DescribeSchedule indicates an expected call of DescribeSchedule. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) DescribeSchedule(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeSchedule", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).DescribeSchedule), arg0, arg1) +} + +// EncryptionAtRest mocks base method. +func (m *MockAtlasOperatorGenericStore) EncryptionAtRest(arg0 string) (*admin.EncryptionAtRest, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EncryptionAtRest", arg0) + ret0, _ := ret[0].(*admin.EncryptionAtRest) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// EncryptionAtRest indicates an expected call of EncryptionAtRest. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) EncryptionAtRest(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EncryptionAtRest", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).EncryptionAtRest), arg0) +} + +// GetOrgProjects mocks base method. +func (m *MockAtlasOperatorGenericStore) GetOrgProjects(arg0 string, arg1 *mongodbatlas.ProjectsListOptions) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOrgProjects", arg0, arg1) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetOrgProjects indicates an expected call of GetOrgProjects. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) GetOrgProjects(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrgProjects", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).GetOrgProjects), arg0, arg1) +} + +// GetServerlessInstance mocks base method. +func (m *MockAtlasOperatorGenericStore) GetServerlessInstance(arg0, arg1 string) (*admin.ServerlessInstanceDescription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetServerlessInstance", arg0, arg1) + ret0, _ := ret[0].(*admin.ServerlessInstanceDescription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetServerlessInstance indicates an expected call of GetServerlessInstance. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) GetServerlessInstance(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServerlessInstance", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).GetServerlessInstance), arg0, arg1) +} + +// GlobalCluster mocks base method. +func (m *MockAtlasOperatorGenericStore) GlobalCluster(arg0, arg1 string) (*admin.GeoSharding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GlobalCluster", arg0, arg1) + ret0, _ := ret[0].(*admin.GeoSharding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GlobalCluster indicates an expected call of GlobalCluster. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) GlobalCluster(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GlobalCluster", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).GlobalCluster), arg0, arg1) +} + +// Integrations mocks base method. +func (m *MockAtlasOperatorGenericStore) Integrations(arg0 string) (*admin.PaginatedIntegration, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Integrations", arg0) + ret0, _ := ret[0].(*admin.PaginatedIntegration) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Integrations indicates an expected call of Integrations. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) Integrations(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Integrations", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).Integrations), arg0) +} + +// MaintenanceWindow mocks base method. +func (m *MockAtlasOperatorGenericStore) MaintenanceWindow(arg0 string) (*admin.GroupMaintenanceWindow, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MaintenanceWindow", arg0) + ret0, _ := ret[0].(*admin.GroupMaintenanceWindow) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// MaintenanceWindow indicates an expected call of MaintenanceWindow. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) MaintenanceWindow(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MaintenanceWindow", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).MaintenanceWindow), arg0) +} + +// PeeringConnections mocks base method. +func (m *MockAtlasOperatorGenericStore) PeeringConnections(arg0 string, arg1 *mongodbatlas.ContainersListOptions) ([]admin.BaseNetworkPeeringConnectionSettings, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PeeringConnections", arg0, arg1) + ret0, _ := ret[0].([]admin.BaseNetworkPeeringConnectionSettings) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PeeringConnections indicates an expected call of PeeringConnections. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) PeeringConnections(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeeringConnections", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).PeeringConnections), arg0, arg1) +} + +// PrivateEndpoints mocks base method. +func (m *MockAtlasOperatorGenericStore) PrivateEndpoints(arg0, arg1 string) ([]admin.EndpointService, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrivateEndpoints", arg0, arg1) + ret0, _ := ret[0].([]admin.EndpointService) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PrivateEndpoints indicates an expected call of PrivateEndpoints. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) PrivateEndpoints(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrivateEndpoints", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).PrivateEndpoints), arg0, arg1) +} + +// Project mocks base method. +func (m *MockAtlasOperatorGenericStore) Project(arg0 string) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Project", arg0) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Project indicates an expected call of Project. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) Project(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Project", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).Project), arg0) +} + +// ProjectByName mocks base method. +func (m *MockAtlasOperatorGenericStore) ProjectByName(arg0 string) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectByName", arg0) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectByName indicates an expected call of ProjectByName. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ProjectByName(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectByName", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ProjectByName), arg0) +} + +// ProjectClusters mocks base method. +func (m *MockAtlasOperatorGenericStore) ProjectClusters(arg0 string, arg1 *mongodbatlas.ListOptions) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectClusters", arg0, arg1) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectClusters indicates an expected call of ProjectClusters. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ProjectClusters(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectClusters", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ProjectClusters), arg0, arg1) +} + +// ProjectIPAccessLists mocks base method. +func (m *MockAtlasOperatorGenericStore) ProjectIPAccessLists(arg0 string, arg1 *mongodbatlas.ListOptions) (*admin.PaginatedNetworkAccess, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectIPAccessLists", arg0, arg1) + ret0, _ := ret[0].(*admin.PaginatedNetworkAccess) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectIPAccessLists indicates an expected call of ProjectIPAccessLists. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ProjectIPAccessLists(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectIPAccessLists", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ProjectIPAccessLists), arg0, arg1) +} + +// ProjectSettings mocks base method. +func (m *MockAtlasOperatorGenericStore) ProjectSettings(arg0 string) (*admin.GroupSettings, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectSettings", arg0) + ret0, _ := ret[0].(*admin.GroupSettings) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectSettings indicates an expected call of ProjectSettings. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ProjectSettings(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectSettings", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ProjectSettings), arg0) +} + +// ProjectTeams mocks base method. +func (m *MockAtlasOperatorGenericStore) ProjectTeams(arg0 string) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProjectTeams", arg0) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProjectTeams indicates an expected call of ProjectTeams. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ProjectTeams(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProjectTeams", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ProjectTeams), arg0) +} + +// Projects mocks base method. +func (m *MockAtlasOperatorGenericStore) Projects(arg0 *mongodbatlas.ListOptions) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Projects", arg0) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Projects indicates an expected call of Projects. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) Projects(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Projects", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).Projects), arg0) +} + +// ServerlessInstance mocks base method. +func (m *MockAtlasOperatorGenericStore) ServerlessInstance(arg0, arg1 string) (*mongodbatlas.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ServerlessInstance", arg0, arg1) + ret0, _ := ret[0].(*mongodbatlas.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ServerlessInstance indicates an expected call of ServerlessInstance. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ServerlessInstance(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ServerlessInstance", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ServerlessInstance), arg0, arg1) +} + +// ServerlessInstances mocks base method. +func (m *MockAtlasOperatorGenericStore) ServerlessInstances(arg0 string, arg1 *mongodbatlas.ListOptions) (*admin.PaginatedServerlessInstanceDescription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ServerlessInstances", arg0, arg1) + ret0, _ := ret[0].(*admin.PaginatedServerlessInstanceDescription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ServerlessInstances indicates an expected call of ServerlessInstances. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ServerlessInstances(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ServerlessInstances", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ServerlessInstances), arg0, arg1) +} + +// ServerlessPrivateEndpoints mocks base method. +func (m *MockAtlasOperatorGenericStore) ServerlessPrivateEndpoints(arg0, arg1 string) ([]admin.ServerlessTenantEndpoint, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ServerlessPrivateEndpoints", arg0, arg1) + ret0, _ := ret[0].([]admin.ServerlessTenantEndpoint) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ServerlessPrivateEndpoints indicates an expected call of ServerlessPrivateEndpoints. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) ServerlessPrivateEndpoints(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ServerlessPrivateEndpoints", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ServerlessPrivateEndpoints), arg0, arg1) +} + +// ServiceVersion mocks base method. +func (m *MockAtlasOperatorGenericStore) 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 *MockAtlasOperatorGenericStoreMockRecorder) ServiceVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ServiceVersion", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).ServiceVersion)) +} + +// TeamByID mocks base method. +func (m *MockAtlasOperatorGenericStore) TeamByID(arg0, arg1 string) (*mongodbatlas.Team, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TeamByID", arg0, arg1) + ret0, _ := ret[0].(*mongodbatlas.Team) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TeamByID indicates an expected call of TeamByID. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) TeamByID(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TeamByID", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).TeamByID), arg0, arg1) +} + +// TeamByName mocks base method. +func (m *MockAtlasOperatorGenericStore) TeamByName(arg0, arg1 string) (*mongodbatlas.Team, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TeamByName", arg0, arg1) + ret0, _ := ret[0].(*mongodbatlas.Team) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TeamByName indicates an expected call of TeamByName. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) TeamByName(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TeamByName", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).TeamByName), arg0, arg1) +} + +// TeamUsers mocks base method. +func (m *MockAtlasOperatorGenericStore) TeamUsers(arg0, arg1 string) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TeamUsers", arg0, arg1) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TeamUsers indicates an expected call of TeamUsers. +func (mr *MockAtlasOperatorGenericStoreMockRecorder) TeamUsers(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TeamUsers", reflect.TypeOf((*MockAtlasOperatorGenericStore)(nil).TeamUsers), arg0, arg1) +} diff --git a/internal/mocks/mock_atlas_operator_db_users_store.go b/internal/mocks/mock_atlas_operator_db_users_store.go new file mode 100644 index 0000000000..a23e2c1bee --- /dev/null +++ b/internal/mocks/mock_atlas_operator_db_users_store.go @@ -0,0 +1,51 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: AtlasOperatorDBUsersStore) + +// Package mocks is a generated GoMock package. +package mocks + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + admin "go.mongodb.org/atlas-sdk/v20230201004/admin" + mongodbatlas "go.mongodb.org/atlas/mongodbatlas" +) + +// MockAtlasOperatorDBUsersStore is a mock of AtlasOperatorDBUsersStore interface. +type MockAtlasOperatorDBUsersStore struct { + ctrl *gomock.Controller + recorder *MockAtlasOperatorDBUsersStoreMockRecorder +} + +// MockAtlasOperatorDBUsersStoreMockRecorder is the mock recorder for MockAtlasOperatorDBUsersStore. +type MockAtlasOperatorDBUsersStoreMockRecorder struct { + mock *MockAtlasOperatorDBUsersStore +} + +// NewMockAtlasOperatorDBUsersStore creates a new mock instance. +func NewMockAtlasOperatorDBUsersStore(ctrl *gomock.Controller) *MockAtlasOperatorDBUsersStore { + mock := &MockAtlasOperatorDBUsersStore{ctrl: ctrl} + mock.recorder = &MockAtlasOperatorDBUsersStoreMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAtlasOperatorDBUsersStore) EXPECT() *MockAtlasOperatorDBUsersStoreMockRecorder { + return m.recorder +} + +// DatabaseUsers mocks base method. +func (m *MockAtlasOperatorDBUsersStore) DatabaseUsers(arg0 string, arg1 *mongodbatlas.ListOptions) (*admin.PaginatedApiAtlasDatabaseUser, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DatabaseUsers", arg0, arg1) + ret0, _ := ret[0].(*admin.PaginatedApiAtlasDatabaseUser) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DatabaseUsers indicates an expected call of DatabaseUsers. +func (mr *MockAtlasOperatorDBUsersStoreMockRecorder) DatabaseUsers(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DatabaseUsers", reflect.TypeOf((*MockAtlasOperatorDBUsersStore)(nil).DatabaseUsers), arg0, arg1) +} diff --git a/internal/mocks/mock_atlas_operator_org_store.go b/internal/mocks/mock_atlas_operator_org_store.go new file mode 100644 index 0000000000..1072cf3b27 --- /dev/null +++ b/internal/mocks/mock_atlas_operator_org_store.go @@ -0,0 +1,64 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: AtlasOperatorOrgStore) + +// Package mocks is a generated GoMock package. +package mocks + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + mongodbatlas "go.mongodb.org/atlas/mongodbatlas" +) + +// MockAtlasOperatorOrgStore is a mock of AtlasOperatorOrgStore interface. +type MockAtlasOperatorOrgStore struct { + ctrl *gomock.Controller + recorder *MockAtlasOperatorOrgStoreMockRecorder +} + +// MockAtlasOperatorOrgStoreMockRecorder is the mock recorder for MockAtlasOperatorOrgStore. +type MockAtlasOperatorOrgStoreMockRecorder struct { + mock *MockAtlasOperatorOrgStore +} + +// NewMockAtlasOperatorOrgStore creates a new mock instance. +func NewMockAtlasOperatorOrgStore(ctrl *gomock.Controller) *MockAtlasOperatorOrgStore { + mock := &MockAtlasOperatorOrgStore{ctrl: ctrl} + mock.recorder = &MockAtlasOperatorOrgStoreMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAtlasOperatorOrgStore) EXPECT() *MockAtlasOperatorOrgStoreMockRecorder { + return m.recorder +} + +// AssignProjectAPIKey mocks base method. +func (m *MockAtlasOperatorOrgStore) AssignProjectAPIKey(arg0, arg1 string, arg2 *mongodbatlas.AssignAPIKey) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AssignProjectAPIKey", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// AssignProjectAPIKey indicates an expected call of AssignProjectAPIKey. +func (mr *MockAtlasOperatorOrgStoreMockRecorder) AssignProjectAPIKey(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssignProjectAPIKey", reflect.TypeOf((*MockAtlasOperatorOrgStore)(nil).AssignProjectAPIKey), arg0, arg1, arg2) +} + +// CreateOrganizationAPIKey mocks base method. +func (m *MockAtlasOperatorOrgStore) CreateOrganizationAPIKey(arg0 string, arg1 *mongodbatlas.APIKeyInput) (*mongodbatlas.APIKey, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateOrganizationAPIKey", arg0, arg1) + ret0, _ := ret[0].(*mongodbatlas.APIKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateOrganizationAPIKey indicates an expected call of CreateOrganizationAPIKey. +func (mr *MockAtlasOperatorOrgStoreMockRecorder) CreateOrganizationAPIKey(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrganizationAPIKey", reflect.TypeOf((*MockAtlasOperatorOrgStore)(nil).CreateOrganizationAPIKey), arg0, arg1) +} diff --git a/internal/mocks/mock_data_federation.go b/internal/mocks/mock_data_federation.go new file mode 100644 index 0000000000..ff44c0b62d --- /dev/null +++ b/internal/mocks/mock_data_federation.go @@ -0,0 +1,103 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/mongodb/mongodb-atlas-cli/internal/store (interfaces: DataFederationLister,DataFederationStore) + +// Package mocks is a generated GoMock package. +package mocks + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + admin "go.mongodb.org/atlas-sdk/v20230201004/admin" +) + +// MockDataFederationLister is a mock of DataFederationLister interface. +type MockDataFederationLister struct { + ctrl *gomock.Controller + recorder *MockDataFederationListerMockRecorder +} + +// MockDataFederationListerMockRecorder is the mock recorder for MockDataFederationLister. +type MockDataFederationListerMockRecorder struct { + mock *MockDataFederationLister +} + +// NewMockDataFederationLister creates a new mock instance. +func NewMockDataFederationLister(ctrl *gomock.Controller) *MockDataFederationLister { + mock := &MockDataFederationLister{ctrl: ctrl} + mock.recorder = &MockDataFederationListerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDataFederationLister) EXPECT() *MockDataFederationListerMockRecorder { + return m.recorder +} + +// DataFederationList mocks base method. +func (m *MockDataFederationLister) DataFederationList(arg0 string) ([]admin.DataLakeTenant, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DataFederationList", arg0) + ret0, _ := ret[0].([]admin.DataLakeTenant) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DataFederationList indicates an expected call of DataFederationList. +func (mr *MockDataFederationListerMockRecorder) DataFederationList(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DataFederationList", reflect.TypeOf((*MockDataFederationLister)(nil).DataFederationList), arg0) +} + +// MockDataFederationStore is a mock of DataFederationStore interface. +type MockDataFederationStore struct { + ctrl *gomock.Controller + recorder *MockDataFederationStoreMockRecorder +} + +// MockDataFederationStoreMockRecorder is the mock recorder for MockDataFederationStore. +type MockDataFederationStoreMockRecorder struct { + mock *MockDataFederationStore +} + +// NewMockDataFederationStore creates a new mock instance. +func NewMockDataFederationStore(ctrl *gomock.Controller) *MockDataFederationStore { + mock := &MockDataFederationStore{ctrl: ctrl} + mock.recorder = &MockDataFederationStoreMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDataFederationStore) EXPECT() *MockDataFederationStoreMockRecorder { + return m.recorder +} + +// DataFederation mocks base method. +func (m *MockDataFederationStore) DataFederation(arg0, arg1 string) (*admin.DataLakeTenant, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DataFederation", arg0, arg1) + ret0, _ := ret[0].(*admin.DataLakeTenant) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DataFederation indicates an expected call of DataFederation. +func (mr *MockDataFederationStoreMockRecorder) DataFederation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DataFederation", reflect.TypeOf((*MockDataFederationStore)(nil).DataFederation), arg0, arg1) +} + +// DataFederationList mocks base method. +func (m *MockDataFederationStore) DataFederationList(arg0 string) ([]admin.DataLakeTenant, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DataFederationList", arg0) + ret0, _ := ret[0].([]admin.DataLakeTenant) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DataFederationList indicates an expected call of DataFederationList. +func (mr *MockDataFederationStoreMockRecorder) DataFederationList(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DataFederationList", reflect.TypeOf((*MockDataFederationStore)(nil).DataFederationList), arg0) +} diff --git a/internal/store/atlas/store.go b/internal/store/atlas/store.go index 1c4714ed10..f97c61ec4c 100644 --- a/internal/store/atlas/store.go +++ b/internal/store/atlas/store.go @@ -254,7 +254,7 @@ type AuthenticatedConfig interface { type ServiceGetter interface { Service() string - // Name of the config value for custom service URL. Named opsmannager for legacy reasons. + // Name of the config value for custom service URL. Named opsmanager for legacy reasons. OpsManagerURL() string } diff --git a/internal/store/data_federation.go b/internal/store/data_federation.go new file mode 100644 index 0000000000..716165c461 --- /dev/null +++ b/internal/store/data_federation.go @@ -0,0 +1,44 @@ +// Copyright 2023 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 ( + atlas "github.com/mongodb/mongodb-atlas-cli/internal/store/atlas" + "go.mongodb.org/atlas-sdk/v20230201004/admin" +) + +//go:generate mockgen -destination=../mocks/mock_data_federation.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store DataFederationLister,DataFederationStore + +type DataFederationStore interface { + DataFederationLister + atlas.DataFederationDescriber +} + +type DataFederationLister interface { + DataFederationList(string) ([]admin.DataLakeTenant, error) +} + +// DataFederationList encapsulates the logic to manage different cloud providers. +func (s *Store) DataFederationList(projectID string) ([]admin.DataLakeTenant, error) { + req := s.clientv2.DataFederationApi.ListFederatedDatabases(s.ctx, projectID) + result, _, err := req.Execute() + return result, err +} + +// DataFederation encapsulates the logic to manage different cloud providers. +func (s *Store) DataFederation(projectID, id string) (*admin.DataLakeTenant, error) { + result, _, err := s.clientv2.DataFederationApi.GetFederatedDatabase(s.ctx, projectID, id).Execute() + return result, err +} diff --git a/internal/store/operator.go b/internal/store/operator.go index add79d0d0f..32b0259e34 100644 --- a/internal/store/operator.go +++ b/internal/store/operator.go @@ -16,6 +16,9 @@ package store //go:generate mockgen -destination=../mocks/mock_atlas_operator_cluster_store.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AtlasOperatorClusterStore //go:generate mockgen -destination=../mocks/mock_atlas_operator_project_store.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AtlasOperatorProjectStore +//go:generate mockgen -destination=../mocks/mock_atlas_operator_db_users_store.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AtlasOperatorDBUsersStore +//go:generate mockgen -destination=../mocks/mock_atlas_operator_org_store.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AtlasOperatorOrgStore +//go:generate mockgen -destination=../mocks/mock_atlas_generic_store.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/store AtlasOperatorGenericStore type AtlasOperatorProjectStore interface { AtlasOperatorTeamsStore @@ -71,4 +74,5 @@ type AtlasOperatorGenericStore interface { AtlasOperatorProjectStore AtlasOperatorClusterStore AtlasOperatorDBUsersStore + DataFederationStore } diff --git a/internal/usage/usage.go b/internal/usage/usage.go index 6875930f6e..d10ee2df67 100644 --- a/internal/usage/usage.go +++ b/internal/usage/usage.go @@ -443,6 +443,7 @@ dbName and collection are required only for built-in roles.` BackupCompliancePolicyFile = "Path to a JSON configuration file that defines backup compliance policy settings." DataFederationType = "Type of Federated Database Instances to return." DataFederation = "Identifier of the Federated Database Instance." + ExporterDataFederationName = "One or more comma separated data federation names to import" DataFederationQueryLimitValue = "Value given to the query limit." OverrunPolicy = "Action to take when the usage limit is exceeded." AuthorizedEmail = "Email address of a security or legal representative." diff --git a/test/e2e/atlas/atlas_e2e_test_generator_test.go b/test/e2e/atlas/atlas_e2e_test_generator_test.go index 415f65f345..d44df9a127 100644 --- a/test/e2e/atlas/atlas_e2e_test_generator_test.go +++ b/test/e2e/atlas/atlas_e2e_test_generator_test.go @@ -46,6 +46,7 @@ type atlasE2ETestGenerator struct { teamUser string dbUser string tier string + dataFedName string enableBackup bool firstProcess *atlasv2.ApiHostViewAtlas t *testing.T @@ -360,6 +361,33 @@ func (g *atlasE2ETestGenerator) generateProjectAndCluster(prefix string) { g.generateCluster() } +func (g *atlasE2ETestGenerator) generateDataFederation() { + var err error + g.t.Helper() + + if g.projectID == "" { + g.t.Fatal("unexpected error: project must be generated") + } + + g.dataFedName, err = createDataFederationForProject(g.projectID) + storeName := g.dataFedName + if err != nil { + g.Logf("projectID=%q, dataFedName=%q", g.projectID, g.dataFedName) + g.t.Errorf("unexpected error deploying data federation: %v", err) + } else { + g.Logf("dataFedName=%q", g.dataFedName) + } + + g.t.Cleanup(func() { + g.Logf("Data Federation cleanup %q\n", storeName) + if e := deleteDataFederationForProject(g.projectID, storeName); e != nil { + g.t.Errorf("unexpected error deleting data federation: %v", e) + } else { + g.Logf("data federation %q successfully deleted", storeName) + } + }) +} + // newAvailableRegion returns the first region for the provider/tier. func (g *atlasE2ETestGenerator) newAvailableRegion(tier, provider string) (string, error) { g.t.Helper() diff --git a/test/e2e/atlas/helper_test.go b/test/e2e/atlas/helper_test.go index 26417989aa..a3f4fcc238 100644 --- a/test/e2e/atlas/helper_test.go +++ b/test/e2e/atlas/helper_test.go @@ -354,7 +354,7 @@ func newAvailableRegion(projectID, tier, provider string) (string, error) { var cloudProviders mongodbatlas.CloudProviders err = json.Unmarshal(resp, &cloudProviders) if err != nil { - return "", fmt.Errorf("error unmashaling response %w: %s", err, string(resp)) + return "", fmt.Errorf("error unmarshaling response %w: %s", err, string(resp)) } if len(cloudProviders.Results) == 0 || len(cloudProviders.Results[0].InstanceSizes) == 0 { @@ -775,6 +775,54 @@ func createDBUserWithCert(projectID, username string) error { return nil } +func createDataFederationForProject(projectID string) (string, error) { + cliPath, err := e2e.AtlasCLIBin() + if err != nil { + return "", err + } + + n, err := e2e.RandInt(1000) + if err != nil { + return "", err + } + dataFederationName := fmt.Sprintf("e2e-data-federation-%v", n) + + cmd := exec.Command(cliPath, + datafederationEntity, + "create", + dataFederationName, + "--projectId", projectID, + "--region", "DUBLIN_IRL") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + if err != nil { + return "", fmt.Errorf("%s (%w)", string(resp), err) + } + + return dataFederationName, nil +} + +func deleteDataFederationForProject(projectID, dataFedName string) error { + cliPath, err := e2e.AtlasCLIBin() + if err != nil { + return err + } + + cmd := exec.Command(cliPath, + datafederationEntity, + "delete", + dataFedName, + "--projectId", projectID, + "--force") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("%s (%w)", string(resp), err) + } + + return nil +} + func ensureCluster(t *testing.T, cluster *atlasv2.AdvancedClusterDescription, clusterName, version string, diskSizeGB float64, terminationProtection bool) { t.Helper() a := assert.New(t) diff --git a/test/e2e/atlas/kubernetes_config_generate_test.go b/test/e2e/atlas/kubernetes_config_generate_test.go index 062cfbadd3..16ef685a79 100644 --- a/test/e2e/atlas/kubernetes_config_generate_test.go +++ b/test/e2e/atlas/kubernetes_config_generate_test.go @@ -1513,3 +1513,210 @@ func atlasBackupSchedule(objects []runtime.Object) (*atlasV1.AtlasBackupSchedule } return nil, false } + +func referenceDataFederation(name, namespace, projectName string, labels map[string]string) *atlasV1.AtlasDataFederation { + dictionary := resources.AtlasNameToKubernetesName() + return &atlasV1.AtlasDataFederation{ + TypeMeta: v1.TypeMeta{ + Kind: "AtlasDataFederation", + APIVersion: "atlas.mongodb.com/v1", + }, + ObjectMeta: v1.ObjectMeta{ + Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, name), dictionary), + Namespace: namespace, + Labels: labels, + }, + Spec: atlasV1.DataFederationSpec{ + Project: common.ResourceRefNamespaced{ + Name: resources.NormalizeAtlasName(projectName, dictionary), + Namespace: namespace, + }, + Name: name, + CloudProviderConfig: &atlasV1.CloudProviderConfig{}, + DataProcessRegion: &atlasV1.DataProcessRegion{ + CloudProvider: "AWS", + Region: "DUBLIN_IRL", + }, + Storage: &atlasV1.Storage{ + Databases: nil, + Stores: nil, + }, + }, + Status: status.DataFederationStatus{ + Common: status.Common{ + Conditions: []status.Condition{}, + }, + }, + } +} + +func TestKubernetesConfigGenerate_DataFederation(t *testing.T) { + n, err := e2e.RandInt(255) + require.NoError(t, err) + g := newAtlasE2ETestGenerator(t) + g.generateProject(fmt.Sprintf("kubernetes-%s", n)) + g.generateDataFederation() + var storeNames []string + storeNames = append(storeNames, g.dataFedName) + g.generateDataFederation() + storeNames = append(storeNames, g.dataFedName) + expectedDataFederation := referenceDataFederation(storeNames[0], targetNamespace, g.projectName, expectedLabels) + + cliPath, err := e2e.AtlasCLIBin() + require.NoError(t, err) + + // always register atlas entities + require.NoError(t, atlasV1.AddToScheme(scheme.Scheme)) + + t.Run("Generate valid resources of ONE project and ONE data federation", func(t *testing.T) { + cmd := exec.Command(cliPath, + "kubernetes", + "config", + "generate", + "--projectId", + g.projectID, + "--dataFederationName", + storeNames[0], + "--targetNamespace", + targetNamespace) + cmd.Env = os.Environ() + + resp, err := cmd.CombinedOutput() + t.Log(string(resp)) + + a := assert.New(t) + a.NoError(err, string(resp)) + + var objects []runtime.Object + t.Run("Output can be decoded", func(t *testing.T) { + objects, err = getK8SEntities(resp) + require.NoError(t, err, "should not fail on decode") + require.NotEmpty(t, objects, "result should not be empty") + }) + t.Run("Project present with valid name", func(t *testing.T) { + p, found := findAtlasProject(objects) + if !found { + t.Fatal("AtlasProject is not found in results") + } + assert.Equal(t, targetNamespace, p.Namespace) + }) + t.Run("Deployment present with valid data", func(t *testing.T) { + found := false + var datafederation *atlasV1.AtlasDataFederation + var ok bool + for i := range objects { + datafederation, ok = objects[i].(*atlasV1.AtlasDataFederation) + if ok { + found = true + break + } + } + if !found { + t.Fatal("AtlasDataFederation is not found in results") + } + a.Equal(expectedDataFederation, datafederation) + }) + }) + + t.Run("Generate valid resources of ONE project and TWO data federation", func(t *testing.T) { + cmd := exec.Command(cliPath, + "kubernetes", + "config", + "generate", + "--projectId", + g.projectID, + "--dataFederationName", + fmt.Sprintf("%s,%s", storeNames[0], storeNames[1]), + "--targetNamespace", + targetNamespace) + cmd.Env = os.Environ() + + resp, err := cmd.CombinedOutput() + t.Log(string(resp)) + + a := assert.New(t) + a.NoError(err, string(resp)) + + var objects []runtime.Object + t.Run("Output can be decoded", func(t *testing.T) { + objects, err = getK8SEntities(resp) + require.NoError(t, err, "should not fail on decode") + require.NotEmpty(t, objects, "result should not be empty") + }) + t.Run("Project present with valid name", func(t *testing.T) { + p, found := findAtlasProject(objects) + if !found { + t.Fatal("AtlasProject is not found in results") + } + assert.Equal(t, targetNamespace, p.Namespace) + }) + t.Run("Deployments present with valid data", func(t *testing.T) { + dataFeds := atlasDataFederations(objects) + require.Len(t, dataFeds, len(storeNames)) + checkDataFederationData(t, dataFeds, storeNames, targetNamespace, g.projectName) + }) + }) + + t.Run("Generate valid resources of ONE project and TWO data federation without listing data federation instances", func(t *testing.T) { + cmd := exec.Command(cliPath, + "kubernetes", + "config", + "generate", + "--projectId", + g.projectID, + "--targetNamespace", + targetNamespace) + cmd.Env = os.Environ() + + resp, err := cmd.CombinedOutput() + t.Log(string(resp)) + + a := assert.New(t) + a.NoError(err, string(resp)) + + var objects []runtime.Object + t.Run("Output can be decoded", func(t *testing.T) { + objects, err = getK8SEntities(resp) + require.NoError(t, err, "should not fail on decode") + require.NotEmpty(t, objects, "result should not be empty") + }) + t.Run("Project present with valid name", func(t *testing.T) { + p, found := findAtlasProject(objects) + if !found { + t.Fatal("AtlasProject is not found in results") + } + assert.Equal(t, targetNamespace, p.Namespace) + }) + t.Run("Deployments present with valid data", func(t *testing.T) { + dataFeds := atlasDataFederations(objects) + checkDataFederationData(t, dataFeds, storeNames, targetNamespace, g.projectName) + }) + }) +} + +func atlasDataFederations(objects []runtime.Object) []*atlasV1.AtlasDataFederation { + var df []*atlasV1.AtlasDataFederation + for i := range objects { + d, ok := objects[i].(*atlasV1.AtlasDataFederation) + if ok { + df = append(df, d) + } + } + return df +} + +func checkDataFederationData(t *testing.T, dataFederations []*atlasV1.AtlasDataFederation, dataFedNames []string, namespace, projectName string) { + t.Helper() + assert.Len(t, dataFederations, len(dataFedNames)) + var entries []string + for _, instance := range dataFederations { + if ok := search.StringInSlice(dataFedNames, instance.Spec.Name); ok { + name := instance.Spec.Name + expectedDeployment := referenceDataFederation(name, namespace, projectName, expectedLabels) + assert.Equal(t, expectedDeployment, instance) + entries = append(entries, name) + } + } + assert.Len(t, entries, len(dataFedNames)) + assert.ElementsMatch(t, dataFedNames, entries) +}