• 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

20.37
/internal/cli/integrations/create/webhook.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 webhookIntegrationType = "WEBHOOK"
32

33
type WebhookOpts struct {
34
        cli.ProjectOpts
35
        cli.OutputOpts
36
        url    string
37
        secret string
38
        store  IntegrationCreator
39
}
40

41
func (opts *WebhookOpts) 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 createTemplateWebhook = "Webhook integration configured.\n"
50

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

59
func (opts *WebhookOpts) newWebhookIntegration() *atlasv2.ThirdPartyIntegration {
1✔
60
        return &atlasv2.ThirdPartyIntegration{
1✔
61
                Type:   &webhookIntegrationType,
1✔
62
                Url:    &opts.url,
1✔
63
                Secret: &opts.secret,
1✔
64
        }
1✔
65
}
1✔
66

67
// atlas integration(s) create WEBHOOK --url url --secret secret [--projectId projectId].
68
func WebhookBuilder() *cobra.Command {
×
69
        opts := &WebhookOpts{}
×
70
        cmd := &cobra.Command{
×
71
                Use:     webhookIntegrationType,
×
72
                Aliases: []string{"webhook"},
×
73
                Short:   "Create or update a webhook integration for your project.",
×
74
                Long: `The requesting API key must have the Organization Owner or Project Owner role to configure a webhook integration.
×
75

×
76
` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
77
                Annotations: map[string]string{
×
78
                        "output": createTemplateWebhook,
×
79
                },
×
80
                Example: `  # Integrate a webhook with Atlas that uses the secret mySecret for the project with the ID 5e2211c17a3e5a48f5497de3:
×
81
  atlas integrations create WEBHOOK --url http://9b4ac7aa.abc.io/payload --secret mySecret --projectId 5e2211c17a3e5a48f5497de3 --output json`,
×
82
                Args: require.NoArgs,
×
83
                PreRunE: func(cmd *cobra.Command, _ []string) error {
×
84
                        return opts.PreRunE(
×
85
                                opts.ValidateProjectID,
×
86
                                opts.initStore(cmd.Context()),
×
87
                                opts.InitOutput(cmd.OutOrStdout(), createTemplateWebhook),
×
88
                        )
×
89
                },
×
90
                RunE: func(_ *cobra.Command, _ []string) error {
×
91
                        return opts.Run()
×
92
                },
×
93
        }
94

95
        cmd.Flags().StringVar(&opts.url, flag.URL, "", usage.URL)
×
96
        cmd.Flags().StringVar(&opts.secret, flag.Secret, "", usage.Secret)
×
97

×
98
        opts.AddProjectOptsFlags(cmd)
×
99
        opts.AddOutputOptFlags(cmd)
×
100

×
101
        _ = cmd.MarkFlagRequired(flag.URL)
×
102
        _ = cmd.MarkFlagRequired(flag.Secret)
×
103

×
104
        return cmd
×
105
}
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