• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb / mongodb-atlas-cli / 26228926989

21 May 2026 01:27PM UTC coverage: 22.63% (-41.6%) from 64.198%
26228926989

push

github

apix-bot[bot]
Update compliance report for v1.55.0

8987 of 39713 relevant lines covered (22.63%)

0.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.07
/internal/cli/datafederation/create.go
1
// Copyright 2023 MongoDB Inc
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
// This code was autogenerated at 2023-06-21T13:32:21+01:00. Note: Manual updates are allowed, but may be overwritten.
16

17
package datafederation
18

19
import (
20
        "context"
21
        "fmt"
22

23
        "github.com/mongodb/atlas-cli-core/config"
24
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
25
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
26
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/file"
27
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
28
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
29
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
30
        "github.com/spf13/afero"
31
        "github.com/spf13/cobra"
32
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312018/admin"
33
)
34

35
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=create_mock_test.go -package=datafederation -source=create.go
36

37
type Creator interface {
38
        CreateDataFederation(string, *atlasv2.DataLakeTenant) (*atlasv2.DataLakeTenant, error)
39
}
40

41
type CreateOpts struct {
42
        cli.ProjectOpts
43
        cli.OutputOpts
44
        store         Creator
45
        fs            afero.Fs
46
        name          string
47
        filename      string
48
        region        string
49
        awsRoleID     string
50
        awsTestBucket string
51
}
52

53
func (opts *CreateOpts) initStore(ctx context.Context) func() error {
×
54
        return func() error {
×
55
                var err error
×
56
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
57
                return err
×
58
        }
×
59
}
60

61
var createTemplate = `Data federation {{.Name}} created.`
62

63
func (opts *CreateOpts) Run() error {
1✔
64
        createRequest, err := opts.newCreateRequest()
1✔
65
        if err != nil {
1✔
66
                return err
×
67
        }
×
68

69
        r, err := opts.store.CreateDataFederation(opts.ConfigProjectID(), createRequest)
1✔
70
        if err != nil {
1✔
71
                return err
×
72
        }
×
73

74
        return opts.Print(r)
1✔
75
}
76

77
func (opts *CreateOpts) newCreateRequest() (*atlasv2.DataLakeTenant, error) {
1✔
78
        if opts.filename != "" {
1✔
79
                tenant := atlasv2.DataLakeTenant{}
×
80
                if err := file.Load(opts.fs, opts.filename, &tenant); err != nil {
×
81
                        return nil, err
×
82
                }
×
83
                tenant.Name = &opts.name
×
84
                return &tenant, nil
×
85
        }
86

87
        ret := atlasv2.NewDataLakeTenant()
1✔
88
        ret.Name = &opts.name
1✔
89

1✔
90
        if opts.region != "" {
1✔
91
                ret.DataProcessRegion = &atlasv2.DataLakeDataProcessRegion{
×
92
                        CloudProvider: "AWS",
×
93
                        Region:        opts.region,
×
94
                }
×
95
        }
×
96

97
        if opts.awsRoleID != "" || opts.awsTestBucket != "" {
1✔
98
                ret.CloudProviderConfig = &atlasv2.DataLakeCloudProviderConfig{
×
99
                        Aws: &atlasv2.DataLakeAWSCloudProviderConfig{
×
100
                                RoleId:       opts.awsRoleID,
×
101
                                TestS3Bucket: opts.awsTestBucket,
×
102
                        },
×
103
                }
×
104
        }
×
105

106
        return ret, nil
1✔
107
}
108

109
// atlas dataFederation create <name> [--projectId projectId].
110
func CreateBuilder() *cobra.Command {
×
111
        opts := &CreateOpts{
×
112
                fs: afero.NewOsFs(),
×
113
        }
×
114
        cmd := &cobra.Command{
×
115
                Use:   "create <name>",
×
116
                Short: "Creates a new Data Federation database.",
×
117
                Long:  fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
118
                Args:  require.ExactArgs(1),
×
119
                Annotations: map[string]string{
×
120
                        "nameDesc": "Name of the data federation database.",
×
121
                        "output":   createTemplate,
×
122
                },
×
123
                Example: `# create data federation database:
×
124
  atlas dataFederation create DataFederation1 --region us_east_1 --awsRoleId role --awsTestS3Bucket bucket
×
125
`,
×
126
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
127
                        opts.name = args[0]
×
128
                        return opts.PreRunE(
×
129
                                opts.ValidateProjectID,
×
130
                                opts.initStore(cmd.Context()),
×
131
                                opts.InitOutput(cmd.OutOrStdout(), createTemplate),
×
132
                        )
×
133
                },
×
134
                RunE: func(_ *cobra.Command, _ []string) error {
×
135
                        return opts.Run()
×
136
                },
×
137
        }
138

139
        cmd.Flags().StringVar(&opts.region, flag.Region, "", usage.DataLakeRegion)
×
140
        cmd.Flags().StringVar(&opts.awsRoleID, flag.AWSRoleID, "", usage.DataLakeRole)
×
141
        cmd.Flags().StringVar(&opts.awsTestBucket, flag.AWSTestS3Bucket, "", usage.DataLakeTestBucket)
×
142
        cmd.Flags().StringVarP(&opts.filename, flag.File, flag.FileShort, "", usage.DataFederationFile)
×
143

×
144
        cmd.MarkFlagsMutuallyExclusive(flag.File, flag.Region)
×
145
        cmd.MarkFlagsMutuallyExclusive(flag.File, flag.AWSRoleID)
×
146
        cmd.MarkFlagsMutuallyExclusive(flag.File, flag.AWSTestS3Bucket)
×
147

×
148
        opts.AddProjectOptsFlags(cmd)
×
149
        opts.AddOutputOptFlags(cmd)
×
150

×
151
        return cmd
×
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc