-
Notifications
You must be signed in to change notification settings - Fork 0
TA-4289: Add command to find staging node #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ksalihu
merged 9 commits into
master
from
ksalihu/TA-4289-add-command-to-find-staging-node
Oct 27, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cf0a4c7
TA-4289: Add command to find staging node
ksalihu 4c6c543
TA-4289: add documentation
ksalihu 8f44a0b
TA-4289: rename spec file
ksalihu 4595cb7
TA-4289: pretty print json
ksalihu a792df4
TA-4289: rename method
ksalihu d57f09a
TA-4289: fix spacing
ksalihu 067168a
TA-4289: log invalid configuration
ksalihu c0e4b90
TA-4289: update command description
ksalihu 4e54e19
TA-4289: update documentation
ksalihu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,10 @@ | |
| - [Listing package variables](#listing-package-variables) | ||
| - [Listing assignments](#listing-assignments) | ||
| - [Mapping variables](#mapping-variables) | ||
| - [Finding staging nodes](#finding-staging-nodes) | ||
| - [Find a node](#find-a-node) | ||
| - [Find a node with configuration](#find-a-node-with-configuration) | ||
| - [Export node as JSON](#export-node-as-json) | ||
| - [Data Pool export / import commands](#data-pool-export--import-commands) | ||
| - [Export Data Pool](#export-data-pool) | ||
| - [Batch Import multiple Data Pools](#batch-import-multiple-data-pools) | ||
|
|
@@ -634,6 +638,60 @@ This mapping should be saved and then used during import. | |
| Since the format of the variables.json file on import is the same JSON structure as the list variables result, you can either map the values to the variables.json file for each variable, or replace the variables.json file with the result of the listing & mapping altogether. | ||
| If the mapping of variables is skipped, you should delete the variables.json file before importing. | ||
|
|
||
| #### Finding nodes | ||
|
|
||
| The **config nodes find** command allows you to retrieve information about a specific node within a package. | ||
|
|
||
| ##### Find a staging node | ||
| To find a specific node in a package, use the following command: | ||
| ``` | ||
| content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> | ||
| ``` | ||
|
|
||
| The command will display the node information in the console: | ||
| ``` | ||
| info: ID: node-id-123 | ||
| info: Key: node-key | ||
| info: Name: My Node | ||
| info: Type: VIEW | ||
| info: Package Node Key: package-node-key | ||
| info: Parent Node Key: parent-node-key | ||
| info: Created By: [email protected] | ||
| info: Updated By: [email protected] | ||
| info: Creation Date: 2025-10-22T10:30:00.000Z | ||
| info: Change Date: 2025-10-22T15:45:00.000Z | ||
| info: Flavor: STUDIO | ||
| ``` | ||
|
|
||
| ##### Find a staging node with configuration | ||
| By default, the node configuration is not included in the response. To include the node's configuration, use the `--withConfiguration` flag: | ||
| ``` | ||
| content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration | ||
| ``` | ||
|
|
||
| When configuration is included, it will be displayed as a JSON string in the output: | ||
| ``` | ||
| info: Configuration: {"key":"value","nested":{"field":"data"}} | ||
| ``` | ||
|
|
||
| ##### Export staging node as JSON | ||
| To export the node information as a JSON file instead of displaying it in the console, use the `--json` option: | ||
| ``` | ||
| content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --json | ||
| ``` | ||
|
|
||
| This will create a JSON file in the current working directory with a UUID filename: | ||
| ``` | ||
| info: File downloaded successfully. New filename: 9560f81f-f746-4117-83ee-dd1f614ad624.json | ||
| ``` | ||
|
|
||
| The JSON file contains the complete node information including all fields and, if requested, the configuration. | ||
|
|
||
| You can combine options to export a node with its configuration: | ||
| ``` | ||
| content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration --json | ||
| ``` | ||
|
|
||
| ### Deployment commands (beta) | ||
| The **deployment** command group allows you to create deployments, list their history, check active deployments, and retrieve deployables and targets. | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { HttpClient } from "../../../core/http/http-client"; | ||
| import { Context } from "../../../core/command/cli-context"; | ||
| import { NodeTransport } from "../interfaces/node.interfaces"; | ||
| import { FatalError } from "../../../core/utils/logger"; | ||
|
|
||
| export class NodeApi { | ||
| private httpClient: () => HttpClient; | ||
|
|
||
| constructor(context: Context) { | ||
| this.httpClient = () => context.httpClient; | ||
| } | ||
|
|
||
| public async findStagingNodeByKey(packageKey: string, nodeKey: string, withConfiguration: boolean): Promise<NodeTransport> { | ||
| const queryParams = new URLSearchParams(); | ||
| queryParams.set("withConfiguration", withConfiguration.toString()); | ||
|
|
||
| return this.httpClient() | ||
| .get(`/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?${queryParams.toString()}`) | ||
| .catch((e) => { | ||
| throw new FatalError(`Problem finding node ${nodeKey} in package ${packageKey}: ${e}`); | ||
| }); | ||
| } | ||
| } | ||
|
|
22 changes: 22 additions & 0 deletions
22
src/commands/configuration-management/interfaces/node.interfaces.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| export interface NodeConfiguration { | ||
| [key: string]: any; | ||
| } | ||
|
|
||
| export interface NodeTransport { | ||
| id: string; | ||
| key: string; | ||
| name: string; | ||
| packageNodeKey: string; | ||
| parentNodeKey?: string; | ||
| packageNodeId: string; | ||
| type: string; | ||
| configuration?: NodeConfiguration; | ||
| invalidConfiguration?: string; | ||
| invalidContent: boolean; | ||
| creationDate: string; | ||
| changeDate: string; | ||
| createdBy: string; | ||
| updatedBy: string; | ||
| schemaVersion: number; | ||
| flavor?: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { NodeApi } from "./api/node-api"; | ||
| 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"; | ||
|
|
||
| export class NodeService { | ||
| private nodeApi: NodeApi; | ||
|
|
||
| constructor(context: Context) { | ||
| this.nodeApi = new NodeApi(context); | ||
| } | ||
|
|
||
| public async findNode(packageKey: string, nodeKey: string, withConfiguration: boolean, jsonResponse: boolean): Promise<void> { | ||
| const node = await this.nodeApi.findStagingNodeByKey(packageKey, nodeKey, withConfiguration); | ||
|
|
||
| if (jsonResponse) { | ||
| const filename = uuidv4() + ".json"; | ||
| 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}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
175 changes: 175 additions & 0 deletions
175
tests/commands/configuration-management/config-node.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| import { NodeTransport } from "../../../src/commands/configuration-management/interfaces/node.interfaces"; | ||
| import { mockAxiosGet } from "../../utls/http-requests-mock"; | ||
| import { NodeService } from "../../../src/commands/configuration-management/node.service"; | ||
| import { testContext } from "../../utls/test-context"; | ||
| import { loggingTestTransport, mockWriteFileSync } from "../../jest.setup"; | ||
| import { FileService } from "../../../src/core/utils/file-service"; | ||
| import * as path from "path"; | ||
|
|
||
| describe("Node find", () => { | ||
| const node: NodeTransport = { | ||
| id: "node-id", | ||
| key: "node-key", | ||
| name: "Node Name", | ||
| packageNodeKey: "package-node-key", | ||
| parentNodeKey: "parent-node-key", | ||
| packageNodeId: "package-node-id", | ||
| type: "VIEW", | ||
| invalidContent: false, | ||
| creationDate: new Date().toISOString(), | ||
| changeDate: new Date().toISOString(), | ||
| createdBy: "user-id", | ||
| updatedBy: "user-id", | ||
| schemaVersion: 1, | ||
| flavor: "STUDIO", | ||
| }; | ||
|
|
||
| it("Should find node without configuration", async () => { | ||
| const packageKey = "package-key"; | ||
| const nodeKey = "node-key"; | ||
| mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, node); | ||
|
|
||
| await new NodeService(testContext).findNode(packageKey, nodeKey, false, false); | ||
|
|
||
| expect(loggingTestTransport.logMessages.length).toBe(11); | ||
| expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${node.id}`); | ||
| expect(loggingTestTransport.logMessages[1].message).toContain(`Key: ${node.key}`); | ||
| expect(loggingTestTransport.logMessages[2].message).toContain(`Name: ${node.name}`); | ||
| expect(loggingTestTransport.logMessages[3].message).toContain(`Type: ${node.type}`); | ||
| expect(loggingTestTransport.logMessages[4].message).toContain(`Package Node Key: ${node.packageNodeKey}`); | ||
| expect(loggingTestTransport.logMessages[5].message).toContain(`Parent Node Key: ${node.parentNodeKey}`); | ||
| expect(loggingTestTransport.logMessages[6].message).toContain(`Created By: ${node.createdBy}`); | ||
| expect(loggingTestTransport.logMessages[7].message).toContain(`Updated By: ${node.updatedBy}`); | ||
| expect(loggingTestTransport.logMessages[8].message).toContain(`Creation Date: ${new Date(node.creationDate).toISOString()}`); | ||
| expect(loggingTestTransport.logMessages[9].message).toContain(`Change Date: ${new Date(node.changeDate).toISOString()}`); | ||
| expect(loggingTestTransport.logMessages[10].message).toContain(`Flavor: ${node.flavor}`); | ||
| }); | ||
|
|
||
| it("Should find node with configuration", async () => { | ||
| const packageKey = "package-key"; | ||
| const nodeKey = "node-key"; | ||
| const nodeWithConfig: NodeTransport = { | ||
| ...node, | ||
| configuration: { | ||
| someKey: "someValue", | ||
| anotherKey: 123, | ||
| }, | ||
| }; | ||
|
|
||
| mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=true`, nodeWithConfig); | ||
|
|
||
| await new NodeService(testContext).findNode(packageKey, nodeKey, true, false); | ||
|
|
||
| expect(loggingTestTransport.logMessages.length).toBe(12); | ||
| expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${nodeWithConfig.id}`); | ||
| expect(loggingTestTransport.logMessages[10].message).toContain(`Configuration: ${JSON.stringify(nodeWithConfig.configuration, null, 2)}`); | ||
| expect(loggingTestTransport.logMessages[11].message).toContain(`Flavor: ${nodeWithConfig.flavor}`); | ||
| }); | ||
|
|
||
| it("Should find node without parent node key", async () => { | ||
| const packageKey = "package-key"; | ||
| const nodeKey = "node-key"; | ||
| const nodeWithoutParent: NodeTransport = { | ||
| ...node, | ||
| parentNodeKey: undefined, | ||
| }; | ||
|
|
||
| mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithoutParent); | ||
|
|
||
| await new NodeService(testContext).findNode(packageKey, nodeKey, false, false); | ||
|
|
||
| expect(loggingTestTransport.logMessages.length).toBe(10); | ||
| // Verify that parent node key is not logged | ||
| const parentNodeKeyMessage = loggingTestTransport.logMessages.find(log => log.message.includes("Parent Node Key")); | ||
| expect(parentNodeKeyMessage).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("Should find node and return as JSON", async () => { | ||
| const packageKey = "package-key"; | ||
| const nodeKey = "node-key"; | ||
| mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, node); | ||
|
|
||
| await new NodeService(testContext).findNode(packageKey, nodeKey, 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"}); | ||
|
|
||
| const nodeTransport = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as NodeTransport; | ||
|
|
||
| expect(nodeTransport).toEqual(node); | ||
| }); | ||
|
|
||
| it("Should find node with configuration and return as JSON", async () => { | ||
| const packageKey = "package-key"; | ||
| const nodeKey = "node-key"; | ||
| const nodeWithConfig: NodeTransport = { | ||
| ...node, | ||
| configuration: { | ||
| someKey: "someValue", | ||
| nested: { | ||
| value: true, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=true`, nodeWithConfig); | ||
|
|
||
| await new NodeService(testContext).findNode(packageKey, nodeKey, true, 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"}); | ||
|
|
||
| const nodeTransport = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as NodeTransport; | ||
|
|
||
| expect(nodeTransport).toEqual(nodeWithConfig); | ||
| expect(nodeTransport.configuration).toEqual(nodeWithConfig.configuration); | ||
| }); | ||
|
|
||
| it("Should find node with invalid configuration", async () => { | ||
| const packageKey = "package-key"; | ||
| const nodeKey = "node-key"; | ||
| const invalidConfigMessage = "Invalid JSON: Unexpected token at position 10"; | ||
| const nodeWithInvalidConfig: NodeTransport = { | ||
| ...node, | ||
| invalidContent: true, | ||
| invalidConfiguration: invalidConfigMessage, | ||
| }; | ||
|
|
||
| mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithInvalidConfig); | ||
|
|
||
| await new NodeService(testContext).findNode(packageKey, nodeKey, false, false); | ||
|
|
||
| expect(loggingTestTransport.logMessages.length).toBe(12); | ||
| expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${nodeWithInvalidConfig.id}`); | ||
| expect(loggingTestTransport.logMessages[10].message).toContain(`Invalid Configuration: ${invalidConfigMessage}`); | ||
| expect(loggingTestTransport.logMessages[11].message).toContain(`Flavor: ${nodeWithInvalidConfig.flavor}`); | ||
| }); | ||
|
|
||
| it("Should find node with invalid configuration and return as JSON", async () => { | ||
| const packageKey = "package-key"; | ||
| const nodeKey = "node-key"; | ||
| const invalidConfigMessage = "Syntax error in configuration"; | ||
| const nodeWithInvalidConfig: NodeTransport = { | ||
| ...node, | ||
| invalidContent: true, | ||
| invalidConfiguration: invalidConfigMessage, | ||
| }; | ||
|
|
||
| mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithInvalidConfig); | ||
|
|
||
| await new NodeService(testContext).findNode(packageKey, nodeKey, 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"}); | ||
|
|
||
| const nodeTransport = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as NodeTransport; | ||
|
|
||
| expect(nodeTransport).toEqual(nodeWithInvalidConfig); | ||
| expect(nodeTransport.invalidConfiguration).toEqual(invalidConfigMessage); | ||
| expect(nodeTransport.invalidContent).toBe(true); | ||
| }); | ||
| }); | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.