Skip to content

Commit f993f37

Browse files
authored
Pass proxy environment variables if set (#413)
1 parent 4be0cd7 commit f993f37

File tree

2 files changed

+98
-35
lines changed

2 files changed

+98
-35
lines changed

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

Lines changed: 82 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,92 @@ describe(__filename, () => {
3232
assert.deepEqual(task.problemMatchers, ["$bricks-sync"]);
3333
});
3434

35-
it("should create pseudo terminal with correct environment variables", () => {
36-
const mockDbWorkspace = mock(DatabricksWorkspace);
37-
when(mockDbWorkspace.authProvider).thenReturn(
38-
new ProfileAuthProvider(
39-
new URL("https://000000000000.00.azuredatabricks.net/"),
40-
"profile"
41-
)
42-
);
35+
describe("pseudo terminal", () => {
36+
let env: NodeJS.ProcessEnv;
4337

44-
const mockSyncDestination = mock(SyncDestination);
45-
when(mockSyncDestination.vscodeWorkspacePath).thenReturn(
46-
Uri.file("/path/to/local/workspace")
47-
);
38+
beforeEach(() => {
39+
// Save environment.
40+
env = process.env;
4841

49-
when(connection.databricksWorkspace).thenReturn(
50-
instance(mockDbWorkspace)
51-
);
52-
when(connection.syncDestination).thenReturn(
53-
instance(mockSyncDestination)
54-
);
42+
// Create copy so it is safe to mutate it in tests.
43+
process.env = {
44+
...env,
45+
};
46+
});
5547

56-
const terminal = new LazyCustomSyncTerminal(
57-
instance(connection),
58-
instance(cli),
59-
"full",
60-
() => {}
61-
);
48+
afterEach(() => {
49+
// Restore original environment.
50+
process.env = env;
51+
});
52+
53+
let terminal: LazyCustomSyncTerminal;
54+
55+
beforeEach(() => {
56+
const mockDbWorkspace = mock(DatabricksWorkspace);
57+
when(mockDbWorkspace.authProvider).thenReturn(
58+
new ProfileAuthProvider(
59+
new URL("https://000000000000.00.azuredatabricks.net/"),
60+
"profile"
61+
)
62+
);
63+
64+
const mockSyncDestination = mock(SyncDestination);
65+
when(mockSyncDestination.vscodeWorkspacePath).thenReturn(
66+
Uri.file("/path/to/local/workspace")
67+
);
68+
69+
when(connection.databricksWorkspace).thenReturn(
70+
instance(mockDbWorkspace)
71+
);
72+
73+
when(connection.syncDestination).thenReturn(
74+
instance(mockSyncDestination)
75+
);
76+
77+
terminal = new LazyCustomSyncTerminal(
78+
instance(connection),
79+
instance(cli),
80+
"full",
81+
() => {}
82+
);
83+
});
84+
85+
it("should receive correct environment variables", () => {
86+
delete process.env["HTTP_PROXY"];
87+
delete process.env["HTTPS_PROXY"];
88+
89+
assert.deepEqual(terminal.getProcessOptions(), {
90+
cwd: Uri.file("/path/to/local/workspace").fsPath,
91+
env: {
92+
/* eslint-disable @typescript-eslint/naming-convention */
93+
BRICKS_ROOT: Uri.file("/path/to/local/workspace").fsPath,
94+
DATABRICKS_CONFIG_PROFILE: "profile",
95+
DATABRICKS_CONFIG_FILE: undefined,
96+
HOME: process.env.HOME,
97+
PATH: process.env.PATH,
98+
/* eslint-enable @typescript-eslint/naming-convention */
99+
},
100+
});
101+
});
102+
103+
it("should pass through proxy variables if set", () => {
104+
process.env.HTTP_PROXY = "http_proxy";
105+
process.env.HTTPS_PROXY = "https_proxy";
62106

63-
assert.deepEqual(terminal.getProcessOptions(), {
64-
cwd: Uri.file("/path/to/local/workspace").fsPath,
65-
env: {
66-
/* eslint-disable @typescript-eslint/naming-convention */
67-
BRICKS_ROOT: Uri.file("/path/to/local/workspace").fsPath,
68-
DATABRICKS_CONFIG_PROFILE: "profile",
69-
DATABRICKS_CONFIG_FILE: undefined,
70-
HOME: process.env.HOME,
71-
PATH: process.env.PATH,
72-
/* eslint-enable @typescript-eslint/naming-convention */
73-
},
107+
assert.deepEqual(terminal.getProcessOptions(), {
108+
cwd: Uri.file("/path/to/local/workspace").fsPath,
109+
env: {
110+
/* eslint-disable @typescript-eslint/naming-convention */
111+
BRICKS_ROOT: Uri.file("/path/to/local/workspace").fsPath,
112+
DATABRICKS_CONFIG_PROFILE: "profile",
113+
DATABRICKS_CONFIG_FILE: undefined,
114+
HOME: process.env.HOME,
115+
PATH: process.env.PATH,
116+
HTTP_PROXY: "http_proxy",
117+
HTTPS_PROXY: "https_proxy",
118+
/* eslint-enable @typescript-eslint/naming-convention */
119+
},
120+
});
74121
});
75122
});
76123
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ export class LazyCustomSyncTerminal extends CustomSyncTerminal {
231231
);
232232
}
233233

234+
// Pass through proxy settings to child process.
235+
const proxySettings: {[key: string]: string | undefined} = {
236+
/* eslint-disable @typescript-eslint/naming-convention */
237+
HTTP_PROXY: process.env.HTTP_PROXY,
238+
HTTPS_PROXY: process.env.HTTPS_PROXY,
239+
/* eslint-enable @typescript-eslint/naming-convention */
240+
};
241+
242+
// Remove undefined keys.
243+
Object.keys(proxySettings).forEach((key) => {
244+
if (proxySettings[key] === undefined) {
245+
delete proxySettings[key];
246+
}
247+
});
248+
234249
return {
235250
cwd: workspacePath,
236251
env: {
@@ -239,6 +254,7 @@ export class LazyCustomSyncTerminal extends CustomSyncTerminal {
239254
DATABRICKS_CONFIG_FILE: process.env.DATABRICKS_CONFIG_FILE,
240255
HOME: process.env.HOME,
241256
PATH: process.env.PATH,
257+
...proxySettings,
242258
...dbWorkspace.authProvider.getEnvVars(),
243259
/* eslint-enable @typescript-eslint/naming-convention */
244260
},

0 commit comments

Comments
 (0)