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

mongodb / mongodb-atlas-cli / 25848964073

14 May 2026 07:59AM UTC coverage: 22.479% (-41.3%) from 63.771%
25848964073

push

github

web-flow
build(deps): bump test-summary/action from 2.4 to 2.6 (#4576)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

8987 of 39979 relevant lines covered (22.48%)

0.25 hits per line

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

6.52
/internal/cli/dbusers/delete.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 dbusers
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/convert"
25
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
26
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
27
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
28
        "github.com/spf13/cobra"
29
)
30

31
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=delete_mock_test.go -package=dbusers -source=delete.go
32

33
type DatabaseUserDeleter interface {
34
        DeleteDatabaseUser(string, string, string) error
35
}
36

37
type DeleteOpts struct {
38
        cli.ProjectOpts
39
        *cli.DeleteOpts
40
        authDB string
41
        store  DatabaseUserDeleter
42
}
43

44
func (opts *DeleteOpts) initStore(ctx context.Context) func() error {
×
45
        return func() error {
×
46
                var err error
×
47
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
48
                return err
×
49
        }
×
50
}
51

52
func (opts *DeleteOpts) Run() error {
1✔
53
        return opts.Delete(opts.store.DeleteDatabaseUser, opts.authDB, opts.ConfigProjectID())
1✔
54
}
1✔
55

56
// atlas dbuser(s) delete <username> --force.
57
func DeleteBuilder() *cobra.Command {
×
58
        opts := &DeleteOpts{
×
59
                DeleteOpts: cli.NewDeleteOpts("DB user '%s' deleted\n", "DB user not deleted"),
×
60
        }
×
61
        cmd := &cobra.Command{
×
62
                Use:     "delete <username>",
×
63
                Aliases: []string{"rm"},
×
64
                Short:   "Remove the specified database user from your project.",
×
65
                Long:    fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
66
                Args:    require.ExactArgs(1),
×
67
                Annotations: map[string]string{
×
68
                        "usernameDesc": "Username to delete from the MongoDB database. The format of the username depends on the user's method of authentication.",
×
69
                        "output":       opts.SuccessMessage(),
×
70
                },
×
71
                Example: `  # Delete the SCRAM SHA-authenticating database user named dylan for the project with the ID 5e2211c17a3e5a48f5497de3:
×
72
  atlas dbusers delete dylan --projectId 5e2211c17a3e5a48f5497de3
×
73

×
74
  # Delete the AWS IAM-authenticating database user with the ARN arn:aws:iam::123456789012:user/sales/enterprise/DylanBloggs for the project with ID 5e2211c17a3e5a48f5497de3. Prepend $external with \ to escape the special-use character:
×
75
  atlas dbusers delete arn:aws:iam::123456789012:user/sales/enterprise/DylanBloggs --authDB \$external --projectId 5e2211c17a3e5a48f5497de3
×
76
                        
×
77
  # Delete the xLDAP-authenticating database user with the RFC 2253 Distinguished Name CN=Dylan Bloggs,OU=Enterprise,OU=Sales,DC=Example,DC=COM for the project with ID 5e2211c17a3e5a48f5497de3. Prepend $external with \ to escape the special-use character:
×
78
  atlas dbusers delete CN=Dylan Bloggs,OU=Enterprise,OU=Sales,DC=Example,DC=COM --authDB \$external --projectId 5e2211c17a3e5a48f5497de3`,
×
79
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
80
                        if err := opts.PreRunE(opts.ValidateProjectID, opts.initStore(cmd.Context())); err != nil {
×
81
                                return err
×
82
                        }
×
83
                        opts.Entry = args[0]
×
84
                        return opts.Prompt()
×
85
                },
86
                RunE: func(_ *cobra.Command, _ []string) error {
×
87
                        return opts.Run()
×
88
                },
×
89
        }
90

91
        cmd.Flags().BoolVar(&opts.Confirm, flag.Force, false, usage.Force)
×
92
        cmd.Flags().StringVar(&opts.authDB, flag.AuthDB, convert.AdminDB, usage.AtlasAuthDB)
×
93

×
94
        opts.AddProjectOptsFlags(cmd)
×
95

×
96
        return cmd
×
97
}
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