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/packages/vsce/CHANGELOG.md b/packages/vsce/CHANGELOG.md index 6cb29eba..80119e41 100644 --- a/packages/vsce/CHANGELOG.md +++ b/packages/vsce/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to the "cics-extension-for-zowe" extension will be documented in this file. +## Recent Changes + +- BugFix: Opening CICS connections prevents other Zowe sessions connecting. [#159](https://github.com/zowe/cics-for-zowe-client/issues/159) ## `3.1.1` diff --git a/packages/vsce/src/commands/closeLocalFileCommand.ts b/packages/vsce/src/commands/closeLocalFileCommand.ts index 1e613013..3d973a30 100644 --- a/packages/vsce/src/commands/closeLocalFileCommand.ts +++ b/packages/vsce/src/commands/closeLocalFileCommand.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 { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; @@ -52,8 +51,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 +61,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 +118,7 @@ export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView async function closeLocalFile( session: imperative.AbstractSession, - parms: { name: string; regionName: string; cicsPlex: string }, + parms: { name: string; regionName: string; cicsPlex: string; }, 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 21ce7aa6..034e8a86 100644 --- a/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts @@ -52,8 +52,6 @@ export function getDisableLocalFileCommand(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( diff --git a/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts b/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts index 3a1ffa1f..4679ea19 100644 --- a/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts @@ -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 diff --git a/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts b/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts index aa718227..1f398aeb 100644 --- a/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts @@ -45,7 +45,6 @@ export function getEnableLocalFileCommand(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 +99,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: { name: string; regionName: string; cicsPlex: string; }): 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 b1509c0f..ebf68d79 100644 --- a/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableTransactionCommand.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 { findSelectedNodes } from "../../utils/commandUtils"; import { CICSTransactionTreeItem } from "../../trees/treeItems/CICSTransactionTreeItem"; @@ -46,7 +45,6 @@ export function getEnableTransactionCommand(tree: CICSTree, treeview: TreeView { +async function enableTransaction(session: imperative.AbstractSession, parms: { name: string; regionName: string; cicsPlex: string; }): 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 b59a06f9..06e79cfd 100644 --- a/packages/vsce/src/commands/openLocalFileCommand.ts +++ b/packages/vsce/src/commands/openLocalFileCommand.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 { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; @@ -45,27 +44,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 +103,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: { name: string; regionName: string; cicsPlex: string; }): Promise { const requestBody: any = { request: { action: { diff --git a/packages/vsce/src/commands/phaseInCommand.ts b/packages/vsce/src/commands/phaseInCommand.ts index b77d1073..f80f00fa 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 128782c1..93c58400 100644 --- a/packages/vsce/src/commands/purgeTaskCommand.ts +++ b/packages/vsce/src/commands/purgeTaskCommand.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 { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; import { CICSTaskTreeItem } from "../trees/treeItems/CICSTaskTreeItem"; import { CICSRegionsContainer } from "../trees/CICSRegionsContainer"; @@ -55,8 +54,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 +64,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 +130,7 @@ export function getPurgeTaskCommand(tree: CICSTree, treeview: TreeView) { */ async function purgeTask( session: imperative.AbstractSession, - parms: { name: string; regionName: string; cicsPlex: string }, + parms: { name: string; regionName: string; cicsPlex: string; }, purgeType: string ): Promise { const requestBody: any = { diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts index 4417cd73..7a874a5e 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts @@ -9,18 +9,19 @@ * */ -import { TreeItemCollapsibleState, TreeItem, window, ProgressLocation, workspace } from "vscode"; -import { CICSPlexTree } from "../CICSPlexTree"; -import { CICSProgramTreeItem } from "../treeItems/CICSProgramTreeItem"; -import { CICSRegionTree } from "../CICSRegionTree"; -import { CICSTree } from "../CICSTree"; -import { ProfileManagement } from "../../utils/profileManagement"; -import { ViewMore } from "../treeItems/utils/ViewMore"; import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; +import { imperative } from "@zowe/zowe-explorer-api"; +import { ProgressLocation, TreeItem, TreeItemCollapsibleState, window, workspace } from "vscode"; import { toEscapedCriteriaString } from "../../utils/filterUtils"; +import { ProfileManagement } from "../../utils/profileManagement"; +import { getIconPathInResources } from "../../utils/profileUtils"; +import { CICSPlexTree } from "../CICSPlexTree"; import { CICSRegionsContainer } from "../CICSRegionsContainer"; +import { CICSRegionTree } from "../CICSRegionTree"; +import { CICSTree } from "../CICSTree"; +import { CICSProgramTreeItem } from "../treeItems/CICSProgramTreeItem"; import { TextTreeItem } from "../treeItems/utils/TextTreeItem"; -import { getIconPathInResources } from "../../utils/profileUtils"; +import { ViewMore } from "../treeItems/utils/ViewMore"; export class CICSCombinedProgramTree extends TreeItem { children: (CICSProgramTreeItem | ViewMore)[] | [TextTreeItem] | null; @@ -66,8 +67,8 @@ export class CICSCombinedProgramTree extends TreeItem { this.getParent().getGroupName() ); if (cacheTokenInfo) { - const recordsCount = cacheTokenInfo.recordCount; - if (parseInt(recordsCount, 10)) { + const recordsCount = parseInt(cacheTokenInfo.recordCount, 10); + if (recordsCount) { let allPrograms; if (recordsCount <= this.incrementCount) { allPrograms = await ProfileManagement.getCachedResources( @@ -75,7 +76,7 @@ export class CICSCombinedProgramTree extends TreeItem { cacheTokenInfo.cacheToken, this.constant, 1, - parseInt(recordsCount, 10) + recordsCount ); } else { allPrograms = await ProfileManagement.getCachedResources( @@ -85,7 +86,7 @@ export class CICSCombinedProgramTree extends TreeItem { 1, this.incrementCount ); - count = parseInt(recordsCount); + count = recordsCount; } this.addProgramsUtil([], allPrograms, count); this.iconPath = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); @@ -99,12 +100,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, + " " + )}` + ); + } } } ); diff --git a/packages/vsce/src/trees/CICSLibraryTree.ts b/packages/vsce/src/trees/CICSLibraryTree.ts index fb5e953d..c8cc2a46 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 { getIconPathInResources } 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 = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 fcf8524a..c4df0fc8 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 { getIconPathInResources } 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 = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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..1abf278d 100644 --- a/packages/vsce/src/trees/CICSPlexTree.ts +++ b/packages/vsce/src/trees/CICSPlexTree.ts @@ -71,14 +71,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 495f6815..54bd7001 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 { getIconPathInResources } from "../utils/profileUtils"; +import { toArray } from "../utils/commandUtils"; export class CICSProgramTree extends TreeItem { children: CICSProgramTreeItem[] = []; parentRegion: CICSRegionTree; @@ -41,7 +41,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", @@ -49,10 +48,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); @@ -60,7 +56,6 @@ export class CICSProgramTree extends TreeItem { } this.iconPath = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 d905494c..d4efe983 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 { getIconPathInResources } 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 1477ff26..d3a3d564 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 { getIconPathInResources } 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 = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 352a59d6..da428aa0 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 { getIconPathInResources } 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 = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 58cb5392..3eac8f44 100644 --- a/packages/vsce/src/trees/CICSTree.ts +++ b/packages/vsce/src/trees/CICSTree.ts @@ -28,7 +28,6 @@ import { addProfileHtml } from "../utils/webviewHTML"; 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"; @@ -229,15 +228,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, @@ -247,7 +243,6 @@ export class CICSTree implements TreeDataProvider { ); newSessionTree.addRegion(newRegionTree); } catch (error) { - https.globalAgent.options.rejectUnauthorized = undefined; console.log(error); } } else { @@ -274,7 +269,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 62b72680..90a62b8e 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 { getIconPathInResources } from "../../utils/profileUtils"; import { CICSLibraryDatasets } from "./CICSLibraryDatasets"; import { toEscapedCriteriaString } from "../../utils/filterUtils"; +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 = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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([]); } else { window.showErrorMessage( `Something went wrong when fetching datasets - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace( @@ -98,6 +89,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 1fcd4390..b314448d 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts @@ -13,7 +13,6 @@ 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 { getIconPathInResources } from "../../../utils/profileUtils"; export class CICSPipelineTree extends TreeItem { @@ -41,7 +40,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", @@ -49,10 +47,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); @@ -61,7 +56,6 @@ export class CICSPipelineTree extends TreeItem { } this.iconPath = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 6573d2c3..3dad87b0 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts @@ -13,7 +13,6 @@ 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 { getIconPathInResources } from "../../../utils/profileUtils"; export class CICSTCPIPServiceTree extends TreeItem { @@ -41,7 +40,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", @@ -49,10 +47,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); @@ -63,7 +58,6 @@ export class CICSTCPIPServiceTree extends TreeItem { } this.iconPath = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 920f2859..d8e4c79b 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts @@ -13,7 +13,6 @@ 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 { getIconPathInResources } from "../../../utils/profileUtils"; export class CICSURIMapTree extends TreeItem { @@ -41,7 +40,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", @@ -49,10 +47,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); @@ -63,7 +58,6 @@ export class CICSURIMapTree extends TreeItem { } this.iconPath = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 a8ddd16e..b6e19a07 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts @@ -13,7 +13,6 @@ 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 { getIconPathInResources } from "../../../utils/profileUtils"; export class CICSWebServiceTree extends TreeItem { @@ -41,7 +40,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", @@ -49,10 +47,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); @@ -61,7 +56,6 @@ export class CICSWebServiceTree extends TreeItem { } this.iconPath = getIconPathInResources("folder-open-dark.svg", "folder-open-light.svg"); } 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 43f1a969..e08ebd74 100644 --- a/packages/vsce/src/utils/profileManagement.ts +++ b/packages/vsce/src/utils/profileManagement.ts @@ -9,20 +9,20 @@ * */ -import { ProfilesCache, Types, ZoweVsCodeExtension, imperative } from "@zowe/zowe-explorer-api"; -import axios, { AxiosRequestConfig } from "axios"; +import { getCache, getResource, ICMCIApiResponse } 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 { LoggerUtils } from "./loggerUtils"; +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) { @@ -69,273 +69,249 @@ 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 })); } + 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 checkIfSystemGroup: ICMCIApiResponse; + try { + checkIfSystemGroup = await getResource(session, { + name: "CICSRegionGroup", + cicsPlex: profile.cicsPlex, + regionName: profile.regionName, + criteria: `GROUP=${profile.regionName}`, + }); + } catch (error) { + if (error instanceof imperative.ImperativeError) { + if (!error.mDetails.msg.toUpperCase().includes("NODATA")) { + throw error; + } + } + } + + return checkIfSystemGroup?.response.resultsummary.recordcount !== "0"; + } + + 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; + } + } + throw error; + } + } + + public static async regionPlexProvided(session: Session, profile: imperative.IProfile): Promise { + + const infoLoaded: InfoLoaded[] = []; + + const { response } = await getResource(session, { + name: "CICSManagedRegion", + cicsPlex: profile.cicsPlex, + regionName: profile.regionName, + }); + + 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"); + } + + 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 { + 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) { + const { response } = await getCache(session, { cacheToken: isPlex, nodiscard: false }); + // const uniqueReturnedPlexes = testIfPlexResponse.response.records.cicscicsplex.filter( + // (plex: any, index: number) => index === + // testIfPlexResponse.response.records.cicscicsplex.findIndex((found: any) => + // found.plexname === plex.plexname)); + for (const plex of response.records.cicscicsplex || []) { + infoLoaded.push({ + plexname: plex.plexname, + regions: [], + group: false, + }); + } + } else { + // TODO: Error checking!! + const singleRegion = await getResource(session, { + name: "CICSRegion", + }); + infoLoaded.push({ + plexname: null, + regions: toArray(singleRegion.response.records.cicsregion), + group: false, + }); + } + + return infoLoaded; + } + /** * 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, - }, - }; - const infoLoaded: InfoLoaded[] = []; - https.globalAgent.options.rejectUnauthorized = profile.profile.rejectUnauthorized; - - 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 - ); - 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"); - } - } + 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 { - 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; - infoLoaded.push({ - plexname: null, - regions: [singleRegion], - 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; - } - } - } + return this.noneProvided(session); } - https.globalAgent.options.rejectUnauthorized = undefined; - return infoLoaded; } /** * 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 + ) { + 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: resultsSummary.recordcount }; } - } catch (error) { - console.log(error); - throw error; } } 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; } } }