Skip to content

Commit

Permalink
Bring back login public API (#1217)
Browse files Browse the repository at this point in the history
Tested on databricks driver for the SQLTools extension. Databricks Power
Tools extension doesn't work even with 1.3 version. With this v2 API it
has the same "Connection is not valid!" issue as in 1.3.
  • Loading branch information
ilia-db authored May 6, 2024
1 parent 151e4e5 commit e224333
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/databricks-vscode-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface PublicApi {
connectionManager: {
onDidChangeState: Event<ConnectionState>;

login(interactive?: boolean, force?: boolean): Promise<void>;
waitForConnect(): Promise<void>;

get state(): ConnectionState;
Expand Down
12 changes: 12 additions & 0 deletions packages/databricks-vscode/src/configuration/ConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {Mutex} from "../locking";
import {MetadataService} from "./auth/MetadataService";
import {Events, Telemetry} from "../telemetry";
import {AutoLoginSource, ManualLoginSource} from "../telemetry/constants";
import {Barrier} from "../locking/Barrier";

// eslint-disable-next-line @typescript-eslint/naming-convention
const {NamedLogger} = logging;
Expand Down Expand Up @@ -59,6 +60,8 @@ export class ConnectionManager implements Disposable {
public readonly onDidChangeSyncDestination =
this.onDidChangeSyncDestinationEmitter.event;

private readonly initialization = new Barrier();

constructor(
private cli: CliWrapper,
private readonly configModel: ConfigModel,
Expand Down Expand Up @@ -169,6 +172,7 @@ export class ConnectionManager implements Disposable {
this.loginWithSavedAuth.bind(this, "targetChange")
)
);
this.initialization.resolve();
}
}

Expand Down Expand Up @@ -205,6 +209,14 @@ export class ConnectionManager implements Disposable {
return this.apiClient?.config.authType;
}

// Only used through public API
public async login(interactive?: boolean, force?: boolean) {
await this.initialization.promise;
if (this.state !== "CONNECTED" || force) {
await this.configureLogin("api");
}
}

private async loginWithSavedAuth(source: AutoLoginSource) {
const recordEvent = this.telemetry.start(Events.AUTO_LOGIN);
try {
Expand Down
9 changes: 9 additions & 0 deletions packages/databricks-vscode/src/locking/Barrier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Barrier {
public promise: Promise<void>;
public resolve: () => void = () => {};
constructor() {
this.promise = new Promise((resolve) => {
this.resolve = resolve;
});
}
}
6 changes: 5 additions & 1 deletion packages/databricks-vscode/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export enum Events {
/* eslint-enable @typescript-eslint/naming-convention */

export type AutoLoginSource = "init" | "hostChange" | "targetChange";
export type ManualLoginSource = "authTypeSwitch" | "authTypeLogin" | "command";
export type ManualLoginSource =
| "authTypeSwitch"
| "authTypeLogin"
| "command"
| "api";
export type BundleRunResourceType = "pipelines" | "jobs";

/** Documentation about all of the properties and metrics of the event. */
Expand Down

0 comments on commit e224333

Please sign in to comment.