UNPKG

@zowe/zos-files-for-zowe-sdk

Version:

Zowe SDK to interact with files and data sets on z/OS

104 lines 5.73 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 }); exports.Mount = void 0; const imperative_1 = require("@zowe/imperative"); const core_for_zowe_sdk_1 = require("@zowe/core-for-zowe-sdk"); 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 mount file systems through the z/OS MF APIs */ class Mount { /** * Mount a Unix file system * * @param {AbstractSession} session - z/OS MF connection info * @param {string} fileSystemName - contains the file system name * @param {string} mountPoint - contains the mount point * @param {IListOptions} [options={}] - contains the options to be sent * * @returns {Promise<IZosFilesResponse>} A response indicating the outcome of the API * * @throws {ImperativeError} file system name must be set * @throws {Error} When the {@link ZosmfRestClient} throws an error * * @see https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.izua700/IZUHPINFO_API_MountUnixFile.htm */ static fs(session, fileSystemName, mountPoint, options) { return __awaiter(this, void 0, void 0, function* () { // We require the file system name and mount point imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(fileSystemName, ZosFiles_messages_1.ZosFilesMessages.missingFileSystemName.message); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(mountPoint, ZosFiles_messages_1.ZosFilesMessages.missingMountPoint.message); // Removes undefined properties const tempOptions = !(options == null) ? JSON.parse(JSON.stringify(options)) : {}; this.fsValidateOptions(tempOptions); tempOptions.action = "mount"; tempOptions["mount-point"] = mountPoint; const endpoint = ZosFiles_constants_1.ZosFilesConstants.RESOURCE + ZosFiles_constants_1.ZosFilesConstants.RES_MFS + "/" + encodeURIComponent(fileSystemName); const jsonContent = JSON.stringify(tempOptions); const headers = [{ "Content-Length": jsonContent.length }, core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING]; if (options && options.responseTimeout != null) { headers.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() }); } const data = yield core_for_zowe_sdk_1.ZosmfRestClient.putExpectString(session, endpoint, headers, jsonContent); return { success: true, commandResponse: ZosFiles_messages_1.ZosFilesMessages.fsMountedSuccessfully.message, apiResponse: data }; }); } /** * Validate the options for the command to mount a z/OS file system * @param options - options for the mounting of the file system */ static fsValidateOptions(options) { imperative_1.ImperativeExpect.toNotBeNullOrUndefined(options, ZosFiles_messages_1.ZosFilesMessages.missingFilesMountOptions.message); /* If our caller does not supply these options, we supply default values for them, * so they should exist at this point. */ imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(options["fs-type"], ZosFiles_messages_1.ZosFilesMessages.missingFsOption.message + "fs-type"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(options.mode, ZosFiles_messages_1.ZosFilesMessages.missingFsOption.message + "mode"); // validate specific options for (const option in options) { if (Object.prototype.hasOwnProperty.call(options, option)) { switch (option) { case "mode": if (options.mode !== "rdonly" && options.mode !== "rdwr") { throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidMountModeOption.message + options.mode }); } break; case "fs-type": case "responseTimeout": // no validation at this time break; default: throw new imperative_1.ImperativeError({ msg: ZosFiles_messages_1.ZosFilesMessages.invalidFilesMountOption.message + option }); } // end switch } } // end for } } exports.Mount = Mount; //# sourceMappingURL=Mount.js.map