diff --git a/docs/command/atlas-config-init.txt b/docs/command/atlas-config-init.txt deleted file mode 100644 index 8f19185975..0000000000 --- a/docs/command/atlas-config-init.txt +++ /dev/null @@ -1,84 +0,0 @@ -.. _atlas-config-init: - -================= -atlas config init -================= - -.. default-domain:: mongodb - -.. contents:: On this page - :local: - :backlinks: none - :depth: 1 - :class: singlecol - -Configure a profile to store access settings for your MongoDB deployment. - -Public Preview: The atlas api sub-command, automatically generated from the MongoDB Atlas Admin API, offers full coverage of the Admin API and is currently in Public Preview (please provide feedback at https://feedback.mongodb.com/forums/930808-atlas-cli). -Admin API capabilities have their own release lifecycle, which you can check via the provided API endpoint documentation link. - - - - - -Syntax ------- - -.. code-block:: - :caption: Command Syntax - - atlas config init [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 - * - --gov - - - - false - - Create a default profile for atlas for gov - * - -h, --help - - - - false - - help for init - -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. - -Examples --------- - -.. code-block:: - :copyable: false - - # To configure the tool to work with Atlas: - atlas config init - - -.. code-block:: - :copyable: false - - # To configure the tool to work with Atlas for Government: - atlas config init --gov diff --git a/docs/command/atlas-config.txt b/docs/command/atlas-config.txt index 14f6b198bb..b8086417d9 100644 --- a/docs/command/atlas-config.txt +++ b/docs/command/atlas-config.txt @@ -64,7 +64,6 @@ Related Commands * :ref:`atlas-config-delete` - Delete a profile. * :ref:`atlas-config-describe` - Return the profile you specify. * :ref:`atlas-config-edit` - Opens the config file with the default text editor. -* :ref:`atlas-config-init` - Configure a profile to store access settings for your MongoDB deployment. * :ref:`atlas-config-list` - Return a list of available profiles by name. * :ref:`atlas-config-rename` - Rename a profile. * :ref:`atlas-config-set` - Configure specific properties of a profile. @@ -76,7 +75,6 @@ Related Commands delete describe edit - init list rename set diff --git a/internal/cli/auth/login.go b/internal/cli/auth/login.go index a2fd9a9601..3d165d2dff 100644 --- a/internal/cli/auth/login.go +++ b/internal/cli/auth/login.go @@ -425,7 +425,6 @@ func LoginBuilder() *cobra.Command { opts.SyncWithOAuthAccessProfile(defaultProfile), opts.InitFlow(defaultProfile), opts.LoginPreRun(cmd.Context()), - validate.NoAPIKeys, validate.NoAccessToken, ) }, diff --git a/internal/cli/commonerrors/errors.go b/internal/cli/commonerrors/errors.go index a4fa11c127..8263410454 100644 --- a/internal/cli/commonerrors/errors.go +++ b/internal/cli/commonerrors/errors.go @@ -29,8 +29,7 @@ var ( errAsymmetricShardUnsupported = errors.New("trying to run a cluster wide scaling command on an independent shard scaling cluster. Use --autoScalingMode 'independentShardScaling' instead") ErrUnauthorized = errors.New(`this action requires authentication -To log in using your Atlas username and password, run: atlas auth login -To set credentials using API keys, run: atlas config init`) +To log in using your Atlas username and password or to set credentials using API keys, run: atlas auth login`) ErrInvalidRefreshToken = errors.New(`session expired Please note that your session expires periodically. diff --git a/internal/cli/config/init.go b/internal/cli/config/init.go index dccb59a99e..783d52dc26 100644 --- a/internal/cli/config/init.go +++ b/internal/cli/config/init.go @@ -15,106 +15,18 @@ package config 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/flag" - "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/prompt" - "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/telemetry" - "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage" + "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/auth" "github.com/spf13/cobra" ) -const atlas = "atlas" - -type initOpts struct { - cli.DigestConfigOpts - gov bool -} - -func (opts *initOpts) SetUpAccess() { - opts.Service = config.CloudService - if opts.gov { - opts.Service = config.CloudGovService - } - - opts.SetUpServiceAndKeys() -} - -func (opts *initOpts) Run(ctx context.Context) error { - _, _ = fmt.Fprintf(opts.OutWriter, `You are configuring a profile for %s. - -All values are optional and you can use environment variables (MONGODB_ATLAS_*) instead. - -Enter [?] on any option to get help. - -`, atlas) - - q := prompt.AccessQuestions() - if err := telemetry.TrackAsk(q, opts); err != nil { - return err - } - opts.SetUpAccess() - - if err := opts.InitStore(ctx); err != nil { - return err - } - - if config.IsAccessSet() { - if err := opts.AskOrg(); err != nil { - return err - } - if err := opts.AskProject(); err != nil { - return err - } - } else { - q := prompt.TenantQuestions() - if err := telemetry.TrackAsk(q, opts); err != nil { - return err - } - } - opts.SetUpProject() - opts.SetUpOrg() - - if err := telemetry.TrackAsk(opts.DefaultQuestions(), opts); err != nil { - return err - } - opts.SetUpOutput() - - if err := config.Save(); err != nil { - return err - } - - _, _ = fmt.Fprintf(opts.OutWriter, "\nYour profile is now configured.\n") - if config.Name() != config.DefaultProfile { - _, _ = fmt.Fprintf(opts.OutWriter, "To use this profile, you must set the flag [-%s %s] for every command.\n", flag.ProfileShort, config.Name()) - } - _, _ = fmt.Fprintf(opts.OutWriter, "You can use [%s config set] to change these settings at a later time.\n", atlas) - return nil -} - func InitBuilder() *cobra.Command { - opts := &initOpts{} - cmd := &cobra.Command{ - Use: "init", - Short: "Configure a profile to store access settings for your MongoDB deployment.", - Example: ` # To configure the tool to work with Atlas: + cmd := auth.LoginBuilder() + cmd.Use = "init" + cmd.Example = ` # To configure the tool to work with Atlas: atlas config init # To configure the tool to work with Atlas for Government: - atlas config init --gov`, - PreRun: func(cmd *cobra.Command, _ []string) { - opts.OutWriter = cmd.OutOrStdout() - }, - RunE: func(cmd *cobra.Command, _ []string) error { - return opts.Run(cmd.Context()) - }, - Args: require.NoArgs, - } - cmd.Flags().BoolVar(&opts.gov, flag.Gov, false, usage.Gov) - + atlas config init --gov` + cmd.Deprecated = "Please use the 'atlas auth login' command instead." return cmd } diff --git a/test/e2e/config/config_test.go b/test/e2e/config/config_test.go index f4d0158ddf..c518d6a224 100644 --- a/test/e2e/config/config_test.go +++ b/test/e2e/config/config_test.go @@ -77,6 +77,15 @@ func TestConfig(t *testing.T) { if err = cmd.Start(); err != nil { t.Fatal(err) } + if _, err = c.ExpectString("Select authentication type"); err != nil { + t.Fatal(err) + } + if _, err := c.Send("\x1B[B"); err != nil { + t.Fatalf("Send(Down) = %v", err) + } + if _, err := c.SendLine(""); err != nil { + t.Fatalf("SendLine() = %v", err) + } if _, err = c.ExpectString("Public API Key"); err != nil { t.Fatal(err)