-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLOUDP-291622: Add delete command for Atlas Stream Processing PrivateLinks #3671
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
.. _atlas-streams-privateLinks-delete: | ||
|
||
================================= | ||
atlas streams privateLinks delete | ||
================================= | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 1 | ||
:class: singlecol | ||
|
||
Deletes an Atlas Stream Processing PrivateLink endpoint. | ||
|
||
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. | ||
|
||
Syntax | ||
------ | ||
|
||
.. code-block:: | ||
:caption: Command Syntax | ||
|
||
atlas streams privateLinks delete <connectionID> [options] | ||
|
||
.. Code end marker, please don't delete this comment | ||
|
||
Arguments | ||
--------- | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 20 10 10 60 | ||
|
||
* - Name | ||
- Type | ||
- Required | ||
- Description | ||
* - connectionID | ||
- string | ||
- true | ||
- ID of the PrivateLink endpoint. | ||
|
||
Options | ||
------- | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 20 10 10 60 | ||
|
||
* - Name | ||
- Type | ||
- Required | ||
- Description | ||
* - --force | ||
- | ||
- false | ||
- Flag that indicates whether to skip the confirmation prompt before proceeding with the requested action. | ||
* - -h, --help | ||
- | ||
- false | ||
- help for delete | ||
* - --projectId | ||
- string | ||
- false | ||
- Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable. | ||
|
||
Inherited Options | ||
----------------- | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 20 10 10 60 | ||
|
||
* - Name | ||
- Type | ||
- Required | ||
- Description | ||
* - -P, --profile | ||
- string | ||
- false | ||
- 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. | ||
|
||
Output | ||
------ | ||
|
||
If the command succeeds, the CLI returns output similar to the following sample. Values in brackets represent your values. | ||
|
||
.. code-block:: | ||
|
||
Atlas Stream Processing PrivateLink endpoint '<Name>' deleted. | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
.. code-block:: | ||
:copyable: false | ||
|
||
# delete an Atlas Stream Processing PrivateLink endpoint: | ||
atlas streams privateLink delete 5e2211c17a3e5a48f5497de3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2025 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package privatelink | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var successDeleteTemplate = "Atlas Stream Processing PrivateLink endpoint '%s' deleted.\n" | ||
var failDeleteTemplate = "Atlas Stream Processing PrivateLink endpoint not deleted" | ||
|
||
type DeleteOpts struct { | ||
cli.ProjectOpts | ||
*cli.DeleteOpts | ||
store store.PrivateLinkDeleter | ||
} | ||
|
||
func (opts *DeleteOpts) Run() error { | ||
return opts.Delete(opts.store.DeletePrivateLinkEndpoint, opts.ConfigProjectID()) | ||
} | ||
|
||
func (opts *DeleteOpts) initStore(ctx context.Context) func() error { | ||
return func() error { | ||
var err error | ||
opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx)) | ||
return err | ||
} | ||
} | ||
|
||
// atlas streams privateLink deleted <connectionID> | ||
// Deletes a PrivateLink endpoint. | ||
func DeleteBuilder() *cobra.Command { | ||
opts := &DeleteOpts{ | ||
DeleteOpts: cli.NewDeleteOpts(successDeleteTemplate, failDeleteTemplate), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "delete <connectionID>", | ||
Aliases: []string{"rm"}, | ||
Short: "Deletes an Atlas Stream Processing PrivateLink endpoint.", | ||
Long: fmt.Sprintf(usage.RequiredOneOfRoles, commandRoles), | ||
Args: require.ExactArgs(1), | ||
Annotations: map[string]string{ | ||
"connectionIDDesc": "ID of the PrivateLink endpoint.", | ||
"output": successDeleteTemplate, | ||
}, | ||
Example: `# delete an Atlas Stream Processing PrivateLink endpoint: | ||
atlas streams privateLink delete 5e2211c17a3e5a48f5497de3 | ||
`, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
if err := opts.PreRunE( | ||
opts.ValidateProjectID, | ||
opts.initStore(cmd.Context()), | ||
); err != nil { | ||
return err | ||
} | ||
opts.Entry = args[0] | ||
return opts.Prompt() | ||
}, | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&opts.Confirm, flag.Force, false, usage.Force) | ||
|
||
opts.AddProjectOptsFlags(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2025 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package privatelink | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDeleteOpts_Run(t *testing.T) { | ||
t.Run("should call the store delete privateLink method with the correct parameters", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockPrivateLinkDeleter(ctrl) | ||
|
||
const projectID = "a-project-id" | ||
const connectionID = "the-connection-id" | ||
|
||
deleteOpts := &DeleteOpts{ | ||
store: mockStore, | ||
ProjectOpts: cli.ProjectOpts{ | ||
ProjectID: projectID, | ||
}, | ||
DeleteOpts: &cli.DeleteOpts{ | ||
Confirm: true, | ||
Entry: connectionID, | ||
}, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
DeletePrivateLinkEndpoint(gomock.Eq(projectID), gomock.Eq(connectionID)). | ||
Times(1) | ||
|
||
require.NoError(t, deleteOpts.Run()) | ||
}) | ||
|
||
t.Run("should delete without error", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockPrivateLinkDeleter(ctrl) | ||
|
||
deleteOpts := &DeleteOpts{ | ||
DeleteOpts: &cli.DeleteOpts{ | ||
Entry: "some-connection-id", | ||
Confirm: true, | ||
}, | ||
store: mockStore, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
DeletePrivateLinkEndpoint(gomock.Any(), gomock.Any()). | ||
Return(nil). | ||
Times(1) | ||
|
||
err := deleteOpts.Run() | ||
|
||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("should not call delete if confirm is false", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockPrivateLinkDeleter(ctrl) | ||
|
||
deleteOpts := &DeleteOpts{ | ||
DeleteOpts: &cli.DeleteOpts{ | ||
Entry: "another-connection-id", | ||
Confirm: false, | ||
}, | ||
store: mockStore, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
DeletePrivateLinkEndpoint(gomock.Any(), gomock.Any()). | ||
Times(0) | ||
|
||
err := deleteOpts.Run() | ||
|
||
require.NoError(t, err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to have tests asserting the success and failure templates? I can see an argument that is validating the cli delete helper so feel free to tell me "no" 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found a clean way to check this in unit tests and we aren't verifying the output for other delete tests.
I added an additional test for the non-confirm delete case and we have an e2e test that verifies output for a successful delete.