Skip to content

Commit aebe77e

Browse files
TN-7814: Add --version option on find node command (#274)
1 parent 8e2f86b commit aebe77e

File tree

5 files changed

+94
-18
lines changed

5 files changed

+94
-18
lines changed

DOCUMENTATION.md

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
- [Listing package variables](#listing-package-variables)
2828
- [Listing assignments](#listing-assignments)
2929
- [Mapping variables](#mapping-variables)
30-
- [Finding staging nodes](#finding-staging-nodes)
31-
- [Find a node](#find-a-node)
32-
- [Find a node with configuration](#find-a-node-with-configuration)
30+
- [Finding nodes](#finding-nodes)
31+
- [Find a staging node](#find-a-staging-node)
32+
- [Find a staging node with configuration](#find-a-staging-node-with-configuration)
33+
- [Find a versioned node](#find-a-versioned-node)
34+
- [Find a versioned node with configuration](#find-a-versioned-node-with-configuration)
3335
- [Export node as JSON](#export-node-as-json)
3436
- [Diffing node configurations](#diffing-node-configurations)
3537
- [Diff two versions of a node](#diff-two-versions-of-a-node)
@@ -669,18 +671,55 @@ info: Flavor: STUDIO
669671
##### Find a staging node with configuration
670672
By default, the node configuration is not included in the response. To include the node's configuration, use the `--withConfiguration` flag:
671673
```
672-
content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration
674+
content-cli config nodes get --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration
673675
```
674676

675677
When configuration is included, it will be displayed as a JSON string in the output:
676678
```
677679
info: Configuration: {"key":"value","nested":{"field":"data"}}
678680
```
679681

680-
##### Export staging node as JSON
682+
##### Find a versioned node
683+
To find a specific node in a package by version, use the `--version` option:
684+
```
685+
content-cli config nodes get --packageKey <packageKey> --nodeKey <nodeKey> --version <version>
686+
```
687+
688+
For example, to find a node in version 1.2.3:
689+
```
690+
content-cli config nodes get --packageKey my-package --nodeKey my-node --version 1.2.3
691+
```
692+
693+
The command will display the node information in the console with the same format as staging nodes:
694+
```
695+
info: ID: node-id-123
696+
info: Key: node-key
697+
info: Name: My Node
698+
info: Type: VIEW
699+
info: Package Node Key: package-node-key
700+
info: Parent Node Key: parent-node-key
701+
info: Created By: [email protected]
702+
info: Updated By: [email protected]
703+
info: Creation Date: 2025-10-22T10:30:00.000Z
704+
info: Change Date: 2025-10-22T15:45:00.000Z
705+
info: Flavor: STUDIO
706+
```
707+
708+
##### Find a versioned node with configuration
709+
You can combine the `--version` and `--withConfiguration` options to retrieve a versioned node with its configuration:
710+
```
711+
content-cli config nodes get --packageKey <packageKey> --nodeKey <nodeKey> --version <version> --withConfiguration
712+
```
713+
714+
When configuration is included, it will be displayed as a JSON string in the output:
715+
```
716+
info: Configuration: {"key":"value","nested":{"field":"data"}}
717+
```
718+
719+
##### Export node as JSON
681720
To export the node information as a JSON file instead of displaying it in the console, use the `--json` option:
682721
```
683-
content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --json
722+
content-cli config nodes get --packageKey <packageKey> --nodeKey <nodeKey> --json
684723
```
685724

686725
This will create a JSON file in the current working directory with a UUID filename:
@@ -692,7 +731,17 @@ The JSON file contains the complete node information including all fields and, i
692731

693732
You can combine options to export a node with its configuration:
694733
```
695-
content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration --json
734+
content-cli config nodes get --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration --json
735+
```
736+
737+
You can also export versioned nodes as JSON:
738+
```
739+
content-cli config nodes get --packageKey <packageKey> --nodeKey <nodeKey> --version <version> --json
740+
```
741+
742+
Or combine all options for a versioned node with configuration:
743+
```
744+
content-cli config nodes get --packageKey <packageKey> --nodeKey <nodeKey> --version <version> --withConfiguration --json
696745
```
697746
#### Diffing node configurations
698747

src/commands/configuration-management/api/node-api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,17 @@ export class NodeApi {
2020
throw new FatalError(`Problem finding node ${nodeKey} in package ${packageKey}: ${e}`);
2121
});
2222
}
23+
24+
public async findVersionedNodeByKey(packageKey: string, nodeKey: string, version: string, withConfiguration: boolean): Promise<NodeTransport> {
25+
const queryParams = new URLSearchParams();
26+
queryParams.set("version", version);
27+
queryParams.set("withConfiguration", withConfiguration.toString());
28+
29+
return this.httpClient()
30+
.get(`/pacman/api/core/packages/${packageKey}/nodes/${nodeKey}?${queryParams.toString()}`)
31+
.catch((e) => {
32+
throw new FatalError(`Problem finding node ${nodeKey} in package ${packageKey} for version ${version}: ${e}`);
33+
});
34+
}
2335
}
2436

src/commands/configuration-management/module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ class Module extends IModule {
7373
const nodesCommand = configCommand.command("nodes")
7474
.description("Commands related to nodes of the package");
7575

76-
nodesCommand.command("find")
76+
nodesCommand.command("get")
7777
.description("Find a specific node in a package")
7878
.requiredOption("--packageKey <packageKey>", "Identifier of the package")
7979
.requiredOption("--nodeKey <nodeKey>", "Identifier of the node")
80+
.option("--version <version>", "Version of the package")
8081
.option("--withConfiguration", "Include node configuration in the response", false)
8182
.option("--json", "Return the response as a JSON file")
8283
.action(this.findNode);
@@ -138,7 +139,7 @@ class Module extends IModule {
138139
}
139140

140141
private async findNode(context: Context, command: Command, options: OptionValues): Promise<void> {
141-
await new NodeService(context).findNode(options.packageKey, options.nodeKey, options.withConfiguration, options.json);
142+
await new NodeService(context).findNode(options.packageKey, options.nodeKey, options.withConfiguration, options.version ?? null, options.json);
142143
}
143144

144145
private async diffNode(context: Context, command: Command, options: OptionValues): Promise<void> {

src/commands/configuration-management/node.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export class NodeService {
1111
this.nodeApi = new NodeApi(context);
1212
}
1313

14-
public async findNode(packageKey: string, nodeKey: string, withConfiguration: boolean, jsonResponse: boolean): Promise<void> {
15-
const node = await this.nodeApi.findStagingNodeByKey(packageKey, nodeKey, withConfiguration);
14+
public async findNode(packageKey: string, nodeKey: string, withConfiguration: boolean, version: string | null, jsonResponse: boolean): Promise<void> {
15+
const node = version
16+
? await this.nodeApi.findVersionedNodeByKey(packageKey, nodeKey, version, withConfiguration)
17+
: await this.nodeApi.findStagingNodeByKey(packageKey, nodeKey, withConfiguration);
1618

1719
if (jsonResponse) {
1820
const filename = uuidv4() + ".json";

tests/commands/configuration-management/config-node.spec.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("Node find", () => {
2929
const nodeKey = "node-key";
3030
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, node);
3131

32-
await new NodeService(testContext).findNode(packageKey, nodeKey, false, false);
32+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, null, false);
3333

3434
expect(loggingTestTransport.logMessages.length).toBe(11);
3535
expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${node.id}`);
@@ -45,6 +45,18 @@ describe("Node find", () => {
4545
expect(loggingTestTransport.logMessages[10].message).toContain(`Flavor: ${node.flavor}`);
4646
});
4747

48+
it("Should find versioned node without configuration", async () => {
49+
const packageKey = "package-key";
50+
const nodeKey = "node-key";
51+
const version = "1.2.3.4";
52+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/packages/${packageKey}/nodes/${nodeKey}?version=${version}&withConfiguration=false`, node);
53+
54+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, version, false);
55+
56+
expect(loggingTestTransport.logMessages.length).toBe(11);
57+
expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${node.id}`);
58+
});
59+
4860
it("Should find node with configuration", async () => {
4961
const packageKey = "package-key";
5062
const nodeKey = "node-key";
@@ -58,7 +70,7 @@ describe("Node find", () => {
5870

5971
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=true`, nodeWithConfig);
6072

61-
await new NodeService(testContext).findNode(packageKey, nodeKey, true, false);
73+
await new NodeService(testContext).findNode(packageKey, nodeKey, true, null, false);
6274

6375
expect(loggingTestTransport.logMessages.length).toBe(12);
6476
expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${nodeWithConfig.id}`);
@@ -76,7 +88,7 @@ describe("Node find", () => {
7688

7789
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithoutParent);
7890

79-
await new NodeService(testContext).findNode(packageKey, nodeKey, false, false);
91+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, null, false);
8092

8193
expect(loggingTestTransport.logMessages.length).toBe(10);
8294
// Verify that parent node key is not logged
@@ -89,7 +101,7 @@ describe("Node find", () => {
89101
const nodeKey = "node-key";
90102
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, node);
91103

92-
await new NodeService(testContext).findNode(packageKey, nodeKey, false, true);
104+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, null, true);
93105

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

@@ -115,7 +127,7 @@ describe("Node find", () => {
115127

116128
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=true`, nodeWithConfig);
117129

118-
await new NodeService(testContext).findNode(packageKey, nodeKey, true, true);
130+
await new NodeService(testContext).findNode(packageKey, nodeKey, true, null, true);
119131

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

@@ -139,7 +151,7 @@ describe("Node find", () => {
139151

140152
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithInvalidConfig);
141153

142-
await new NodeService(testContext).findNode(packageKey, nodeKey, false, false);
154+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, null, false);
143155

144156
expect(loggingTestTransport.logMessages.length).toBe(12);
145157
expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${nodeWithInvalidConfig.id}`);
@@ -159,7 +171,7 @@ describe("Node find", () => {
159171

160172
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithInvalidConfig);
161173

162-
await new NodeService(testContext).findNode(packageKey, nodeKey, false, true);
174+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, null, true);
163175

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

0 commit comments

Comments
 (0)