-
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-291623: Add list command for ASP PrivateLink endpoints #3655
Open
tcannon91
wants to merge
2
commits into
mongodb:master
Choose a base branch
from
tcannon91:CLOUDP-291668
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+330
−9
Open
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,88 @@ | ||
.. _atlas-streams-privateLinks-list: | ||
|
||
=============================== | ||
atlas streams privateLinks list | ||
=============================== | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 1 | ||
:class: singlecol | ||
|
||
Lists the PrivateLink endpoints in the project that can be used as Atlas Stream Processor connections. | ||
|
||
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 list [options] | ||
|
||
.. Code end marker, please don't delete this comment | ||
|
||
Options | ||
------- | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 20 10 10 60 | ||
|
||
* - Name | ||
- Type | ||
- Required | ||
- Description | ||
* - -h, --help | ||
- | ||
- false | ||
- help for list | ||
* - -o, --output | ||
- string | ||
- false | ||
- Output format. Valid values are json, json-path, go-template, or go-template-file. To see the full output, use the -o json option. | ||
* - --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:: | ||
|
||
ID PROVIDER REGION VENDOR STATE INTERFACE_ENDPOINT_ID SERVICE_ENDPOINT_ID DNS_DOMAIN DNS_SUBDOMAIN | ||
<Id> <Provider> <Region> <Vendor> <State> <InterfaceEndpointId> <ServiceEndpointId> <DnsDomain> <DnsSubDomain> | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
.. code-block:: | ||
:copyable: false | ||
|
||
# list PrivateLink endpoints for Atlas Stream Processing: | ||
atlas streams privateLink list | ||
|
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
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,87 @@ | ||
// 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/store" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var listTemplate = `ID PROVIDER REGION VENDOR STATE INTERFACE_ENDPOINT_ID SERVICE_ENDPOINT_ID DNS_DOMAIN DNS_SUBDOMAIN{{range valueOrEmptySlice .Results}} | ||
{{.Id}} {{.Provider}} {{.Region}} {{.Vendor}} {{.State}} {{.InterfaceEndpointId}} {{.ServiceEndpointId}} {{.DnsDomain}} {{.DnsSubDomain}}{{end}} | ||
` | ||
|
||
type ListOpts struct { | ||
cli.ProjectOpts | ||
cli.OutputOpts | ||
store store.PrivateLinkLister | ||
} | ||
|
||
func (opts *ListOpts) Run() error { | ||
result, err := opts.store.ListPrivateLinkEndpoints(opts.ConfigProjectID()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return opts.Print(result) | ||
} | ||
|
||
func (opts *ListOpts) 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 list | ||
// List the PrivateLink endpoints in the project that can be used as Atlas Stream Processor connections. | ||
func ListBuilder() *cobra.Command { | ||
opts := &ListOpts{} | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists the PrivateLink endpoints in the project that can be used as Atlas Stream Processor connections.", | ||
Long: fmt.Sprintf(usage.RequiredOneOfRoles, commandRoles), | ||
Args: require.NoArgs, | ||
Annotations: map[string]string{ | ||
"output": listTemplate, | ||
}, | ||
Example: `# list PrivateLink endpoints for Atlas Stream Processing: | ||
atlas streams privateLink list | ||
`, | ||
PreRunE: func(cmd *cobra.Command, _ []string) error { | ||
return opts.PreRunE( | ||
opts.ValidateProjectID, | ||
opts.initStore(cmd.Context()), | ||
opts.InitOutput(cmd.OutOrStdout(), createTemplate), | ||
) | ||
}, | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
opts.AddProjectOptsFlags(cmd) | ||
opts.AddOutputOptFlags(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,72 @@ | ||
// 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 ( | ||
"bytes" | ||
"fmt" | ||
"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/mongodb/mongodb-atlas-cli/atlascli/internal/test" | ||
"github.com/stretchr/testify/require" | ||
atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin" | ||
) | ||
|
||
func getPrivateLinkConnections() []atlasv2.StreamsPrivateLinkConnection { | ||
var connections []atlasv2.StreamsPrivateLinkConnection | ||
|
||
for i := 0; i < 5; i++ { | ||
conn := atlasv2.NewStreamsPrivateLinkConnection() | ||
conn.SetId(fmt.Sprintf("testId%d", i)) | ||
conn.SetProvider("Azure") | ||
conn.SetRegion("US_EAST_2") | ||
conn.SetServiceEndpointId("/subscriptions/fd01adff-b37e-4693-8497-83ecf183a145/resourceGroups/test-rg/providers/Microsoft.EventHub/namespaces/test-namespace") | ||
conn.SetDnsDomain("test-namespace.servicebus.windows.net") | ||
|
||
connections = append(connections, *conn) | ||
} | ||
|
||
return connections | ||
} | ||
|
||
func TestListOpts_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockPrivateLinkLister(ctrl) | ||
|
||
buf := new(bytes.Buffer) | ||
listOpts := &ListOpts{ | ||
store: mockStore, | ||
OutputOpts: cli.OutputOpts{ | ||
Template: listTemplate, | ||
OutWriter: buf, | ||
}, | ||
} | ||
|
||
connections := getPrivateLinkConnections() | ||
expected := atlasv2.NewPaginatedApiStreamsPrivateLink() | ||
expected.SetResults(connections) | ||
|
||
mockStore. | ||
EXPECT(). | ||
ListPrivateLinkEndpoints(gomock.Eq(listOpts.ConfigProjectID())). | ||
Return(expected, nil). | ||
Times(1) | ||
|
||
require.NoError(t, listOpts.Run()) | ||
test.VerifyOutputTemplate(t, listTemplate, expected) | ||
} |
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ func Builder() *cobra.Command { | |
|
||
cmd.AddCommand( | ||
CreateBuilder(), | ||
ListBuilder(), | ||
) | ||
|
||
return cmd | ||
|
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.
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.
The changes here and in other non streams files were autofixed by the cli lint command... just drive bying them.