Skip to content

Commit 506d40f

Browse files
committed
CLOUDP-291622: Add delete command for Atlas Stream Processing PrivateLinks
1 parent 8dc44f2 commit 506d40f

File tree

9 files changed

+339
-2
lines changed

9 files changed

+339
-2
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
.. _atlas-streams-privateLinks-delete:
2+
3+
=================================
4+
atlas streams privateLinks delete
5+
=================================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Deletes an Atlas Stream Processing PrivateLink endpoint.
16+
17+
To use this command, you must authenticate with a user account or an API key with any of the following roles: Project Owner, Project Stream Processing Owner.
18+
19+
Syntax
20+
------
21+
22+
.. code-block::
23+
:caption: Command Syntax
24+
25+
atlas streams privateLinks delete <connectionID> [options]
26+
27+
.. Code end marker, please don't delete this comment
28+
29+
Arguments
30+
---------
31+
32+
.. list-table::
33+
:header-rows: 1
34+
:widths: 20 10 10 60
35+
36+
* - Name
37+
- Type
38+
- Required
39+
- Description
40+
* - connectionID
41+
- string
42+
- true
43+
- ID of the PrivateLink endpoint.
44+
45+
Options
46+
-------
47+
48+
.. list-table::
49+
:header-rows: 1
50+
:widths: 20 10 10 60
51+
52+
* - Name
53+
- Type
54+
- Required
55+
- Description
56+
* - --force
57+
-
58+
- false
59+
- Flag that indicates whether to skip the confirmation prompt before proceeding with the requested action.
60+
* - -h, --help
61+
-
62+
- false
63+
- help for delete
64+
* - --projectId
65+
- string
66+
- false
67+
- Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable.
68+
69+
Inherited Options
70+
-----------------
71+
72+
.. list-table::
73+
:header-rows: 1
74+
:widths: 20 10 10 60
75+
76+
* - Name
77+
- Type
78+
- Required
79+
- Description
80+
* - -P, --profile
81+
- string
82+
- false
83+
- Name of the profile to use from your configuration file. To learn about profiles for the Atlas CLI, see https://dochub.mongodb.org/core/atlas-cli-save-connection-settings.
84+
85+
Output
86+
------
87+
88+
If the command succeeds, the CLI returns output similar to the following sample. Values in brackets represent your values.
89+
90+
.. code-block::
91+
92+
Atlas Stream Processing PrivateLink endpoint '<Name>' deleted.
93+
94+
95+
Examples
96+
--------
97+
98+
.. code-block::
99+
:copyable: false
100+
101+
# delete an Atlas Stream Processing PrivateLink endpoint:
102+
atlas streams privateLink delete 5e2211c17a3e5a48f5497de3
103+

docs/command/atlas-streams-privateLinks.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Related Commands
5252
----------------
5353

5454
* :ref:`atlas-streams-privateLinks-create` - Creates a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
55+
* :ref:`atlas-streams-privateLinks-delete` - Deletes an Atlas Stream Processing PrivateLink endpoint.
5556
* :ref:`atlas-streams-privateLinks-describe` - Describes a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
5657
* :ref:`atlas-streams-privateLinks-list` - Lists the PrivateLink endpoints in the project that can be used as Atlas Stream Processor connections.
5758

@@ -60,6 +61,7 @@ Related Commands
6061
:titlesonly:
6162

6263
create </command/atlas-streams-privateLinks-create>
64+
delete </command/atlas-streams-privateLinks-delete>
6365
describe </command/atlas-streams-privateLinks-describe>
6466
list </command/atlas-streams-privateLinks-list>
6567

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2025 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 privatelink
16+
17+
import (
18+
"context"
19+
"fmt"
20+
21+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
22+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
23+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
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+
)
29+
30+
var successDeleteTemplate = "Atlas Stream Processing PrivateLink endpoint '%s' deleted.\n"
31+
var failDeleteTemplate = "Atlas Stream Processing PrivateLink endpoint not deleted"
32+
33+
type DeleteOpts struct {
34+
cli.ProjectOpts
35+
*cli.DeleteOpts
36+
store store.PrivateLinkDeleter
37+
}
38+
39+
func (opts *DeleteOpts) Run() error {
40+
return opts.Delete(opts.store.DeletePrivateLinkEndpoint, opts.ConfigProjectID())
41+
}
42+
43+
func (opts *DeleteOpts) initStore(ctx context.Context) func() error {
44+
return func() error {
45+
var err error
46+
opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
47+
return err
48+
}
49+
}
50+
51+
// atlas streams privateLink deleted <connectionID>
52+
// Deletes a PrivateLink endpoint.
53+
func DeleteBuilder() *cobra.Command {
54+
opts := &DeleteOpts{
55+
DeleteOpts: cli.NewDeleteOpts(successDeleteTemplate, failDeleteTemplate),
56+
}
57+
cmd := &cobra.Command{
58+
Use: "delete <connectionID>",
59+
Aliases: []string{"rm"},
60+
Short: "Deletes an Atlas Stream Processing PrivateLink endpoint.",
61+
Long: fmt.Sprintf(usage.RequiredOneOfRoles, commandRoles),
62+
Args: require.ExactArgs(1),
63+
Annotations: map[string]string{
64+
"connectionIDDesc": "ID of the PrivateLink endpoint.",
65+
"output": successDeleteTemplate,
66+
},
67+
Example: `# delete an Atlas Stream Processing PrivateLink endpoint:
68+
atlas streams privateLink delete 5e2211c17a3e5a48f5497de3
69+
`,
70+
PreRunE: func(cmd *cobra.Command, args []string) error {
71+
if err := opts.PreRunE(
72+
opts.ValidateProjectID,
73+
opts.initStore(cmd.Context()),
74+
); err != nil {
75+
return err
76+
}
77+
opts.Entry = args[0]
78+
return opts.Prompt()
79+
},
80+
RunE: func(_ *cobra.Command, _ []string) error {
81+
return opts.Run()
82+
},
83+
}
84+
85+
cmd.Flags().BoolVar(&opts.Confirm, flag.Force, false, usage.Force)
86+
87+
opts.AddProjectOptsFlags(cmd)
88+
89+
return cmd
90+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2025 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 privatelink
16+
17+
import (
18+
"testing"
19+
20+
"github.com/golang/mock/gomock"
21+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
22+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestDeleteOpts_Run(t *testing.T) {
27+
t.Run("should call the store delete privateLink method with the correct parameters", func(t *testing.T) {
28+
ctrl := gomock.NewController(t)
29+
mockStore := mocks.NewMockPrivateLinkDeleter(ctrl)
30+
31+
const projectID = "a-project-id"
32+
const connectionID = "the-connection-id"
33+
34+
deleteOpts := &DeleteOpts{
35+
store: mockStore,
36+
ProjectOpts: cli.ProjectOpts{
37+
ProjectID: projectID,
38+
},
39+
DeleteOpts: &cli.DeleteOpts{
40+
Confirm: true,
41+
Entry: connectionID,
42+
},
43+
}
44+
45+
mockStore.
46+
EXPECT().
47+
DeletePrivateLinkEndpoint(gomock.Eq(projectID), gomock.Eq(connectionID)).
48+
Times(1)
49+
50+
require.NoError(t, deleteOpts.Run())
51+
})
52+
53+
t.Run("should delete without error", func(t *testing.T) {
54+
ctrl := gomock.NewController(t)
55+
mockStore := mocks.NewMockPrivateLinkDeleter(ctrl)
56+
57+
deleteOpts := &DeleteOpts{
58+
DeleteOpts: &cli.DeleteOpts{
59+
Entry: "some-connection-id",
60+
Confirm: true,
61+
},
62+
store: mockStore,
63+
}
64+
65+
mockStore.
66+
EXPECT().
67+
DeletePrivateLinkEndpoint(gomock.Any(), gomock.Any()).
68+
Return(nil).
69+
Times(1)
70+
71+
err := deleteOpts.Run()
72+
73+
require.NoError(t, err)
74+
})
75+
}

internal/cli/streams/privatelink/privatelink.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func Builder() *cobra.Command {
3636
CreateBuilder(),
3737
ListBuilder(),
3838
DescribeBuilder(),
39+
DeleteBuilder(),
3940
)
4041

4142
return cmd

internal/mocks/mock_streams.go

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/store/streams.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
atlasv2 "go.mongodb.org/atlas-sdk/v20241113005/admin"
2222
)
2323

24-
//go:generate mockgen -destination=../mocks/mock_streams.go -package=mocks github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store StreamsLister,StreamsDescriber,StreamsCreator,StreamsDeleter,StreamsUpdater,StreamsDownloader,ConnectionCreator,ConnectionDeleter,ConnectionUpdater,StreamsConnectionDescriber,StreamsConnectionLister,PrivateLinkCreator,PrivateLinkLister,PrivateLinkDescriber
24+
//go:generate mockgen -destination=../mocks/mock_streams.go -package=mocks github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store StreamsLister,StreamsDescriber,StreamsCreator,StreamsDeleter,StreamsUpdater,StreamsDownloader,ConnectionCreator,ConnectionDeleter,ConnectionUpdater,StreamsConnectionDescriber,StreamsConnectionLister,PrivateLinkCreator,PrivateLinkLister,PrivateLinkDescriber,PrivateLinkDeleter
2525

2626
type StreamsLister interface {
2727
ProjectStreams(*atlasv2.ListStreamInstancesApiParams) (*atlasv2.PaginatedApiStreamsTenant, error)
@@ -79,6 +79,10 @@ type PrivateLinkDescriber interface {
7979
DescribePrivateLinkEndpoint(projectID, connectionID string) (*atlasv2.StreamsPrivateLinkConnection, error)
8080
}
8181

82+
type PrivateLinkDeleter interface {
83+
DeletePrivateLinkEndpoint(projectID, connectionID string) error
84+
}
85+
8286
func (s *Store) ProjectStreams(opts *atlasv2.ListStreamInstancesApiParams) (*atlasv2.PaginatedApiStreamsTenant, error) {
8387
result, _, err := s.clientv2.StreamsApi.ListStreamInstancesWithParams(s.ctx, opts).Execute()
8488
return result, err
@@ -159,3 +163,8 @@ func (s *Store) DescribePrivateLinkEndpoint(projectID, connectionID string) (*at
159163
result, _, err := s.clientv2.StreamsApi.GetPrivateLinkConnection(s.ctx, projectID, connectionID).Execute()
160164
return result, err
161165
}
166+
167+
func (s *Store) DeletePrivateLinkEndpoint(projectID, connectionID string) error {
168+
_, _, err := s.clientv2.StreamsApi.DeletePrivateLinkConnection(s.ctx, projectID, connectionID).Execute()
169+
return err
170+
}

test/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
| `streams privateLink create` | Y | Y |
198198
| `streams privateLink list` | Y | Y |
199199
| `streams privateLink describe` | Y | Y |
200+
| `streams privateLink delete` | Y | Y |
200201
| `config` | | |
201202
| `completion` | Y | Y |
202203
| `config delete` | Y | Y |

0 commit comments

Comments
 (0)