• 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

19.3
/internal/cli/integrations/create/datadog.go
1
// Copyright 2020 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
package create
16

17
import (
18
        "context"
19
        "fmt"
20

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

31
var datadogType = "DATADOG"
32

33
type DatadogOpts struct {
34
        cli.ProjectOpts
35
        cli.OutputOpts
36
        apiKey string
37
        region string
38
        store  IntegrationCreator
39
}
40

41
func (opts *DatadogOpts) initStore(ctx context.Context) func() error {
×
42
        return func() error {
×
43
                var err error
×
44
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
45
                return err
×
46
        }
×
47
}
48

49
var createTemplateDatadog = "Datadog integration configured.\n"
50

51
func (opts *DatadogOpts) Run() error {
1✔
52
        r, err := opts.store.CreateIntegration(opts.ConfigProjectID(), datadogType, opts.newDatadogIntegration())
1✔
53
        if err != nil {
1✔
54
                return err
×
55
        }
×
56
        return opts.Print(r)
1✔
57
}
58

59
func (opts *DatadogOpts) newDatadogIntegration() *atlasv2.ThirdPartyIntegration {
1✔
60
        return &atlasv2.ThirdPartyIntegration{
1✔
61
                Type:   &datadogType,
1✔
62
                ApiKey: &opts.apiKey,
1✔
63
                Region: &opts.region,
1✔
64
        }
1✔
65
}
1✔
66

67
// atlas integration(s) create DATADOG --apiKey apiKey --region region [--projectId projectId].
68
func DatadogBuilder() *cobra.Command {
×
69
        opts := &DatadogOpts{}
×
70
        cmd := &cobra.Command{
×
71
                Use:     datadogType,
×
72
                Aliases: []string{"datadog"},
×
73
                Short:   "Create or update a Datadog integration for your project.",
×
74
                Long: `The requesting API key must have the Organization Owner or Project Owner role to configure an integration with Datadog.
×
75

×
76
After you integrate with Datadog, you can send metric data about your project to your Datadog dashboard. To learn more about the metrics available to Datadog, see https://www.mongodb.com/docs/atlas/tutorial/datadog-integration/.
×
77
                
×
78
Datadog integration is available only for M10+ clusters.
×
79

×
80
` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
81
                Annotations: map[string]string{
×
82
                        "output": createTemplateDatadog,
×
83
                },
×
84
                Args: require.NoArgs,
×
85
                Example: `  # Integrate Datadog with Atlas for the project with the ID 5e2211c17a3e5a48f5497de3:
×
86
  atlas integrations create DATADOG --apiKey a1a23bcdef45ghijk6789 --projectId 5e2211c17a3e5a48f5497de3 --output json`,
×
87
                PreRunE: func(cmd *cobra.Command, _ []string) error {
×
88
                        return opts.PreRunE(
×
89
                                opts.ValidateProjectID,
×
90
                                opts.initStore(cmd.Context()),
×
91
                                opts.InitOutput(cmd.OutOrStdout(), createTemplateDatadog),
×
92
                        )
×
93
                },
×
94
                RunE: func(_ *cobra.Command, _ []string) error {
×
95
                        return opts.Run()
×
96
                },
×
97
        }
98

99
        cmd.Flags().StringVar(&opts.apiKey, flag.APIKey, "", usage.DatadogAPIKey)
×
100
        cmd.Flags().StringVar(&opts.region, flag.Region, "US", usage.DatadogAPIRegion)
×
101

×
102
        opts.AddProjectOptsFlags(cmd)
×
103
        opts.AddOutputOptFlags(cmd)
×
104

×
105
        _ = cmd.MarkFlagRequired(flag.APIKey)
×
106

×
107
        return cmd
×
108
}
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