diff --git a/.editorconfig b/.editorconfig index 2536d66b..5760be58 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [*] indent_style = space -indent_size = 4 +indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true diff --git a/package-lock.json b/package-lock.json index 566b4006..75c42f90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3907,17 +3907,8 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true }, "node_modules/babel-jest": { "version": "29.7.0", @@ -4669,6 +4660,7 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -4995,6 +4987,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, "engines": { "node": ">=0.4.0" } @@ -6411,25 +6404,6 @@ "deprecated": "flatten is deprecated in favor of utility frameworks such as lodash.", "dev": true }, - "node_modules/follow-redirects": { - "version": "1.15.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", - "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/foreground-child": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.2.1.tgz", @@ -6449,6 +6423,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -8777,6 +8752,7 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, "engines": { "node": ">= 0.6" } @@ -8785,6 +8761,7 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -10582,11 +10559,6 @@ "node": ">= 6" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, "node_modules/pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -12873,7 +12845,6 @@ "@zowe/cics-for-zowe-sdk": "6.2.4", "@zowe/core-for-zowe-sdk": "^8.0.0", "@zowe/zowe-explorer-api": "^3.0.3", - "axios": "^1.6.7", "xml-js": "~1.6.11" }, "devDependencies": { diff --git a/packages/vsce/CHANGELOG.md b/packages/vsce/CHANGELOG.md index 25d80356..a04a0da5 100644 --- a/packages/vsce/CHANGELOG.md +++ b/packages/vsce/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the "cics-extension-for-zowe" extension will be documente - BugFix: Updated commands to use Utils.getResourceURI. [#178](https://github.com/zowe/cics-for-zowe-client/issues/178) - BugFix: Regions icon updates when plex tree is expanded. [#194](https://github.com/zowe/cics-for-zowe-client/issues/194) +- BugFix: Opening CICS connections prevents other Zowe sessions connecting. [#159](https://github.com/zowe/cics-for-zowe-client/issues/159) ## `3.2.3` diff --git a/packages/vsce/package.json b/packages/vsce/package.json index dc65f304..753c74db 100644 --- a/packages/vsce/package.json +++ b/packages/vsce/package.json @@ -895,7 +895,6 @@ "@zowe/cics-for-zowe-sdk": "6.2.4", "@zowe/core-for-zowe-sdk": "^8.0.0", "@zowe/zowe-explorer-api": "^3.0.3", - "axios": "^1.6.7", "xml-js": "~1.6.11" } } diff --git a/packages/vsce/src/commands/ICommandParams.ts b/packages/vsce/src/commands/ICommandParams.ts new file mode 100644 index 00000000..0d66a7b9 --- /dev/null +++ b/packages/vsce/src/commands/ICommandParams.ts @@ -0,0 +1,28 @@ +/** + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + * + */ + +/** + * Parameters passed to a command + */ +export interface ICommandParams { + /** + * Name of resource to find in filter + */ + name: string; + /** + * Region Applid to perform action + */ + regionName: string; + /** + * CICS Plex to perform action + */ + cicsPlex: string; +} diff --git a/packages/vsce/src/commands/closeLocalFileCommand.ts b/packages/vsce/src/commands/closeLocalFileCommand.ts index 62d23a3e..77a66ae2 100644 --- a/packages/vsce/src/commands/closeLocalFileCommand.ts +++ b/packages/vsce/src/commands/closeLocalFileCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../trees/CICSRegionTree"; import { CICSTree } from "../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../trees/CICSRegionsContainer"; import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; +import { ICommandParams } from "./ICommandParams"; export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.closeLocalFile", async (clickedNode) => { @@ -52,8 +52,6 @@ export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; - try { await closeLocalFile( currentNode.parentRegion.parentSession.session, @@ -64,20 +62,17 @@ export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView }, busyDecision ); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage) { // @ts-ignore const [_, resp2, respAlt, eibfnAlt] = splitCmciErrorMessage(error.mMessage); window.showErrorMessage( - `Perform CLOSE on local file "${ - allSelectedNodes[parseInt(index)].localFile.file + `Perform CLOSE on local file "${allSelectedNodes[parseInt(index)].localFile.file }" failed: EXEC CICS command (${eibfnAlt}) RESP(${respAlt}) RESP2(${resp2})` ); } else { @@ -124,7 +119,7 @@ export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView async function closeLocalFile( session: imperative.AbstractSession, - parms: { name: string; regionName: string; cicsPlex: string }, + parms: ICommandParams, busyDecision: string ): Promise { const requestBody: any = { diff --git a/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts b/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts index e2f5d7b6..a85ad65d 100644 --- a/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../../trees/CICSRegionTree"; import { CICSTree } from "../../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../../trees/CICSRegionsContainer"; import { findSelectedNodes } from "../../utils/commandUtils"; import { CICSLocalFileTreeItem } from "../../trees/treeItems/CICSLocalFileTreeItem"; import { CICSCombinedLocalFileTree } from "../../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; +import { ICommandParams } from "../ICommandParams"; export function getDisableLocalFileCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.disableLocalFile", async (clickedNode) => { @@ -52,8 +52,6 @@ export function getDisableLocalFileCommand(tree: CICSTree, treeview: TreeView { const requestBody: any = { diff --git a/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts b/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts index c5369349..f1c2b040 100644 --- a/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../../trees/CICSRegionTree"; import { CICSTree } from "../../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../../trees/CICSRegionsContainer"; import { findSelectedNodes } from "../../utils/commandUtils"; import { CICSProgramTreeItem } from "../../trees/treeItems/CICSProgramTreeItem"; import { CICSCombinedProgramTree } from "../../trees/CICSCombinedTrees/CICSCombinedProgramTree"; +import { ICommandParams } from "../ICommandParams"; /** * Performs disable on selected CICSProgram nodes. @@ -50,7 +50,6 @@ export function getDisableProgramCommand(tree: CICSTree, treeview: TreeView }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; try { await disableProgram(currentNode.parentRegion.parentSession.session, { @@ -58,12 +57,10 @@ export function getDisableProgramCommand(tree: CICSTree, treeview: TreeView regionName: currentNode.parentRegion.label, cicsPlex: currentNode.parentRegion.parentPlex ? currentNode.parentRegion.parentPlex.getPlexName() : undefined, }); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore window.showErrorMessage( `Something went wrong when performing a disable - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace( @@ -105,7 +102,7 @@ export function getDisableProgramCommand(tree: CICSTree, treeview: TreeView }); } -function disableProgram(session: imperative.AbstractSession, parms: { name: string; regionName: string; cicsPlex: string }): Promise { +function disableProgram(session: imperative.AbstractSession, parms: ICommandParams): Promise { const requestBody: any = { request: { action: { diff --git a/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts b/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts index 2ece866f..76db5bd6 100644 --- a/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../../trees/CICSRegionTree"; import { CICSTree } from "../../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../../trees/CICSRegionsContainer"; import { findSelectedNodes, splitCmciErrorMessage } from "../../utils/commandUtils"; import { CICSTransactionTreeItem } from "../../trees/treeItems/CICSTransactionTreeItem"; import { CICSCombinedTransactionsTree } from "../../trees/CICSCombinedTrees/CICSCombinedTransactionTree"; +import { ICommandParams } from "../ICommandParams"; export function getDisableTransactionCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.disableTransaction", async (clickedNode) => { @@ -45,7 +45,6 @@ export function getDisableTransactionCommand(tree: CICSTree, treeview: TreeView< }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; try { await disableTransaction(currentNode.parentRegion.parentSession.session, { @@ -53,12 +52,10 @@ export function getDisableTransactionCommand(tree: CICSTree, treeview: TreeView< regionName: currentNode.parentRegion.label, cicsPlex: currentNode.parentRegion.parentPlex ? currentNode.parentRegion.parentPlex.getPlexName() : undefined, }); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage) { // @ts-ignore @@ -112,7 +109,7 @@ export function getDisableTransactionCommand(tree: CICSTree, treeview: TreeView< async function disableTransaction( session: imperative.AbstractSession, - parms: { name: string; regionName: string; cicsPlex: string } + parms: ICommandParams ): Promise { const requestBody: any = { request: { diff --git a/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts b/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts index 417616b5..6d0f8fbf 100644 --- a/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../../trees/CICSRegionTree"; import { CICSTree } from "../../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../../trees/CICSRegionsContainer"; import { CICSLocalFileTreeItem } from "../../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes } from "../../utils/commandUtils"; import { CICSCombinedLocalFileTree } from "../../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; +import { ICommandParams } from "../ICommandParams"; export function getEnableLocalFileCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.enableLocalFile", async (clickedNode) => { @@ -45,7 +45,6 @@ export function getEnableLocalFileCommand(tree: CICSTree, treeview: TreeView { +async function enableLocalFile(session: imperative.AbstractSession, parms: ICommandParams): Promise { const requestBody: any = { request: { action: { diff --git a/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts b/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts index 56a1c5c3..95b0afda 100644 --- a/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../../trees/CICSRegionTree"; import { CICSTree } from "../../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../../trees/CICSRegionsContainer"; import { CICSProgramTreeItem } from "../../trees/treeItems/CICSProgramTreeItem"; import { findSelectedNodes } from "../../utils/commandUtils"; import { CICSCombinedProgramTree } from "../../trees/CICSCombinedTrees/CICSCombinedProgramTree"; +import { ICommandParams } from "../ICommandParams"; /** * Performs enable on selected CICSProgram nodes. @@ -50,20 +50,16 @@ export function getEnableProgramCommand(tree: CICSTree, treeview: TreeView) }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; - try { await enableProgram(currentNode.parentRegion.parentSession.session, { name: currentNode.program.program, regionName: currentNode.parentRegion.label, cicsPlex: currentNode.parentRegion.parentPlex ? currentNode.parentRegion.parentPlex.getPlexName() : undefined, }); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; window.showErrorMessage( `Something went wrong when performing an ENABLE - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace( /(\\n\t|\\n|\\t)/gm, @@ -104,7 +100,7 @@ export function getEnableProgramCommand(tree: CICSTree, treeview: TreeView) }); } -async function enableProgram(session: imperative.AbstractSession, parms: { name: string; regionName: string; cicsPlex: string }): Promise { +async function enableProgram(session: imperative.AbstractSession, parms: ICommandParams): Promise { const requestBody: any = { request: { action: { diff --git a/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts b/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts index 40cdfe35..25b6d909 100644 --- a/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../../trees/CICSRegionTree"; import { CICSTree } from "../../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../../trees/CICSRegionsContainer"; import { findSelectedNodes } from "../../utils/commandUtils"; import { CICSTransactionTreeItem } from "../../trees/treeItems/CICSTransactionTreeItem"; import { CICSCombinedTransactionsTree } from "../../trees/CICSCombinedTrees/CICSCombinedTransactionTree"; +import { ICommandParams } from "../ICommandParams"; export function getEnableTransactionCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.enableTransaction", async (clickedNode) => { @@ -46,7 +46,6 @@ export function getEnableTransactionCommand(tree: CICSTree, treeview: TreeView { +async function enableTransaction(session: imperative.AbstractSession, parms: ICommandParams): Promise { const requestBody: any = { request: { action: { diff --git a/packages/vsce/src/commands/newCopyCommand.ts b/packages/vsce/src/commands/newCopyCommand.ts index e0482650..1ee82a48 100644 --- a/packages/vsce/src/commands/newCopyCommand.ts +++ b/packages/vsce/src/commands/newCopyCommand.ts @@ -13,7 +13,6 @@ import { programNewcopy } from "@zowe/cics-for-zowe-sdk"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../trees/CICSRegionTree"; import { CICSTree } from "../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../trees/CICSRegionsContainer"; import { CICSProgramTreeItem } from "../trees/treeItems/CICSProgramTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; @@ -49,28 +48,23 @@ export function getNewCopyCommand(tree: CICSTree, treeview: TreeView) { }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; - try { await programNewcopy(currentNode.parentRegion.parentSession.session, { name: currentNode.program.program, regionName: currentNode.parentRegion.label, cicsPlex: currentNode.parentRegion.parentPlex ? currentNode.parentRegion.parentPlex.getPlexName() : undefined, }); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { // CMCI new copy error - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage) { // @ts-ignore const [_, resp2, respAlt, eibfnAlt] = splitCmciErrorMessage(error.mMessage); window.showErrorMessage( - `Perform NEWCOPY on Program "${ - allSelectedNodes[parseInt(index)].program.program + `Perform NEWCOPY on Program "${allSelectedNodes[parseInt(index)].program.program }" failed: EXEC CICS command (${eibfnAlt}) RESP(${respAlt}) RESP2(${resp2})` ); } else { diff --git a/packages/vsce/src/commands/openLocalFileCommand.ts b/packages/vsce/src/commands/openLocalFileCommand.ts index 2251786c..f0b68d56 100644 --- a/packages/vsce/src/commands/openLocalFileCommand.ts +++ b/packages/vsce/src/commands/openLocalFileCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../trees/CICSRegionTree"; import { CICSTree } from "../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../trees/CICSRegionsContainer"; import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; +import { ICommandParams } from "./ICommandParams"; export function getOpenLocalFileCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.openLocalFile", async (clickedNode) => { @@ -45,27 +45,22 @@ export function getOpenLocalFileCommand(tree: CICSTree, treeview: TreeView) }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; - try { await openLocalFile(currentNode.parentRegion.parentSession.session, { name: currentNode.localFile.file, regionName: currentNode.parentRegion.label, cicsPlex: currentNode.parentRegion.parentPlex ? currentNode.parentRegion.parentPlex.getPlexName() : undefined, }); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage) { // @ts-ignore const [_, resp2, respAlt, eibfnAlt] = splitCmciErrorMessage(error.mMessage); window.showErrorMessage( - `Perform OPEN on local file "${ - allSelectedNodes[parseInt(index)].localFile.file + `Perform OPEN on local file "${allSelectedNodes[parseInt(index)].localFile.file }" failed: EXEC CICS command (${eibfnAlt}) RESP(${respAlt}) RESP2(${resp2})` ); } else { @@ -109,7 +104,7 @@ export function getOpenLocalFileCommand(tree: CICSTree, treeview: TreeView) }); } -async function openLocalFile(session: imperative.AbstractSession, parms: { name: string; regionName: string; cicsPlex: string }): Promise { +async function openLocalFile(session: imperative.AbstractSession, parms: ICommandParams): Promise { const requestBody: any = { request: { action: { diff --git a/packages/vsce/src/commands/phaseInCommand.ts b/packages/vsce/src/commands/phaseInCommand.ts index fcb38f10..f896a6a9 100644 --- a/packages/vsce/src/commands/phaseInCommand.ts +++ b/packages/vsce/src/commands/phaseInCommand.ts @@ -14,7 +14,6 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../trees/CICSRegionTree"; import { CICSTree } from "../trees/CICSTree"; -import * as https from "https"; import { CICSRegionsContainer } from "../trees/CICSRegionsContainer"; import { CICSProgramTreeItem } from "../trees/treeItems/CICSProgramTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; @@ -50,28 +49,23 @@ export function getPhaseInCommand(tree: CICSTree, treeview: TreeView) { }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; - try { await performPhaseIn(currentNode.parentRegion.parentSession.session, { name: currentNode.program.program, regionName: currentNode.parentRegion.label, cicsPlex: currentNode.parentRegion.parentPlex ? currentNode.parentRegion.parentPlex.getPlexName() : undefined, }); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage) { // @ts-ignore const [_, resp2, respAlt, eibfnAlt] = splitCmciErrorMessage(error.mMessage); window.showErrorMessage( - `Perform PHASEIN on Program "${ - allSelectedNodes[parseInt(index)].program.program + `Perform PHASEIN on Program "${allSelectedNodes[parseInt(index)].program.program }" failed: EXEC CICS command (${eibfnAlt}) RESP(${respAlt}) RESP2(${resp2})` ); } else { @@ -116,7 +110,7 @@ export function getPhaseInCommand(tree: CICSTree, treeview: TreeView) { }); } -async function performPhaseIn(session: imperative.AbstractSession, parms: { cicsPlex: string | null; regionName: string; name: string }) { +async function performPhaseIn(session: imperative.AbstractSession, parms: { cicsPlex: string | null; regionName: string; name: string; }) { const requestBody: any = { request: { action: { diff --git a/packages/vsce/src/commands/purgeTaskCommand.ts b/packages/vsce/src/commands/purgeTaskCommand.ts index 9ef8236d..a134a266 100644 --- a/packages/vsce/src/commands/purgeTaskCommand.ts +++ b/packages/vsce/src/commands/purgeTaskCommand.ts @@ -14,11 +14,11 @@ import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSRegionTree } from "../trees/CICSRegionTree"; import { CICSTree } from "../trees/CICSTree"; -import * as https from "https"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; import { CICSTaskTreeItem } from "../trees/treeItems/CICSTaskTreeItem"; import { CICSRegionsContainer } from "../trees/CICSRegionsContainer"; import { CICSCombinedTaskTree } from "../trees/CICSCombinedTrees/CICSCombinedTaskTree"; +import { ICommandParams } from "./ICommandParams"; /** * Purge a CICS Task and reload the CICS Task tree contents and the combined Task tree contents @@ -55,8 +55,6 @@ export function getPurgeTaskCommand(tree: CICSTree, treeview: TreeView) { }); const currentNode = allSelectedNodes[parseInt(index)]; - https.globalAgent.options.rejectUnauthorized = currentNode.parentRegion.parentSession.session.ISession.rejectUnauthorized; - try { await purgeTask( currentNode.parentRegion.parentSession.session, @@ -67,19 +65,16 @@ export function getPurgeTaskCommand(tree: CICSTree, treeview: TreeView) { }, purgeType ); - https.globalAgent.options.rejectUnauthorized = undefined; if (!parentRegions.includes(currentNode.parentRegion)) { parentRegions.push(currentNode.parentRegion); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage) { // @ts-ignore const [_, resp2, respAlt, eibfnAlt] = splitCmciErrorMessage(error.mMessage); window.showErrorMessage( - `Perform ${purgeType?.toUpperCase()} on CICSTask "${ - allSelectedNodes[parseInt(index)].task.task + `Perform ${purgeType?.toUpperCase()} on CICSTask "${allSelectedNodes[parseInt(index)].task.task }" failed: EXEC CICS command (${eibfnAlt}) RESP(${respAlt}) RESP2(${resp2})` ); } else { @@ -136,7 +131,7 @@ export function getPurgeTaskCommand(tree: CICSTree, treeview: TreeView) { */ async function purgeTask( session: imperative.AbstractSession, - parms: { name: string; regionName: string; cicsPlex: string }, + parms: ICommandParams, purgeType: string ): Promise { const requestBody: any = { diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts index 571c23d5..c6b293c8 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts @@ -66,7 +66,7 @@ export class CICSCombinedLibraryTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allLibraries; if (recordsCount <= this.incrementCount) { allLibraries = await ProfileManagement.getCachedResources( @@ -74,7 +74,7 @@ export class CICSCombinedLibraryTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allLibraries = await ProfileManagement.getCachedResources( @@ -84,7 +84,7 @@ export class CICSCombinedLibraryTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addLibrariesUtil([], allLibraries, count); this.iconPath = getIconOpen(true); @@ -153,7 +153,7 @@ export class CICSCombinedLibraryTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allLibraries = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts index d667c9d9..c51c9e3e 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts @@ -66,7 +66,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allLocalFiles; if (recordsCount <= this.incrementCount) { allLocalFiles = await ProfileManagement.getCachedResources( @@ -74,7 +74,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allLocalFiles = await ProfileManagement.getCachedResources( @@ -84,7 +84,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addLocalFilesUtil([], allLocalFiles, count); this.iconPath = getIconOpen(true); @@ -148,7 +148,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allLocalFiles = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts index 4021f4dc..4697a3ac 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts @@ -66,7 +66,7 @@ export class CICSCombinedPipelineTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allPipelines; if (recordsCount <= this.incrementCount) { allPipelines = await ProfileManagement.getCachedResources( @@ -74,7 +74,7 @@ export class CICSCombinedPipelineTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allPipelines = await ProfileManagement.getCachedResources( @@ -84,7 +84,7 @@ export class CICSCombinedPipelineTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addPipelinesUtil([], allPipelines, count); this.iconPath = getIconOpen(true); @@ -153,7 +153,7 @@ export class CICSCombinedPipelineTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allPipelines = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts index e05b660b..431c9830 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts @@ -20,7 +20,8 @@ import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; import { toEscapedCriteriaString } from "../../utils/filterUtils"; import { CICSRegionsContainer } from "../CICSRegionsContainer"; import { TextTreeItem } from "../treeItems/utils/TextTreeItem"; -import { getIconOpen } from "../../utils/profileUtils"; +import { getIconOpen, getIconPathInResources } from "../../utils/profileUtils"; +import { imperative } from "@zowe/zowe-explorer-api"; export class CICSCombinedProgramTree extends TreeItem { children: (CICSProgramTreeItem | ViewMore)[] | [TextTreeItem] | null; @@ -49,9 +50,8 @@ export class CICSCombinedProgramTree extends TreeItem { cancellable: true, }, async (_, token) => { - token.onCancellationRequested(() => { - console.log("Cancelling the load"); - }); + token.onCancellationRequested(() => { }); + let recordsCount: number; try { let criteria; if (this.activeFilter) { @@ -66,8 +66,8 @@ export class CICSCombinedProgramTree extends TreeItem { this.getParent().getGroupName() ); if (cacheTokenInfo) { - const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + recordsCount = cacheTokenInfo.recordCount; + if (recordsCount) { let allPrograms; if (recordsCount <= this.incrementCount) { allPrograms = await ProfileManagement.getCachedResources( @@ -75,7 +75,7 @@ export class CICSCombinedProgramTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allPrograms = await ProfileManagement.getCachedResources( @@ -85,7 +85,7 @@ export class CICSCombinedProgramTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addProgramsUtil([], allPrograms, count); this.iconPath = getIconOpen(true); @@ -99,12 +99,20 @@ export class CICSCombinedProgramTree extends TreeItem { } } } catch (error) { - window.showErrorMessage( - `Something went wrong when fetching programs - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace( - /(\\n\t|\\n|\\t)/gm, - " " - )}` - ); + if (error instanceof imperative.ImperativeError && error.mDetails.msg.includes("NOTAVAILABLE")) { + this.children = []; + this.iconPath = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); + tree._onDidChangeTreeData.fire(undefined); + window.showInformationMessage(`No programs found`); + this.label = `All Programs${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${recordsCount}]`; + } else { + window.showErrorMessage( + `Something went wrong when fetching programs - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace( + /(\\n\t|\\n|\\t)/gm, + " " + )}` + ); + } } } ); @@ -155,7 +163,7 @@ export class CICSCombinedProgramTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allPrograms = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts index 05a28272..7958b4e9 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts @@ -48,9 +48,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { cancellable: true, }, async (_, token) => { - token.onCancellationRequested(() => { - console.log("Cancelling the load"); - }); + token.onCancellationRequested(() => { }); try { let criteria; if (this.activeFilter) { @@ -66,7 +64,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allTCPIPS; if (recordsCount <= this.incrementCount) { allTCPIPS = await ProfileManagement.getCachedResources( @@ -74,7 +72,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allTCPIPS = await ProfileManagement.getCachedResources( @@ -84,7 +82,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addTCPIPSUtil([], allTCPIPS, count); this.iconPath = getIconOpen(true); @@ -156,7 +154,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allTCPIPS = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts index e1eeaf26..47aee1d6 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts @@ -48,9 +48,7 @@ export class CICSCombinedTaskTree extends TreeItem { cancellable: true, }, async (_, token) => { - token.onCancellationRequested(() => { - console.log("Cancelling the load"); - }); + token.onCancellationRequested(() => { }); try { let criteria; if (this.activeFilter) { @@ -66,7 +64,7 @@ export class CICSCombinedTaskTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allTasks; if (recordsCount <= this.incrementCount) { allTasks = await ProfileManagement.getCachedResources( @@ -74,7 +72,7 @@ export class CICSCombinedTaskTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allTasks = await ProfileManagement.getCachedResources( @@ -84,7 +82,7 @@ export class CICSCombinedTaskTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addTasksUtil([], allTasks, count); this.iconPath = getIconOpen(true); @@ -153,7 +151,7 @@ export class CICSCombinedTaskTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allTasks = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts index 0502d556..f99c2443 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts @@ -67,7 +67,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allLocalTransactions; if (recordsCount <= this.incrementCount) { allLocalTransactions = await ProfileManagement.getCachedResources( @@ -75,7 +75,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allLocalTransactions = await ProfileManagement.getCachedResources( @@ -85,7 +85,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addLocalTransactionsUtil([], allLocalTransactions, count); this.iconPath = getIconOpen(true); @@ -149,7 +149,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allLocalTransactions = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts index 1b401189..499a039f 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts @@ -48,9 +48,7 @@ export class CICSCombinedURIMapTree extends TreeItem { cancellable: true, }, async (_, token) => { - token.onCancellationRequested(() => { - console.log("Cancelling the load"); - }); + token.onCancellationRequested(() => { }); try { let criteria; if (this.activeFilter) { @@ -66,7 +64,7 @@ export class CICSCombinedURIMapTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allURIMaps; if (recordsCount <= this.incrementCount) { allURIMaps = await ProfileManagement.getCachedResources( @@ -74,7 +72,7 @@ export class CICSCombinedURIMapTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allURIMaps = await ProfileManagement.getCachedResources( @@ -84,7 +82,7 @@ export class CICSCombinedURIMapTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addURIMapsUtil([], allURIMaps, count); this.iconPath = getIconOpen(true); @@ -158,7 +156,7 @@ export class CICSCombinedURIMapTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allURIMaps = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts index ea1089b4..dbbe92ba 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts @@ -48,9 +48,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { cancellable: true, }, async (_, token) => { - token.onCancellationRequested(() => { - console.log("Cancelling the load"); - }); + token.onCancellationRequested(() => { }); try { let criteria; if (this.activeFilter) { @@ -66,7 +64,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { ); if (cacheTokenInfo) { const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + if (recordsCount) { let allWebServices; if (recordsCount <= this.incrementCount) { allWebServices = await ProfileManagement.getCachedResources( @@ -74,7 +72,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allWebServices = await ProfileManagement.getCachedResources( @@ -84,7 +82,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addWebServicesUtil([], allWebServices, count); this.iconPath = getIconOpen(true); @@ -154,7 +152,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { if (cacheTokenInfo) { // record count may have updated const recordsCount = cacheTokenInfo.recordCount; - const count = parseInt(recordsCount); + const count = recordsCount; const allWebServices = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), cacheTokenInfo.cacheToken, diff --git a/packages/vsce/src/trees/CICSLibraryTree.ts b/packages/vsce/src/trees/CICSLibraryTree.ts index 288f4406..d5508c24 100644 --- a/packages/vsce/src/trees/CICSLibraryTree.ts +++ b/packages/vsce/src/trees/CICSLibraryTree.ts @@ -12,10 +12,10 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSRegionTree } from "./CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { getIconOpen } from "../utils/profileUtils"; import { CICSLibraryTreeItem } from "./treeItems/CICSLibraryTreeItem"; import { toEscapedCriteriaString } from "../utils/filterUtils"; +import { toArray } from "../utils/commandUtils"; export class CICSLibraryTree extends TreeItem { children: CICSLibraryTreeItem[] = []; @@ -42,7 +42,6 @@ export class CICSLibraryTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const libraryResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSLibrary", @@ -50,10 +49,7 @@ export class CICSLibraryTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const librariesArray = Array.isArray(libraryResponse.response.records.cicslibrary) - ? libraryResponse.response.records.cicslibrary - : [libraryResponse.response.records.cicslibrary]; + const librariesArray = toArray(libraryResponse.response.records.cicslibrary); this.label = `Libraries${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${librariesArray.length}]`; for (const library of librariesArray) { const newLibraryItem = new CICSLibraryTreeItem(library, this.parentRegion, this); @@ -61,7 +57,6 @@ export class CICSLibraryTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a library filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/trees/CICSLocalFileTree.ts b/packages/vsce/src/trees/CICSLocalFileTree.ts index 13a5f998..6aec556e 100644 --- a/packages/vsce/src/trees/CICSLocalFileTree.ts +++ b/packages/vsce/src/trees/CICSLocalFileTree.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window, workspace } from "vscode"; import { CICSLocalFileTreeItem } from "./treeItems/CICSLocalFileTreeItem"; import { getResource } from "@zowe/cics-for-zowe-sdk"; import { CICSRegionTree } from "./CICSRegionTree"; -import * as https from "https"; import { toEscapedCriteriaString } from "../utils/filterUtils"; import { getIconOpen } from "../utils/profileUtils"; +import { toArray } from "../utils/commandUtils"; export class CICSLocalFileTree extends TreeItem { children: CICSLocalFileTreeItem[] = []; @@ -46,7 +46,6 @@ export class CICSLocalFileTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const localFileResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSLocalFile", @@ -54,10 +53,7 @@ export class CICSLocalFileTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const localFileArray = Array.isArray(localFileResponse.response.records.cicslocalfile) - ? localFileResponse.response.records.cicslocalfile - : [localFileResponse.response.records.cicslocalfile]; + const localFileArray = toArray(localFileResponse.response.records.cicslocalfile); this.label = `Local Files${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${localFileArray.length}]`; for (const localFile of localFileArray) { const newLocalFileItem = new CICSLocalFileTreeItem(localFile, this.parentRegion, this); @@ -65,7 +61,6 @@ export class CICSLocalFileTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a local file filter to narrow search`); diff --git a/packages/vsce/src/trees/CICSPlexTree.ts b/packages/vsce/src/trees/CICSPlexTree.ts index c725884a..7597a98a 100644 --- a/packages/vsce/src/trees/CICSPlexTree.ts +++ b/packages/vsce/src/trees/CICSPlexTree.ts @@ -14,7 +14,6 @@ import { CICSRegionTree } from "./CICSRegionTree"; import { imperative } from "@zowe/zowe-explorer-api"; import { CICSSessionTree } from "./CICSSessionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { CICSCombinedProgramTree } from "./CICSCombinedTrees/CICSCombinedProgramTree"; import { CICSCombinedTransactionsTree } from "./CICSCombinedTrees/CICSCombinedTransactionTree"; import { CICSCombinedLocalFileTree } from "./CICSCombinedTrees/CICSCombinedLocalFileTree"; @@ -71,14 +70,12 @@ export class CICSPlexTree extends TreeItem { */ public async loadOnlyRegion() { const plexProfile = this.getProfile(); - https.globalAgent.options.rejectUnauthorized = plexProfile.profile.rejectUnauthorized; const session = this.getParent().getSession(); const regionsObtained = await getResource(session, { name: "CICSRegion", cicsPlex: plexProfile.profile.cicsPlex, regionName: plexProfile.profile.regionName, }); - https.globalAgent.options.rejectUnauthorized = undefined; const newRegionTree = new CICSRegionTree( plexProfile.profile.regionName, regionsObtained.response.records.cicsregion, diff --git a/packages/vsce/src/trees/CICSProgramTree.ts b/packages/vsce/src/trees/CICSProgramTree.ts index d32bbf0e..d11f160a 100644 --- a/packages/vsce/src/trees/CICSProgramTree.ts +++ b/packages/vsce/src/trees/CICSProgramTree.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSProgramTreeItem } from "./treeItems/CICSProgramTreeItem"; import { CICSRegionTree } from "./CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { getDefaultProgramFilter, toEscapedCriteriaString } from "../utils/filterUtils"; import { getIconOpen } from "../utils/profileUtils"; +import { toArray } from "../utils/commandUtils"; export class CICSProgramTree extends TreeItem { children: CICSProgramTreeItem[] = []; @@ -42,7 +42,6 @@ export class CICSProgramTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const programResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSProgram", @@ -50,10 +49,7 @@ export class CICSProgramTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const programsArray = Array.isArray(programResponse.response.records.cicsprogram) - ? programResponse.response.records.cicsprogram - : [programResponse.response.records.cicsprogram]; + const programsArray = toArray(programResponse.response.records.cicsprogram); this.label = `Programs${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${programsArray.length}]`; for (const program of programsArray) { const newProgramItem = new CICSProgramTreeItem(program, this.parentRegion, this); @@ -61,7 +57,6 @@ export class CICSProgramTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a program filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/trees/CICSRegionsContainer.ts b/packages/vsce/src/trees/CICSRegionsContainer.ts index 59496858..33243afa 100644 --- a/packages/vsce/src/trees/CICSRegionsContainer.ts +++ b/packages/vsce/src/trees/CICSRegionsContainer.ts @@ -16,7 +16,7 @@ import { CICSTree } from "./CICSTree"; import { ProfileManagement } from "../utils/profileManagement"; import { getIconOpen } from "../utils/profileUtils"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; +import { toArray } from "../utils/commandUtils"; export class CICSRegionsContainer extends TreeItem { children: CICSRegionTree[]; @@ -61,18 +61,14 @@ export class CICSRegionsContainer extends TreeItem { public async loadRegionsInCICSGroup(tree: CICSTree) { const parentPlex = this.getParent(); const plexProfile = parentPlex.getProfile(); - https.globalAgent.options.rejectUnauthorized = plexProfile.profile.rejectUnauthorized; const session = parentPlex.getParent().getSession(); const regionsObtained = await getResource(session, { name: "CICSManagedRegion", cicsPlex: plexProfile.profile.cicsPlex, regionName: plexProfile.profile.regionName, }); - https.globalAgent.options.rejectUnauthorized = undefined; this.clearChildren(); - const regionsArray = Array.isArray(regionsObtained.response.records.cicsmanagedregion) - ? regionsObtained.response.records.cicsmanagedregion - : [regionsObtained.response.records.cicsmanagedregion]; + const regionsArray = toArray(regionsObtained.response.records.cicsmanagedregion); this.addRegionsUtility(regionsArray); // Keep container open after label change this.collapsibleState = TreeItemCollapsibleState.Expanded; @@ -93,11 +89,12 @@ export class CICSRegionsContainer extends TreeItem { * Count the number of total and active regions * @param regionsArray */ - private addRegionsUtility(regionsArray: [any]) { + private addRegionsUtility(regionsArray: any[]) { let activeCount = 0; let totalCount = 0; const parentPlex = this.getParent(); - const regionFilterRegex = this.activeFilter ? new RegExp(this.patternIntoRegex(this.activeFilter)) : ""; //parentPlex.getActiveFilter() ? RegExp(parentPlex.getActiveFilter()!) : undefined; + //parentPlex.getActiveFilter() ? RegExp(parentPlex.getActiveFilter()!) : undefined; + const regionFilterRegex = this.activeFilter ? new RegExp(this.patternIntoRegex(this.activeFilter)) : ""; for (const region of regionsArray) { // If region filter exists then match it if (!regionFilterRegex || region.cicsname.match(regionFilterRegex)) { diff --git a/packages/vsce/src/trees/CICSTaskTree.ts b/packages/vsce/src/trees/CICSTaskTree.ts index d4faa5de..6ecb495a 100644 --- a/packages/vsce/src/trees/CICSTaskTree.ts +++ b/packages/vsce/src/trees/CICSTaskTree.ts @@ -12,10 +12,10 @@ import { TreeItemCollapsibleState, TreeItem, window, workspace } from "vscode"; import { CICSRegionTree } from "./CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { toEscapedCriteriaString } from "../utils/filterUtils"; import { getIconOpen } from "../utils/profileUtils"; import { CICSTaskTreeItem } from "./treeItems/CICSTaskTreeItem"; +import { toArray } from "../utils/commandUtils"; export class CICSTaskTree extends TreeItem { children: CICSTaskTreeItem[] = []; @@ -46,7 +46,6 @@ export class CICSTaskTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const taskResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSTASK", @@ -54,11 +53,8 @@ export class CICSTaskTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const tasksArray = Array.isArray(taskResponse.response.records.cicstask) - ? taskResponse.response.records.cicstask - : [taskResponse.response.records.cicstask]; + const tasksArray = toArray(taskResponse.response.records.cicstask); this.label = `Tasks${this.activeTransactionFilter ? ` (${this.activeTransactionFilter}) ` : " "}[${tasksArray.length}]`; for (const task of tasksArray) { const newTaskItem = new CICSTaskTreeItem(task, this.parentRegion, this); @@ -72,7 +68,6 @@ export class CICSTaskTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a task filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/trees/CICSTransactionTree.ts b/packages/vsce/src/trees/CICSTransactionTree.ts index d4a65b97..0d272991 100644 --- a/packages/vsce/src/trees/CICSTransactionTree.ts +++ b/packages/vsce/src/trees/CICSTransactionTree.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSTransactionTreeItem } from "./treeItems/CICSTransactionTreeItem"; import { CICSRegionTree } from "./CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { getDefaultTransactionFilter, toEscapedCriteriaString } from "../utils/filterUtils"; import { getIconOpen } from "../utils/profileUtils"; +import { toArray } from "../utils/commandUtils"; export class CICSTransactionTree extends TreeItem { children: CICSTransactionTreeItem[] = []; @@ -42,7 +42,6 @@ export class CICSTransactionTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const transactionResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSLocalTransaction", @@ -50,10 +49,7 @@ export class CICSTransactionTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const transactionArray = Array.isArray(transactionResponse.response.records.cicslocaltransaction) - ? transactionResponse.response.records.cicslocaltransaction - : [transactionResponse.response.records.cicslocaltransaction]; + const transactionArray = toArray(transactionResponse.response.records.cicslocaltransaction); this.label = `Transactions${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${transactionArray.length}]`; for (const transaction of transactionArray) { const newTransactionItem = new CICSTransactionTreeItem(transaction, this.parentRegion, this); @@ -61,7 +57,6 @@ export class CICSTransactionTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // @ts-ignore if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a transaction filter to narrow search`); diff --git a/packages/vsce/src/trees/CICSTree.ts b/packages/vsce/src/trees/CICSTree.ts index 9d681d75..ec27ed53 100644 --- a/packages/vsce/src/trees/CICSTree.ts +++ b/packages/vsce/src/trees/CICSTree.ts @@ -27,7 +27,6 @@ import { isTheia, openConfigFile } from "../utils/workspaceUtils"; import { CICSPlexTree } from "./CICSPlexTree"; import { CICSRegionTree } from "./CICSRegionTree"; import { CICSSessionTree } from "./CICSSessionTree"; -import * as https from "https"; import { getIconPathInResources, missingSessionParameters, promptCredentials } from "../utils/profileUtils"; import { Gui, imperative } from "@zowe/zowe-explorer-api"; @@ -215,15 +214,12 @@ export class CICSTree implements TreeDataProvider { protocol: profile.profile.protocol, }); try { - https.globalAgent.options.rejectUnauthorized = profile.profile.rejectUnauthorized; - const regionsObtained = await getResource(session, { name: "CICSRegion", regionName: item.regions[0].applid, }); // 200 OK received newSessionTree.setAuthorized(); - https.globalAgent.options.rejectUnauthorized = undefined; const newRegionTree = new CICSRegionTree( item.regions[0].applid, regionsObtained.response.records.cicsregion, @@ -233,7 +229,6 @@ export class CICSTree implements TreeDataProvider { ); newSessionTree.addRegion(newRegionTree); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; console.log(error); } } else { @@ -260,7 +255,6 @@ export class CICSTree implements TreeDataProvider { } this._onDidChangeTreeData.fire(undefined); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; // Change session tree icon to disconnected upon error newSessionTree = new CICSSessionTree(profile, getIconPathInResources("profile-disconnected-dark.svg", "profile-disconnected-light.svg")); // If method was called when expanding profile diff --git a/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts b/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts index 09a30e5d..c624b52a 100644 --- a/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts +++ b/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSRegionTree } from "../CICSRegionTree"; import { getIconPathInResources } from "../../utils/profileUtils"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { CICSProgramTreeItem } from "./CICSProgramTreeItem"; import { toEscapedCriteriaString } from "../../utils/filterUtils"; +import { toArray } from "../../utils/commandUtils"; export class CICSLibraryDatasets extends TreeItem { children: CICSProgramTreeItem[] = []; @@ -58,25 +58,20 @@ export class CICSLibraryDatasets extends TreeItem { this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const datasetResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSProgram", regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const programsArray = Array.isArray(datasetResponse.response.records.cicsprogram) - ? datasetResponse.response.records.cicsprogram - : [datasetResponse.response.records.cicsprogram]; + const programsArray = toArray(datasetResponse.response.records.cicsprogram); this.label = `${this.dataset.dsname}${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${programsArray.length}]`; for (const program of programsArray) { const newProgramItem = new CICSProgramTreeItem(program, this.parentRegion, this); this.addProgram(newProgramItem); } } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a program filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts b/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts index 9ec83cb3..799ce3d9 100644 --- a/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts +++ b/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts @@ -12,10 +12,10 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSRegionTree } from "../CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { CICSLibraryDatasets } from "./CICSLibraryDatasets"; import { toEscapedCriteriaString } from "../../utils/filterUtils"; import { getIconOpen } from "../../utils/profileUtils"; +import { toArray } from "../../utils/commandUtils"; export class CICSLibraryTreeItem extends TreeItem { children: CICSLibraryDatasets[] = []; @@ -58,7 +58,6 @@ export class CICSLibraryTreeItem extends TreeItem { this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const libraryResponse = await getResource(this.parentRegion.parentSession.session, { name: "cicslibrarydatasetname", @@ -66,27 +65,19 @@ export class CICSLibraryTreeItem extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const datasetArray = Array.isArray(libraryResponse.response.records.cicslibrarydatasetname) - ? libraryResponse.response.records.cicslibrarydatasetname - : [libraryResponse.response.records.cicslibrarydatasetname]; - this.label = `${this.library.name}${this.parentRegion.parentPlex ? ` (${this.library.eyu_cicsname})` : ""}${ - this.activeFilter ? ` (${this.activeFilter}) ` : " " - }[${datasetArray.length}]`; + const datasetArray = toArray(libraryResponse.response.records.cicslibrarydatasetname); + this.label = this.buildLabel(datasetArray); for (const dataset of datasetArray) { const newDatasetItem = new CICSLibraryDatasets(dataset, this.parentRegion, this); //this=CICSLibraryTreeItem this.addDataset(newDatasetItem); } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a datasets filter to narrow search`); } else if (this.children.length === 0) { window.showInformationMessage(`No datasets found`); - this.label = `${this.library.name}${this.parentRegion.parentPlex ? ` (${this.library.eyu_cicsname})` : ""}${ - this.activeFilter ? ` (${this.activeFilter}) ` : " " - }[0]`; + this.label = this.buildLabel([]); this.iconPath = getIconOpen(true); } else { window.showErrorMessage( @@ -99,6 +90,16 @@ export class CICSLibraryTreeItem extends TreeItem { } } + private buildLabel(arr?: any[]) { + let labelContent = this.library.name; + labelContent += this.parentRegion.parentPlex ? ` (${this.library.eyu_cicsname})` : ""; + labelContent += this.activeFilter ? ` (${this.activeFilter}) ` : " "; + if (arr) { + labelContent += `[${arr.length}]`; + } + return labelContent; + } + public clearFilter() { this.activeFilter = undefined; this.contextValue = `cicslibrary.${this.activeFilter ? "filtered" : "unfiltered"}${this.library.name}`; diff --git a/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts b/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts index ca67e817..78f2ced0 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSPipelineTreeItem } from "./treeItems/CICSPipelineTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getIconOpen } from "../../../utils/profileUtils"; +import { toArray } from "../../../utils/commandUtils"; export class CICSPipelineTree extends TreeItem { children: CICSPipelineTreeItem[] = []; @@ -42,7 +42,6 @@ export class CICSPipelineTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const pipelineResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSPipeline", @@ -50,10 +49,7 @@ export class CICSPipelineTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const pipelinesArray = Array.isArray(pipelineResponse.response.records.cicspipeline) - ? pipelineResponse.response.records.cicspipeline - : [pipelineResponse.response.records.cicspipeline]; + const pipelinesArray = toArray(pipelineResponse.response.records.cicspipeline); this.label = `Pipelines${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${pipelinesArray.length}]`; for (const pipeline of pipelinesArray) { const newPipelineItem = new CICSPipelineTreeItem(pipeline, this.parentRegion, this); @@ -62,7 +58,6 @@ export class CICSPipelineTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a Pipeline filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts b/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts index 0aa8547a..bbcf380d 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSTCPIPServiceTreeItem } from "./treeItems/CICSTCPIPServiceTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getIconOpen } from "../../../utils/profileUtils"; +import { toArray } from "../../../utils/commandUtils"; export class CICSTCPIPServiceTree extends TreeItem { children: CICSTCPIPServiceTreeItem[] = []; @@ -42,7 +42,6 @@ export class CICSTCPIPServiceTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const tcpipsResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSTCPIPService", @@ -50,10 +49,7 @@ export class CICSTCPIPServiceTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const tcpipservicesArray = Array.isArray(tcpipsResponse.response.records.cicstcpipservice) - ? tcpipsResponse.response.records.cicstcpipservice - : [tcpipsResponse.response.records.cicstcpipservice]; + const tcpipservicesArray = toArray(tcpipsResponse.response.records.cicstcpipservice); this.label = `TCPIP Services${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${tcpipservicesArray.length}]`; for (const tcpips of tcpipservicesArray) { const newTCPIPServiceItem = new CICSTCPIPServiceTreeItem(tcpips, this.parentRegion, this); @@ -64,7 +60,6 @@ export class CICSTCPIPServiceTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a TCPIPService filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts b/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts index f48682bf..2d5aa4ad 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSURIMapTreeItem } from "./treeItems/CICSURIMapTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getIconOpen } from "../../../utils/profileUtils"; +import { toArray } from "../../../utils/commandUtils"; export class CICSURIMapTree extends TreeItem { children: CICSURIMapTreeItem[] = []; @@ -42,7 +42,6 @@ export class CICSURIMapTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const urimapResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSURIMap", @@ -50,10 +49,7 @@ export class CICSURIMapTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const urimapArray = Array.isArray(urimapResponse.response.records.cicsurimap) - ? urimapResponse.response.records.cicsurimap - : [urimapResponse.response.records.cicsurimap]; + const urimapArray = toArray(urimapResponse.response.records.cicsurimap); this.label = `URI Maps${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${urimapArray.length}]`; for (const urimap of urimapArray) { const newURIMapItem = new CICSURIMapTreeItem(urimap, this.parentRegion, this); @@ -64,7 +60,6 @@ export class CICSURIMapTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a URIMap filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts b/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts index 2c7c7b85..23c92ea3 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts @@ -13,9 +13,9 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSWebServiceTreeItem } from "./treeItems/CICSWebServiceTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; import { getResource } from "@zowe/cics-for-zowe-sdk"; -import * as https from "https"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getIconOpen } from "../../../utils/profileUtils"; +import { toArray } from "../../../utils/commandUtils"; export class CICSWebServiceTree extends TreeItem { children: CICSWebServiceTreeItem[] = []; @@ -42,7 +42,6 @@ export class CICSWebServiceTree extends TreeItem { } this.children = []; try { - https.globalAgent.options.rejectUnauthorized = this.parentRegion.parentSession.session.ISession.rejectUnauthorized; const webserviceResponse = await getResource(this.parentRegion.parentSession.session, { name: "CICSWebService", @@ -50,10 +49,7 @@ export class CICSWebServiceTree extends TreeItem { cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, criteria: criteria, }); - https.globalAgent.options.rejectUnauthorized = undefined; - const webservicesArray = Array.isArray(webserviceResponse.response.records.cicswebservice) - ? webserviceResponse.response.records.cicswebservice - : [webserviceResponse.response.records.cicswebservice]; + const webservicesArray = toArray(webserviceResponse.response.records.cicswebservice); this.label = `Web Services${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${webservicesArray.length}]`; for (const webservice of webservicesArray) { const newWebServiceItem = new CICSWebServiceTreeItem(webservice, this.parentRegion, this); @@ -62,7 +58,6 @@ export class CICSWebServiceTree extends TreeItem { } this.iconPath = getIconOpen(true); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; if (error.mMessage!.includes("exceeded a resource limit")) { window.showErrorMessage(`Resource Limit Exceeded - Set a Web Services filter to narrow search`); } else if (this.children.length === 0) { diff --git a/packages/vsce/src/utils/commandUtils.ts b/packages/vsce/src/utils/commandUtils.ts index 34ad1273..559629f9 100644 --- a/packages/vsce/src/utils/commandUtils.ts +++ b/packages/vsce/src/utils/commandUtils.ts @@ -62,3 +62,7 @@ export function splitCmciErrorMessage(message: any) { } return [resp, resp2, respAlt, eibfnAlt]; } + +export function toArray(input: T | [T]): [T] { + return Array.isArray(input) ? input : [input]; +} diff --git a/packages/vsce/src/utils/profileManagement.ts b/packages/vsce/src/utils/profileManagement.ts index 658e2d7c..7ef1fd5d 100644 --- a/packages/vsce/src/utils/profileManagement.ts +++ b/packages/vsce/src/utils/profileManagement.ts @@ -9,19 +9,20 @@ * */ -import { Types, ZoweVsCodeExtension, imperative } from "@zowe/zowe-explorer-api"; -import axios, { AxiosRequestConfig } from "axios"; +import { getCache, getResource } from "@zowe/cics-for-zowe-sdk"; +import { Session } from "@zowe/imperative"; +import { imperative, Types, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api"; import { window } from "vscode"; import { xml2json } from "xml-js"; -import cicsProfileMeta from "./profileDefinition"; -import * as https from "https"; import { CICSPlexTree } from "../trees/CICSPlexTree"; +import { toArray } from "./commandUtils"; +import cicsProfileMeta from "./profileDefinition"; export class ProfileManagement { private static zoweExplorerAPI = ZoweVsCodeExtension.getZoweExplorerApi(); private static ProfilesCache = ProfileManagement.zoweExplorerAPI.getExplorerExtenderApi().getProfilesCache(); - constructor() {} + constructor() { } public static apiDoesExist() { if (ProfileManagement.zoweExplorerAPI) { @@ -52,273 +53,295 @@ export class ProfileManagement { return mProfileInfo; } - /** - * Makes axios GET request with path and axios config object given - * @param path - * @param config - * @returns - */ - public static async makeRequest(path: string, config: AxiosRequestConfig) { - const response = await axios.get(path, config); - return response; - } - public static cmciResponseXml2Json(data: string) { return JSON.parse(xml2json(data, { compact: true, spaces: 4 })); } - /** - * Populates the info - * @param profile - * @returns Array of type InfoLoaded - */ - public static async getPlexInfo(profile: imperative.IProfileLoaded): Promise { - const config: AxiosRequestConfig = { - baseURL: `${profile.profile.protocol}://${profile.profile.host}:${profile.profile.port}/CICSSystemManagement`, - auth: { - username: profile.profile.user, - password: profile.profile.password, - }, - }; + public static getSessionFromProfile(profile: imperative.IProfile): Session { + return new Session({ + protocol: profile.protocol, + hostname: profile.host, + port: profile.port, + type: "basic", + user: profile.user, + password: profile.password, + rejectUnauthorized: 'rejectUnauthorized' in profile ? profile.rejectUnauthorized : true, + }); + } + + public static async regionIsGroup(session: Session, profile: imperative.IProfile): Promise { + + let isGroup = false; + try { + const checkIfSystemGroup = await getResource(session, { + name: "CICSRegionGroup", + cicsPlex: profile.cicsPlex, + regionName: profile.regionName, + criteria: `GROUP=${profile.regionName}`, + }); + if (checkIfSystemGroup && checkIfSystemGroup.response.resultsummary.recordcount !== "0") { + isGroup = true; + } + } catch (error) { + if (error instanceof imperative.ImperativeError) { + if (!error.mDetails.msg.toUpperCase().includes("NODATA")) { + throw error; + } + } + } + + return isGroup; + } + + public static async isPlex(session: Session): Promise { + try { + const { response } = await getResource(session, { + name: "CICSCICSPlex", + queryParams: { + summonly: true, + nodiscard: true, + } + }); + return response.resultsummary.api_response1_alt === "OK" ? + response.resultsummary.cachetoken : null; + } catch (error) { + if (error instanceof imperative.RestClientError) { + if (`${error.mDetails.errorCode}` === "404") { + return null; + } + window.showErrorMessage( + `${error.causeErrors.code} - ${error.causeErrors.message}`, + ); + } else { + window.showErrorMessage( + `Error getting CICSCICSPlex resource - ${JSON.stringify(error)}`, + ); + } + throw error; + } + } + + public static async regionPlexProvided(session: Session, profile: imperative.IProfile): Promise { + const infoLoaded: InfoLoaded[] = []; - https.globalAgent.options.rejectUnauthorized = profile.profile.rejectUnauthorized; + try { + const { response } = await getResource(session, { + name: "CICSManagedRegion", + cicsPlex: profile.cicsPlex, + regionName: profile.regionName, + }); - if (profile.profile.cicsPlex) { - if (profile.profile.regionName) { - /** - * Both Supplied, no searching required - Only load 1 region - */ - const checkIfSystemGroup = await ProfileManagement.makeRequest( - `/CICSRegionGroup/${profile.profile.cicsPlex}/${profile.profile.regionName}?CRITERIA=(GROUP=${profile.profile.regionName})`, - config + if (response.records?.cicsmanagedregion) { + infoLoaded.push({ + plexname: profile.cicsPlex, + regions: toArray(response.records.cicsmanagedregion), + group: await this.regionIsGroup(session, profile), + }); + } else { + window.showErrorMessage( + `Cannot find region ${profile.regionName} in plex ${profile.cicsPlex} for profile ${profile.name}` + ); + throw new Error("Region Not Found"); + } + } catch (error) { + if (error instanceof imperative.RestClientError) { + window.showErrorMessage( + `${error.causeErrors.code} - ${error.causeErrors.message}`, + ); + } else if (error instanceof imperative.ImperativeError && ( + error.mDetails.msg.toUpperCase().includes("INVALIDATA") || error.mDetails.msg.toUpperCase().includes("INVALIDPARM"))) { + window.showErrorMessage( + `Plex ${profile.cicsPlex} and Region ${profile.regionName} not found - ${JSON.stringify(error)}`, ); - const regionGroupJson = ProfileManagement.cmciResponseXml2Json(checkIfSystemGroup.data); - if ( - regionGroupJson.response.resultsummary && - regionGroupJson.response.resultsummary._attributes && - regionGroupJson.response.resultsummary._attributes.recordcount !== "0" - ) { - // CICSGroup - const singleGroupResponse = await ProfileManagement.makeRequest( - `/CICSManagedRegion/${profile.profile.cicsPlex}/${profile.profile.regionName}`, - config - ); - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(singleGroupResponse.data); - const allRegions = jsonFromXml.response.records.cicsmanagedregion.map((item: { _attributes: any }) => item._attributes); - infoLoaded.push({ - plexname: profile.profile.cicsPlex, - regions: [allRegions], - group: true, - }); - } else { - // Region - const singleRegionResponse = await ProfileManagement.makeRequest( - `/CICSManagedRegion/${profile.profile.cicsPlex}/${profile.profile.regionName}`, - config - ); - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(singleRegionResponse.data); - if (jsonFromXml.response.records && jsonFromXml.response.records.cicsmanagedregion) { - const singleRegion = jsonFromXml.response.records.cicsmanagedregion._attributes; - infoLoaded.push({ - plexname: profile.profile.cicsPlex, - regions: [singleRegion], - group: false, - }); - } else { - window.showErrorMessage( - `Cannot find region ${profile.profile.regionName} in plex ${profile.profile.cicsPlex} for profile ${profile.name}` - ); - https.globalAgent.options.rejectUnauthorized = undefined; - throw new Error("Region Not Found"); - } - } } else { - /** - * Plex given - must search for regions - */ - const allRegionResponse = await ProfileManagement.makeRequest(`/CICSManagedRegion/${profile.profile.cicsPlex}`, config); - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(allRegionResponse.data); - if (jsonFromXml.response.records && jsonFromXml.response.records.cicsmanagedregion) { - const allRegions = jsonFromXml.response.records.cicsmanagedregion.map((item: { _attributes: any }) => item._attributes); - infoLoaded.push({ - plexname: profile.profile.cicsPlex, - regions: allRegions, - group: false, - }); - } else { - window.showErrorMessage(`Cannot find plex ${profile.profile.cicsPlex} for profile ${profile.name}`); - https.globalAgent.options.rejectUnauthorized = undefined; - throw new Error("Plex Not Found"); - } + window.showErrorMessage( + `Error getting CICSManagedRegion resource - ${JSON.stringify(error)}`, + ); } + throw error; + } + + return infoLoaded; + } + + public static async plexProvided(session: Session, profile: imperative.IProfile): Promise { + + const infoLoaded: InfoLoaded[] = []; + + const { response } = await getResource(session, { + name: "CICSManagedRegion", + cicsPlex: profile.cicsPlex, + }); + + if (response.records?.cicsmanagedregion) { + infoLoaded.push({ + plexname: profile.cicsPlex, + regions: toArray(response.records.cicsmanagedregion), + group: false, + }); } else { - if (profile.profile.regionName) { - /** - * Region but no plex - Single region system, use that - */ - const singleRegionResponse = await ProfileManagement.makeRequest(`/CICSRegion/${profile.profile.regionName}`, config); - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(singleRegionResponse.data); - if (jsonFromXml.response.records && jsonFromXml.response.records.cicsregion) { - const singleRegion = jsonFromXml.response.records.cicsregion._attributes; + window.showErrorMessage(`Cannot find plex ${profile.cicsPlex} for profile ${profile.name}`); + throw new Error("Plex Not Found"); + } + + return infoLoaded; + } + + public static async regionProvided(session: Session, profile: imperative.IProfile): Promise { + + const infoLoaded: InfoLoaded[] = []; + + const { response } = await getResource(session, { + name: "CICSRegion", + regionName: profile.regionName, + }); + + if (response.records.cicsregion) { + infoLoaded.push({ + plexname: null, + regions: toArray(response.records.cicsregion), + group: false, + }); + } else { + window.showErrorMessage(`Cannot find region ${profile.regionName}`); + throw new Error("Region Not Found"); + } + + return infoLoaded; + } + + public static async noneProvided(session: Session): Promise { + + const infoLoaded: InfoLoaded[] = []; + + const isPlex = await this.isPlex(session); + if (isPlex) { + try { + const { response } = await getCache(session, { cacheToken: isPlex, nodiscard: false }); + for (const plex of response.records.cicscicsplex || []) { infoLoaded.push({ - plexname: null, - regions: [singleRegion], + plexname: plex.plexname, + regions: [], group: false, }); - } else { - window.showErrorMessage(`Cannot find region ${profile.profile.regionName} for profile ${profile.name}`); - https.globalAgent.options.rejectUnauthorized = undefined; - throw new Error("Region Not Found"); } - } else { - /** - * Nothing given - Test if plex and find all info - */ - try { - const testIfPlexResponse = await ProfileManagement.makeRequest(`/CICSCICSPlex`, config); - if (testIfPlexResponse.status === 200) { - // Plex - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(testIfPlexResponse.data); - if (jsonFromXml.response.records && jsonFromXml.response.records.cicscicsplex) { - const returnedPlexes = jsonFromXml.response.records.cicscicsplex.map((item: { _attributes: any }) => item._attributes); - const uniqueReturnedPlexes = returnedPlexes.filter( - (plex: any, index: number) => index === returnedPlexes.findIndex((found: any) => found.plexname === plex.plexname) - ); - for (const plex of uniqueReturnedPlexes) { - try { - // Regions are empty because we only load Plex when session is expanded - infoLoaded.push({ - plexname: plex.plexname, - regions: [], - group: false, - }); - } catch (error) { - console.log(error); - } - } - } - } else { - // Not Plex - const singleRegion = await ProfileManagement.makeRequest(`/CICSRegion`, config); - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(singleRegion.data); - const returnedRegion = jsonFromXml.response.records.cicsregion._attributes; - infoLoaded.push({ - plexname: null, - regions: [returnedRegion], - group: false, - }); - } - } catch (error) { - // Not Plex - Could be error - try { - const singleRegion = await ProfileManagement.makeRequest(`/CICSRegion`, config); - const jsonFromXml = JSON.parse(xml2json(singleRegion.data, { compact: true, spaces: 4 })); - if (!jsonFromXml) { - throw error; - } - const returnedRegion = jsonFromXml.response.records.cicsregion._attributes; - infoLoaded.push({ - plexname: null, - regions: [returnedRegion], - group: false, - }); - } catch (e2) { - https.globalAgent.options.rejectUnauthorized = undefined; - throw e2; + } catch (error) { + window.showErrorMessage( + `Error retrieving cache - ${JSON.stringify(error)}`, + ); + throw error; + } + } else { + try { + const singleRegion = await getResource(session, { + name: "CICSRegion", + }); + infoLoaded.push({ + plexname: null, + regions: toArray(singleRegion.response.records.cicsregion), + group: false, + }); + } catch (error) { + if (error instanceof imperative.RestClientError) { + if (`${error.mDetails.errorCode}` === "404") { + window.showErrorMessage( + `CMCI Endpoint not found - ${error.mDetails.protocol}://${error.mDetails.host}:${error.mDetails.port}${error.mDetails.resource}`, + ); } + } else { + window.showErrorMessage( + `Error making request - ${JSON.stringify(error)}`, + ); } + throw error; } } - https.globalAgent.options.rejectUnauthorized = undefined; + return infoLoaded; } + /** + * Populates the info + * @param profile + * @returns Array of type InfoLoaded + */ + public static async getPlexInfo(profile: imperative.IProfileLoaded): Promise { + + const session = this.getSessionFromProfile(profile.profile); + + if (profile.profile.cicsPlex && profile.profile.regionName) { + return this.regionPlexProvided(session, profile.profile); + } else if (profile.profile.cicsPlex) { + return this.plexProvided(session, profile.profile); + } else if (profile.profile.regionName) { + return this.regionProvided(session, profile.profile); + } else { + return this.noneProvided(session); + } + } + /** * Return all the regions in a given plex */ - public static async getRegionInfoInPlex(plex: CICSPlexTree) { + public static async getRegionInfoInPlex(plex: CICSPlexTree): Promise { try { - const profile = plex.getProfile(); - const config: AxiosRequestConfig = { - baseURL: `${profile.profile.protocol}://${profile.profile.host}:${profile.profile.port}/CICSSystemManagement`, - auth: { - username: profile.profile.user, - password: profile.profile.password, - }, - }; - https.globalAgent.options.rejectUnauthorized = profile.profile.rejectUnauthorized; - const regionResponse = await ProfileManagement.makeRequest(`/CICSManagedRegion/${plex.getPlexName()}`, config); - https.globalAgent.options.rejectUnauthorized = undefined; - if (regionResponse.status === 200) { - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(regionResponse.data); - if (jsonFromXml.response.records && jsonFromXml.response.records.cicsmanagedregion) { - const returnedRegions = jsonFromXml.response.records.cicsmanagedregion.map((item: { _attributes: any }) => item._attributes); - return returnedRegions; - } + const session = this.getSessionFromProfile(plex.getProfile().profile); + const { response } = await getResource(session, { + name: "CICSManagedRegion", + cicsPlex: plex.getPlexName(), + }); + if (response.resultsummary.api_response1_alt === "OK") { + return toArray(response.records.cicsmanagedregion); } } catch (error) { - console.log(error); - window.showErrorMessage(`Cannot find plex ${plex.getPlexName()} for profile ${plex.getParent().label}`); - throw new Error("Plex Not Found"); + if (error instanceof imperative.ImperativeError && !error.mDetails.msg.includes("NOTAVAILABLE")) { + window.showErrorMessage(`Error retrieving ManagedRegions for plex ${plex.getPlexName()} with profile ${plex.getParent().label} - ${error}`); + } } } - public static async generateCacheToken(profile: imperative.IProfileLoaded, plexName: string, resourceName: string, criteria?: string, group?: string) { - try { - const config: AxiosRequestConfig = { - baseURL: `${profile.profile.protocol}://${profile.profile.host}:${profile.profile.port}/CICSSystemManagement`, - auth: { - username: profile.profile.user, - password: profile.profile.password, - }, - params: { - OVERRIDEWARNINGCOUNT: "YES", - CRITERIA: criteria, - NODISCARD: "", - SUMMONLY: "", - }, - }; - https.globalAgent.options.rejectUnauthorized = profile.profile.rejectUnauthorized; - const allProgramsResponse = await ProfileManagement.makeRequest(`/${resourceName}/${plexName}${group ? `/${group}` : ""}`, config); - https.globalAgent.options.rejectUnauthorized = undefined; - if (allProgramsResponse.status === 200) { - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(allProgramsResponse.data); - if (jsonFromXml.response && jsonFromXml.response.resultsummary) { - const resultsSummary = jsonFromXml.response.resultsummary._attributes; - return { cacheToken: resultsSummary.cachetoken, recordCount: resultsSummary.recordcount }; - } + public static async generateCacheToken( + profile: imperative.IProfileLoaded, + plexName: string, + resourceName: string, + criteria?: string, + group?: string + ): Promise<{ cacheToken: string; recordCount: number; }> { + const session = this.getSessionFromProfile(profile.profile); + const allProgramsResponse = await getResource(session, { + name: resourceName, + cicsPlex: plexName, + ...group ? { regionName: group } : {}, + criteria: criteria, + queryParams: { + summonly: true, + nodiscard: true, + overrideWarningCount: true, + } + }); + if (allProgramsResponse.response.resultsummary.api_response1_alt === "OK") { + if (allProgramsResponse.response && allProgramsResponse.response.resultsummary) { + const resultsSummary = allProgramsResponse.response.resultsummary; + return { cacheToken: resultsSummary.cachetoken, recordCount: parseInt(resultsSummary.recordcount, 10) }; } - } catch (error) { - console.log(error); - throw error; } + return { cacheToken: null, recordCount: 0 }; } public static async getCachedResources(profile: imperative.IProfileLoaded, cacheToken: string, resourceName: string, start = 1, increment = 800) { - try { - const config: AxiosRequestConfig = { - baseURL: `${profile.profile.protocol}://${profile.profile.host}:${profile.profile.port}/CICSSystemManagement`, - auth: { - username: profile.profile.user, - password: profile.profile.password, - }, - }; - https.globalAgent.options.rejectUnauthorized = profile.profile.rejectUnauthorized; - const allItemsResponse = await ProfileManagement.makeRequest(`/CICSResultCache/${cacheToken}/${start}/${increment}`, config); - https.globalAgent.options.rejectUnauthorized = undefined; - if (allItemsResponse.status === 200) { - const jsonFromXml = ProfileManagement.cmciResponseXml2Json(allItemsResponse.data); - if (jsonFromXml.response && jsonFromXml.response.records && jsonFromXml.response.records[resourceName.toLowerCase()]) { - const recordAttributes = jsonFromXml.response.records[resourceName.toLowerCase()]; - const recordAttributesArr = Array.isArray(recordAttributes) ? recordAttributes : [recordAttributes]; - const returnedResources = recordAttributesArr.map((item: { _attributes: any }) => item._attributes); - return returnedResources; - } + const session = this.getSessionFromProfile(profile.profile); + const allItemsresponse = await getCache(session, { + cacheToken, + startIndex: start, + count: increment, + }); + + if (allItemsresponse.response.resultsummary.api_response1_alt === "OK") { + if (allItemsresponse.response && allItemsresponse.response.records && allItemsresponse.response.records[resourceName.toLowerCase()]) { + const recordAttributes = allItemsresponse.response.records[resourceName.toLowerCase()]; + return toArray(recordAttributes); } - } catch (error) { - console.log(error); - throw error; } } }