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.

96 lines 4.94 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 path_1 = require("path"); const imperative_1 = require("@zowe/imperative"); const ZosFiles_messages_1 = require("../../constants/ZosFiles.messages"); const ZosmfHeaders_1 = require("../../../../../rest/src/ZosmfHeaders"); const ZosFiles_constants_1 = require("../../constants/ZosFiles.constants"); const rest_1 = require("../../../../../rest"); /** * This class holds helper functions that are used to get the content of data sets or USS files through the z/OSMF APIs * @export * @class Get */ class Get { /** * Retrieve data sets content * * @param {AbstractSession} session - z/OSMF connection info * @param {string} dataSetName - contains the data set name * @param {IViewOptions} [options={}] - contains the options to be sent * * @returns {Promise<Buffer>} Promise that resolves to the content of the data set * * @throws {ImperativeError} */ 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); let endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES, dataSetName); let reqHeaders = []; if (options.binary) { reqHeaders = [ZosmfHeaders_1.ZosmfHeaders.X_IBM_BINARY]; } if (options.volume) { endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES, `-(${options.volume})`, dataSetName); } const content = yield rest_1.ZosmfRestClient.getExpectBuffer(session, endpoint, reqHeaders); return content; }); } /** * Retrieve USS file content * * @param {AbstractSession} session - z/OSMF connection info * @param {string} USSFileName - contains the data set name * @param {IViewOptions} [options={}] - contains the options to be sent * * @returns {Promise<Buffer>} Promise that resolves to the content of the uss file * * @throws {ImperativeError} */ static USSFile(session, USSFileName, options = {}) { return __awaiter(this, void 0, void 0, function* () { imperative_1.ImperativeExpect.toNotBeNullOrUndefined(USSFileName, ZosFiles_messages_1.ZosFilesMessages.missingUSSFileName.message); imperative_1.ImperativeExpect.toNotBeEqual(USSFileName, "", ZosFiles_messages_1.ZosFilesMessages.missingUSSFileName.message); USSFileName = path_1.posix.normalize(USSFileName); // Get a proper destination for the file to be downloaded // If the "file" is not provided, we create a folder structure similar to the uss file structure if (USSFileName.substr(0, 1) === "/") { USSFileName = USSFileName.substr(1); } const encodedFileName = encodeURIComponent(USSFileName); const endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, ZosFiles_constants_1.ZosFilesConstants.RES_USS_FILES, encodedFileName); let reqHeaders = []; if (options.binary) { if (options.binary === true) { reqHeaders = [ZosmfHeaders_1.ZosmfHeaders.X_IBM_BINARY]; } } const content = yield rest_1.ZosmfRestClient.getExpectBuffer(session, endpoint, reqHeaders); return content; }); } } exports.Get = Get; //# sourceMappingURL=Get.js.map