Skip to content

Commit fd8ae92

Browse files
Read data from global workspace block in databaricks.yml (#1059)
## Changes * Bundles support loading workspace data (host, sync destination) from a global "workspace" block, which is overriden by value of the optional workspace block in each target block. * This PR adds support for this behaviour. ## Tests <!-- How is this tested? -->
1 parent 626e134 commit fd8ae92

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

packages/databricks-vscode/src/bundle/models/BundlePreValidateModel.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {Uri} from "vscode";
22
import {BundleFileSet, BundleWatcher} from "..";
3-
import {BundleTarget} from "../types";
3+
import {BundleSchema, BundleTarget} from "../types";
44
import {BaseModelWithStateCache} from "../../configuration/models/BaseModelWithStateCache";
55
import {UrlUtils} from "../../utils";
66
import {Mutex} from "../../locking";
7+
import * as lodash from "lodash";
78

89
export type BundlePreValidateState = {
910
host?: URL;
@@ -32,9 +33,16 @@ export class BundlePreValidateModel extends BaseModelWithStateCache<BundlePreVal
3233
}
3334

3435
get targets() {
35-
return this.bundleFileSet.bundleDataCache.value.then(
36-
(data) => data?.targets
37-
);
36+
return (async () => {
37+
const bundle = await this.bundleFileSet.bundleDataCache.value;
38+
const targets = Object.assign({}, bundle.targets ?? {});
39+
40+
Object.keys(targets ?? {}).map((key) => {
41+
targets[key] = this.getRawTargetData(bundle, key);
42+
});
43+
44+
return targets;
45+
})();
3846
}
3947

4048
get defaultTarget() {
@@ -67,16 +75,30 @@ export class BundlePreValidateModel extends BaseModelWithStateCache<BundlePreVal
6775
: undefined;
6876
}
6977

78+
private getRawTargetData(bundle: BundleSchema, target: string) {
79+
const targetObject = Object.assign({}, bundle?.targets?.[target]);
80+
const globalWorkspace = Object.assign({}, bundle?.workspace);
81+
if (targetObject !== undefined) {
82+
targetObject.workspace = lodash.merge(
83+
globalWorkspace ?? {},
84+
targetObject.workspace
85+
);
86+
}
87+
return targetObject;
88+
}
89+
7090
@Mutex.synchronise("mutex")
7191
protected async readState() {
7292
if (this.target === undefined) {
7393
return {};
7494
}
7595

76-
const targetObject = (await this.bundleFileSet.bundleDataCache.value)
77-
.targets?.[this.target];
78-
79-
return this.readStateFromTarget(targetObject) ?? {};
96+
const bundle = await this.bundleFileSet.bundleDataCache.value;
97+
return (
98+
this.readStateFromTarget(
99+
this.getRawTargetData(bundle, this.target)
100+
) ?? {}
101+
);
80102
}
81103

82104
public async getFileToWrite(key: string) {

0 commit comments

Comments
 (0)