-
Notifications
You must be signed in to change notification settings - Fork 88
CLOUDP-291620: Add streams privateLink create command #3616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7019e36
CLOUDP-291620: Add streams privateLink create command
tcannon91 b1f9683
update copyright date, remove dup readme
tcannon91 5ec1d8f
Code review feedback
tcannon91 2898433
use setters, rename privateLinks subcommand to use plurals, compare a…
tcannon91 e8a93e7
Add t.parallel to test matrix tests
tcannon91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,91 @@ | ||
| .. _atlas-streams-privateLink-create: | ||
|
|
||
| ================================ | ||
| atlas streams privateLink 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 privateLink 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 | ||
|
|
This file contains hidden or 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,61 @@ | ||
| .. _atlas-streams-privateLink: | ||
|
|
||
| ========================= | ||
| atlas streams privateLink | ||
| ========================= | ||
|
|
||
| .. 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 privateLink | ||
|
|
||
| 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-privateLink-create` - Creates a PrivateLink endpoint that can be used as an Atlas Stream Processor connection. | ||
|
|
||
|
|
||
| .. toctree:: | ||
| :titlesonly: | ||
|
|
||
| create </command/atlas-streams-privateLink-create> | ||
|
|
This file contains hidden or 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 hidden or 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,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.Provider == nil || len(*privateLinkEndpoint.Provider) == 0 { | ||
| 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 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.