diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 0c7aafba..2a3ce585 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the IBM® CICS® Plug-in for Zowe CLI will be documented in this file. + +## Recent Changes + +- Enhancement: Added CICS resource names to available constants. [#217](https://github.com/zowe/cics-for-zowe-client/issues/217) + ## `6.3.3` - Enhancement: Add requestOptions to getResource and getCache method. [#220](https://github.com/zowe/cics-for-zowe-client/issues/220) diff --git a/packages/sdk/src/constants/CicsCmci.constants.ts b/packages/sdk/src/constants/CicsCmci.constants.ts index a915cd27..1469f4ac 100644 --- a/packages/sdk/src/constants/CicsCmci.constants.ts +++ b/packages/sdk/src/constants/CicsCmci.constants.ts @@ -18,6 +18,11 @@ export const CicsCmciConstants = { */ CICS_SYSTEM_MANAGEMENT: "CICSSystemManagement", + /** + * Specifies the required part of the REST interface URI to access system initialization parameters + */ + CICS_SYSTEM_PARAMETER: "CICSSystemParameter", + /** * Specifies the required part of the REST interface URI to access program definitions */ @@ -38,6 +43,11 @@ export const CicsCmciConstants = { */ CICS_PROGRAM_RESOURCE: "CICSProgram", + /** + * Specifies the required part of the REST interface URI to access library resources + */ + CICS_LIBRARY_RESOURCE: "CICSLibrary", + /** * Specifies the required part of the REST interface URI to access URIMap definitions */ @@ -48,6 +58,11 @@ export const CicsCmciConstants = { */ CICS_DEFINITION_WEBSERVICE: "CICSDefinitionWebService", + /** + * Specifies the required part of the REST interface URI to access tcp/ip service resources + */ + CICS_TCPIPSERVICE_RESOURCE: "CICSTCPIPService", + /* * Specifies the required part of the REST interface URI to access URIMaps */ diff --git a/packages/vsce/CHANGELOG.md b/packages/vsce/CHANGELOG.md index d4bd20df..8f8b81ad 100644 --- a/packages/vsce/CHANGELOG.md +++ b/packages/vsce/CHANGELOG.md @@ -4,10 +4,12 @@ All notable changes to the "cics-extension-for-zowe" extension will be documente ## Recent Changes +- Enhancement: Use LTPA tokens to allow CMCI "sessions" [#217](https://github.com/zowe/cics-for-zowe-client/issues/217) - Enhancement: Create icons for library and Web resources. [#229](https://github.com/zowe/cics-for-zowe-client/issues/229) - Updated icon sizes [#235](https://github.com/zowe/cics-for-zowe-client/issues/235) ## `3.3.3` + - BugFix: Duplicate CICSplex exist when connecting to a multi-CMAS system. [#227](https://github.com/zowe/cics-for-zowe-client/issues/227) - Enhancement: Show CMCI error response codes when failing to make requests. [#220](https://github.com/zowe/cics-for-zowe-client/issues/220) diff --git a/packages/vsce/__tests__/__unit__/trees/CICSRegionsContainer.unit.test.ts b/packages/vsce/__tests__/__unit__/trees/CICSRegionsContainer.unit.test.ts index bbb1906c..4ba44771 100644 --- a/packages/vsce/__tests__/__unit__/trees/CICSRegionsContainer.unit.test.ts +++ b/packages/vsce/__tests__/__unit__/trees/CICSRegionsContainer.unit.test.ts @@ -87,7 +87,8 @@ describe("Test suite for CICSRegionsContainer", () => { await sut.loadRegionsInCICSGroup(CICSTreeMock as any as CICSTree); - expect(getResourceMock).toHaveBeenCalledWith(sut.getParent().getParent().getSession(), testData); + expect(getResourceMock).toHaveBeenCalledWith(sut.getParent().getParent().getSession(), testData, + { failOnNoData: false, useCICSCmciRestError: true }); expect(sut.label).toBe("Regions (cics) [1/1]"); expect(sut.collapsibleState).toBe(2); }); @@ -103,7 +104,7 @@ describe("Test suite for CICSRegionsContainer", () => { it("Should load all regions of plex", async () => { await sut.loadRegionsInPlex(); - + expect(getRegionInfoInPlexMock).toHaveBeenCalledTimes(1); expect(sut.label).toBe("Regions [2/2]"); expect(sut.collapsibleState).toBe(2); diff --git a/packages/vsce/__tests__/__unit__/trees/CICSSessionTree.unit.test.ts b/packages/vsce/__tests__/__unit__/trees/CICSSessionTree.unit.test.ts index f47c43d6..409c53a1 100644 --- a/packages/vsce/__tests__/__unit__/trees/CICSSessionTree.unit.test.ts +++ b/packages/vsce/__tests__/__unit__/trees/CICSSessionTree.unit.test.ts @@ -16,11 +16,12 @@ import { CICSRegionTree } from "../../../src/trees/CICSRegionTree"; import { CICSSessionTree } from "../../../src/trees/CICSSessionTree"; import * as globalMocks from "../../__utils__/globalMocks"; + jest.mock("@zowe/zowe-explorer-api"); jest.mock("../../../src/utils/iconUtils", () => { return { getIconFilePathFromName: getIconFilePathFromNameMock }; }); -const cicsTreeMock = jest.fn(); +const cicstreeMock = jest.fn(); const treeResourceMock = globalMocks.getDummyTreeResources("cicsmanagedregion", "fileName*"); const profile = { profile: { user: "user", password: "pwd", hostname: "hostname", protocol: "https", type: "basic", rejectUnauthorized: false, port: 8080 }, @@ -28,50 +29,53 @@ const profile = { describe("Test suite for CICSSessionTree", () => { let sut: CICSSessionTree; - beforeEach(() => { - getIconFilePathFromNameMock.mockReturnValue(treeResourceMock.iconPath); + describe("Validation", () => { - sut = new CICSSessionTree(profile); - sut.isUnauthorized = true; - expect(getIconFilePathFromNameMock).toHaveBeenCalledWith("profile-unverified"); - }); + beforeEach(() => { + getIconFilePathFromNameMock.mockReturnValue(treeResourceMock.iconPath); - afterEach(() => { - jest.resetAllMocks(); - }); + sut = new CICSSessionTree(profile); + sut.isUnauthorized = true; + expect(getIconFilePathFromNameMock).toHaveBeenCalledWith("profile-unverified"); + }); - describe("Test suite for addRegion", () => { - it("should push CICSRegionTree object into children", () => { - sut.addRegion(cicsTreeMock as any as CICSRegionTree); - expect(sut.getChildren().length).toBeGreaterThanOrEqual(1); + afterEach(() => { + jest.resetAllMocks(); }); - }); - describe("Test suite for addPlex", () => { - it("should push CICSPlexTree object into children", () => { - sut.addPlex(cicsTreeMock as any as CICSPlexTree); - expect(sut.getChildren().length).toBeGreaterThanOrEqual(1); + + describe("Test suite for addRegion", () => { + it("should push CICSRegionTree object into children", () => { + sut.addRegion(cicstreeMock as any as CICSRegionTree); + expect(sut.getChildren().length).toBeGreaterThanOrEqual(1); + }); }); - }); - describe("Test suite for getChildren", () => { - it("should return an array of childrens", () => { - expect(sut.getChildren().length).toBeGreaterThanOrEqual(0); + describe("Test suite for addPlex", () => { + it("should push CICSPlexTree object into children", () => { + sut.addPlex(cicstreeMock as any as CICSPlexTree); + expect(sut.getChildren().length).toBeGreaterThanOrEqual(1); + }); }); - }); - describe("Test suite for setUnauthorized", () => { - it("should set isUnauthorized to true", () => { - sut.setUnauthorized(); - expect(sut.isUnauthorized).toBeTruthy(); + describe("Test suite for getChildren", () => { + it("should return an array of childrens", () => { + expect(sut.getChildren().length).toBeGreaterThanOrEqual(0); + }); }); - }); - describe("Test suite for setAuthorized", () => { - it("should set isUnauthorized to false", () => { - sut.setAuthorized(); - expect(sut.isUnauthorized).toBeFalsy(); + describe("Test suite for setUnauthorized", () => { + it("should set isUnauthorized to true", () => { + sut.setUnauthorized(); + expect(sut.isUnauthorized).toBeTruthy(); + }); }); - }); - describe("Test suite for getIsUnauthorized", () => { - it("should return the object of isUnauthorized", () => { - expect(sut.getIsUnauthorized()).toBeTruthy(); + describe("Test suite for setAuthorized", () => { + it("should set isUnauthorized to false", () => { + sut.setAuthorized(); + expect(sut.isUnauthorized).toBeFalsy(); + }); + }); + describe("Test suite for getIsUnauthorized", () => { + it("should return the object of isUnauthorized", () => { + expect(sut.getIsUnauthorized()).toBeTruthy(); + }); }); }); }); diff --git a/packages/vsce/__tests__/__unit__/trees/CICSSessionTreeLtpa.unit.test.ts b/packages/vsce/__tests__/__unit__/trees/CICSSessionTreeLtpa.unit.test.ts new file mode 100644 index 00000000..9c1eacae --- /dev/null +++ b/packages/vsce/__tests__/__unit__/trees/CICSSessionTreeLtpa.unit.test.ts @@ -0,0 +1,90 @@ +/** + * 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. + * + */ + +const getIconFilePathFromNameMock = jest.fn(); + +import { imperative } from "@zowe/zowe-explorer-api"; +import { CICSSessionTree } from "../../../src/trees/CICSSessionTree"; + +jest.mock("../../../src/utils/iconUtils", () => { + return { getIconFilePathFromName: getIconFilePathFromNameMock }; +}); + +describe("Test suite for CICSSessionTree", () => { + let sut: CICSSessionTree; + let ses: imperative.Session; + + const cicsProfileMock = { + failNotFound: false, + message: "", + name: "A NAME", + profile: { + host: "a.b.c.d", + port: 12345, + rejectUnauthorized: false, + protocol: "http", + user: "A USER", + password: "A PASSWORD", + }, + type: "cics" + }; + + describe("cookies", () => { + + beforeEach(() => { + sut = new CICSSessionTree(cicsProfileMock); + }); + + afterEach(() => { + jest.resetAllMocks(); + }); + + it("Should not store invalid cookie", () => { + const cookie = { + Cookie: "blah=hello" + }; + + ses = sut.getSession(); + ses.storeCookie(cookie); + + expect(ses.ISession.tokenType).toEqual("LtpaToken2"); + expect(ses.ISession.tokenValue).toBeUndefined(); + }); + + it("Should store valid cookie", () => { + const cookies = { + Cookie: "LtpaToken2=testValue" + }; + + sut = new CICSSessionTree(cicsProfileMock); + ses = sut.getSession(); + + ses.storeCookie(cookies); + + expect(ses.ISession.tokenType).toEqual("LtpaToken2"); + expect(ses.ISession.tokenValue).toEqual("testValue"); + }); + + it("Should store valid cookie if more the one returned", () => { + const cookies = { + Cookie: "blah=hello;LtpaToken2=testValue" + }; + + sut = new CICSSessionTree(cicsProfileMock); + ses = sut.getSession(); + + ses.storeCookie(cookies); + + expect(ses.ISession.tokenType).toEqual("LtpaToken2"); + expect(ses.ISession.tokenValue).toEqual("testValue"); + }); + }); +}); diff --git a/packages/vsce/src/commands/closeLocalFileCommand.ts b/packages/vsce/src/commands/closeLocalFileCommand.ts index d9c165cb..b4e62461 100644 --- a/packages/vsce/src/commands/closeLocalFileCommand.ts +++ b/packages/vsce/src/commands/closeLocalFileCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; @@ -19,6 +19,7 @@ import { CICSTree } from "../trees/CICSTree"; import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; import { ICommandParams } from "./ICommandParams"; +import { runPutResource } from "../utils/resourceUtils"; import constants from "../utils/constants"; export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView) { @@ -116,12 +117,18 @@ export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView }); } -function closeLocalFile( +async function closeLocalFile( session: imperative.AbstractSession, parms: ICommandParams, busyDecision: string ): Promise { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `FILE='${parms.name}'`} + }, { request: { action: { $: { @@ -135,15 +142,5 @@ function closeLocalFile( }, }, }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `FILE='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + }); } diff --git a/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts b/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts index 8ab01f2e..dce4f204 100644 --- a/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedLocalFileTree } from "../../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; @@ -20,6 +20,7 @@ import { findSelectedNodes } from "../../utils/commandUtils"; import { ICommandParams } from "../ICommandParams"; import { CICSLocalFileTreeItem } from "../../trees/treeItems/CICSLocalFileTreeItem"; import constants from "../../utils/constants"; +import { runPutResource } from "../../utils/resourceUtils"; export function getDisableLocalFileCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.disableLocalFile", async (clickedNode) => { @@ -110,7 +111,13 @@ function disableLocalFile( parms: ICommandParams, busyDecision: string ): Promise { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `FILE='${parms.name}'`} + }, { request: { action: { $: { @@ -123,16 +130,6 @@ function disableLocalFile( }, }, }, - }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `FILE='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + } + }); } diff --git a/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts b/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts index 0e93cc17..f0927e40 100644 --- a/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableProgramCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedProgramTree } from "../../trees/CICSCombinedTrees/CICSCombinedProgramTree"; @@ -20,6 +20,7 @@ import { findSelectedNodes } from "../../utils/commandUtils"; import { CICSProgramTreeItem } from "../../trees/treeItems/CICSProgramTreeItem"; import { ICommandParams } from "../ICommandParams"; import constants from "../../utils/constants"; +import { runPutResource } from "../../utils/resourceUtils"; /** * Performs disable on selected CICSProgram nodes. @@ -102,7 +103,13 @@ export function getDisableProgramCommand(tree: CICSTree, treeview: TreeView } function disableProgram(session: imperative.AbstractSession, parms: ICommandParams): Promise { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `PROGRAM='${parms.name}'`} + }, { request: { action: { $: { @@ -110,15 +117,5 @@ function disableProgram(session: imperative.AbstractSession, parms: ICommandPara }, }, }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `PROGRAM='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_PROGRAM_RESOURCE, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + }); } diff --git a/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts b/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts index 256cb35d..df9019e8 100644 --- a/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts +++ b/packages/vsce/src/commands/disableCommands/disableTransactionCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedTransactionsTree } from "../../trees/CICSCombinedTrees/CICSCombinedTransactionTree"; @@ -20,6 +20,7 @@ import { findSelectedNodes, splitCmciErrorMessage } from "../../utils/commandUti import { CICSTransactionTreeItem } from "../../trees/treeItems/CICSTransactionTreeItem"; import { ICommandParams } from "../ICommandParams"; import constants from "../../utils/constants"; +import { runPutResource } from "../../utils/resourceUtils"; export function getDisableTransactionCommand(tree: CICSTree, treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.disableTransaction", async (clickedNode) => { @@ -109,7 +110,13 @@ function disableTransaction( session: imperative.AbstractSession, parms: ICommandParams ): Promise { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_LOCAL_TRANSACTION, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `TRANID='${parms.name}'`} + }, { request: { action: { $: { @@ -117,15 +124,5 @@ function disableTransaction( }, }, }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `TRANID='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_LOCAL_TRANSACTION, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + }); } diff --git a/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts b/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts index d9049b7a..6d543a17 100644 --- a/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableLocalFileCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedLocalFileTree } from "../../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; @@ -19,6 +19,7 @@ import { CICSTree } from "../../trees/CICSTree"; import { CICSLocalFileTreeItem } from "../../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes } from "../../utils/commandUtils"; import { ICommandParams } from "../ICommandParams"; +import { runPutResource } from "../../utils/resourceUtils"; import constants from "../../utils/constants"; export function getEnableLocalFileCommand(tree: CICSTree, treeview: TreeView) { @@ -96,23 +97,19 @@ export function getEnableLocalFileCommand(tree: CICSTree, treeview: TreeView { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `FILE='${parms.name}'`} + },{ request: { action: { $: { name: "ENABLE", }, }, - }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `FILE='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + } + }); } diff --git a/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts b/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts index 2d024e42..3a22ec7f 100644 --- a/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableProgramCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedProgramTree } from "../../trees/CICSCombinedTrees/CICSCombinedProgramTree"; @@ -19,6 +19,7 @@ import { CICSTree } from "../../trees/CICSTree"; import { CICSProgramTreeItem } from "../../trees/treeItems/CICSProgramTreeItem"; import { findSelectedNodes } from "../../utils/commandUtils"; import { ICommandParams } from "../ICommandParams"; +import { runPutResource } from "../../utils/resourceUtils"; import constants from "../../utils/constants"; /** @@ -100,23 +101,19 @@ export function getEnableProgramCommand(tree: CICSTree, treeview: TreeView) } function enableProgram(session: imperative.AbstractSession, parms: ICommandParams): Promise { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `PROGRAM='${parms.name}'`} + },{ request: { action: { $: { name: "ENABLE", }, }, - }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `PROGRAM='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_PROGRAM_RESOURCE, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + } + }); } diff --git a/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts b/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts index 30572421..1bc1c590 100644 --- a/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts +++ b/packages/vsce/src/commands/enableCommands/enableTransactionCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedTransactionsTree } from "../../trees/CICSCombinedTrees/CICSCombinedTransactionTree"; @@ -19,6 +19,7 @@ import { CICSTree } from "../../trees/CICSTree"; import { findSelectedNodes } from "../../utils/commandUtils"; import { CICSTransactionTreeItem } from "../../trees/treeItems/CICSTransactionTreeItem"; import { ICommandParams } from "../ICommandParams"; +import { runPutResource } from "../../utils/resourceUtils"; import constants from "../../utils/constants"; export function getEnableTransactionCommand(tree: CICSTree, treeview: TreeView) { @@ -96,23 +97,19 @@ export function getEnableTransactionCommand(tree: CICSTree, treeview: TreeView { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_LOCAL_TRANSACTION, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `TRANID='${parms.name}'`} + },{ request: { action: { $: { name: "ENABLE", }, }, - }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `TRANID='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_LOCAL_TRANSACTION, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + } + }); } diff --git a/packages/vsce/src/commands/openLocalFileCommand.ts b/packages/vsce/src/commands/openLocalFileCommand.ts index f9a2b7f4..08b4737c 100644 --- a/packages/vsce/src/commands/openLocalFileCommand.ts +++ b/packages/vsce/src/commands/openLocalFileCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree"; @@ -19,6 +19,7 @@ import { CICSTree } from "../trees/CICSTree"; import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; import { ICommandParams } from "./ICommandParams"; +import { runPutResource } from "../utils/resourceUtils"; import constants from "../utils/constants"; export function getOpenLocalFileCommand(tree: CICSTree, treeview: TreeView) { @@ -104,7 +105,13 @@ export function getOpenLocalFileCommand(tree: CICSTree, treeview: TreeView) } function openLocalFile(session: imperative.AbstractSession, parms: ICommandParams): Promise { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `FILE='${parms.name}'`} + }, { request: { action: { $: { @@ -112,15 +119,5 @@ function openLocalFile(session: imperative.AbstractSession, parms: ICommandParam }, }, }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `FILE='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + }); } diff --git a/packages/vsce/src/commands/phaseInCommand.ts b/packages/vsce/src/commands/phaseInCommand.ts index 2aac6612..cad7507b 100644 --- a/packages/vsce/src/commands/phaseInCommand.ts +++ b/packages/vsce/src/commands/phaseInCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedProgramTree } from "../trees/CICSCombinedTrees/CICSCombinedProgramTree"; @@ -18,6 +18,7 @@ import { CICSRegionTree } from "../trees/CICSRegionTree"; import { CICSTree } from "../trees/CICSTree"; import { CICSProgramTreeItem } from "../trees/treeItems/CICSProgramTreeItem"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; +import { runPutResource } from "../utils/resourceUtils"; import constants from "../utils/constants"; /** @@ -110,7 +111,13 @@ export function getPhaseInCommand(tree: CICSTree, treeview: TreeView) { } async function performPhaseIn(session: imperative.AbstractSession, parms: { cicsPlex: string | null; regionName: string; name: string; }) { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `PROGRAM='${parms.name}'`} + }, { request: { action: { $: { @@ -118,15 +125,5 @@ async function performPhaseIn(session: imperative.AbstractSession, parms: { cics }, }, }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `PROGRAM='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_PROGRAM_RESOURCE, options); - - return (await CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody)) as any; + }); } diff --git a/packages/vsce/src/commands/purgeTaskCommand.ts b/packages/vsce/src/commands/purgeTaskCommand.ts index 8d6fe42c..cf88f405 100644 --- a/packages/vsce/src/commands/purgeTaskCommand.ts +++ b/packages/vsce/src/commands/purgeTaskCommand.ts @@ -9,7 +9,7 @@ * */ -import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk"; +import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk"; import { imperative } from "@zowe/zowe-explorer-api"; import { commands, ProgressLocation, TreeView, window } from "vscode"; import { CICSCombinedTaskTree } from "../trees/CICSCombinedTrees/CICSCombinedTaskTree"; @@ -19,6 +19,7 @@ import { CICSTree } from "../trees/CICSTree"; import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils"; import { CICSTaskTreeItem } from "../trees/treeItems/CICSTaskTreeItem"; import { ICommandParams } from "./ICommandParams"; +import { runPutResource } from "../utils/resourceUtils"; import constants from "../utils/constants"; /** @@ -133,7 +134,13 @@ function purgeTask( parms: ICommandParams, purgeType: string ): Promise { - const requestBody: any = { + return runPutResource({ + session: session, + resourceName: CicsCmciConstants.CICS_CMCI_TASK, + cicsPlex: parms.cicsPlex, + regionName: parms.regionName, + params: {"criteria": `TASK='${parms.name}'`} + }, { request: { action: { $: { @@ -147,15 +154,5 @@ function purgeTask( }, }, }, - }; - - const options: IGetResourceUriOptions = { - "cicsPlex": parms.cicsPlex, - "regionName": parms.regionName, - "criteria": `TASK='${parms.name}'` - }; - - const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_TASK, options); - - return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + }); } diff --git a/packages/vsce/src/commands/showParameterCommand.ts b/packages/vsce/src/commands/showParameterCommand.ts index 5baab075..48f6b0be 100644 --- a/packages/vsce/src/commands/showParameterCommand.ts +++ b/packages/vsce/src/commands/showParameterCommand.ts @@ -9,11 +9,12 @@ * */ -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { commands, TreeView, WebviewPanel, window } from "vscode"; import { CICSRegionTree } from "../trees/CICSRegionTree"; import { findSelectedNodes } from "../utils/commandUtils"; import { getParametersHtml } from "../utils/webviewHTML"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export function getShowRegionSITParametersCommand(treeview: TreeView) { return commands.registerCommand("cics-extension-for-zowe.showRegionParameters", async (node) => { @@ -28,11 +29,12 @@ export function getShowRegionSITParametersCommand(treeview: TreeView) { continue; } - const db2transactionResponse = await getResource(regionTree.parentSession.session, { - name: "CICSSystemParameter", + const { response } = await runGetResource({ + session: regionTree.parentSession.session, + resourceName: CicsCmciConstants.CICS_SYSTEM_PARAMETER, regionName: regionTree.label, cicsPlex: regionTree.parentPlex ? regionTree.parentPlex!.getPlexName() : undefined, - parameter: "PARMSRCE(COMBINED) PARMTYPE(SIT)", + params: { parameter: "PARMSRCE(COMBINED) PARMTYPE(SIT)" }, }); let webText = `CICS Name Source @@ -46,7 +48,7 @@ export function getShowRegionSITParametersCommand(treeview: TreeView) { Value`; webText += ""; - for (const systemParameter of db2transactionResponse.response.records.cicssystemparameter) { + for (const systemParameter of response.records.cicssystemparameter) { webText += `${systemParameter.keyword.toUpperCase()}`; webText += `${systemParameter.source.toUpperCase()}${systemParameter.value.toUpperCase()}`; } diff --git a/packages/vsce/src/extension.ts b/packages/vsce/src/extension.ts index 81e401b7..b15fd30b 100644 --- a/packages/vsce/src/extension.ts +++ b/packages/vsce/src/extension.ts @@ -10,7 +10,6 @@ */ import { ExtensionContext, ProgressLocation, TreeItemCollapsibleState, window } from "vscode"; -import { CICSSessionTree } from "./trees/CICSSessionTree"; import { CICSTree } from "./trees/CICSTree"; import { plexExpansionHandler, regionContainerExpansionHandler, sessionExpansionHandler } from "./utils/expansionHandler"; import { ProfileManagement } from "./utils/profileManagement"; @@ -122,8 +121,7 @@ export async function activate(context: ExtensionContext) { try { plexExpansionHandler(node.element, treeDataProv); } catch (error) { - const newSessionTree = new CICSSessionTree(node.element.getParent().profile, getIconFilePathFromName("profile-disconnected")); - treeDataProv.loadedProfiles.splice(treeDataProv.getLoadedProfiles().indexOf(node.element.getParent()), 1, newSessionTree); + node.element.getParent().iconPath = getIconFilePathFromName("profile-disconnected"); treeDataProv._onDidChangeTreeData.fire(undefined); } }, diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts index 25d71603..aa6e2159 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLibraryTree.ts @@ -20,6 +20,7 @@ import { CICSLibraryTreeItem } from "../treeItems/CICSLibraryTreeItem"; import { TextTreeItem } from "../treeItems/utils/TextTreeItem"; import { getFolderIcon } from "../../utils/iconUtils"; import { ViewMore } from "../treeItems/utils/ViewMore"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSCombinedLibraryTree extends TreeItem { children: (CICSLibraryTreeItem | ViewMore)[] | [TextTreeItem] | null; @@ -40,7 +41,7 @@ export class CICSCombinedLibraryTree extends TreeItem { this.activeFilter = undefined; this.currentCount = 0; this.incrementCount = +`${workspace.getConfiguration().get("zowe.cics.allLibraries.recordCountIncrement")}`; - this.constant = "CICSLibrary"; + this.constant = CicsCmciConstants.CICS_LIBRARY_RESOURCE; } public async loadContents(tree: CICSTree) { @@ -60,6 +61,7 @@ export class CICSCombinedLibraryTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -72,6 +74,7 @@ export class CICSCombinedLibraryTree extends TreeItem { if (recordsCount <= this.incrementCount) { allLibraries = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -80,6 +83,7 @@ export class CICSCombinedLibraryTree extends TreeItem { } else { allLibraries = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -148,6 +152,7 @@ export class CICSCombinedLibraryTree extends TreeItem { } const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -159,6 +164,7 @@ export class CICSCombinedLibraryTree extends TreeItem { const count = recordsCount; const allLibraries = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -203,4 +209,8 @@ export class CICSCombinedLibraryTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts index a77ecfbd..97908d07 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedLocalFileTree.ts @@ -60,6 +60,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { try { const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -72,6 +73,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { if (recordsCount <= this.incrementCount) { allLocalFiles = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -80,6 +82,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { } else { allLocalFiles = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -144,6 +147,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { async () => { const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, this.getParent().getGroupName(), @@ -154,6 +158,7 @@ export class CICSCombinedLocalFileTree extends TreeItem { const count = recordsCount; const allLocalFiles = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -198,4 +203,8 @@ export class CICSCombinedLocalFileTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts index dd6405df..1ce8582b 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedPipelineTree.ts @@ -60,6 +60,7 @@ export class CICSCombinedPipelineTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -72,6 +73,7 @@ export class CICSCombinedPipelineTree extends TreeItem { if (recordsCount <= this.incrementCount) { allPipelines = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -80,6 +82,7 @@ export class CICSCombinedPipelineTree extends TreeItem { } else { allPipelines = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -148,6 +151,7 @@ export class CICSCombinedPipelineTree extends TreeItem { } const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -159,6 +163,7 @@ export class CICSCombinedPipelineTree extends TreeItem { const count = recordsCount; const allPipelines = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -203,4 +208,8 @@ export class CICSCombinedPipelineTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts index c980e662..182d8e2f 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedProgramTree.ts @@ -63,6 +63,7 @@ export class CICSCombinedProgramTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -75,6 +76,7 @@ export class CICSCombinedProgramTree extends TreeItem { if (recordsCount <= this.incrementCount) { allPrograms = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -83,6 +85,7 @@ export class CICSCombinedProgramTree extends TreeItem { } else { allPrograms = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -160,6 +163,7 @@ export class CICSCombinedProgramTree extends TreeItem { } const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -171,6 +175,7 @@ export class CICSCombinedProgramTree extends TreeItem { const count = recordsCount; const allPrograms = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -215,4 +220,8 @@ export class CICSCombinedProgramTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts index 1d653089..62ae96c6 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTCPIPServiceTree.ts @@ -20,6 +20,7 @@ import { TextTreeItem } from "../treeItems/utils/TextTreeItem"; import { getFolderIcon } from "../../utils/iconUtils"; import { ViewMore } from "../treeItems/utils/ViewMore"; import { CICSTCPIPServiceTreeItem } from "../treeItems/web/treeItems/CICSTCPIPServiceTreeItem"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSCombinedTCPIPServiceTree extends TreeItem { children: (CICSTCPIPServiceTreeItem | ViewMore)[] | [TextTreeItem] | null; @@ -40,7 +41,8 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { this.activeFilter = undefined; this.currentCount = 0; this.incrementCount = +`${workspace.getConfiguration().get("zowe.cics.allTCPIPS.recordCountIncrement")}`; - this.constant = "CICSTCPIPService"; + this.constant = CicsCmciConstants.CICS_TCPIPSERVICE_RESOURCE; + } public async loadContents(tree: CICSTree) { @@ -60,6 +62,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -72,6 +75,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { if (recordsCount <= this.incrementCount) { allTCPIPS = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -80,6 +84,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { } else { allTCPIPS = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -151,6 +156,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { } const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -162,6 +168,7 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { const count = recordsCount; const allTCPIPS = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -206,4 +213,8 @@ export class CICSCombinedTCPIPServiceTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts index ca7a638d..355a8600 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTaskTree.ts @@ -60,6 +60,7 @@ export class CICSCombinedTaskTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -72,6 +73,7 @@ export class CICSCombinedTaskTree extends TreeItem { if (recordsCount <= this.incrementCount) { allTasks = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -80,6 +82,7 @@ export class CICSCombinedTaskTree extends TreeItem { } else { allTasks = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -149,6 +152,7 @@ export class CICSCombinedTaskTree extends TreeItem { async () => { const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, this.getParent().getGroupName(), @@ -159,6 +163,7 @@ export class CICSCombinedTaskTree extends TreeItem { const count = recordsCount; const allTasks = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -200,4 +205,8 @@ export class CICSCombinedTaskTree extends TreeItem { // direct parent return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts index 52b1ef7f..2ff4ece1 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedTransactionTree.ts @@ -61,6 +61,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -73,6 +74,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { if (recordsCount <= this.incrementCount) { allLocalTransactions = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -81,6 +83,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { } else { allLocalTransactions = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -145,6 +148,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { async () => { const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, this.getParent().getGroupName(), @@ -155,6 +159,7 @@ export class CICSCombinedTransactionsTree extends TreeItem { const count = recordsCount; const allLocalTransactions = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -199,4 +204,8 @@ export class CICSCombinedTransactionsTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts index f71143f6..b25637f0 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedURIMapTree.ts @@ -60,6 +60,7 @@ export class CICSCombinedURIMapTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -72,6 +73,7 @@ export class CICSCombinedURIMapTree extends TreeItem { if (recordsCount <= this.incrementCount) { allURIMaps = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -80,6 +82,7 @@ export class CICSCombinedURIMapTree extends TreeItem { } else { allURIMaps = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -153,6 +156,7 @@ export class CICSCombinedURIMapTree extends TreeItem { } const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -164,6 +168,7 @@ export class CICSCombinedURIMapTree extends TreeItem { const count = recordsCount; const allURIMaps = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -208,4 +213,8 @@ export class CICSCombinedURIMapTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts index 431876e1..2fc7e590 100644 --- a/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts +++ b/packages/vsce/src/trees/CICSCombinedTrees/CICSCombinedWebServiceTree.ts @@ -60,6 +60,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { let count; const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -72,6 +73,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { if (recordsCount <= this.incrementCount) { allWebServices = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -80,6 +82,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { } else { allWebServices = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, 1, @@ -149,6 +152,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { } const cacheTokenInfo = await ProfileManagement.generateCacheToken( this.parentPlex.getProfile(), + this.getSession(), this.parentPlex.getPlexName(), this.constant, criteria, @@ -160,6 +164,7 @@ export class CICSCombinedWebServiceTree extends TreeItem { const count = recordsCount; const allWebServices = await ProfileManagement.getCachedResources( this.parentPlex.getProfile(), + this.getSession(), cacheTokenInfo.cacheToken, this.constant, this.currentCount + 1, @@ -204,4 +209,8 @@ export class CICSCombinedWebServiceTree extends TreeItem { public getParent() { return this.parentPlex; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSLibraryTree.ts b/packages/vsce/src/trees/CICSLibraryTree.ts index 781bf259..1e1e7c40 100644 --- a/packages/vsce/src/trees/CICSLibraryTree.ts +++ b/packages/vsce/src/trees/CICSLibraryTree.ts @@ -11,11 +11,12 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSRegionTree } from "./CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { getFolderIcon } from "../utils/iconUtils"; import { CICSLibraryTreeItem } from "./treeItems/CICSLibraryTreeItem"; import { toEscapedCriteriaString } from "../utils/filterUtils"; import { toArray } from "../utils/commandUtils"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSLibraryTree extends TreeItem { children: CICSLibraryTreeItem[] = []; @@ -42,13 +43,14 @@ export class CICSLibraryTree extends TreeItem { } this.children = []; try { - - const libraryResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSLibrary", + const libraryResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: CicsCmciConstants.CICS_LIBRARY_RESOURCE, + cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, regionName: this.parentRegion.getRegionName(), - cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria} }); + const librariesArray = toArray(libraryResponse.response.records.cicslibrary); this.label = `Libraries${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${librariesArray.length}]`; for (const library of librariesArray) { diff --git a/packages/vsce/src/trees/CICSLocalFileTree.ts b/packages/vsce/src/trees/CICSLocalFileTree.ts index a72987cf..b9ef8586 100644 --- a/packages/vsce/src/trees/CICSLocalFileTree.ts +++ b/packages/vsce/src/trees/CICSLocalFileTree.ts @@ -11,11 +11,11 @@ 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 { toEscapedCriteriaString } from "../utils/filterUtils"; import { getFolderIcon } from "../utils/iconUtils"; import { toArray } from "../utils/commandUtils"; +import { runGetResource } from "../utils/resourceUtils"; export class CICSLocalFileTree extends TreeItem { children: CICSLocalFileTreeItem[] = []; @@ -47,11 +47,12 @@ export class CICSLocalFileTree extends TreeItem { this.children = []; try { - const localFileResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSLocalFile", + const localFileResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: "CICSLocalFile", regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const localFileArray = toArray(localFileResponse.response.records.cicslocalfile); this.label = `Local Files${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${localFileArray.length}]`; diff --git a/packages/vsce/src/trees/CICSPlexTree.ts b/packages/vsce/src/trees/CICSPlexTree.ts index 33e28ff4..586547a8 100644 --- a/packages/vsce/src/trees/CICSPlexTree.ts +++ b/packages/vsce/src/trees/CICSPlexTree.ts @@ -13,7 +13,6 @@ import { TreeItemCollapsibleState, TreeItem } from "vscode"; import { CICSRegionTree } from "./CICSRegionTree"; import { imperative } from "@zowe/zowe-explorer-api"; import { CICSSessionTree } from "./CICSSessionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { CICSCombinedProgramTree } from "./CICSCombinedTrees/CICSCombinedProgramTree"; import { CICSCombinedTransactionsTree } from "./CICSCombinedTrees/CICSCombinedTransactionTree"; import { CICSCombinedLocalFileTree } from "./CICSCombinedTrees/CICSCombinedLocalFileTree"; @@ -25,6 +24,8 @@ import { CICSCombinedTCPIPServiceTree } from "./CICSCombinedTrees/CICSCombinedTC import { CICSCombinedURIMapTree } from "./CICSCombinedTrees/CICSCombinedURIMapTree"; import { CICSCombinedPipelineTree } from "./CICSCombinedTrees/CICSCombinedPipelineTree"; import { CICSCombinedWebServiceTree } from "./CICSCombinedTrees/CICSCombinedWebServiceTree"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSPlexTree extends TreeItem { children: ( @@ -69,8 +70,9 @@ export class CICSPlexTree extends TreeItem { public async loadOnlyRegion() { const plexProfile = this.getProfile(); const session = this.getParent().getSession(); - const regionsObtained = await getResource(session, { - name: "CICSRegion", + const regionsObtained = await runGetResource({ + session: session, + resourceName: CicsCmciConstants.CICS_CMCI_REGION, cicsPlex: plexProfile.profile.cicsPlex, regionName: plexProfile.profile.regionName, }); @@ -178,4 +180,8 @@ export class CICSPlexTree extends TreeItem { public getGroupName() { return this.groupName; } + + getSession() { + return this.parent.getSession(); + } } diff --git a/packages/vsce/src/trees/CICSProgramTree.ts b/packages/vsce/src/trees/CICSProgramTree.ts index 3702b632..792acf3b 100644 --- a/packages/vsce/src/trees/CICSProgramTree.ts +++ b/packages/vsce/src/trees/CICSProgramTree.ts @@ -12,10 +12,11 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSProgramTreeItem } from "./treeItems/CICSProgramTreeItem"; import { CICSRegionTree } from "./CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { getDefaultProgramFilter, toEscapedCriteriaString } from "../utils/filterUtils"; import { getFolderIcon } from "../utils/iconUtils"; import { toArray } from "../utils/commandUtils"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSProgramTree extends TreeItem { children: CICSProgramTreeItem[] = []; @@ -45,11 +46,12 @@ export class CICSProgramTree extends TreeItem { } this.children = []; try { - const programResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSProgram", + const programResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE, regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const programsArray = toArray(programResponse.response.records.cicsprogram); this.label = `Programs${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${programsArray.length}]`; diff --git a/packages/vsce/src/trees/CICSRegionsContainer.ts b/packages/vsce/src/trees/CICSRegionsContainer.ts index 4dd82fb0..e6706e53 100644 --- a/packages/vsce/src/trees/CICSRegionsContainer.ts +++ b/packages/vsce/src/trees/CICSRegionsContainer.ts @@ -9,7 +9,6 @@ * */ -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from "vscode"; import { ProfileManagement } from "../utils/profileManagement"; import { CICSPlexTree } from "./CICSPlexTree"; @@ -17,6 +16,8 @@ import { CICSRegionTree } from "./CICSRegionTree"; import { CICSTree } from "./CICSTree"; import { getFolderIcon } from "../utils/iconUtils"; import { toArray } from "../utils/commandUtils"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSRegionsContainer extends TreeItem { children: CICSRegionTree[]; @@ -63,8 +64,9 @@ export class CICSRegionsContainer extends TreeItem { const parentPlex = this.getParent(); const plexProfile = parentPlex.getProfile(); const session = parentPlex.getParent().getSession(); - const regionsObtained = await getResource(session, { - name: "CICSManagedRegion", + const regionsObtained = await runGetResource({ + session: session, + resourceName: CicsCmciConstants.CICS_CMCI_MANAGED_REGION, cicsPlex: plexProfile.profile.cicsPlex, regionName: plexProfile.profile.regionName, }); @@ -145,4 +147,8 @@ export class CICSRegionsContainer extends TreeItem { public clearChildren() { this.children = []; } + + public getSession() { + return this.getParent().getSession(); + } } diff --git a/packages/vsce/src/trees/CICSSessionTree.ts b/packages/vsce/src/trees/CICSSessionTree.ts index 05aa067b..4d94d145 100644 --- a/packages/vsce/src/trees/CICSSessionTree.ts +++ b/packages/vsce/src/trees/CICSSessionTree.ts @@ -14,22 +14,24 @@ import { CICSRegionTree } from "./CICSRegionTree"; import { CICSPlexTree } from "./CICSPlexTree"; import { imperative } from "@zowe/zowe-explorer-api"; import { getIconFilePathFromName } from "../utils/iconUtils"; +import { SessConstants } from "@zowe/imperative"; export class CICSSessionTree extends TreeItem { children: (CICSPlexTree | CICSRegionTree)[]; session: imperative.Session; profile: any; isUnauthorized: boolean | undefined; + iconPath = getIconFilePathFromName("profile-unverified"); - constructor( - profile: any, - public readonly iconPath = getIconFilePathFromName("profile-unverified"), - ) { + constructor(profile: any) { super(profile.name, TreeItemCollapsibleState.Collapsed); this.children = []; this.contextValue = `cicssession.${profile.name}`; + this.session = new imperative.Session({ - type: "basic", + type: SessConstants.AUTH_TYPE_TOKEN, + storeCookie: true, + tokenType: SessConstants.TOKEN_TYPE_LTPA, hostname: profile.profile!.host, port: Number(profile.profile!.port), user: profile.profile!.user || "", @@ -37,6 +39,7 @@ export class CICSSessionTree extends TreeItem { rejectUnauthorized: profile.profile!.rejectUnauthorized, protocol: profile.profile!.protocol, }); + this.profile = profile; this.isUnauthorized = undefined; } @@ -45,6 +48,10 @@ export class CICSSessionTree extends TreeItem { this.children.push(region); } + public clearChildren() { + this.children = []; + } + public addPlex(plex: CICSPlexTree) { this.children.push(plex); } @@ -59,10 +66,12 @@ export class CICSSessionTree extends TreeItem { public setUnauthorized() { this.isUnauthorized = true; + this.iconPath = getIconFilePathFromName("profile-disconnected"); } public setAuthorized() { this.isUnauthorized = false; + this.iconPath = getIconFilePathFromName("profile"); } public getIsUnauthorized() { @@ -72,4 +81,8 @@ export class CICSSessionTree extends TreeItem { public getParent(): null { return null; } + + public setIsExpanded(isExpanded: boolean) { + this.collapsibleState = isExpanded ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed; + } } diff --git a/packages/vsce/src/trees/CICSTaskTree.ts b/packages/vsce/src/trees/CICSTaskTree.ts index aa74d5ca..cc564834 100644 --- a/packages/vsce/src/trees/CICSTaskTree.ts +++ b/packages/vsce/src/trees/CICSTaskTree.ts @@ -11,11 +11,12 @@ import { TreeItemCollapsibleState, TreeItem, window, workspace } from "vscode"; import { CICSRegionTree } from "./CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { toEscapedCriteriaString } from "../utils/filterUtils"; import { getFolderIcon } from "../utils/iconUtils"; import { CICSTaskTreeItem } from "./treeItems/CICSTaskTreeItem"; import { toArray } from "../utils/commandUtils"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk/lib/constants"; export class CICSTaskTree extends TreeItem { children: CICSTaskTreeItem[] = []; @@ -49,11 +50,12 @@ export class CICSTaskTree extends TreeItem { } this.children = []; try { - const taskResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSTASK", + const taskResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: CicsCmciConstants.CICS_CMCI_TASK, regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const tasksArray = toArray(taskResponse.response.records.cicstask); diff --git a/packages/vsce/src/trees/CICSTransactionTree.ts b/packages/vsce/src/trees/CICSTransactionTree.ts index 2dbf1423..fccc417b 100644 --- a/packages/vsce/src/trees/CICSTransactionTree.ts +++ b/packages/vsce/src/trees/CICSTransactionTree.ts @@ -12,10 +12,11 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSTransactionTreeItem } from "./treeItems/CICSTransactionTreeItem"; import { CICSRegionTree } from "./CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { getDefaultTransactionFilter, toEscapedCriteriaString } from "../utils/filterUtils"; import { getFolderIcon } from "../utils/iconUtils"; import { toArray } from "../utils/commandUtils"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSTransactionTree extends TreeItem { children: CICSTransactionTreeItem[] = []; @@ -45,11 +46,12 @@ export class CICSTransactionTree extends TreeItem { } this.children = []; try { - const transactionResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSLocalTransaction", + const transactionResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_TRANSACTION, regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const transactionArray = toArray(transactionResponse.response.records.cicslocaltransaction); this.label = `Transactions${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${transactionArray.length}]`; diff --git a/packages/vsce/src/trees/CICSTree.ts b/packages/vsce/src/trees/CICSTree.ts index b7062256..569e36b2 100644 --- a/packages/vsce/src/trees/CICSTree.ts +++ b/packages/vsce/src/trees/CICSTree.ts @@ -10,8 +10,6 @@ */ import { FilterDescriptor } from "../utils/filterUtils"; -import { findSelectedNodes } from "../utils/commandUtils"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { Gui, imperative, FileManagement, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api"; import { commands, @@ -30,12 +28,14 @@ import { import constants from "../utils/constants"; import { PersistentStorage } from "../utils/PersistentStorage"; import { InfoLoaded, ProfileManagement } from "../utils/profileManagement"; -import { missingSessionParameters, promptCredentials } from "../utils/profileUtils"; -import { getIconFilePathFromName } from "../utils/iconUtils"; +import { updateProfile } from "../utils/profileUtils"; import { openConfigFile } from "../utils/workspaceUtils"; import { CICSPlexTree } from "./CICSPlexTree"; import { CICSRegionTree } from "./CICSRegionTree"; import { CICSSessionTree } from "./CICSSessionTree"; +import { getErrorCode } from "../utils/errorUtils"; +import { runGetResource } from "../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSTree implements TreeDataProvider { loadedProfiles: CICSSessionTree[] = []; @@ -211,10 +211,10 @@ export class CICSTree implements TreeDataProvider { * to replace position of current CICSSessionTree. * @param sessionTree current CICSSessionTree only passed in if expanding a profile */ - async loadProfile(profile?: imperative.IProfileLoaded, position?: number | undefined, sessionTree?: CICSSessionTree) { + async loadProfile(profile: imperative.IProfileLoaded, sessionTree: CICSSessionTree) { const persistentStorage = new PersistentStorage("zowe.cics.persistent"); await persistentStorage.addLoadedCICSProfile(profile.name); - let newSessionTree: CICSSessionTree; + window.withProgress( { title: "Load profile", @@ -230,183 +230,67 @@ export class CICSTree implements TreeDataProvider { try { const configInstance = await ProfileManagement.getConfigInstance(); if (configInstance.getTeamConfig().exists) { - let missingParamters = missingSessionParameters(profile.profile); - if (missingParamters.length) { - const userPass = ["user", "password"]; - if (missingParamters.includes(userPass[0]) || missingParamters.includes(userPass[1])) { - const updatedProfile = await promptCredentials(profile.name, true); - if (!updatedProfile) { - return; + // Initialise session tree + let plexInfo: InfoLoaded[]; + try { + plexInfo = await ProfileManagement.getPlexInfo(profile, sessionTree.getSession()); + sessionTree.setAuthorized(); + } catch (error) { + if (getErrorCode(error) === constants.HTTP_ERROR_UNAUTHORIZED) { + sessionTree.setUnauthorized(); + const newProfile = await updateProfile(profile, sessionTree); + + if (!newProfile) { + throw error; } - profile = updatedProfile; - // Remove "user" and "password" from missing params array - missingParamters = missingParamters.filter((param) => userPass.indexOf(param) === -1); - } - if (missingParamters.length) { - window.showInformationMessage( - `The following fields are missing from ${profile.name}: ${missingParamters.join(", ")}. Please update them in your config file.`, - ); - return; - } - // If profile is expanded and it previously had 401 error code - } else if (sessionTree && sessionTree.getIsUnauthorized()) { - const updatedProfile = await promptCredentials(profile.name, true); - if (!updatedProfile) { - return; - } - profile = updatedProfile; - } - } - const plexInfo: InfoLoaded[] = await ProfileManagement.getPlexInfo(profile); - // Initialise session tree - newSessionTree = new CICSSessionTree(profile, getIconFilePathFromName("profile")); - // For each InfoLoaded object - happens if there are multiple plexes - for (const item of plexInfo) { - // No plex - if (item.plexname === null) { - const session = new imperative.Session({ - type: "basic", - hostname: profile.profile.host, - port: Number(profile.profile.port), - user: profile.profile.user, - password: profile.profile.password, - rejectUnauthorized: profile.profile.rejectUnauthorized, - protocol: profile.profile.protocol, - }); - const regionsObtained = await getResource(session, { - name: "CICSRegion", - regionName: item.regions[0].applid, - }); - // 200 OK received - newSessionTree.setAuthorized(); - const newRegionTree = new CICSRegionTree( - item.regions[0].applid, - regionsObtained.response.records.cicsregion, - newSessionTree, - undefined, - newSessionTree, - ); - newSessionTree.addRegion(newRegionTree); - } else { - if (item.group) { - const newPlexTree = new CICSPlexTree(item.plexname, profile, newSessionTree, profile.profile.regionName); - newPlexTree.setLabel(`${item.plexname} - ${profile.profile.regionName}`); - newSessionTree.addPlex(newPlexTree); + + profile = newProfile; + plexInfo = await ProfileManagement.getPlexInfo(profile, sessionTree.getSession()); + sessionTree.setAuthorized(); } else { - //Plex - const newPlexTree = new CICSPlexTree(item.plexname, profile, newSessionTree); - newSessionTree.addPlex(newPlexTree); + throw error; } } - } - // If method was called when expanding profile - if (sessionTree) { - this.loadedProfiles.splice(position, 1, newSessionTree); - } - // If method was called when updating profile - else if (position || position === 0) { - this.loadedProfiles.splice(position, 0, newSessionTree); - } else { - this.loadedProfiles.push(newSessionTree); - } - this._onDidChangeTreeData.fire(undefined); - } catch (error) { - // Change session tree icon to disconnected upon error - newSessionTree = new CICSSessionTree(profile, getIconFilePathFromName("profile-disconnected")); - // If method was called when expanding profile - if (sessionTree) { - this.loadedProfiles.splice(position, 1, newSessionTree); - } - // If method was called when updating profile - else if (position || position === 0) { - this.loadedProfiles.splice(position, 0, newSessionTree); - } else { - this.loadedProfiles.push(newSessionTree); - } - this._onDidChangeTreeData.fire(undefined); - if (typeof error === "object") { - if ("code" in error) { - switch (error.code) { - case "ETIMEDOUT": - window.showErrorMessage(`Error: connect ETIMEDOUT ${profile.profile.host}:${profile.profile.port} (${profile.name})`); - break; - case "ENOTFOUND": - window.showErrorMessage(`Error: getaddrinfo ENOTFOUND ${profile.profile.host}:${profile.profile.port} (${profile.name})`); - break; - case "ECONNRESET": - window.showErrorMessage(`Error: socket hang up ${profile.profile.host}:${profile.profile.port} (${profile.name})`); - break; - case "EPROTO": - window.showErrorMessage(`Error: write EPROTO ${profile.profile.host}:${profile.profile.port} (${profile.name})`); - break; - case "DEPTH_ZERO_SELF_SIGNED_CERT": - case "SELF_SIGNED_CERT_IN_CHAIN": - case "ERR_TLS_CERT_ALTNAME_INVALID": - case "CERT_HAS_EXPIRED": - // If re-expanding a profile that has an expired certificate - if (sessionTree) { - const decision = await window.showInformationMessage( - `Warning: Your connection is not private (${error.code}) - ` + - `would you still like to proceed to ${profile.profile.host} (unsafe)?`, - ...["Yes", "No"], - ); - if (decision) { - if (decision === "Yes") { - const configInstance = await ProfileManagement.getConfigInstance(); - let updatedProfile; - if (configInstance.getTeamConfig().exists) { - const upd = { profileName: profile.name, profileType: "cics" }; - // const configInstance = await ProfileManagement.getConfigInstance(); - // flip rejectUnauthorized to false - await configInstance.updateProperty({ ...upd, property: "rejectUnauthorized", value: false }); - updatedProfile = await ProfileManagement.getProfilesCache().getLoadedProfConfig(profile.name); - } else { - await ProfileManagement.profilesCacheRefresh(); - updatedProfile = await ProfileManagement.getProfilesCache().loadNamedProfile(profile.name, "cics"); - } - await this.removeSession(sessionTree, updatedProfile, position); - } - } - } - break; - default: - window.showErrorMessage( - `Error: An error has occurred ${profile.profile.host}:${profile.profile.port} (${profile.name}) - ${JSON.stringify( - error, - Object.getOwnPropertyNames(error), - ).replace(/(\\n\t|\\n|\\t)/gm, " ")}`, - ); - } - } else if ("response" in error) { - if (error.response !== "undefined" && error.response.status) { - switch (error.response.status) { - case constants.HTTP_ERROR_UNAUTHORIZED: - window.showErrorMessage(`Error: Request failed with status code 401 for Profile '${profile.name}'`); - // set the unauthorized flag to true for reprompting of credentials. - newSessionTree.setUnauthorized(); - // Replace old profile tree with new disconnected profile tree item - this.loadedProfiles.splice(position, 1, newSessionTree); - break; - case constants.HTTP_ERROR_NOT_FOUND: - window.showErrorMessage(`Error: Request failed with status code 404 for Profile '${profile.name}' - Not Found`); - break; - case constants.HTTP_ERROR_SERVER_ERROR: - window.showErrorMessage(`Error: Request failed with status code 500 for Profile '${profile.name}'`); - break; - default: - window.showErrorMessage(`Error: Request failed with status code ${error.response.status} for Profile '${profile.name}'`); - } - } else { - window.showErrorMessage( - `Error: An error has occurred ${profile.profile.host}:${profile.profile.port} (${profile.name}) - ${JSON.stringify( - error, - Object.getOwnPropertyNames(error), - ).replace(/(\\n\t|\\n|\\t)/gm, " ")}`, + // For each InfoLoaded object - happens if there are multiple plexes + sessionTree.clearChildren(); + for (const item of plexInfo) { + // No plex + if (item.plexname === null) { + + const regionsObtained = await runGetResource({ + session: sessionTree.getSession(), + resourceName: CicsCmciConstants.CICS_CMCI_REGION, + regionName: item.regions[0].applid, + }); + + // 200 OK received + const newRegionTree = new CICSRegionTree( + item.regions[0].applid, + regionsObtained.response.records.cicsregion, + sessionTree, + undefined, + sessionTree, ); + sessionTree.addRegion(newRegionTree); + } else { + if (item.group) { + const newPlexTree = new CICSPlexTree(item.plexname, profile, sessionTree, profile.profile.regionName); + newPlexTree.setLabel(`${item.plexname} - ${profile.profile.regionName}`); + sessionTree.addPlex(newPlexTree); + } else { + //Plex + const newPlexTree = new CICSPlexTree(item.plexname, profile, sessionTree); + sessionTree.addPlex(newPlexTree); + } } } + this._onDidChangeTreeData.fire(undefined); } + } catch (error) { + sessionTree.setUnauthorized(); + sessionTree.setIsExpanded(false); + this._onDidChangeTreeData.fire(undefined); } }, ); @@ -443,13 +327,10 @@ export class CICSTree implements TreeDataProvider { this._onDidChangeTreeData.fire(undefined); } - async removeSession(session: CICSSessionTree, profile?: imperative.IProfileLoaded, position?: number) { + async removeSession(session: CICSSessionTree) { const persistentStorage = new PersistentStorage("zowe.cics.persistent"); await persistentStorage.removeLoadedCICSProfile(session.label.toString()); this.loadedProfiles = this.loadedProfiles.filter((p) => p.profile.name !== session.label?.toString()); - if (profile && position !== undefined) { - await this.loadProfile(profile, position); - } this._onDidChangeTreeData.fire(undefined); } diff --git a/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts b/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts index ced9098f..a2b25bdd 100644 --- a/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts +++ b/packages/vsce/src/trees/treeItems/CICSLibraryDatasets.ts @@ -12,10 +12,11 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSRegionTree } from "../CICSRegionTree"; import { getIconFilePathFromName } from "../../utils/iconUtils"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { CICSProgramTreeItem } from "./CICSProgramTreeItem"; import { toEscapedCriteriaString } from "../../utils/filterUtils"; import { toArray } from "../../utils/commandUtils"; +import { runGetResource } from "../../utils/resourceUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSLibraryDatasets extends TreeItem { children: CICSProgramTreeItem[] = []; @@ -58,11 +59,12 @@ export class CICSLibraryDatasets extends TreeItem { this.children = []; try { - const datasetResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSProgram", + const datasetResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE, regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const programsArray = toArray(datasetResponse.response.records.cicsprogram); diff --git a/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts b/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts index cb20a294..b33383c7 100644 --- a/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts +++ b/packages/vsce/src/trees/treeItems/CICSLibraryTreeItem.ts @@ -11,10 +11,11 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSRegionTree } from "../CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; +import { runGetResource } from "../../utils/resourceUtils"; import { CICSLibraryDatasets } from "./CICSLibraryDatasets"; -import { getIconFilePathFromName } from "../../utils/iconUtils"; + import { toArray } from "../../utils/commandUtils"; +import { getIconFilePathFromName } from "../../utils/iconUtils"; export class CICSLibraryTreeItem extends TreeItem { children: CICSLibraryDatasets[] = []; @@ -57,11 +58,12 @@ export class CICSLibraryTreeItem extends TreeItem { this.children = []; try { - const libraryResponse = await getResource(this.parentRegion.parentSession.session, { - name: "cicslibrarydatasetname", + const libraryResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: "cicslibrarydatasetname", regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: { criteria: criteria }, }); const datasetArray = toArray(libraryResponse.response.records.cicslibrarydatasetname); this.label = this.buildLabel(datasetArray); diff --git a/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts b/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts index 8ee61142..86949ee9 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSPipelineTree.ts @@ -12,7 +12,7 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSPipelineTreeItem } from "./treeItems/CICSPipelineTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; +import { runGetResource } from "../../../utils/resourceUtils"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getFolderIcon } from "../../../utils/iconUtils"; import { toArray } from "../../../utils/commandUtils"; @@ -45,11 +45,12 @@ export class CICSPipelineTree extends TreeItem { } this.children = []; try { - const pipelineResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSPipeline", + const pipelineResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: "CICSPipeline", regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const pipelinesArray = toArray(pipelineResponse.response.records.cicspipeline); this.label = `Pipelines${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${pipelinesArray.length}]`; diff --git a/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts b/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts index dda648ae..d9cd101f 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSTCPIPServiceTree.ts @@ -12,10 +12,11 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSTCPIPServiceTreeItem } from "./treeItems/CICSTCPIPServiceTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; +import { runGetResource } from "../../../utils/resourceUtils"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getFolderIcon } from "../../../utils/iconUtils"; import { toArray } from "../../../utils/commandUtils"; +import { CicsCmciConstants } from "@zowe/cics-for-zowe-sdk"; export class CICSTCPIPServiceTree extends TreeItem { children: CICSTCPIPServiceTreeItem[] = []; @@ -45,11 +46,12 @@ export class CICSTCPIPServiceTree extends TreeItem { } this.children = []; try { - const tcpipsResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSTCPIPService", + const tcpipsResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: CicsCmciConstants.CICS_TCPIPSERVICE_RESOURCE, regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const tcpipservicesArray = toArray(tcpipsResponse.response.records.cicstcpipservice); this.label = `TCPIP Services${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${tcpipservicesArray.length}]`; diff --git a/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts b/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts index 6833f15a..6d491c51 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSURIMapTree.ts @@ -12,7 +12,7 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSURIMapTreeItem } from "./treeItems/CICSURIMapTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; +import { runGetResource } from "../../../utils/resourceUtils"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getFolderIcon } from "../../../utils/iconUtils"; import { toArray } from "../../../utils/commandUtils"; @@ -45,11 +45,12 @@ export class CICSURIMapTree extends TreeItem { } this.children = []; try { - const urimapResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSURIMap", + const urimapResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: "CICSURIMap", regionName: this.parentRegion.getRegionName(), cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria}, }); const urimapArray = toArray(urimapResponse.response.records.cicsurimap); this.label = `URI Maps${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${urimapArray.length}]`; diff --git a/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts b/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts index 08dafadf..d0c86d96 100644 --- a/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts +++ b/packages/vsce/src/trees/treeItems/web/CICSWebServiceTree.ts @@ -12,10 +12,10 @@ import { TreeItemCollapsibleState, TreeItem, window } from "vscode"; import { CICSWebServiceTreeItem } from "./treeItems/CICSWebServiceTreeItem"; import { CICSRegionTree } from "../../CICSRegionTree"; -import { getResource } from "@zowe/cics-for-zowe-sdk"; import { toEscapedCriteriaString } from "../../../utils/filterUtils"; import { getFolderIcon } from "../../../utils/iconUtils"; import { toArray } from "../../../utils/commandUtils"; +import { runGetResource } from "../../../utils/resourceUtils"; export class CICSWebServiceTree extends TreeItem { children: CICSWebServiceTreeItem[] = []; @@ -45,12 +45,14 @@ export class CICSWebServiceTree extends TreeItem { } this.children = []; try { - const webserviceResponse = await getResource(this.parentRegion.parentSession.session, { - name: "CICSWebService", + const webserviceResponse = await runGetResource({ + session: this.parentRegion.parentSession.session, + resourceName: "CICSWebService", + cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, regionName: this.parentRegion.getRegionName(), - cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined, - criteria: criteria, + params: {criteria: criteria} }); + const webservicesArray = toArray(webserviceResponse.response.records.cicswebservice); this.label = `Web Services${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${webservicesArray.length}]`; for (const webservice of webservicesArray) { diff --git a/packages/vsce/src/utils/errorUtils.ts b/packages/vsce/src/utils/errorUtils.ts new file mode 100644 index 00000000..632880b7 --- /dev/null +++ b/packages/vsce/src/utils/errorUtils.ts @@ -0,0 +1,14 @@ +/** + * 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. + * + */ + +export function getErrorCode(error: any) { + return error.mDetails?.errorCode || error.response?.status; +} diff --git a/packages/vsce/src/utils/expansionHandler.ts b/packages/vsce/src/utils/expansionHandler.ts index dd847209..83d28750 100644 --- a/packages/vsce/src/utils/expansionHandler.ts +++ b/packages/vsce/src/utils/expansionHandler.ts @@ -22,7 +22,7 @@ export async function sessionExpansionHandler(session: CICSSessionTree, tree: CI if (profile == null) { throw new Error("sessionExpansionHandler: Profile is not defined"); } - await tree.loadProfile(profile, tree.getLoadedProfiles().indexOf(session), session); + await tree.loadProfile(profile, session); } export function regionContainerExpansionHandler(regionContiner: CICSRegionsContainer, tree: CICSTree) { diff --git a/packages/vsce/src/utils/profileManagement.ts b/packages/vsce/src/utils/profileManagement.ts index 2fe01a92..04a91e9f 100644 --- a/packages/vsce/src/utils/profileManagement.ts +++ b/packages/vsce/src/utils/profileManagement.ts @@ -12,9 +12,7 @@ import { CicsCmciConstants, CicsCmciRestError, - getCache, - getResource, - IResourceQueryParams + getCache } from "@zowe/cics-for-zowe-sdk"; import { Session } from "@zowe/imperative"; import { Gui, imperative, MessageSeverity, Types, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api"; @@ -23,6 +21,7 @@ import { toArray } from "./commandUtils"; import constants from "./constants"; import cicsProfileMeta from "./profileDefinition"; import { getBestCICSplexes } from "./plexUtils"; +import { runGetResource } from "./resourceUtils"; export class ProfileManagement { private static zoweExplorerAPI = ZoweVsCodeExtension.getZoweExplorerApi(); @@ -90,35 +89,19 @@ export class ProfileManagement { }); } - public static async runGetResource({ session, resourceName, profile, params }: { - session: Session, - resourceName: string, - profile?: imperative.IProfile, - params?: { criteria?: string, parameter?: string; queryParams?: IResourceQueryParams; }; - }) { - const { response } = await getResource(session, { - name: resourceName, - ...profile?.regionName && { regionName: profile.regionName }, - ...profile?.cicsPlex && { cicsPlex: profile.cicsPlex }, - ...params?.criteria && { criteria: params.criteria }, - ...params?.parameter && { parameter: params.parameter }, - ...params?.queryParams && { queryParams: params.queryParams }, - }, { failOnNoData: false, useCICSCmciRestError: true }); - return response; - } - public static async regionIsGroup(session: Session, profile: imperative.IProfile): Promise { let isGroup = false; try { - const { resultsummary } = await this.runGetResource({ + const { response } = await runGetResource({ session, resourceName: CicsCmciConstants.CICS_CMCI_REGION_GROUP, - profile, + ...profile?.regionName && { regionName: profile.regionName }, + ...profile?.cicsPlex && {cicsPlex: profile.cicsPlex }, params: { criteria: `GROUP=${profile.regionName}`, queryParams: { summonly: true, nodiscard: false } } }); - isGroup = resultsummary.recordcount !== "0"; + isGroup = response.resultsummary.recordcount !== "0"; } catch (error) { let errorMessage = `Error requesting region groups - ${JSON.stringify(error)}`; if (error instanceof CicsCmciRestError) { @@ -137,7 +120,7 @@ export class ProfileManagement { public static async isPlex(session: Session): Promise { try { - const { resultsummary } = await this.runGetResource({ + const { response } = await runGetResource({ session, resourceName: CicsCmciConstants.CICS_CMCI_CICS_PLEX, params: { @@ -147,7 +130,7 @@ export class ProfileManagement { } } }); - return resultsummary.api_response1 === `${CicsCmciConstants.RESPONSE_1_CODES.OK}` ? resultsummary.cachetoken : null; + return response.resultsummary.api_response1 === `${CicsCmciConstants.RESPONSE_1_CODES.OK}` ? response.resultsummary.cachetoken : null; } catch (error) { @@ -173,16 +156,17 @@ export class ProfileManagement { const infoLoaded: InfoLoaded[] = []; try { - const { records } = await this.runGetResource({ + const { response } = await runGetResource({ session, resourceName: CicsCmciConstants.CICS_CMCI_MANAGED_REGION, - profile, + ...profile?.regionName && { regionName: profile.regionName }, + ...profile?.cicsPlex && {cicsPlex: profile.cicsPlex }, }); - if (records?.cicsmanagedregion) { + if (response.records?.cicsmanagedregion) { infoLoaded.push({ plexname: profile.cicsPlex, - regions: toArray(records.cicsmanagedregion), + regions: toArray(response.records.cicsmanagedregion), group: await this.regionIsGroup(session, profile), }); } else { @@ -215,16 +199,17 @@ export class ProfileManagement { try { - const { records } = await this.runGetResource({ + const { response } = await runGetResource({ session, - profile, + ...profile?.regionName && { regionName: profile.regionName }, + ...profile?.cicsPlex && {cicsPlex: profile.cicsPlex }, resourceName: CicsCmciConstants.CICS_CMCI_MANAGED_REGION, }); - if (records?.cicsmanagedregion) { + if (response.records?.cicsmanagedregion) { infoLoaded.push({ plexname: profile.cicsPlex, - regions: toArray(records.cicsmanagedregion), + regions: toArray(response.records.cicsmanagedregion), group: false, }); } else { @@ -258,16 +243,17 @@ export class ProfileManagement { const infoLoaded: InfoLoaded[] = []; try { - const { records } = await this.runGetResource({ + const { response } = await runGetResource({ session, - profile, + ...profile?.regionName && { regionName: profile.regionName }, + ...profile?.cicsPlex && {cicsPlex: profile.cicsPlex }, resourceName: CicsCmciConstants.CICS_CMCI_REGION, }); - if (records?.cicsregion) { + if (response.records?.cicsregion) { infoLoaded.push({ plexname: null, - regions: toArray(records.cicsregion), + regions: toArray(response.records.cicsregion), group: false, }); } else { @@ -323,14 +309,14 @@ export class ProfileManagement { } } else { try { - const { records } = await this.runGetResource({ + const { response } = await runGetResource({ session, resourceName: CicsCmciConstants.CICS_CMCI_REGION, }); - if (records?.cicsregion) { + if (response.records?.cicsregion) { infoLoaded.push({ plexname: null, - regions: toArray(records.cicsregion), + regions: toArray(response.records.cicsregion), group: false, }); } @@ -356,9 +342,7 @@ export class ProfileManagement { * @param profile * @returns Array of type InfoLoaded */ - public static async getPlexInfo(profile: imperative.IProfileLoaded): Promise { - - const session = this.getSessionFromProfile(profile.profile); + public static async getPlexInfo(profile: imperative.IProfileLoaded, session: Session): Promise { if (profile.profile.cicsPlex && profile.profile.regionName) { return this.regionPlexProvided(session, profile.profile); @@ -376,14 +360,14 @@ export class ProfileManagement { */ public static async getRegionInfoInPlex(plex: CICSPlexTree): Promise { try { - const session = this.getSessionFromProfile(plex.getProfile().profile); - const { resultsummary, records } = await this.runGetResource({ + const session: Session = plex.getSession(); + const { response } = await runGetResource({ session, resourceName: CicsCmciConstants.CICS_CMCI_MANAGED_REGION, - profile: { cicsPlex: plex.getPlexName() } + cicsPlex: plex.getPlexName() }); - if (resultsummary?.api_response1 === `${CicsCmciConstants.RESPONSE_1_CODES.OK}` && records?.cicsmanagedregion) { - return toArray(records.cicsmanagedregion); + if (response.resultsummary?.api_response1 === `${CicsCmciConstants.RESPONSE_1_CODES.OK}` && response.records?.cicsmanagedregion) { + return toArray(response.records.cicsmanagedregion); } } catch (error) { let errorMessage = `Error requesting CICSManagedRegion - ${JSON.stringify(error)}`; @@ -404,24 +388,27 @@ export class ProfileManagement { public static async generateCacheToken( profile: imperative.IProfileLoaded, + session: Session, plexName: string, resourceName: string, criteria?: string, group?: string ): Promise<{ cacheToken: string; recordCount: number; }> { - const session = this.getSessionFromProfile(profile.profile); try { - const { response } = await getResource(session, { - name: resourceName, + const { response } = await runGetResource({ + session: session, + resourceName: resourceName, cicsPlex: plexName, ...group ? { regionName: group } : {}, - criteria: criteria, - queryParams: { - summonly: true, - nodiscard: true, - overrideWarningCount: true, + params: { + criteria: criteria, + queryParams: { + summonly: true, + nodiscard: true, + overrideWarningCount: true, + } } - }, { failOnNoData: false, useCICSCmciRestError: true }); + }); if (response.resultsummary.api_response1 === `${CicsCmciConstants.RESPONSE_1_CODES.OK}`) { const resultsSummary = response.resultsummary; return { cacheToken: resultsSummary.cachetoken, recordCount: parseInt(resultsSummary.recordcount, 10) }; @@ -436,11 +423,11 @@ export class ProfileManagement { public static async getCachedResources( profile: imperative.IProfileLoaded, + session: Session, cacheToken: string, resourceName: string, start = 1, increment = constants.RESOURCES_MAX) { - const session = this.getSessionFromProfile(profile.profile); const allItemsresponse = await getCache(session, { cacheToken, startIndex: start, diff --git a/packages/vsce/src/utils/profileUtils.ts b/packages/vsce/src/utils/profileUtils.ts index c0c767d5..b7cee3fe 100644 --- a/packages/vsce/src/utils/profileUtils.ts +++ b/packages/vsce/src/utils/profileUtils.ts @@ -12,6 +12,7 @@ import { ZoweVsCodeExtension, imperative } from "@zowe/zowe-explorer-api"; import { window } from "vscode"; import { ProfileManagement } from "./profileManagement"; +import { CICSSessionTree } from "../trees/CICSSessionTree"; export function missingSessionParameters(profileProfile: any): (string | undefined)[] { const params = ["host", "port", "user", "password", "rejectUnauthorized", "protocol"]; @@ -24,7 +25,40 @@ export function missingSessionParameters(profileProfile: any): (string | undefin return missing; } +export function missingUsernamePassword(missingParamters: any): boolean { + if (missingParamters.length > 0) { + const userPass = ["user", "password"]; + if (missingParamters.includes(userPass[0]) || missingParamters.includes(userPass[1])) { + return true; + } + } + + return false; +} + +export async function updateProfile(profile?: imperative.IProfileLoaded, sessionTree?: CICSSessionTree): Promise { + let missingParamters = missingSessionParameters(profile.profile); + if (missingUsernamePassword(missingParamters) || + // If profile is expanded and it previously had 401 error code + (sessionTree && sessionTree.getIsUnauthorized())) { + const updatedProfile = await promptCredentials(profile.name, true); + if (updatedProfile) { + profile = updatedProfile; + // Remove "user" and "password" from missing params array + missingParamters = missingParamters.filter((param) => ["user", "password"].indexOf(param) === -1); + } + + if (missingParamters.length) { + window.showInformationMessage( + `The following fields are missing from ${profile.name}: ${missingParamters.join(", ")}. Please update them in your config file.`, + ); + } else { + return profile; + } + } + return undefined; +} export async function promptCredentials(sessionName: string, rePrompt?: boolean): Promise { // const mProfileInfo = new ProfileInfo("zowe", { diff --git a/packages/vsce/src/utils/resourceUtils.ts b/packages/vsce/src/utils/resourceUtils.ts new file mode 100644 index 00000000..5e5b700b --- /dev/null +++ b/packages/vsce/src/utils/resourceUtils.ts @@ -0,0 +1,92 @@ +/** + * 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. + * + */ + +import { + CicsCmciRestClient, + getResource, + IGetResourceUriOptions, + IResourceQueryParams, + Utils +} from "@zowe/cics-for-zowe-sdk"; +import { Session } from "@zowe/imperative"; +import constants from "./constants"; +import { getErrorCode } from "./errorUtils"; + +export async function runGetResource({ session, resourceName, regionName, cicsPlex, params }: { + session: Session, + resourceName: string, + regionName?: string, + cicsPlex?: string, + params?: { criteria?: string, parameter?: string; queryParams?: IResourceQueryParams; }; +}) { + const resourceParams = { + name: resourceName, + ...regionName && { regionName: regionName}, + ...cicsPlex && { cicsPlex: cicsPlex }, + ...params?.criteria && { criteria: params.criteria }, + ...params?.parameter && { parameter: params.parameter }, + ...params?.queryParams && { queryParams: params.queryParams }, + }; + const requestOptions = { + failOnNoData: false, + useCICSCmciRestError: true + }; + + try { + // First attempt + return await getResource( + session, + resourceParams, + requestOptions); + } catch (error){ + // Make sure the error is not caused by the ltpa token expiring + if (getErrorCode(error) !== constants.HTTP_ERROR_UNAUTHORIZED || !session.ISession.tokenValue) { + throw error; + } + } + + // Making a second attempt as ltpa token has expired + session.ISession.tokenValue = null; + return await getResource( + session, + resourceParams, + requestOptions); +} + +export async function runPutResource({ session, resourceName, regionName, cicsPlex, params }: { + session: Session, + resourceName: string, + regionName?: string, + cicsPlex?: string, + params?: { criteria?: string, parameter?: string; queryParams?: IResourceQueryParams; }; +}, requestBody: any) { + + const options: IGetResourceUriOptions = { + "cicsPlex": cicsPlex, + "regionName": regionName, + ...params + }; + const cmciResource = Utils.getResourceUri(resourceName, options); + + try { + // First attempt + return await CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); + } catch (error){ + // Make sure the error is not caused by the ltpa token expiring + if (getErrorCode(error) !== constants.HTTP_ERROR_UNAUTHORIZED || !session.ISession.tokenValue) { + throw error; + } + } + + // Making a second attempt as ltpa token has expired + session.ISession.tokenValue = null; + return await CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody); +} \ No newline at end of file