Skip to content

Commit 231beb6

Browse files
committed
CLOUDP-291668: Add list command for ASP PrivateLink endpoints
1 parent 32b812f commit 231beb6

File tree

9 files changed

+325
-2
lines changed

9 files changed

+325
-2
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
.. _atlas-streams-privateLinks-list:
2+
3+
===============================
4+
atlas streams privateLinks list
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+
Lists the PrivateLink endpoints in the project that can be used as Atlas Stream Processor connections.
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 list [options]
26+
27+
.. Code end marker, please don't delete this comment
28+
29+
Options
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+
* - -h, --help
41+
-
42+
- false
43+
- help for list
44+
* - -o, --output
45+
- string
46+
- false
47+
- Output format. Valid values are json, json-path, go-template, or go-template-file. To see the full output, use the -o json option.
48+
* - --projectId
49+
- string
50+
- false
51+
- Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable.
52+
53+
Inherited Options
54+
-----------------
55+
56+
.. list-table::
57+
:header-rows: 1
58+
:widths: 20 10 10 60
59+
60+
* - Name
61+
- Type
62+
- Required
63+
- Description
64+
* - -P, --profile
65+
- string
66+
- false
67+
- 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.
68+
69+
Output
70+
------
71+
72+
If the command succeeds, the CLI returns output similar to the following sample. Values in brackets represent your values.
73+
74+
.. code-block::
75+
76+
ID PROVIDER REGION VENDOR STATE INTERFACE_ENDPOINT_ID SERVICE_ENDPOINT_ID DNS_DOMAIN DNS_SUBDOMAIN
77+
<Id> <Provider> <Region> <Vendor> <State> <InterfaceEndpointId> <ServiceEndpointId> <DnsDomain> <DnsSubDomain>
78+
79+
80+
Examples
81+
--------
82+
83+
.. code-block::
84+
:copyable: false
85+
86+
# list PrivateLink endpoints for Atlas Stream Processing:
87+
atlas streams privateLink list
88+

docs/command/atlas-streams-privateLinks.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ Related Commands
5353

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

5758

5859
.. toctree::
5960
:titlesonly:
6061

6162
create </command/atlas-streams-privateLinks-create>
6263
describe </command/atlas-streams-privateLinks-describe>
64+
list </command/atlas-streams-privateLinks-list>
6365

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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/store"
25+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
26+
"github.com/spf13/cobra"
27+
)
28+
29+
var listTemplate = `ID PROVIDER REGION VENDOR STATE INTERFACE_ENDPOINT_ID SERVICE_ENDPOINT_ID DNS_DOMAIN DNS_SUBDOMAIN{{range valueOrEmptySlice .Results}}
30+
{{.Id}} {{.Provider}} {{.Region}} {{.Vendor}} {{.State}} {{.InterfaceEndpointId}} {{.ServiceEndpointId}} {{.DnsDomain}} {{.DnsSubDomain}}{{end}}
31+
`
32+
33+
type ListOpts struct {
34+
cli.ProjectOpts
35+
cli.OutputOpts
36+
store store.PrivateLinkLister
37+
}
38+
39+
func (opts *ListOpts) Run() error {
40+
result, err := opts.store.ListPrivateLinkEndpoints(opts.ConfigProjectID())
41+
if err != nil {
42+
return err
43+
}
44+
45+
return opts.Print(result)
46+
}
47+
48+
func (opts *ListOpts) initStore(ctx context.Context) func() error {
49+
return func() error {
50+
var err error
51+
opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
52+
return err
53+
}
54+
}
55+
56+
// atlas streams privateLink list
57+
// List the PrivateLink endpoints in the project that can be used as Atlas Stream Processor connections.
58+
func ListBuilder() *cobra.Command {
59+
opts := &ListOpts{}
60+
cmd := &cobra.Command{
61+
Use: "list",
62+
Short: "Lists the PrivateLink endpoints in the project that can be used as Atlas Stream Processor connections.",
63+
Long: fmt.Sprintf(usage.RequiredOneOfRoles, commandRoles),
64+
Args: require.NoArgs,
65+
Annotations: map[string]string{
66+
"output": listTemplate,
67+
},
68+
Example: `# list PrivateLink endpoints for Atlas Stream Processing:
69+
atlas streams privateLink list
70+
`,
71+
PreRunE: func(cmd *cobra.Command, _ []string) error {
72+
return opts.PreRunE(
73+
opts.ValidateProjectID,
74+
opts.initStore(cmd.Context()),
75+
opts.InitOutput(cmd.OutOrStdout(), createTemplate),
76+
)
77+
},
78+
RunE: func(_ *cobra.Command, _ []string) error {
79+
return opts.Run()
80+
},
81+
}
82+
83+
opts.AddProjectOptsFlags(cmd)
84+
opts.AddOutputOptFlags(cmd)
85+
86+
return cmd
87+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
"bytes"
19+
"fmt"
20+
"testing"
21+
22+
"github.com/golang/mock/gomock"
23+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
24+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
25+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
26+
"github.com/stretchr/testify/require"
27+
atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin"
28+
)
29+
30+
func getPrivateLinkConnections() []atlasv2.StreamsPrivateLinkConnection {
31+
var connections []atlasv2.StreamsPrivateLinkConnection
32+
33+
for i := 0; i < 5; i++ {
34+
conn := atlasv2.NewStreamsPrivateLinkConnection()
35+
conn.SetId(fmt.Sprintf("testId%d", i))
36+
conn.SetProvider("Azure")
37+
conn.SetRegion("US_EAST_2")
38+
conn.SetServiceEndpointId("/subscriptions/fd01adff-b37e-4693-8497-83ecf183a145/resourceGroups/test-rg/providers/Microsoft.EventHub/namespaces/test-namespace")
39+
conn.SetDnsDomain("test-namespace.servicebus.windows.net")
40+
41+
connections = append(connections, *conn)
42+
}
43+
44+
return connections
45+
}
46+
47+
func TestListOpts_Run(t *testing.T) {
48+
ctrl := gomock.NewController(t)
49+
mockStore := mocks.NewMockPrivateLinkLister(ctrl)
50+
51+
buf := new(bytes.Buffer)
52+
listOpts := &ListOpts{
53+
store: mockStore,
54+
OutputOpts: cli.OutputOpts{
55+
Template: listTemplate,
56+
OutWriter: buf,
57+
},
58+
}
59+
60+
connections := getPrivateLinkConnections()
61+
expected := atlasv2.NewPaginatedApiStreamsPrivateLink()
62+
expected.SetResults(connections)
63+
64+
mockStore.
65+
EXPECT().
66+
ListPrivateLinkEndpoints(gomock.Eq(listOpts.ConfigProjectID())).
67+
Return(expected, nil).
68+
Times(1)
69+
70+
require.NoError(t, listOpts.Run())
71+
test.VerifyOutputTemplate(t, listTemplate, expected)
72+
}

internal/cli/streams/privatelink/privatelink.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func Builder() *cobra.Command {
3434

3535
cmd.AddCommand(
3636
CreateBuilder(),
37+
ListBuilder(),
3738
DescribeBuilder(),
3839
)
3940

internal/mocks/mock_streams.go

Lines changed: 39 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,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
2525

2626
type StreamsLister interface {
2727
ProjectStreams(*atlasv2.ListStreamInstancesApiParams) (*atlasv2.PaginatedApiStreamsTenant, error)
@@ -71,6 +71,10 @@ type PrivateLinkCreator interface {
7171
CreatePrivateLinkEndpoint(projectID string, connection *atlasv2.StreamsPrivateLinkConnection) (*atlasv2.StreamsPrivateLinkConnection, error)
7272
}
7373

74+
type PrivateLinkLister interface {
75+
ListPrivateLinkEndpoints(projectID string) (*atlasv2.PaginatedApiStreamsPrivateLink, error)
76+
}
77+
7478
type PrivateLinkDescriber interface {
7579
DescribePrivateLinkEndpoint(projectID, connectionID string) (*atlasv2.StreamsPrivateLinkConnection, error)
7680
}
@@ -146,6 +150,11 @@ func (s *Store) CreatePrivateLinkEndpoint(projectID string, connection *atlasv2.
146150
return result, err
147151
}
148152

153+
func (s *Store) ListPrivateLinkEndpoints(projectID string) (*atlasv2.PaginatedApiStreamsPrivateLink, error) {
154+
result, _, err := s.clientv2.StreamsApi.ListPrivateLinkConnections(s.ctx, projectID).Execute()
155+
return result, err
156+
}
157+
149158
func (s *Store) DescribePrivateLinkEndpoint(projectID, connectionID string) (*atlasv2.StreamsPrivateLinkConnection, error) {
150159
result, _, err := s.clientv2.StreamsApi.GetPrivateLinkConnection(s.ctx, projectID, connectionID).Execute()
151160
return result, err

test/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
| `streams instance log` | Y | Y |
196196
| `streams privateLink` | | |
197197
| `streams privateLink create` | Y | Y |
198+
| `streams privateLink list` | Y | Y |
198199
| `streams privateLink describe` | Y | Y |
199200
| `config` | | |
200201
| `completion` | Y | Y |

test/e2e/atlas/streams_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,31 @@ func TestStreams(t *testing.T) {
252252
a.Equal("test-namespace.servicebus.windows.net", privateLinkEndpoint.GetDnsDomain())
253253
})
254254

255+
t.Run("List all streams privateLink endpoints", func(t *testing.T) {
256+
streamsCmd := exec.Command(cliPath,
257+
"streams",
258+
"privateLinks",
259+
"list",
260+
"-o=json",
261+
"--projectId",
262+
g.projectID,
263+
)
264+
265+
streamsCmd.Env = os.Environ()
266+
streamsResp, err := e2e.RunAndGetStdOut(streamsCmd)
267+
req.NoError(err, string(streamsResp))
268+
269+
var privateLinkEndpoints atlasv2.PaginatedApiStreamsPrivateLink
270+
req.NoError(json.Unmarshal(streamsResp, &privateLinkEndpoints))
271+
272+
a := assert.New(t)
273+
a.Len(privateLinkEndpoints.GetResults(), 1)
274+
a.Equal("Azure", privateLinkEndpoints.GetResults()[0].GetProvider())
275+
a.Equal("US_EAST_2", privateLinkEndpoints.GetResults()[0].GetRegion())
276+
a.Equal("/subscriptions/fd01adff-b37e-4693-8497-83ecf183a145/resourceGroups/test-rg/providers/Microsoft.EventHub/namespaces/test-namespace", privateLinkEndpoints.GetResults()[0].GetServiceEndpointId())
277+
a.Equal("test-namespace.servicebus.windows.net", privateLinkEndpoints.GetResults()[0].GetDnsDomain())
278+
})
279+
255280
// Connections
256281
t.Run("Creating a streams connection", func(t *testing.T) {
257282
cmd := exec.Command(cliPath,

0 commit comments

Comments
 (0)