@@ -67,13 +67,11 @@ import (
67
67
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/homebrew"
68
68
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/latestrelease"
69
69
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/log"
70
- "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/plugin"
71
70
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/prerun"
72
71
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/sighandle"
73
72
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/telemetry"
74
73
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/terminal"
75
74
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
76
- "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/validate"
77
75
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/version"
78
76
"github.com/spf13/afero"
79
77
"github.com/spf13/cobra"
@@ -88,18 +86,6 @@ type Notifier struct {
88
86
writer io.Writer
89
87
}
90
88
91
- type AuthRequirements int64
92
-
93
- const (
94
- // NoAuth command does not require authentication.
95
- NoAuth AuthRequirements = 0
96
- // RequiredAuth command requires authentication.
97
- RequiredAuth AuthRequirements = 1
98
- // OptionalAuth command can work with or without authentication,
99
- // and if access token is found, try to refresh it.
100
- OptionalAuth AuthRequirements = 2
101
- )
102
-
103
89
func handleSignal () {
104
90
sighandle .Notify (func (sig os.Signal ) {
105
91
telemetry .FinishTrackingCommand (telemetry.TrackOptions {
@@ -149,29 +135,7 @@ Use the --help flag with any command for more info on that command.`,
149
135
config .SetService (config .CloudService )
150
136
}
151
137
152
- authReq := shouldCheckCredentials (cmd )
153
- if authReq == NoAuth {
154
- return nil
155
- }
156
-
157
- if err := prerun .ExecuteE (
158
- opts .InitFlow (config .Default ()),
159
- func () error {
160
- err := opts .RefreshAccessToken (cmd .Context ())
161
- if err != nil && authReq == RequiredAuth {
162
- return err
163
- }
164
- return nil
165
- },
166
- ); err != nil {
167
- return err
168
- }
169
-
170
- if authReq == RequiredAuth {
171
- return validate .Credentials ()
172
- }
173
-
174
- return nil
138
+ return prerun .ExecuteE (opts .InitFlow (config .Default ()))
175
139
},
176
140
// PersistentPostRun only runs if the command is successful
177
141
PersistentPostRun : func (cmd * cobra.Command , _ []string ) {
@@ -289,43 +253,6 @@ func shouldSetService(cmd *cobra.Command) bool {
289
253
return true
290
254
}
291
255
292
- func shouldCheckCredentials (cmd * cobra.Command ) AuthRequirements {
293
- searchByName := []string {
294
- "__complete" ,
295
- "help" ,
296
- }
297
- for _ , n := range searchByName {
298
- if cmd .Name () == n {
299
- return NoAuth
300
- }
301
- }
302
- customRequirements := map [string ]AuthRequirements {
303
- fmt .Sprintf ("%s %s" , atlas , "completion" ): NoAuth , // completion commands do not require credentials
304
- fmt .Sprintf ("%s %s" , atlas , "config" ): NoAuth , // user wants to set credentials
305
- fmt .Sprintf ("%s %s" , atlas , "auth" ): NoAuth , // user wants to set credentials
306
- fmt .Sprintf ("%s %s" , atlas , "register" ): NoAuth , // user wants to set credentials
307
- fmt .Sprintf ("%s %s" , atlas , "login" ): NoAuth , // user wants to set credentials
308
- fmt .Sprintf ("%s %s" , atlas , "logout" ): NoAuth , // user wants to set credentials
309
- fmt .Sprintf ("%s %s" , atlas , "whoami" ): NoAuth , // user wants to set credentials
310
- fmt .Sprintf ("%s %s" , atlas , "setup" ): NoAuth , // user wants to set credentials
311
- fmt .Sprintf ("%s %s" , atlas , "register" ): NoAuth , // user wants to set credentials
312
- fmt .Sprintf ("%s %s" , atlas , "plugin" ): NoAuth , // plugin functionality requires no authentication
313
- fmt .Sprintf ("%s %s" , atlas , "quickstart" ): NoAuth , // command supports login
314
- fmt .Sprintf ("%s %s" , atlas , "deployments" ): OptionalAuth , // command supports local and Atlas
315
- }
316
- for p , r := range customRequirements {
317
- if strings .HasPrefix (cmd .CommandPath (), p ) {
318
- return r
319
- }
320
- }
321
-
322
- if plugin .IsPluginCmd (cmd ) || pluginCmd .IsFirstClassPluginCmd (cmd ) {
323
- return OptionalAuth
324
- }
325
-
326
- return RequiredAuth
327
- }
328
-
329
256
func formattedVersion () string {
330
257
return fmt .Sprintf (verTemplate ,
331
258
version .Version ,
0 commit comments