Skip to content
Merged
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
4 changes: 2 additions & 2 deletions docs/command-graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@
description: "Archive a staging node in a package",
options: ["-p, --profile <profile>", "--packageKey <packageKey>", "--nodeKey <nodeKey>", "--force (default: false)", "-h, --help"] },
{ id: "config_nodes_list", label: "list", group: "command", path: "config nodes list",
description: "List nodes in a specific package version",
options: ["-p, --profile <profile>", "--packageKey <packageKey>", "--packageVersion <packageVersion>", "--limit <limit>", "--offset <offset>", "--withConfiguration (default: false)", "--json", "-h, --help"] },
description: "List nodes in a package. Lists staging nodes by default.",
options: ["-p, --profile <profile>", "--packageKey <packageKey>", "--packageVersion <packageVersion> (if omitted, staging state is used)", "--limit <limit>", "--offset <offset>", "--withConfiguration (default: false)", "--json", "-h, --help"] },
{ id: "config_nodes_diff", label: "diff", group: "command", path: "config nodes diff",
description: "Diff two versions of a specific node in a package",
options: ["-p, --profile <profile>", "--packageKey <packageKey>", "--nodeKey <nodeKey>", "--baseVersion <baseVersion>", "--compareVersion <compareVersion> (mutually exclusive with --file; exactly one required)", "-f, --file <file> (mutually exclusive with --compareVersion; exactly one required)", "--json", "-h, --help"] },
Expand Down
26 changes: 19 additions & 7 deletions docs/user-guide/config-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,16 @@ Use `--force` with care: dependants are not archived for you, and the package ma

## Listing Nodes

The **config nodes list** command allows you to retrieve all nodes within a specific package version.
The **config nodes list** command retrieves all nodes in a package. By default it lists nodes in the **staging (draft) version**. Pass `--packageVersion` to list a published package version instead.

### List Nodes in a Package Version
This command requires **edit permission** on the target package (see [Permissions](#permissions)).

### List Staging Nodes

To list all nodes in a specific package version, use the following command:
To list all nodes in the staging version of a package, omit `--packageVersion`:

```bash
content-cli config nodes list --packageKey <packageKey> --packageVersion <packageVersion>
content-cli config nodes list --packageKey <packageKey>
```

The command will display information for each node in the console as a JSON object:
Expand All @@ -753,20 +755,30 @@ info: {"id":"node-id-456","key":"node-key-2","name":"My Second Node","type":"KNO
...
```

### List Nodes in a Package Version

To list all nodes in a specific package version, use the `--packageVersion` option:

```bash
content-cli config nodes list --packageKey <packageKey> --packageVersion <packageVersion>
```

### Pagination

The response is paginated, and the page size can be controlled with the `--limit` and `--offset` options (defaults to 100 and 0 respectively).

```bash
content-cli config nodes list --packageKey my-package --limit 10
content-cli config nodes list --packageKey my-package --limit 10 --offset 10
content-cli config nodes list --packageKey my-package --packageVersion 1.2.3 --limit 10
content-cli config nodes list --packageKey my-package --packageVersion 1.2.3 --limit 10 --offset 10
```

### List Nodes with Configuration

By default, the node configuration is not included in the response. To include each node's configuration, use the `--withConfiguration` flag:

```bash
content-cli config nodes list --packageKey <packageKey> --withConfiguration
content-cli config nodes list --packageKey <packageKey> --packageVersion <packageVersion> --withConfiguration
```

Expand All @@ -775,13 +787,13 @@ content-cli config nodes list --packageKey <packageKey> --packageVersion <packag
To export the nodes list as a JSON file, use the `--json` option:

```bash
content-cli config nodes list --packageKey <packageKey> --packageVersion <packageVersion> --json
content-cli config nodes list --packageKey <packageKey> --json
```

You can combine options:

```bash
content-cli config nodes list --packageKey <packageKey> --packageVersion <packageVersion> --withConfiguration --json
content-cli config nodes list --packageKey <packageKey> --withConfiguration --json
content-cli config nodes list --packageKey my-package --packageVersion 1.2.3 --limit 50 --offset 100 --json
```

Expand Down
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 @@ -64,6 +64,24 @@ export class NodeApi {
});
}

public async findStagingNodesByPackage(packageKey: string, withConfiguration: boolean, limit: number, offset: number): Promise<NodeTransport[]> {
const queryParams = new URLSearchParams();
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/staging/packages/${packageKey}/nodes?${queryParams.toString()}`)
.catch(e => {
throw new FatalError(`Problem fetching nodes from package ${packageKey}: ${e}`);
});
}

public async findVersionedNodesByPackage(packageKey: string, version: string, withConfiguration: boolean, limit: number, offset: number): Promise<NodeTransport[]> {
const queryParams = new URLSearchParams();
queryParams.set("version", version);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/configuration-management/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ class Module extends IModule {
.action(this.archiveNode);

nodesCommand.command("list")
.description("List nodes in a specific package version")
.description("List nodes in a package. Lists staging nodes by default.")
.requiredOption("--packageKey <packageKey>", "Identifier of the package")
.requiredOption("--packageVersion <packageVersion>", "Version of the package")
.option("--packageVersion <packageVersion>", "Version of the package. If not sent, the staging state of the package will be used.")
.option("--limit <limit>", "Limit the number of results returned")
.option("--offset <offset>", "Offset for pagination")
.option("--withConfiguration", "Include node configuration in the response", false)
Expand Down Expand Up @@ -548,7 +548,7 @@ class Module extends IModule {
}

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);
await new NodeService(context).listNodes(options.packageKey, options.packageVersion ?? null, options.limit, options.offset, options.withConfiguration, options.json);
}

private async diffNode(context: Context, command: Command, options: OptionValues): Promise<void> {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/configuration-management/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export class NodeService {
}
}

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);
public async listNodes(packageKey: string, packageVersion: string | null, limit: number, offset: number, withConfiguration: boolean, jsonResponse: boolean): Promise<void> {
const nodes: NodeTransport[] = packageVersion
? await this.nodeApi.findVersionedNodesByPackage(packageKey, packageVersion, withConfiguration, limit, offset)
: await this.nodeApi.findStagingNodesByPackage(packageKey, withConfiguration, limit, offset);

if (jsonResponse) {
const filename = uuidv4() + ".json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,90 @@ describe("Node list", () => {
const parentKeyMessages = loggingTestTransport.logMessages.filter(log => log.message.includes("Parent Node Key"));
expect(parentKeyMessages.length).toBe(0);
});

it("Should list staging nodes when package version is omitted", async () => {
const packageKey = "package-key";
const limit = 10;
const offset = 0;

const node1 = createNode("node-id-1", "node-key-1", "Node 1", "parent-key");
const node2 = createNode("node-id-2", "node-key-2", "Node 2");
const response: NodeTransport[] = [node1, node2];

mockAxiosGet(
`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes?withConfiguration=false&limit=${limit}`,
response
);

await new NodeService(testContext).listNodes(packageKey, null, limit, offset, false, false);

expect(loggingTestTransport.logMessages).toHaveLength(2);
expect(loggingTestTransport.logMessages[0].message).toContain(JSON.stringify(node1));
expect(loggingTestTransport.logMessages[1].message).toContain(JSON.stringify(node2));
});

it("Should list staging nodes with configuration", async () => {
const packageKey = "package-key";
const limit = 5;
const offset = 0;

const node1: NodeTransport = {
...createNode("node-id-1", "node-key-1", "Node 1"),
configuration: {
setting1: "value1",
}
};
const response: NodeTransport[] = [node1];

mockAxiosGet(
`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes?withConfiguration=true&limit=${limit}`,
response
);

await new NodeService(testContext).listNodes(packageKey, null, limit, offset, true, false);

expect(loggingTestTransport.logMessages).toHaveLength(1);
expect(loggingTestTransport.logMessages[0].message).toContain(`${JSON.stringify(node1.configuration)}`);
});

it("Should list staging nodes with pagination", async () => {
const packageKey = "package-key";
const limit = 50;
const offset = 100;

const node1 = createNode("node-id-101", "node-key-101", "Node 101");
const response: NodeTransport[] = [node1];

mockAxiosGet(
`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes?withConfiguration=false&limit=${limit}&offset=${offset}`,
response
);

await new NodeService(testContext).listNodes(packageKey, null, limit, offset, false, false);

expect(loggingTestTransport.logMessages).toHaveLength(1);
expect(loggingTestTransport.logMessages[0].message).toContain(JSON.stringify(node1));
});

it("Should list staging nodes and return as JSON", async () => {
const packageKey = "package-key";
const limit = 10;
const offset = 0;

const node1 = createNode("node-id-1", "node-key-1", "Node 1");
const node2 = createNode("node-id-2", "node-key-2", "Node 2");
const response: NodeTransport[] = [node1, node2];

mockAxiosGet(
`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes?withConfiguration=false&limit=${limit}`,
response
);

await new NodeService(testContext).listNodes(packageKey, null, limit, offset, false, true);

const nodes = getJsonFromDownloadedFile() as NodeTransport[];

expect(nodes).toEqual([node1, node2]);
expect(nodes).toHaveLength(2);
});
});
Loading