Skip to content

Commit 39b54e9

Browse files
committed
move getCachedResources to getCache SDK method
Signed-off-by: Andrew Twydell <[email protected]>
1 parent 5383b65 commit 39b54e9

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

packages/vsce/src/utils/profileManagement.ts

+20-28
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
*
1010
*/
1111

12-
import { getResource, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
12+
import { getCache, getResource, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
1313
import { Session } from "@zowe/imperative";
1414
import { imperative, Types, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
15-
import axios, { AxiosRequestConfig } from "axios";
1615
import { window } from "vscode";
1716
import { xml2json } from "xml-js";
1817
import { CICSPlexTree } from "../trees/CICSPlexTree";
@@ -70,17 +69,6 @@ export class ProfileManagement {
7069
return mProfileInfo;
7170
}
7271

73-
/**
74-
* Makes axios GET request with path and axios config object given
75-
* @param path
76-
* @param config
77-
* @returns
78-
*/
79-
public static async makeRequest(path: string, config: AxiosRequestConfig) {
80-
const response = await axios.get(path, config);
81-
return response;
82-
}
83-
8472
public static cmciResponseXml2Json(data: string) {
8573
return JSON.parse(xml2json(data, { compact: true, spaces: 4 }));
8674
}
@@ -330,21 +318,25 @@ export class ProfileManagement {
330318

331319
public static async getCachedResources(profile: imperative.IProfileLoaded, cacheToken: string, resourceName: string, start = 1, increment = 800) {
332320
try {
333-
const config: AxiosRequestConfig = {
334-
baseURL: `${profile.profile.protocol}://${profile.profile.host}:${profile.profile.port}/CICSSystemManagement`,
335-
auth: {
336-
username: profile.profile.user,
337-
password: profile.profile.password,
338-
},
339-
};
340-
const allItemsResponse = await ProfileManagement.makeRequest(`/CICSResultCache/${cacheToken}/${start}/${increment}`, config);
341-
if (allItemsResponse.status === 200) {
342-
const jsonFromXml = ProfileManagement.cmciResponseXml2Json(allItemsResponse.data);
343-
if (jsonFromXml.response && jsonFromXml.response.records && jsonFromXml.response.records[resourceName.toLowerCase()]) {
344-
const recordAttributes = jsonFromXml.response.records[resourceName.toLowerCase()];
345-
const recordAttributesArr = toArray(recordAttributes);
346-
const returnedResources = recordAttributesArr.map((item: { _attributes: any; }) => item._attributes);
347-
return returnedResources;
321+
const session = new Session({
322+
protocol: profile.profile.protocol,
323+
hostname: profile.profile.host,
324+
port: profile.profile.port,
325+
type: "basic",
326+
user: profile.profile.user,
327+
password: profile.profile.password,
328+
rejectUnauthorized: profile.profile && 'rejectUnauthorized' in profile.profile ? profile.profile.rejectUnauthorized : true,
329+
});
330+
const allItemsresponse = await getCache(session, {
331+
cacheToken,
332+
startIndex: start,
333+
count: increment,
334+
});
335+
336+
if (allItemsresponse.response.resultsummary.api_response1_alt === "OK") {
337+
if (allItemsresponse.response && allItemsresponse.response.records && allItemsresponse.response.records[resourceName.toLowerCase()]) {
338+
const recordAttributes = allItemsresponse.response.records[resourceName.toLowerCase()];
339+
return toArray(recordAttributes);
348340
}
349341
}
350342
} catch (error) {

0 commit comments

Comments
 (0)