Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions docs/command/atlas-streams-privateLinks-create.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
.. _atlas-streams-privateLinks-create:

=================================
atlas streams privateLinks create
=================================

.. default-domain:: mongodb

.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol

Creates a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.

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 create [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
* - -f, --file
- string
- true
- Path to a JSON configuration file that defines an Atlas Stream Processing PrivateLink endpoint.
* - -h, --help
-
- false
- help for create
* - -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::

Atlas Stream Processing PrivateLink endpoint <InterfaceEndpointId> created.


Examples
--------

.. code-block::
:copyable: false

# create a new PrivateLink endpoint for Atlas Stream Processing:
atlas streams privateLink create -f endpointConfig.json

61 changes: 61 additions & 0 deletions docs/command/atlas-streams-privateLinks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.. _atlas-streams-privateLinks:

==========================
atlas streams privateLinks
==========================

.. default-domain:: mongodb

.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol

Manage Atlas Stream Processing PrivateLink endpoints.

Create your Atlas Stream Processing PrivateLink endpoints

Options
-------

.. list-table::
:header-rows: 1
:widths: 20 10 10 60

* - Name
- Type
- Required
- Description
* - -h, --help
-
- false
- help for privateLinks

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.

Related Commands
----------------

* :ref:`atlas-streams-privateLinks-create` - Creates a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.


.. toctree::
:titlesonly:

create </command/atlas-streams-privateLinks-create>

2 changes: 2 additions & 0 deletions docs/command/atlas-streams.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ Related Commands

* :ref:`atlas-streams-connections` - Manage Atlas Stream Processing connections.
* :ref:`atlas-streams-instances` - Manage Atlas Stream Processing instances.
* :ref:`atlas-streams-privateLinks` - Manage Atlas Stream Processing PrivateLink endpoints.


.. toctree::
:titlesonly:

connections </command/atlas-streams-connections>
instances </command/atlas-streams-instances>
privateLinks </command/atlas-streams-privateLinks>

110 changes: 110 additions & 0 deletions internal/cli/streams/privatelink/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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"
"errors"
"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/file"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
"github.com/spf13/afero"
"github.com/spf13/cobra"
atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin"
)

var createTemplate = "Atlas Stream Processing PrivateLink endpoint {{.InterfaceEndpointId}} created.\n"

type CreateOpts struct {
cli.ProjectOpts
cli.OutputOpts
store store.PrivateLinkCreator
filename string
fs afero.Fs
}

func (opts *CreateOpts) Run() error {
privateLinkEndpoint := atlasv2.NewStreamsPrivateLinkConnection()
if err := file.Load(opts.fs, opts.filename, privateLinkEndpoint); err != nil {
return err
}

// Remaining validation will be done by the API
if privateLinkEndpoint.GetProvider() == "" {
return errors.New("provider missing")
}

result, err := opts.store.CreatePrivateLinkEndpoint(opts.ConfigProjectID(), privateLinkEndpoint)
if err != nil {
return err
}

return opts.Print(result)
}

func (opts *CreateOpts) 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 create
// -f filename: file containing the private link endpoint configuration.
// Create a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.
func CreateBuilder() *cobra.Command {
opts := &CreateOpts{
fs: afero.NewOsFs(),
}
cmd := &cobra.Command{
Use: "create",
Short: "Creates a PrivateLink endpoint that can be used as an Atlas Stream Processor connection.",
Long: fmt.Sprintf(usage.RequiredOneOfRoles, commandRoles),
Args: require.NoArgs,
Annotations: map[string]string{
"output": createTemplate,
},
Example: `# create a new PrivateLink endpoint for Atlas Stream Processing:
atlas streams privateLink create -f endpointConfig.json
`,
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()
},
}

cmd.Flags().StringVarP(&opts.filename, flag.File, flag.FileShort, "", usage.StreamsPrivateLinkFilename)

opts.AddProjectOptsFlags(cmd)
opts.AddOutputOptFlags(cmd)

_ = cmd.MarkFlagFilename(flag.File)
_ = cmd.MarkFlagRequired(flag.File)

return cmd
}
Loading
Loading