|
15 | 15 | package config
|
16 | 16 |
|
17 | 17 | 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" |
28 | 19 | "github.com/spf13/cobra"
|
29 | 20 | )
|
30 | 21 |
|
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 |
| - |
99 | 22 | 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: |
105 | 26 | atlas config init
|
106 | 27 |
|
107 | 28 | # 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." |
119 | 31 | return cmd
|
120 | 32 | }
|
0 commit comments