Skip to content

Commit 32b812f

Browse files
authored
CLOUDP-291621: Add describe command for Atlas Stream Processing PrivateLinks (#3641)
1 parent 4074b06 commit 32b812f

File tree

9 files changed

+374
-6
lines changed

9 files changed

+374
-6
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
.. _atlas-streams-privateLinks-describe:
2+
3+
===================================
4+
atlas streams privateLinks describe
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+
Describes a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
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 describe <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+
* - -h, --help
57+
-
58+
- false
59+
- help for describe
60+
* - -o, --output
61+
- string
62+
- false
63+
- Output format. Valid values are json, json-path, go-template, or go-template-file. To see the full output, use the -o json option.
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+
ID PROVIDER REGION VENDOR STATE INTERFACE_ENDPOINT_ID SERVICE_ENDPOINT_ID DNS_DOMAIN DNS_SUBDOMAIN
93+
<Id> <Provider> <Region> <Vendor> <State> <InterfaceEndpointId> <ServiceEndpointId> <DnsDomain> <DnsSubDomain>
94+
95+
96+
Examples
97+
--------
98+
99+
.. code-block::
100+
:copyable: false
101+
102+
# describe a PrivateLink endpoint for Atlas Stream Processing:
103+
atlas streams privateLink describe 5e2211c17a3e5a48f5497de3
104+

docs/command/atlas-streams-privateLinks.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ 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-describe` - Describes a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
5556

5657

5758
.. toctree::
5859
:titlesonly:
5960

6061
create </command/atlas-streams-privateLinks-create>
62+
describe </command/atlas-streams-privateLinks-describe>
6163

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
"errors"
20+
"fmt"
21+
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/config"
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 describeTemplate = `ID PROVIDER REGION VENDOR STATE INTERFACE_ENDPOINT_ID SERVICE_ENDPOINT_ID DNS_DOMAIN DNS_SUBDOMAIN
31+
{{.Id}} {{.Provider}} {{.Region}} {{.Vendor}} {{.State}} {{.InterfaceEndpointId}} {{.ServiceEndpointId}} {{.DnsDomain}} {{.DnsSubDomain}}
32+
`
33+
34+
type DescribeOpts struct {
35+
cli.ProjectOpts
36+
cli.OutputOpts
37+
store store.PrivateLinkDescriber
38+
connectionID string
39+
}
40+
41+
func (opts *DescribeOpts) Run() error {
42+
if opts.connectionID == "" {
43+
return errors.New("connectionID is missing")
44+
}
45+
46+
result, err := opts.store.DescribePrivateLinkEndpoint(opts.ConfigProjectID(), opts.connectionID)
47+
if err != nil {
48+
return err
49+
}
50+
51+
return opts.Print(result)
52+
}
53+
54+
func (opts *DescribeOpts) initStore(ctx context.Context) func() error {
55+
return func() error {
56+
var err error
57+
opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
58+
return err
59+
}
60+
}
61+
62+
// atlas streams privateLink describe <connectionID>
63+
// Describe a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
64+
func DescribeBuilder() *cobra.Command {
65+
opts := &DescribeOpts{}
66+
cmd := &cobra.Command{
67+
Use: "describe <connectionID>",
68+
Short: "Describes a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.",
69+
Long: fmt.Sprintf(usage.RequiredOneOfRoles, commandRoles),
70+
Args: require.ExactArgs(1),
71+
Annotations: map[string]string{
72+
"connectionIDDesc": "ID of the PrivateLink endpoint.",
73+
"output": describeTemplate,
74+
},
75+
Example: `# describe a PrivateLink endpoint for Atlas Stream Processing:
76+
atlas streams privateLink describe 5e2211c17a3e5a48f5497de3
77+
`,
78+
PreRunE: func(cmd *cobra.Command, args []string) error {
79+
if err := opts.PreRunE(
80+
opts.ValidateProjectID,
81+
opts.initStore(cmd.Context()),
82+
); err != nil {
83+
return err
84+
}
85+
opts.connectionID = args[0]
86+
return nil
87+
},
88+
RunE: func(_ *cobra.Command, _ []string) error {
89+
return opts.Run()
90+
},
91+
}
92+
93+
opts.AddProjectOptsFlags(cmd)
94+
opts.AddOutputOptFlags(cmd)
95+
96+
return cmd
97+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
"testing"
20+
21+
"github.com/golang/mock/gomock"
22+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
23+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
24+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
25+
"github.com/stretchr/testify/require"
26+
atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin"
27+
)
28+
29+
func TestDescribeOpts_Run(t *testing.T) {
30+
t.Run("should error when no connectionID is provided", func(t *testing.T) {
31+
describeOpts := &DescribeOpts{}
32+
33+
require.ErrorContains(t, describeOpts.Run(), "connectionID is missing")
34+
})
35+
36+
t.Run("should call the store get privateLink method with the correct parameters", func(t *testing.T) {
37+
ctrl := gomock.NewController(t)
38+
mockStore := mocks.NewMockPrivateLinkDescriber(ctrl)
39+
40+
connectionID := "123456789012"
41+
describeOpts := &DescribeOpts{
42+
store: mockStore,
43+
connectionID: connectionID,
44+
}
45+
46+
mockStore.
47+
EXPECT().
48+
DescribePrivateLinkEndpoint(gomock.Eq(describeOpts.ConfigProjectID()), gomock.Eq(connectionID)).
49+
Times(1)
50+
51+
require.NoError(t, describeOpts.Run())
52+
})
53+
54+
t.Run("should print the result", func(t *testing.T) {
55+
ctrl := gomock.NewController(t)
56+
mockStore := mocks.NewMockPrivateLinkDescriber(ctrl)
57+
58+
buf := new(bytes.Buffer)
59+
describeOpts := &DescribeOpts{
60+
store: mockStore,
61+
connectionID: "123456789012",
62+
OutputOpts: cli.OutputOpts{
63+
Template: describeTemplate,
64+
OutWriter: buf,
65+
},
66+
}
67+
68+
expected := atlasv2.NewStreamsPrivateLinkConnection()
69+
expected.SetId(describeOpts.connectionID)
70+
expected.SetInterfaceEndpointId("vpce-123456789012345678")
71+
expected.SetServiceEndpointId("/subscriptions/fd01adff-b37e-4693-8497-83ecf183a145/resourceGroups/test-rg/providers/Microsoft.EventHub/namespaces/test-namespace")
72+
expected.SetDnsDomain("test-namespace.servicebus.windows.net")
73+
expected.SetProvider("Azure")
74+
expected.SetRegion("US_EAST_2")
75+
76+
mockStore.
77+
EXPECT().
78+
// This test does not assert the parameters passed to the store method
79+
DescribePrivateLinkEndpoint(gomock.Any(), gomock.Any()).
80+
Return(expected, nil).
81+
Times(1)
82+
83+
require.NoError(t, describeOpts.Run())
84+
test.VerifyOutputTemplate(t, describeTemplate, expected)
85+
})
86+
}

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+
DescribeBuilder(),
3738
)
3839

3940
return cmd

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
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
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 PrivateLinkDescriber interface {
75+
DescribePrivateLinkEndpoint(projectID, connectionID string) (*atlasv2.StreamsPrivateLinkConnection, error)
76+
}
77+
7478
func (s *Store) ProjectStreams(opts *atlasv2.ListStreamInstancesApiParams) (*atlasv2.PaginatedApiStreamsTenant, error) {
7579
result, _, err := s.clientv2.StreamsApi.ListStreamInstancesWithParams(s.ctx, opts).Execute()
7680
return result, err
@@ -141,3 +145,8 @@ func (s *Store) CreatePrivateLinkEndpoint(projectID string, connection *atlasv2.
141145
result, _, err := s.clientv2.StreamsApi.CreatePrivateLinkConnection(s.ctx, projectID, connection).Execute()
142146
return result, err
143147
}
148+
149+
func (s *Store) DescribePrivateLinkEndpoint(projectID, connectionID string) (*atlasv2.StreamsPrivateLinkConnection, error) {
150+
result, _, err := s.clientv2.StreamsApi.GetPrivateLinkConnection(s.ctx, projectID, connectionID).Execute()
151+
return result, err
152+
}

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 describe` | Y | Y |
198199
| `config` | | |
199200
| `completion` | Y | Y |
200201
| `config delete` | Y | Y |

0 commit comments

Comments
 (0)