Skip to content

Commit 8c60fa5

Browse files
authored
Add DATABRICKS_CLI_UPSTREAM env var to CLI calls (#1112)
Also add DATABRICKS_CLI_UPSTREAM_VERSION
1 parent 5b3fbd3 commit 8c60fa5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

packages/databricks-vscode/src/cli/CliWrapper.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ import crypto from "node:crypto";
1818
import {Context} from "@databricks/databricks-sdk/dist/context";
1919
import {logging} from "@databricks/databricks-sdk";
2020
import {LoggerManager} from "../logger";
21+
import {ProfileAuthProvider} from "../configuration/auth/AuthProvider";
22+
import {isMatch} from "lodash";
23+
import {removeUndefinedKeys} from "../utils/envVarGenerators";
2124

2225
const execFile = promisify(execFileCb);
2326
const cliPath = path.join(__dirname, "../../bin/databricks");
2427

28+
// eslint-disable-next-line @typescript-eslint/no-var-requires
29+
const extensionVersion = require("../../package.json").version;
30+
2531
function getTempLogFilePath() {
2632
return path.join(
2733
os.tmpdir(),
@@ -204,4 +210,50 @@ nothing = true
204210
assert.equal(profiles.length, 0);
205211
});
206212
});
213+
214+
it("should set required env vars to the bundle run CLI calls", async () => {
215+
const logFilePath = getTempLogFilePath();
216+
const cli = createCliWrapper(logFilePath);
217+
const authProvider = new ProfileAuthProvider(
218+
new URL("https://test.com"),
219+
"PROFILE",
220+
true
221+
);
222+
const workspaceFolder = Uri.file("/test/123");
223+
const runCmd = cli.getBundleRunCommand(
224+
"dev",
225+
authProvider,
226+
"resource-key",
227+
workspaceFolder
228+
);
229+
const expected = {
230+
args: ["bundle", "run", "--target", "dev", "resource-key"],
231+
cmd: cli.cliPath,
232+
options: {
233+
cwd: workspaceFolder.fsPath,
234+
env: removeUndefinedKeys({
235+
/* eslint-disable @typescript-eslint/naming-convention */
236+
DATABRICKS_CLI_UPSTREAM: "databricks-vscode",
237+
DATABRICKS_CLI_UPSTREAM_VERSION: extensionVersion,
238+
DATABRICKS_CONFIG_PROFILE: "PROFILE",
239+
DATABRICKS_HOST: "https://test.com/",
240+
DATABRICKS_LOG_FILE: logFilePath,
241+
DATABRICKS_LOG_FORMAT: "json",
242+
DATABRICKS_LOG_LEVEL: "debug",
243+
DATABRICKS_OUTPUT_FORMAT: "json",
244+
HOME: process.env.HOME,
245+
PATH: process.env.PATH,
246+
/* eslint-enable @typescript-eslint/naming-convention */
247+
}),
248+
shell: true,
249+
},
250+
};
251+
try {
252+
assert.ok(isMatch(runCmd, expected));
253+
} catch (e) {
254+
// Run this in the "catch" case to show better error messages
255+
assert.deepStrictEqual(runCmd, expected);
256+
throw e;
257+
}
258+
});
207259
});

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ async function waitForProcess(
8787
*/
8888
export class CliWrapper {
8989
private clusterId?: string;
90+
9091
constructor(
9192
private extensionContext: ExtensionContext,
9293
private loggerManager: LoggerManager,

packages/databricks-vscode/src/utils/envVarGenerators.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {logging, Headers} from "@databricks/databricks-sdk";
55
import {ConnectionManager} from "../configuration/ConnectionManager";
66
import {ConfigModel} from "../configuration/models/ConfigModel";
77

8+
// eslint-disable-next-line @typescript-eslint/no-var-requires
9+
const extensionVersion = require("../../package.json").version;
10+
811
//Get env variables from user's .env file
912
export async function getUserEnvVars(userEnvPath: Uri) {
1013
try {
@@ -137,6 +140,8 @@ export function getEnvVarsForCli(configfilePath?: string) {
137140
DATABRICKS_CONFIG_FILE:
138141
configfilePath ?? process.env.DATABRICKS_CONFIG_FILE,
139142
DATABRICKS_OUTPUT_FORMAT: "json",
143+
DATABRICKS_CLI_UPSTREAM: "databricks-vscode",
144+
DATABRICKS_CLI_UPSTREAM_VERSION: extensionVersion,
140145
};
141146
/* eslint-enable @typescript-eslint/naming-convention */
142147
}

0 commit comments

Comments
 (0)