-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-291668: Add list command for ASP PrivateLink endpoints
- Loading branch information
Showing
9 changed files
with
325 additions
and
2 deletions.
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
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
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