Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 18 additions & 0 deletions src/commands/configuration-management/api/node-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,23 @@ export class NodeApi {
throw new FatalError(`Problem finding node ${nodeKey} in package ${packageKey} for version ${version}: ${e}`);
});
}

public async findVersionedNodesByPackage(packageKey: string, version: string, withConfiguration: boolean, limit: number, offset: number): Promise<NodeTransport[]> {
const queryParams = new URLSearchParams();
queryParams.set("version", version);
queryParams.set("withConfiguration", withConfiguration.toString());

if (limit) {
queryParams.set("limit", limit.toString());
}
if (offset) {
queryParams.set("offset", offset.toString());
}
return this.httpClient()
.get(`/pacman/api/core/packages/${packageKey}/nodes?${queryParams.toString()}`)
.catch(e => {
throw new FatalError(`Problem fetching nodes from package ${packageKey} for version ${version}: ${e}`);
});
}
}

14 changes: 14 additions & 0 deletions src/commands/configuration-management/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ class Module extends IModule {
.option("--json", "Return the response as a JSON file")
.action(this.findNode);

nodesCommand.command("list")
.description("List nodes in a specific package version")
.requiredOption("--packageKey <packageKey>", "Identifier of the package")
.requiredOption("--packageVersion <packageVersion>", "Version of the package")
.option("--limit <limit>", "Limit the number of results returned")
.option("--offset <offset>", "Offset for pagination")
.option("--withConfiguration", "Include node configuration in the response", false)
.option("--json", "Return the response as a JSON file")
.action(this.listNodes);

nodesCommand.command("diff")
.description("Diff two versions of a specific node in a package")
.requiredOption("--packageKey <packageKey>", "Identifier of the package")
Expand Down Expand Up @@ -142,6 +152,10 @@ class Module extends IModule {
await new NodeService(context).findNode(options.packageKey, options.nodeKey, options.withConfiguration, options.packageVersion ?? null, options.json);
}

private async listNodes(context: Context, command: Command, options: OptionValues): Promise<void> {
await new NodeService(context).listNodes(options.packageKey, options.packageVersion, options.limit, options.offset, options.withConfiguration, options.json);
}

private async diffNode(context: Context, command: Command, options: OptionValues): Promise<void> {
await new NodeDiffService(context).diff(options.packageKey, options.nodeKey, options.baseVersion, options.compareVersion, options.json);
}
Expand Down
58 changes: 39 additions & 19 deletions src/commands/configuration-management/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Context } from "../../core/command/cli-context";
import { fileService, FileService } from "../../core/utils/file-service";
import { logger } from "../../core/utils/logger";
import { v4 as uuidv4 } from "uuid";
import { NodeTransport } from "./interfaces/node.interfaces";

export class NodeService {
private nodeApi: NodeApi;
Expand All @@ -21,26 +22,45 @@ export class NodeService {
fileService.writeToFileWithGivenName(JSON.stringify(node, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + filename);
} else {
logger.info(`ID: ${node.id}`);
logger.info(`Key: ${node.key}`);
logger.info(`Name: ${node.name}`);
logger.info(`Type: ${node.type}`);
logger.info(`Package Node Key: ${node.packageNodeKey}`);
if (node.parentNodeKey) {
logger.info(`Parent Node Key: ${node.parentNodeKey}`);
}
logger.info(`Created By: ${node.createdBy}`);
logger.info(`Updated By: ${node.updatedBy}`);
logger.info(`Creation Date: ${new Date(node.creationDate).toISOString()}`);
logger.info(`Change Date: ${new Date(node.changeDate).toISOString()}`);
if (node.configuration) {
logger.info(`Configuration: ${JSON.stringify(node.configuration, null, 2)}`);
}
if (node.invalidContent) {
logger.info(`Invalid Configuration: ${node.invalidConfiguration}`);
}
logger.info(`Flavor: ${node.flavor}`);
this.printNode(node);
}
}

public async listNodes(packageKey: string, packageVersion: string, limit: number, offset: number, withConfiguration: boolean, jsonResponse: boolean): Promise<void> {
const nodes: NodeTransport[] = await this.nodeApi.findVersionedNodesByPackage(packageKey, packageVersion, withConfiguration, limit, offset);

if (jsonResponse) {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(nodes, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + filename);
} else {
nodes.forEach(node => {
this.printNode(node)
logger.info("--------------------------------------------------");
Comment thread
ZgjimHaziri marked this conversation as resolved.
Outdated
});
}
}

private printNode(node: NodeTransport): void {
logger.info(`ID: ${node.id}`);
logger.info(`Key: ${node.key}`);
logger.info(`Name: ${node.name}`);
logger.info(`Type: ${node.type}`);
logger.info(`Package Node Key: ${node.packageNodeKey}`);
if (node.parentNodeKey) {
logger.info(`Parent Node Key: ${node.parentNodeKey}`);
}
logger.info(`Created By: ${node.createdBy}`);
logger.info(`Updated By: ${node.updatedBy}`);
logger.info(`Creation Date: ${new Date(node.creationDate).toISOString()}`);
logger.info(`Change Date: ${new Date(node.changeDate).toISOString()}`);
if (node.configuration) {
logger.info(`Configuration: ${JSON.stringify(node.configuration, null, 2)}`);
}
if (node.invalidContent) {
logger.info(`Invalid Configuration: ${node.invalidConfiguration}`);
}
logger.info(`Flavor: ${node.flavor}`);
}
}

Loading