Skip to content

Commit e224333

Browse files
authored
Bring back login public API (#1217)
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.
1 parent 151e4e5 commit e224333

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

packages/databricks-vscode-types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface PublicApi {
1212
connectionManager: {
1313
onDidChangeState: Event<ConnectionState>;
1414

15+
login(interactive?: boolean, force?: boolean): Promise<void>;
1516
waitForConnect(): Promise<void>;
1617

1718
get state(): ConnectionState;

packages/databricks-vscode/src/configuration/ConnectionManager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {Mutex} from "../locking";
2323
import {MetadataService} from "./auth/MetadataService";
2424
import {Events, Telemetry} from "../telemetry";
2525
import {AutoLoginSource, ManualLoginSource} from "../telemetry/constants";
26+
import {Barrier} from "../locking/Barrier";
2627

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

63+
private readonly initialization = new Barrier();
64+
6265
constructor(
6366
private cli: CliWrapper,
6467
private readonly configModel: ConfigModel,
@@ -169,6 +172,7 @@ export class ConnectionManager implements Disposable {
169172
this.loginWithSavedAuth.bind(this, "targetChange")
170173
)
171174
);
175+
this.initialization.resolve();
172176
}
173177
}
174178

@@ -205,6 +209,14 @@ export class ConnectionManager implements Disposable {
205209
return this.apiClient?.config.authType;
206210
}
207211

212+
// Only used through public API
213+
public async login(interactive?: boolean, force?: boolean) {
214+
await this.initialization.promise;
215+
if (this.state !== "CONNECTED" || force) {
216+
await this.configureLogin("api");
217+
}
218+
}
219+
208220
private async loginWithSavedAuth(source: AutoLoginSource) {
209221
const recordEvent = this.telemetry.start(Events.AUTO_LOGIN);
210222
try {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class Barrier {
2+
public promise: Promise<void>;
3+
public resolve: () => void = () => {};
4+
constructor() {
5+
this.promise = new Promise((resolve) => {
6+
this.resolve = resolve;
7+
});
8+
}
9+
}

packages/databricks-vscode/src/telemetry/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export enum Events {
2323
/* eslint-enable @typescript-eslint/naming-convention */
2424

2525
export type AutoLoginSource = "init" | "hostChange" | "targetChange";
26-
export type ManualLoginSource = "authTypeSwitch" | "authTypeLogin" | "command";
26+
export type ManualLoginSource =
27+
| "authTypeSwitch"
28+
| "authTypeLogin"
29+
| "command"
30+
| "api";
2731
export type BundleRunResourceType = "pipelines" | "jobs";
2832

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

0 commit comments

Comments
 (0)