Skip to content

Commit f73c8a8

Browse files
authored
CLOUDP-329797: Make atlas config init alias of atlas auth login (#4044)
1 parent 7f4bec6 commit f73c8a8

File tree

6 files changed

+16
-183
lines changed

6 files changed

+16
-183
lines changed

docs/command/atlas-config-init.txt

Lines changed: 0 additions & 84 deletions
This file was deleted.

docs/command/atlas-config.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Related Commands
6464
* :ref:`atlas-config-delete` - Delete a profile.
6565
* :ref:`atlas-config-describe` - Return the profile you specify.
6666
* :ref:`atlas-config-edit` - Opens the config file with the default text editor.
67-
* :ref:`atlas-config-init` - Configure a profile to store access settings for your MongoDB deployment.
6867
* :ref:`atlas-config-list` - Return a list of available profiles by name.
6968
* :ref:`atlas-config-rename` - Rename a profile.
7069
* :ref:`atlas-config-set` - Configure specific properties of a profile.
@@ -76,7 +75,6 @@ Related Commands
7675
delete </command/atlas-config-delete>
7776
describe </command/atlas-config-describe>
7877
edit </command/atlas-config-edit>
79-
init </command/atlas-config-init>
8078
list </command/atlas-config-list>
8179
rename </command/atlas-config-rename>
8280
set </command/atlas-config-set>

internal/cli/auth/login.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ func LoginBuilder() *cobra.Command {
425425
opts.SyncWithOAuthAccessProfile(defaultProfile),
426426
opts.InitFlow(defaultProfile),
427427
opts.LoginPreRun(cmd.Context()),
428-
validate.NoAPIKeys,
429428
validate.NoAccessToken,
430429
)
431430
},

internal/cli/commonerrors/errors.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ var (
2929
errAsymmetricShardUnsupported = errors.New("trying to run a cluster wide scaling command on an independent shard scaling cluster. Use --autoScalingMode 'independentShardScaling' instead")
3030
ErrUnauthorized = errors.New(`this action requires authentication
3131
32-
To log in using your Atlas username and password, run: atlas auth login
33-
To set credentials using API keys, run: atlas config init`)
32+
To log in using your Atlas username and password or to set credentials using API keys, run: atlas auth login`)
3433
ErrInvalidRefreshToken = errors.New(`session expired
3534
3635
Please note that your session expires periodically.

internal/cli/config/init.go

Lines changed: 6 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -15,106 +15,18 @@
1515
package config
1616

1717
import (
18-
"context"
19-
"fmt"
20-
21-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
22-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
23-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
24-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
25-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/prompt"
26-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/telemetry"
27-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
18+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/auth"
2819
"github.com/spf13/cobra"
2920
)
3021

31-
const atlas = "atlas"
32-
33-
type initOpts struct {
34-
cli.DigestConfigOpts
35-
gov bool
36-
}
37-
38-
func (opts *initOpts) SetUpAccess() {
39-
opts.Service = config.CloudService
40-
if opts.gov {
41-
opts.Service = config.CloudGovService
42-
}
43-
44-
opts.SetUpServiceAndKeys()
45-
}
46-
47-
func (opts *initOpts) Run(ctx context.Context) error {
48-
_, _ = fmt.Fprintf(opts.OutWriter, `You are configuring a profile for %s.
49-
50-
All values are optional and you can use environment variables (MONGODB_ATLAS_*) instead.
51-
52-
Enter [?] on any option to get help.
53-
54-
`, atlas)
55-
56-
q := prompt.AccessQuestions()
57-
if err := telemetry.TrackAsk(q, opts); err != nil {
58-
return err
59-
}
60-
opts.SetUpAccess()
61-
62-
if err := opts.InitStore(ctx); err != nil {
63-
return err
64-
}
65-
66-
if config.IsAccessSet() {
67-
if err := opts.AskOrg(); err != nil {
68-
return err
69-
}
70-
if err := opts.AskProject(); err != nil {
71-
return err
72-
}
73-
} else {
74-
q := prompt.TenantQuestions()
75-
if err := telemetry.TrackAsk(q, opts); err != nil {
76-
return err
77-
}
78-
}
79-
opts.SetUpProject()
80-
opts.SetUpOrg()
81-
82-
if err := telemetry.TrackAsk(opts.DefaultQuestions(), opts); err != nil {
83-
return err
84-
}
85-
opts.SetUpOutput()
86-
87-
if err := config.Save(); err != nil {
88-
return err
89-
}
90-
91-
_, _ = fmt.Fprintf(opts.OutWriter, "\nYour profile is now configured.\n")
92-
if config.Name() != config.DefaultProfile {
93-
_, _ = fmt.Fprintf(opts.OutWriter, "To use this profile, you must set the flag [-%s %s] for every command.\n", flag.ProfileShort, config.Name())
94-
}
95-
_, _ = fmt.Fprintf(opts.OutWriter, "You can use [%s config set] to change these settings at a later time.\n", atlas)
96-
return nil
97-
}
98-
9922
func InitBuilder() *cobra.Command {
100-
opts := &initOpts{}
101-
cmd := &cobra.Command{
102-
Use: "init",
103-
Short: "Configure a profile to store access settings for your MongoDB deployment.",
104-
Example: ` # To configure the tool to work with Atlas:
23+
cmd := auth.LoginBuilder()
24+
cmd.Use = "init"
25+
cmd.Example = ` # To configure the tool to work with Atlas:
10526
atlas config init
10627
10728
# To configure the tool to work with Atlas for Government:
108-
atlas config init --gov`,
109-
PreRun: func(cmd *cobra.Command, _ []string) {
110-
opts.OutWriter = cmd.OutOrStdout()
111-
},
112-
RunE: func(cmd *cobra.Command, _ []string) error {
113-
return opts.Run(cmd.Context())
114-
},
115-
Args: require.NoArgs,
116-
}
117-
cmd.Flags().BoolVar(&opts.gov, flag.Gov, false, usage.Gov)
118-
29+
atlas config init --gov`
30+
cmd.Deprecated = "Please use the 'atlas auth login' command instead."
11931
return cmd
12032
}

test/e2e/config/config_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ func TestConfig(t *testing.T) {
7777
if err = cmd.Start(); err != nil {
7878
t.Fatal(err)
7979
}
80+
if _, err = c.ExpectString("Select authentication type"); err != nil {
81+
t.Fatal(err)
82+
}
83+
if _, err := c.Send("\x1B[B"); err != nil {
84+
t.Fatalf("Send(Down) = %v", err)
85+
}
86+
if _, err := c.SendLine(""); err != nil {
87+
t.Fatalf("SendLine() = %v", err)
88+
}
8089

8190
if _, err = c.ExpectString("Public API Key"); err != nil {
8291
t.Fatal(err)

0 commit comments

Comments
 (0)