• 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

27.12
/internal/cli/datafederation/querylimits/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-23T15:50:57+01:00. Note: Manual updates are allowed, but may be overwritten.
16

17
package querylimits
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/flag"
27
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
28
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
29
        "github.com/spf13/cobra"
30
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312018/admin"
31
)
32

33
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=create_mock_test.go -package=querylimits -source=create.go
34

35
type DataFederationQueryLimitCreator interface {
36
        CreateDataFederationQueryLimit(string, string, string, *atlasv2.DataFederationTenantQueryLimit) (*atlasv2.DataFederationTenantQueryLimit, error)
37
}
38

39
type CreateOpts struct {
40
        cli.ProjectOpts
41
        cli.OutputOpts
42
        store         DataFederationQueryLimitCreator
43
        limitName     string
44
        tenantName    string
45
        value         int64
46
        overrunPolicy string
47
}
48

49
func (opts *CreateOpts) initStore(ctx context.Context) func() error {
×
50
        return func() error {
×
51
                var err error
×
52
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
53
                return err
×
54
        }
×
55
}
56

57
var createTemplate = `Data federation query limit {{.Name}} created.`
58

59
func (opts *CreateOpts) Run() error {
1✔
60
        createRequest := opts.newCreateRequest()
1✔
61

1✔
62
        r, err := opts.store.CreateDataFederationQueryLimit(opts.ConfigProjectID(), opts.tenantName, opts.limitName, createRequest)
1✔
63
        if err != nil {
1✔
64
                return err
×
65
        }
×
66

67
        return opts.Print(r)
1✔
68
}
69

70
func (opts *CreateOpts) newCreateRequest() *atlasv2.DataFederationTenantQueryLimit {
1✔
71
        req := &atlasv2.DataFederationTenantQueryLimit{
1✔
72
                Name:       opts.limitName,
1✔
73
                TenantName: &opts.tenantName,
1✔
74
                Value:      opts.value,
1✔
75
        }
1✔
76
        if opts.overrunPolicy != "" {
2✔
77
                req.OverrunPolicy = &opts.overrunPolicy
1✔
78
        }
1✔
79
        return req
1✔
80
}
81

82
// atlas dataFederation queryLimits create <name> [--projectId projectId].
83
func CreateBuilder() *cobra.Command {
×
84
        opts := &CreateOpts{}
×
85
        cmd := &cobra.Command{
×
86
                Use:   "create <name>",
×
87
                Short: "Creates a new Data Federation query limit.",
×
88
                Long:  "To learn more about the query limits, see https://dochub.mongodb.org/core/adf-query-limits." + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
89
                Args:  require.ExactArgs(1),
×
90
                Annotations: map[string]string{
×
91
                        "nameDesc": "Identifier of the data federation query limit.",
×
92
                        "output":   createTemplate,
×
93
                },
×
94
                Example: `# create data federation query limit:
×
95
  atlas dataFederation queryLimit create bytesProcessed.query --value 1000 --dataFederation DataFederation1
×
96
`,
×
97
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
98
                        opts.limitName = args[0]
×
99
                        return opts.PreRunE(
×
100
                                opts.ValidateProjectID,
×
101
                                opts.initStore(cmd.Context()),
×
102
                                opts.InitOutput(cmd.OutOrStdout(), createTemplate),
×
103
                        )
×
104
                },
×
105
                RunE: func(_ *cobra.Command, _ []string) error {
×
106
                        return opts.Run()
×
107
                },
×
108
        }
109

110
        cmd.Flags().Int64Var(&opts.value, flag.Value, 0, usage.DataFederationQueryLimitValue)
×
111
        cmd.Flags().StringVar(&opts.overrunPolicy, flag.OverrunPolicy, "", usage.OverrunPolicy)
×
112
        cmd.Flags().StringVar(&opts.tenantName, flag.DataFederation, "", usage.DataFederation)
×
113
        opts.AddProjectOptsFlags(cmd)
×
114
        opts.AddOutputOptFlags(cmd)
×
115

×
116
        _ = cmd.MarkFlagRequired(flag.DataFederation)
×
117
        _ = cmd.MarkFlagRequired(flag.Value)
×
118

×
119
        return cmd
×
120
}
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