-
Notifications
You must be signed in to change notification settings - Fork 132
Move usage of config struct in auth login #4310
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
base: main
Are you sure you want to change the base?
Conversation
|
Commit: 092818a
33 interesting tests: 22 KNOWN, 9 flaky, 1 SKIP, 1 RECOVERED
Top 50 slowest tests (at least 2 minutes):
|
cmd/auth/login.go
Outdated
| Host: authArguments.Host, | ||
| AccountID: authArguments.AccountID, | ||
| AuthType: "databricks-cli", | ||
| ConfigFile: os.Getenv("DATABRICKS_CONFIG_FILE"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behaviour is slightly different now: before it overrode ConfigFile only when DATABRICKS_CONFIG_FILE is not empty, and now - all the time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding from the comment at line 165 is that we should not even attempt to read the config file at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behaviour is slightly different now: before it overrode ConfigFile only when DATABRICKS_CONFIG_FILE is not empty, and now - all the time
I had thought the if statement was redundant because cfg.ConfigFile remains "" if the environment variable is not set, but I think it is indeed irrelevant given this:
My understanding from the comment at line 165 is that we should not even attempt to read the config file at all.
Since we aren't providing a profile name, nothing can be loaded from the config file.
I don't see the purpose of adding the ConfigFile path to the config struct, even in the earlier code so I'll remove the line. Please correct me if I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an acceptance test for to ensure the behaviour doesn't change from removing the line (named custom-config-file).
| } | ||
| } | ||
|
|
||
| if profileName != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that condition always true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It surprisingly is not.
func newLoginCommand(authArguments *auth.AuthArguments) *cobra.Command {
// ...
profileName := cmd.Flag("profile").Value.String()
// ...
// If the user has not specified a profile name, prompt for one.
if profileName == "" {
var err error
profileName = getProfileName(authArguments)
if profileName == "" {
profileName = "DEFAULT"
}
profileName, err = promptForProfile(ctx, profileName) // <--- this call
if err != nil {
return err
}
}
// ...
}The call to promptForProfile can return the empty string if interactive prompts are not supported.
func promptForProfile(ctx context.Context, defaultValue string) (string, error) {
if !cmdio.IsPromptSupported(ctx) {
return "", nil
}
// ....
}Which means that the CLI's auth login command actually can be used without saving a profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which means that the CLI's auth login command actually can be used without saving a profile.
Drive by comment: Worth confirming this. My recollection is that if you do not specify a profile, we automatically save to the default profile.
cmd/auth/login.go
Outdated
| Host: authArguments.Host, | ||
| AccountID: authArguments.AccountID, | ||
| AuthType: "databricks-cli", | ||
| ConfigFile: os.Getenv("DATABRICKS_CONFIG_FILE"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding from the comment at line 165 is that we should not even attempt to read the config file at all.
10af05e to
76a6317
Compare
| // An OAuth token has been successfully obtained at this point. | ||
| // We now attempt to save the current configuration as a profile in the config file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
| // An OAuth token has been successfully obtained at this point. | |
| // We now attempt to save the current configuration as a profile in the config file. | |
| // At this point, an OAuth token has been successfully minted and stored | |
| // in the CLI cache. The rest of the command focuses on: | |
| // 1. Configuring cluster and serverless; | |
| // 2. Saving the profile. |
| w, err := databricks.NewWorkspaceClient(&databricks.Config{ | ||
| Host: authArguments.Host, | ||
| AccountID: authArguments.AccountID, | ||
| AuthType: "databricks-cli", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the Go SDK using the CLI in databricks-cli, this will effectively make the CLI spawn a child CLI process. It would be great if we could directly re-use the token that just got minted instead.
Changes
Refactors the
auth logincommand to make it clear that the config struct is only needed for making a request to configure clusters when a--configure-clustersflag is passed.Why
Reduce confusion about what part of the SDK is used by the CLI in the auth login command. This is being done as a part of an effort to make the
databricks-cliauth type consistent across the SDKs by having the Go SDK also rely on the CLI'sauth tokencommand like the Java and Python SDKs.Tests
NO_CHANGELOG=true