Skip to content

Commit

Permalink
[TA-2785] Fix runtime variable assignments export
Browse files Browse the repository at this point in the history
  • Loading branch information
LaberionAjvazi committed Jan 26, 2024
1 parent 457a063 commit 8ae05eb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
6 changes: 6 additions & 0 deletions src/api/variables-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class VariablesApi {
throw new FatalError(`Problem getting variables assignment values for type ${type}: ${e}`);
});
}

public getRuntimeVariableValues(packageKey: string): Promise<VariablesAssignments[]> {
return httpClientV2.get(`/package-manager/api/nodes/by-package-key/${packageKey}/variables/runtime-values`).catch(e => {
throw new FatalError(`Problem getting runtime variables of package ${packageKey}: ${e}`);
});
}
}

export const variablesApi = VariablesApi.INSTANCE;
23 changes: 11 additions & 12 deletions src/services/studio/studio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {dataModelService} from "../package-manager/datamodel-service";
import {IZipEntry} from "adm-zip";
import {parse, stringify} from "../../util/yaml";
import AdmZip = require("adm-zip");
import {nodeApi} from "../../api/node-api";
import {variablesApi} from "../../api/variables-api";

class StudioService {

Expand Down Expand Up @@ -49,23 +51,20 @@ class StudioService {
}

public async getStudioPackageManifests(manifests: PackageManifestTransport[]): Promise<StudioPackageManifest[]> {
const studioManifests: StudioPackageManifest[] = [];
const exportedStudioPackageKeys = manifests
.filter(manifest => manifest.flavor === "STUDIO")
.map(exportedPackage => exportedPackage.packageKey);

const packageWithVariableAssignmentsByKey = await packageApi.findAllPackagesWithVariableAssignments(PackageManagerVariableType.PLAIN_TEXT);
packageWithVariableAssignmentsByKey.forEach(pkg => {
if (exportedStudioPackageKeys.includes(pkg.key)) {
studioManifests.push({
packageKey: pkg.key,
spaceId: pkg.spaceId,
runtimeVariableAssignments: pkg.variableAssignments
})
}
});
return Promise.all(exportedStudioPackageKeys.map(async packageKey => {
const node = await nodeApi.findOneByKeyAndRootNodeKey(packageKey, packageKey);
const variableAssignments = await variablesApi.getRuntimeVariableValues(packageKey);

return studioManifests;
return {
packageKey: packageKey,
spaceId: node.spaceId,
runtimeVariableAssignments: variableAssignments
}
}));
}

public processPackageForExport(exportedPackage: IZipEntry, exportedVariables: VariableManifestTransport[]): AdmZip {
Expand Down
51 changes: 33 additions & 18 deletions tests/config/config-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import * as fs from "fs";
import AdmZip = require("adm-zip");

import { parse, stringify } from "../../src/util/yaml";
import {PackageManagerVariableType, VariableDefinition} from "../../src/interfaces/package-manager.interfaces";
import {
PackageManagerVariableType,
VariableDefinition,
VariablesAssignments
} from "../../src/interfaces/package-manager.interfaces";

describe("Config export", () => {

Expand All @@ -33,18 +37,21 @@ describe("Config export", () => {
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-3", "TEST"));
const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, []);

const firstStudioPackage = PackageManagerApiUtils.buildPackageWithVariableAssignments("key-1", "space-1", [
{
key: "varKey",
type: PackageManagerVariableType.PLAIN_TEXT,
value: "default-value" as unknown as object
}
]);
const secondStudioPackage = PackageManagerApiUtils.buildPackageWithVariableAssignments("key-2", "space-2", []);
const firstStudioPackage = PackageManagerApiUtils.buildContentNodeTransport("key-1", "space-1");
const firstPackageRuntimeVariable: VariablesAssignments = {
key: "varKey",
type: PackageManagerVariableType.PLAIN_TEXT,
value: "default-value" as unknown as object
};

const secondStudioPackage = PackageManagerApiUtils.buildContentNodeTransport("key-2", "space-2");

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch?packageKeys=key-1&packageKeys=key-2&packageKeys=key-3&withDependencies=true", exportedPackagesZip.toBuffer());
mockAxiosPost("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch/variables-with-assignments", []);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=PLAIN_TEXT", [{...firstStudioPackage}, {...secondStudioPackage}]);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${firstStudioPackage.key}/${firstStudioPackage.key}`, firstStudioPackage);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${secondStudioPackage.key}/${secondStudioPackage.key}`, secondStudioPackage);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${firstStudioPackage.key}/variables/runtime-values`, [firstPackageRuntimeVariable]);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${secondStudioPackage.key}/variables/runtime-values`, []);

await new ConfigCommand().batchExportPackages(["key-1", "key-2", "key-3"], true);

Expand All @@ -60,12 +67,12 @@ describe("Config export", () => {
expect(studioManifest).toContainEqual({
packageKey: firstStudioPackage.key,
spaceId: firstStudioPackage.spaceId,
runtimeVariableAssignments: [...firstStudioPackage.variableAssignments]
runtimeVariableAssignments: [firstPackageRuntimeVariable]
});
expect(studioManifest).toContainEqual({
packageKey: secondStudioPackage.key,
spaceId: secondStudioPackage.spaceId,
runtimeVariableAssignments: [...secondStudioPackage.variableAssignments]
runtimeVariableAssignments: []
});
})

Expand Down Expand Up @@ -148,7 +155,10 @@ describe("Config export", () => {

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch?packageKeys=key-1&packageKeys=key-2&withDependencies=true", exportedPackagesZip.toBuffer());
mockAxiosPost("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch/variables-with-assignments", [...exportedVariables]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=PLAIN_TEXT", []);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${firstPackageNode.key}/${firstPackageNode.key}`, firstPackageNode);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${secondPackageNode.key}/${secondPackageNode.key}`, secondPackageNode);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${firstPackageNode.key}/variables/runtime-values`, []);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${secondPackageNode.key}/variables/runtime-values`, []);

await new ConfigCommand().batchExportPackages(["key-1", "key-2"], true);

Expand Down Expand Up @@ -233,7 +243,10 @@ describe("Config export", () => {

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch?packageKeys=key-1&packageKeys=key-2&withDependencies=true", exportedPackagesZip.toBuffer());
mockAxiosPost("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch/variables-with-assignments", []);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=PLAIN_TEXT", []);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${firstPackageNode.key}/${firstPackageNode.key}`, firstPackageNode);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${secondPackageNode.key}/${secondPackageNode.key}`, secondPackageNode);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${firstPackageNode.key}/variables/runtime-values`, []);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${secondPackageNode.key}/variables/runtime-values`, []);

await new ConfigCommand().batchExportPackages(["key-1", "key-2"], true);

Expand Down Expand Up @@ -333,7 +346,10 @@ describe("Config export", () => {

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch?packageKeys=key-1&packageKeys=key-2&withDependencies=true", exportedPackagesZip.toBuffer());
mockAxiosPost("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch/variables-with-assignments", exportedVariables);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=PLAIN_TEXT", []);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${firstPackageNode.key}/${firstPackageNode.key}`, firstPackageNode);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/${secondPackageNode.key}/${secondPackageNode.key}`, secondPackageNode);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${firstPackageNode.key}/variables/runtime-values`, []);
mockAxiosGet(`https://myTeam.celonis.cloud/package-manager/api/nodes/by-package-key/${secondPackageNode.key}/variables/runtime-values`, []);

await new ConfigCommand().batchExportPackages(["key-1", "key-2"], true);

Expand Down Expand Up @@ -371,13 +387,12 @@ describe("Config export", () => {

it("Should export by packageKeys without dependencies", async () => {
const manifest: PackageManifestTransport[] = [];
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-1", "STUDIO"));
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-2", "STUDIO"));
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-1", "TEST"));
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-2", "TEST"));
const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, []);

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch?packageKeys=key-1&packageKeys=key-2&packageKeys=key-3&withDependencies=false", exportedPackagesZip.toBuffer());
mockAxiosPost("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/batch/variables-with-assignments", []);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=PLAIN_TEXT", []);

await new ConfigCommand().batchExportPackages(["key-1", "key-2", "key-3"], false);

Expand Down

0 comments on commit 8ae05eb

Please sign in to comment.