Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/user-guide/config-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ The name of the file will be printed in the console with the following format:
info: File downloaded successfully. New filename: 9560f81f-f746-4117-83ee-dd1f614ad624.json
```

By using the --flavors option, you can filter which packages to list. The available flavors are: **STUDIO** and **OCDM**.
By using the `--flavors` option, you can filter which packages to list. The available flavors are: **STUDIO** and **OCDM**.

To list staging packages instead of deployed packages use the `--staging` option. Please note that this flag is not compatible with the below options.

### List Packages with Dependencies

Expand All @@ -44,7 +46,7 @@ content-cli config list -p <sourceProfile> --withDependencies

```bash
content-cli config list -p <sourceProfile> --packageKeys key1 ... keyN
[optional] –withDependencies
[optional] –-withDependencies
```

## Batch Export Packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@ export class BatchImportExportApi {

queryParams.set("withDependencies", withDependencies.toString());
queryParams.set("includeBranches", includeBranches.toString());
flavors.forEach(flavor => queryParams.append("flavors", flavor))
flavors.forEach(flavor => queryParams.append("flavors", flavor));

return this.httpClient().get(`/package-manager/api/core/packages/export/list?${queryParams.toString()}`).catch(e => {
throw new FatalError(`Problem getting active packages: ${e}`);
});
}

public async findAllStagingPackages(flavors: string[], includeBranches: boolean = false): Promise<PackageExportTransport[]> {
const queryParams = new URLSearchParams();

queryParams.set("includeBranches", includeBranches.toString());
flavors.forEach(flavor => queryParams.append("flavors", flavor));

return this.httpClient().get(`/package-manager/api/core/staging/packages/export/list?${queryParams.toString()}`).catch(e => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

Suggested change
return this.httpClient().get(`/package-manager/api/core/staging/packages/export/list?${queryParams.toString()}`).catch(e => {
return this.httpClient().get(`/pacman/api/core/staging/packages/export/list?${queryParams.toString()}`).catch(e => {

throw new FatalError(`Problem getting staging packages: ${e}`);
});
}

public async findActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string, includeBranches: boolean = false): Promise<PackageExportTransport[]> {
const queryParams = new URLSearchParams();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export class BatchImportExportService {
});
}

public async listStagingPackages(flavors: string[], includeBranches: boolean, jsonResponse: boolean): Promise<void> {
const stagingPackages = await this.batchImportExportApi.findAllStagingPackages(flavors, includeBranches);
if (jsonResponse) {
this.exportListOfPackages(stagingPackages);
} else {
stagingPackages.forEach(pkg => {
logger.info(`${pkg.name} - Key: "${pkg.key}"`);
});
}
}

public async findAndExportListOfPackages(flavors: string[], packageKeys: string[], keysByVersion: string[], withDependencies: boolean, includeBranches: boolean): Promise<void> {
let packagesToExport: PackageExportTransport[];

Expand Down
20 changes: 14 additions & 6 deletions src/commands/configuration-management/config-command.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ export class ConfigCommandService {
this.diffService = new DiffService(context);
}

public async listPackages(jsonResponse: boolean, flavors: string[], withDependencies: boolean, packageKeys: string[], keysByVersion: string[], variableValue: string, variableType: string, includeBranches: boolean): Promise<void> {
if (variableValue) {
public async listPackages(
jsonResponse: boolean,
flavors: string[],
withDependencies: boolean,
packageKeys: string[],
keysByVersion: string[],
variableValue: string,
variableType: string,
includeBranches: boolean,
staging: boolean): Promise<void> {
if (staging) {
await this.batchImportExportService.listStagingPackages(flavors ?? [], includeBranches, jsonResponse);
} else if (variableValue) {
await this.listPackagesByVariableValue(jsonResponse, flavors, variableValue, variableType, includeBranches);
return;
}

if (jsonResponse) {
} else if (jsonResponse) {
await this.batchImportExportService.findAndExportListOfPackages(flavors ?? [], packageKeys ?? [], keysByVersion ?? [], withDependencies, includeBranches);
} else if (keysByVersion) {
await this.batchImportExportService.listPackagesByKeysWithVersion(keysByVersion, withDependencies);
Expand Down
9 changes: 7 additions & 2 deletions src/commands/configuration-management/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ class Module extends IModule {
configCommand.command("list")
.description("Command to list packages")
.option("--json", "Return response as json type", "")
.option("--flavors <flavors...>", "Lists only active packages of the given flavors")
.option("--flavors <flavors...>", "Lists only packages of the given flavors")
.option("--withDependencies", "Include dependencies", "")
.option("--packageKeys <packageKeys...>", "Lists only active versions of given package keys")
.option("--keysByVersion <keysByVersion...>", "Lists packages by given key and version [packageKey.version]")
.option("--variableValue <variableValue>", "Variable value for filtering packages by.")
.option("--variableType <variableType>", "Variable type for filtering packages by.")
.option("--branches", "Include branches", false)
.option("--staging", "List staging packages instead", false)
.action(this.listPackages);

configCommand.command("export")
Expand Down Expand Up @@ -183,6 +184,9 @@ class Module extends IModule {
}

private async listPackages(context: Context, command: Command, options: OptionValues): Promise<void> {
if (options.staging && (options.withDependencies || options.packageKeys || options.keysByVersion || options.variableValue || options.variableType)) {
throw new Error("Staging parameter is not compatible with --withDependencies, --packageKeys, --keysByVersion, --variableValue, --variableType");
Comment thread
Buqeta marked this conversation as resolved.
}
if (options.packageKeys && options.keysByVersion) {
throw new Error("Please provide either --packageKeys or --keysByVersion, but not both.");
}
Expand All @@ -195,7 +199,8 @@ class Module extends IModule {
options.keysByVersion,
options.variableValue,
options.variableType,
options.branches);
options.branches,
options.staging);
}

private async batchExportPackages(context: Context, command: Command, options: OptionValues): Promise<void> {
Expand Down
80 changes: 70 additions & 10 deletions tests/commands/configuration-management/config-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Config list", () => {

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?" + urlParams.toString(), [firstPackage, secondPackage]);

await new ConfigCommandService(testContext).listPackages(false, flavorsArray, false, [], undefined, null, null, false);
await new ConfigCommandService(testContext).listPackages(false, flavorsArray, false, [], undefined, null, null, false, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
Expand All @@ -50,7 +50,7 @@ describe("Config list", () => {
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?withDependencies=false&includeBranches=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);

await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, null, null, false);
await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, null, null, false, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand Down Expand Up @@ -96,7 +96,7 @@ describe("Config list", () => {
};
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/compute-pools/data-models/details", [dataModelDetailResponse]);

await new ConfigCommandService(testContext).listPackages(true, [], true, [], undefined, null, null, false);
await new ConfigCommandService(testContext).listPackages(true, [], true, [], undefined, null, null, false, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -121,7 +121,7 @@ describe("Config list", () => {
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-keys?packageKeys=key-1&packageKeys=key-2&withDependencies=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);

await new ConfigCommandService(testContext).listPackages(true, [], false, [firstPackage.key, secondPackage.key], undefined, null, null, false);
await new ConfigCommandService(testContext).listPackages(true, [], false, [firstPackage.key, secondPackage.key], undefined, null, null, false, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand Down Expand Up @@ -167,7 +167,7 @@ describe("Config list", () => {
};
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/compute-pools/data-models/details", [dataModelDetailResponse]);

await new ConfigCommandService(testContext).listPackages(true, [], true, [firstPackage.key, secondPackage.key], undefined, null, null, false);
await new ConfigCommandService(testContext).listPackages(true, [], true, [firstPackage.key, secondPackage.key], undefined, null, null, false, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -191,7 +191,7 @@ describe("Config list", () => {
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1&includeBranches=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", []);

await new ConfigCommandService(testContext).listPackages(false, [], false, [], undefined, "1", null, false);
await new ConfigCommandService(testContext).listPackages(false, [], false, [], undefined, "1", null, false, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
Expand All @@ -205,7 +205,7 @@ describe("Config list", () => {
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1&includeBranches=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", []);

await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, "1", null, false);
await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, "1", null, false, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -225,7 +225,7 @@ describe("Config list", () => {
[firstPackage, secondPackage]
);

await new ConfigCommandService(testContext).listPackages(false, [], false, undefined, keysByVersion, null, null, false);
await new ConfigCommandService(testContext).listPackages(false, [], false, undefined, keysByVersion, null, null, false, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
Expand All @@ -242,7 +242,7 @@ describe("Config list", () => {
[firstPackage, secondPackage]
);

await new ConfigCommandService(testContext).listPackages(false, [], true, undefined, keysByVersion, null, null, false);
await new ConfigCommandService(testContext).listPackages(false, [], true, undefined, keysByVersion, null, null, false, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
})
Expand All @@ -260,7 +260,7 @@ describe("Config list", () => {
);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);

await new ConfigCommandService(testContext).listPackages(true, [], false, [], keysByVersion, null, null, false);
await new ConfigCommandService(testContext).listPackages(true, [], false, [], keysByVersion, null, null, false, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -275,4 +275,64 @@ describe("Config list", () => {
expect(exportedSecondPackage).toEqual(secondPackage);
expect(exportedFirstPackage).toEqual({...firstPackage, spaceId: "spaceId-1"});
})

it("Should list all staging packages by key for non-json response with flavors", async () => {
Comment thread
promeris marked this conversation as resolved.
const firstPackage = PacmanApiUtils.buildPackageExportTransport("studio", "name-1");
const secondPackage = PacmanApiUtils.buildPackageExportTransport("ocdm", "name-2");

const urlParams = new URLSearchParams();
urlParams.set("includeBranches", "false");
urlParams.append("flavors", "STUDIO");

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/staging/packages/export/list?" + urlParams.toString(), [firstPackage, secondPackage]);

await new ConfigCommandService(testContext).listPackages(false, ["STUDIO"], false, [], undefined, null, null, false, true);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
expect(loggingTestTransport.logMessages[1].message).toContain(`${secondPackage.name} - Key: "${secondPackage.key}"`);
})

it("Should list all staging packages by key for non-json response without flavors", async () => {
const firstPackage = PacmanApiUtils.buildPackageExportTransport("studio", "name-1");
const secondPackage = PacmanApiUtils.buildPackageExportTransport("ocdm", "name-2");

const urlParams = new URLSearchParams();
urlParams.set("includeBranches", "false");

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/staging/packages/export/list?" + urlParams.toString(), [firstPackage, secondPackage]);

await new ConfigCommandService(testContext).listPackages(false, null, false, [], undefined, null, null, false, true);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
expect(loggingTestTransport.logMessages[1].message).toContain(`${secondPackage.name} - Key: "${secondPackage.key}"`);
})

it("Should list all staging packages by key for json response with flavors", async () => {
const firstPackage = PacmanApiUtils.buildPackageExportTransport("studio", "name-1");
const secondPackage = PacmanApiUtils.buildPackageExportTransport("ocdm", "name-2");

const urlParams = new URLSearchParams();
urlParams.set("includeBranches", "false");
urlParams.append("flavors", "STUDIO");

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/staging/packages/export/list?" + urlParams.toString(), [firstPackage, secondPackage]);

await new ConfigCommandService(testContext).listPackages(true, ["STUDIO"], false, [], undefined, null, null, false, true);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

expect(mockWriteFileSync).toHaveBeenCalledWith(path.resolve(process.cwd(), expectedFileName), expect.any(String), {encoding: "utf-8", mode: 0o600});

const exportedTransports = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as PackageExportTransport[];
expect(exportedTransports.length).toBe(2);

const exportedFirstPackage = exportedTransports.find(transport => transport.key === firstPackage.key);
const exportedSecondPackage = exportedTransports.find(transport => transport.key === secondPackage.key);

expect(exportedSecondPackage).toEqual(secondPackage);
expect(exportedFirstPackage).toEqual(firstPackage);

})
})
Loading
Loading