-
Notifications
You must be signed in to change notification settings - Fork 35
Pass CLI path to all auth providers and login only once during bundle init #1114
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ const extensionVersion = require("../../../package.json") | |
| import {AzureCliCheck} from "./AzureCliCheck"; | ||
| import {DatabricksCliCheck} from "./DatabricksCliCheck"; | ||
| import {Loggers} from "../../logger"; | ||
| import {CliWrapper} from "../../cli/CliWrapper"; | ||
|
|
||
| // TODO: Resolve this with SDK's AuthType. | ||
| export type AuthType = | ||
|
|
@@ -98,10 +99,7 @@ export abstract class AuthProvider { | |
| } | ||
| protected abstract getSdkConfig(): Config; | ||
|
|
||
| static fromJSON( | ||
| json: Record<string, any>, | ||
| databricksPath: string | ||
| ): AuthProvider { | ||
| static fromJSON(json: Record<string, any>, cli: CliWrapper): AuthProvider { | ||
| const host = | ||
| json.host instanceof URL | ||
| ? json.host | ||
|
|
@@ -123,20 +121,20 @@ export abstract class AuthProvider { | |
| ); | ||
|
|
||
| case "databricks-cli": | ||
| return new DatabricksCliAuthProvider(host, databricksPath); | ||
| return new DatabricksCliAuthProvider(host, cli); | ||
|
|
||
| case "profile": | ||
| if (!json.profile) { | ||
| throw new Error("Missing profile"); | ||
| } | ||
| return new ProfileAuthProvider(host, json.profile); | ||
| return new ProfileAuthProvider(host, json.profile, cli); | ||
|
|
||
| default: | ||
| throw new Error(`Unknown auth type: ${json.authType}`); | ||
| } | ||
| } | ||
|
|
||
| static fromSdkConfig(config: Config): AuthProvider { | ||
| static fromSdkConfig(config: Config, cli: CliWrapper): AuthProvider { | ||
| if (!config.host) { | ||
| throw new Error("Missing host"); | ||
| } | ||
|
|
@@ -151,33 +149,27 @@ export abstract class AuthProvider { | |
| ); | ||
|
|
||
| case "databricks-cli": | ||
| if (!config.databricksCliPath) { | ||
| throw new Error("Missing path for databricks-cli"); | ||
| } | ||
|
|
||
| return new DatabricksCliAuthProvider( | ||
| host, | ||
| config.databricksCliPath | ||
| ); | ||
| return new DatabricksCliAuthProvider(host, cli); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With so many changes around passing cli to auth providers I'm not sure I can actually understand what exactly we are improving, can you explain it a bit?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the profile does not have a But, we can be using the internal databricks cli instead of relying on the profile to have the path. It is quiet a common profile pattern to not hard code the cli path. In fact, we should not be writing the cli path either because the profile will fail when we update the extension (hence breaking the path).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was breaking oauth for users with existing profiles. |
||
|
|
||
| default: | ||
| if (config.profile) { | ||
| return new ProfileAuthProvider(host, config.profile); | ||
| return new ProfileAuthProvider(host, config.profile, cli); | ||
| } | ||
| throw new Error(`Unknown auth type: ${config.authType}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export class ProfileAuthProvider extends AuthProvider { | ||
| static async from(profile: string, checked = false) { | ||
| static async from(profile: string, cli: CliWrapper, checked = false) { | ||
| const host = await ProfileAuthProvider.getSdkConfig(profile).getHost(); | ||
| return new ProfileAuthProvider(host, profile, checked); | ||
| return new ProfileAuthProvider(host, profile, cli, checked); | ||
| } | ||
|
|
||
| constructor( | ||
| host: URL, | ||
| private readonly profile: string, | ||
| private readonly cli: CliWrapper, | ||
| checked = false | ||
| ) { | ||
| super(host, "profile", checked); | ||
|
|
@@ -223,7 +215,10 @@ export class ProfileAuthProvider extends AuthProvider { | |
| try { | ||
| const sdkConfig = this.getSdkConfig(); | ||
| await sdkConfig.ensureResolved(); | ||
| const authProvider = AuthProvider.fromSdkConfig(sdkConfig); | ||
| const authProvider = AuthProvider.fromSdkConfig( | ||
| sdkConfig, | ||
| this.cli | ||
| ); | ||
|
|
||
| if (authProvider instanceof ProfileAuthProvider) { | ||
| const workspaceClient = this.getWorkspaceClient(); | ||
|
|
@@ -257,7 +252,7 @@ export class ProfileAuthProvider extends AuthProvider { | |
| export class DatabricksCliAuthProvider extends AuthProvider { | ||
| constructor( | ||
| host: URL, | ||
| readonly databricksPath: string | ||
| readonly cli: CliWrapper | ||
| ) { | ||
| super(host, "databricks-cli"); | ||
| } | ||
|
|
@@ -270,15 +265,15 @@ export class DatabricksCliAuthProvider extends AuthProvider { | |
| return { | ||
| host: this.host.toString(), | ||
| authType: this.authType, | ||
| databricksPath: this.databricksPath, | ||
| databricksPath: this.cli.cliPath, | ||
| }; | ||
| } | ||
|
|
||
| getSdkConfig(): Config { | ||
| return new Config({ | ||
| host: this.host.toString(), | ||
| authType: "databricks-cli", | ||
| databricksCliPath: this.databricksPath, | ||
| databricksCliPath: this.cli.cliPath, | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -293,7 +288,6 @@ export class DatabricksCliAuthProvider extends AuthProvider { | |
| return { | ||
| host: this.host.toString(), | ||
| auth_type: "databricks-cli", | ||
| databricks_cli_path: this.databricksPath, | ||
| }; | ||
| } | ||
|
|
||
|
|
||
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.
Maybe move this logic to the OverrideableModel?
Although I'm not even sure we need a concept of the "root" override file (at least not yet). In the "normal" scenario with only one profile per host we won't really need this override, right? After opening that folder we will log-in automatically. Having all this logic around root override seems like a lot of effort for not much benefit, unless we already plan to use it for a bunch of other things.
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.
We don't have a way to enforce 1 profile per host (and should not because we can have multiple auth methods). A lot of bricksfooders ended up creating multiple profiles for the same host when initializing multiple projects. The extension would then be in a login state until they manually reselected their already created profiles.
This allows us to establish some communication method between the pre bundle init extension instance and post bundle init extension instance. Right now it is just this, but in future with env management, I can imagine having to communicate that information, or cluster information as well.