Skip to content

Commit 19189fd

Browse files
committed
CLOUDP-291620: Add streams privateLink create command
1 parent ee11657 commit 19189fd

File tree

11 files changed

+482
-2
lines changed

11 files changed

+482
-2
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
.. _atlas-streams-privateLink-create:
2+
3+
================================
4+
atlas streams privateLink create
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+
Creates 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 privateLink create [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+
* - -f, --file
41+
- string
42+
- true
43+
- Path to a JSON configuration file that defines an Atlas Stream Processing PrivateLink endpoint.
44+
* - -h, --help
45+
-
46+
- false
47+
- help for create
48+
* - -o, --output
49+
- string
50+
- false
51+
- Output format. Valid values are json, json-path, go-template, or go-template-file. To see the full output, use the -o json option.
52+
* - --projectId
53+
- string
54+
- false
55+
- Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable.
56+
57+
Inherited Options
58+
-----------------
59+
60+
.. list-table::
61+
:header-rows: 1
62+
:widths: 20 10 10 60
63+
64+
* - Name
65+
- Type
66+
- Required
67+
- Description
68+
* - -P, --profile
69+
- string
70+
- false
71+
- 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.
72+
73+
Output
74+
------
75+
76+
If the command succeeds, the CLI returns output similar to the following sample. Values in brackets represent your values.
77+
78+
.. code-block::
79+
80+
Atlas Stream Processing PrivateLink endpoint <InterfaceEndpointId> created.
81+
82+
83+
Examples
84+
--------
85+
86+
.. code-block::
87+
:copyable: false
88+
89+
# create a new PrivateLink endpoint for Atlas Stream Processing:
90+
atlas streams privateLink create -f endpointConfig.json
91+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.. _atlas-streams-privateLink:
2+
3+
=========================
4+
atlas streams privateLink
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+
Manage Atlas Stream Processing PrivateLink endpoints.
16+
17+
Create your Atlas Stream Processing PrivateLink endpoints
18+
19+
Options
20+
-------
21+
22+
.. list-table::
23+
:header-rows: 1
24+
:widths: 20 10 10 60
25+
26+
* - Name
27+
- Type
28+
- Required
29+
- Description
30+
* - -h, --help
31+
-
32+
- false
33+
- help for privateLink
34+
35+
Inherited Options
36+
-----------------
37+
38+
.. list-table::
39+
:header-rows: 1
40+
:widths: 20 10 10 60
41+
42+
* - Name
43+
- Type
44+
- Required
45+
- Description
46+
* - -P, --profile
47+
- string
48+
- false
49+
- 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.
50+
51+
Related Commands
52+
----------------
53+
54+
* :ref:`atlas-streams-privateLink-create` - Creates a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
55+
56+
57+
.. toctree::
58+
:titlesonly:
59+
60+
create </command/atlas-streams-privateLink-create>
61+

docs/command/atlas-streams.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-connections` - Manage Atlas Stream Processing connections.
5555
* :ref:`atlas-streams-instances` - Manage Atlas Stream Processing instances.
56+
* :ref:`atlas-streams-privateLink` - Manage Atlas Stream Processing PrivateLink endpoints.
5657

5758

5859
.. toctree::
5960
:titlesonly:
6061

6162
connections </command/atlas-streams-connections>
6263
instances </command/atlas-streams-instances>
64+
privateLink </command/atlas-streams-privateLink>
6365

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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/file"
26+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
27+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
28+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
29+
"github.com/spf13/afero"
30+
"github.com/spf13/cobra"
31+
atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin"
32+
)
33+
34+
var createTemplate = "Atlas Stream Processing PrivateLink endpoint {{.InterfaceEndpointId}} created.\n"
35+
36+
type CreateOpts struct {
37+
cli.ProjectOpts
38+
cli.OutputOpts
39+
store store.PrivateLinkCreator
40+
filename string
41+
fs afero.Fs
42+
}
43+
44+
func (opts *CreateOpts) Run() error {
45+
privateLinkEndpoint := atlasv2.NewStreamsPrivateLinkConnection()
46+
if err := file.Load(opts.fs, opts.filename, privateLinkEndpoint); err != nil {
47+
return err
48+
}
49+
50+
// Remaining validation will be done by the API
51+
if privateLinkEndpoint.Provider == nil || len(*privateLinkEndpoint.Provider) == 0 {
52+
return errors.New("provider missing")
53+
}
54+
55+
result, err := opts.store.CreatePrivateLinkEndpoint(opts.ConfigProjectID(), privateLinkEndpoint)
56+
if err != nil {
57+
return err
58+
}
59+
60+
return opts.Print(result)
61+
}
62+
63+
func (opts *CreateOpts) initStore(ctx context.Context) func() error {
64+
return func() error {
65+
var err error
66+
opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
67+
return err
68+
}
69+
}
70+
71+
// atlas streams privateLink create
72+
// -f filename: file containing the private link endpoint configuration.
73+
// Create a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
74+
func CreateBuilder() *cobra.Command {
75+
opts := &CreateOpts{
76+
fs: afero.NewOsFs(),
77+
}
78+
cmd := &cobra.Command{
79+
Use: "create",
80+
Short: "Creates a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.",
81+
Long: fmt.Sprintf(usage.RequiredOneOfRoles, commandRoles),
82+
Args: require.NoArgs,
83+
Annotations: map[string]string{
84+
"output": createTemplate,
85+
},
86+
Example: `# create a new PrivateLink endpoint for Atlas Stream Processing:
87+
atlas streams privateLink create -f endpointConfig.json
88+
`,
89+
PreRunE: func(cmd *cobra.Command, _ []string) error {
90+
return opts.PreRunE(
91+
opts.ValidateProjectID,
92+
opts.initStore(cmd.Context()),
93+
opts.InitOutput(cmd.OutOrStdout(), createTemplate),
94+
)
95+
},
96+
RunE: func(_ *cobra.Command, _ []string) error {
97+
return opts.Run()
98+
},
99+
}
100+
101+
cmd.Flags().StringVarP(&opts.filename, flag.File, flag.FileShort, "", usage.StreamsPrivateLinkFilename)
102+
103+
opts.AddProjectOptsFlags(cmd)
104+
opts.AddOutputOptFlags(cmd)
105+
106+
_ = cmd.MarkFlagFilename(flag.File)
107+
_ = cmd.MarkFlagRequired(flag.File)
108+
109+
return cmd
110+
}

0 commit comments

Comments
 (0)