UNPKG

@zowe/cli

Version:

Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.

262 lines 12.4 kB
"use strict"; /* * 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. * */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const imperative_1 = require("@zowe/imperative"); const path_1 = require("path"); const rest_1 = require("../../../../../rest"); const ZosmfHeaders_1 = require("../../../../../rest/src/ZosmfHeaders"); const ZosFiles_constants_1 = require("../../constants/ZosFiles.constants"); const ZosFiles_messages_1 = require("../../constants/ZosFiles.messages"); /** * This class holds helper functions that are used to list data sets and its members through the z/OS MF APIs */ class List { /** * Retrieve all members from a PDS * * @param {AbstractSession} session - z/OS MF connection info * @param {string} dataSetName - contains the data set name * @param {IListOptions} [options={}] - contains the options to be sent * * @returns {Promise<IZosFilesResponse>} A response indicating the outcome of the API * * @throws {ImperativeError} data set name must be set * @throws {Error} When the {@link ZosmfRestClient} throws an error * * @see https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.izua700/IZUHPINFO_API_GetListDataSetMembers.htm */ static allMembers(session, dataSetName, options = {}) { return __awaiter(this, void 0, void 0, function* () { // required imperative_1.ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message); imperative_1.ImperativeExpect.toNotBeEqual(dataSetName, "", ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message); try { // Format the endpoint to send the request to const endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES, dataSetName, ZosFiles_constants_1.ZosFilesConstants.RES_DS_MEMBERS); let reqHeaders = []; if (options.attributes) { reqHeaders = [ZosmfHeaders_1.ZosmfHeaders.X_IBM_ATTRIBUTES_BASE]; } if (options.maxLength) { reqHeaders.push({ "X-IBM-Max-Items": `${options.maxLength}` }); } else { reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MAX_ITEMS); } this.log.debug(`Endpoint: ${endpoint}`); const response = yield rest_1.ZosmfRestClient.getExpectJSON(session, endpoint, reqHeaders); return { success: true, commandResponse: null, apiResponse: response }; } catch (error) { this.log.error(error); throw error; } }); } /** * Retrieve all members from a data set name * * @param {AbstractSession} session - z/OS MF connection info * @param {string} dataSetName - contains the data set name * @param {IListOptions} [options={}] - contains the options to be sent * * @returns {Promise<IZosFilesResponse>} A response indicating the outcome of the API * * @throws {ImperativeError} data set name must be set * @throws {Error} When the {@link ZosmfRestClient} throws an error */ static dataSet(session, dataSetName, options = {}) { return __awaiter(this, void 0, void 0, function* () { imperative_1.ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message); imperative_1.ImperativeExpect.toNotBeEqual(dataSetName, "", ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message); try { let endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, `${ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES}?${ZosFiles_constants_1.ZosFilesConstants.RES_DS_LEVEL}=${dataSetName}`); if (options.start) { endpoint = `${endpoint}&start=${options.start}`; } const reqHeaders = []; if (options.attributes) { reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_ATTRIBUTES_BASE); } if (options.maxLength) { reqHeaders.push({ "X-IBM-Max-Items": `${options.maxLength}` }); } else { reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MAX_ITEMS); } // Migrated recall options if (options.recall) { switch (options.recall.toLowerCase()) { case "wait": reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MIGRATED_RECALL_WAIT); break; case "nowait": reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MIGRATED_RECALL_NO_WAIT); break; case "error": reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MIGRATED_RECALL_ERROR); break; } } this.log.debug(`Endpoint: ${endpoint}`); const response = yield rest_1.ZosmfRestClient.getExpectJSON(session, endpoint, reqHeaders); return { success: true, commandResponse: null, apiResponse: response }; } catch (error) { this.log.error(error); throw error; } }); } /** * Retrieve a list of all files from a path name * * @param {AbstractSession} session - z/OS MF connection info * @param {string} path - contains the uss path name * @param {IUSSListOptions} [options={}] - contains the options to be sent * * @returns {Promise<IZosFilesResponse>} A response indicating the outcome of the API * * @throws {ImperativeError} data set name must be set * @throws {Error} When the {@link ZosmfRestClient} throws an error */ static fileList(session, path, options = {}) { return __awaiter(this, void 0, void 0, function* () { imperative_1.ImperativeExpect.toNotBeNullOrUndefined(path, ZosFiles_messages_1.ZosFilesMessages.missingUSSFileName.message); imperative_1.ImperativeExpect.toNotBeEqual(path, "", ZosFiles_messages_1.ZosFilesMessages.missingUSSFileName.message); try { const endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, `${ZosFiles_constants_1.ZosFilesConstants.RES_USS_FILES}?${ZosFiles_constants_1.ZosFilesConstants.RES_PATH}=${encodeURIComponent(path)}`); const reqHeaders = []; if (options.maxLength) { reqHeaders.push({ "X-IBM-Max-Items": `${options.maxLength}` }); } else { reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MAX_ITEMS); } this.log.debug(`Endpoint: ${endpoint}`); const response = yield rest_1.ZosmfRestClient.getExpectJSON(session, endpoint, reqHeaders); return { success: true, commandResponse: null, apiResponse: response }; } catch (error) { this.log.error(error); throw error; } }); } /** * Retrieve zfs files * * @param {AbstractSession} session - z/OS MF connection info * @param {IZfsOptions} [options={}] - contains the options to be sent * * @returns {Promise<IZosFilesResponse>} A response indicating the outcome of the API * * @throws {ImperativeError} data set name must be set * @throws {Error} When the {@link ZosmfRestClient} throws an error */ static fs(session, options = {}) { return __awaiter(this, void 0, void 0, function* () { try { let endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, `${ZosFiles_constants_1.ZosFilesConstants.RES_MFS}`); if (options.fsname) { endpoint = path_1.posix.join(endpoint, `?${ZosFiles_constants_1.ZosFilesConstants.RES_FSNAME}=${encodeURIComponent(options.fsname)}`); } const reqHeaders = []; // if (options.path) { // reqHeaders.push(ZosmfHeaders.X_IBM_ATTRIBUTES_BASE); // } if (options.maxLength) { reqHeaders.push({ "X-IBM-Max-Items": `${options.maxLength}` }); } else { reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MAX_ITEMS); } this.log.debug(`Endpoint: ${endpoint}`); const response = yield rest_1.ZosmfRestClient.getExpectJSON(session, endpoint, reqHeaders); return { success: true, commandResponse: null, apiResponse: response }; } catch (error) { this.log.error(error); throw error; } }); } /** * Retrieve zfs files if indicated path * * @param {AbstractSession} session - z/OS MF connection info * @param {IZfsOptions} [options={}] - contains the options to be sent * * @returns {Promise<IZosFilesResponse>} A response indicating the outcome of the API * * @throws {ImperativeError} data set name must be set * @throws {Error} When the {@link ZosmfRestClient} throws an error */ static fsWithPath(session, options = {}) { return __awaiter(this, void 0, void 0, function* () { try { let endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, `${ZosFiles_constants_1.ZosFilesConstants.RES_MFS}`); if (options.path) { endpoint = path_1.posix.join(endpoint, `?${ZosFiles_constants_1.ZosFilesConstants.RES_PATH}=${encodeURIComponent(options.path)}`); } const reqHeaders = []; if (options.maxLength) { reqHeaders.push({ "X-IBM-Max-Items": `${options.maxLength}` }); } else { reqHeaders.push(ZosmfHeaders_1.ZosmfHeaders.X_IBM_MAX_ITEMS); } this.log.debug(`Endpoint: ${endpoint}`); const response = yield rest_1.ZosmfRestClient.getExpectJSON(session, endpoint, reqHeaders); return { success: true, commandResponse: null, apiResponse: response }; } catch (error) { this.log.error(error); throw error; } }); } static get log() { return imperative_1.Logger.getAppLogger(); } } exports.List = List; //# sourceMappingURL=List.js.map