UNPKG

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

Version:

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

193 lines 10.5 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.Delete = void 0; const imperative_1 = require("@zowe/imperative"); const path_1 = require("path"); 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"); const invoke_1 = require("../invoke"); const ZosFilesUtils_1 = require("../../utils/ZosFilesUtils"); /** * This class holds helper functions that are used to delete files through the * z/OSMF APIs. */ class Delete { /** * Deletes a non-VSAM data set * * @param {AbstractSession} session z/OSMF connection info * @param {string} dataSetName The name of the data set to delete * @param {IDeleteDatasetOptions} [options={}] Additional options for deletion of the data set * * @returns {Promise<IZosFilesResponse>} A response indicating the status of the deletion * * @throws {ImperativeError} Data set name must be specified as a non-empty string * @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_DeleteDataSet.htm */ static dataSet(session_1, dataSetName_1) { return __awaiter(this, arguments, void 0, function* (session, dataSetName, options = {}) { // 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 let endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES); if (options.volume) { endpoint = path_1.posix.join(endpoint, `-(${encodeURIComponent(options.volume)})`); } const reqHeaders = [core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING]; if (options && options.responseTimeout != null) { reqHeaders.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() }); } endpoint = path_1.posix.join(endpoint, encodeURIComponent(dataSetName)); imperative_1.Logger.getAppLogger().debug(`Endpoint: ${endpoint}`); // Since there is a bug with the deleteExpectJSON (doesn't handle 204 no content) we will be using the expect // string api since that doesn't seem to complain. yield core_for_zowe_sdk_1.ZosmfRestClient.deleteExpectString(session, endpoint, reqHeaders); return { success: true, commandResponse: ZosFiles_messages_1.ZosFilesMessages.datasetDeletedSuccessfully.message }; } catch (error) { imperative_1.Logger.getAppLogger().error(error); throw error; } }); } /** * Deletes a VSAM data set * * @param {AbstractSession} session z/OSMF connection info * @param {string} dataSetName The name of the VSAM data set to delete * @param {IDeleteVsamOptions} [options={}] Additional options for deletion of the data set * * @returns {Promise<IDeleteVsamResponse>} A response indicating the status of the deletion * * @throws {ImperativeError} Data set name must be specified as a non-empty string * * @see https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.idai200/delet.htm */ static vsam(session_1, dataSetName_1) { return __awaiter(this, arguments, void 0, function* (session, dataSetName, options = {}) { // required imperative_1.ImperativeExpect.toNotBeNullOrUndefined(dataSetName, ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message); imperative_1.ImperativeExpect.toNotBeEqual(dataSetName, "", ZosFiles_messages_1.ZosFilesMessages.missingDatasetName.message); // Create the control statements const amsControlStatements = [ "DELETE -", `${dataSetName} -`, "CLUSTER -", `${options.erase ? "ERASE" : "NOERASE"} -`, options.purge ? "PURGE" : "NOPURGE" ]; try { const response = yield invoke_1.Invoke.ams(session, amsControlStatements, { responseTimeout: options.responseTimeout }); return { success: true, commandResponse: ZosFiles_messages_1.ZosFilesMessages.datasetDeletedSuccessfully.message, apiResponse: response }; } catch (error) { imperative_1.Logger.getAppLogger().error(error); throw error; } }); } /** * Deletes a USS file or directory * * @param {AbstractSession} session z/OSMF connection info * @param {string} fileName The name of the file or directory to delete * @param {boolean} recursive The indicator to delete directory recursively * @returns {Promise<IDeleteVsamResponse>} A response indicating the status of the deletion * * @throws {ImperativeError} Data set name must be specified as a non-empty string * * @see https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.izua700/IZUHPINFO_API_DeleteUnixFile.htm */ static ussFile(session, fileName, recursive, options) { return __awaiter(this, void 0, void 0, function* () { // required imperative_1.ImperativeExpect.toNotBeNullOrUndefined(fileName, ZosFiles_messages_1.ZosFilesMessages.missingUSSFileName.message); imperative_1.ImperativeExpect.toNotBeEqual(fileName, "", ZosFiles_messages_1.ZosFilesMessages.missingUSSFileName.message); // Format the endpoint to send the request to let endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, ZosFiles_constants_1.ZosFilesConstants.RES_USS_FILES); fileName = ZosFilesUtils_1.ZosFilesUtils.sanitizeUssPathForRestCall(fileName); endpoint = path_1.posix.join(endpoint, fileName); imperative_1.Logger.getAppLogger().debug(`Endpoint: ${endpoint}`); const reqHeaders = [core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING]; if (recursive && recursive === true) { reqHeaders.push({ "X-IBM-Option": "recursive" }); } if (options && options.responseTimeout != null) { reqHeaders.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() }); } try { yield core_for_zowe_sdk_1.ZosmfRestClient.deleteExpectString(session, endpoint, reqHeaders); return { success: true, commandResponse: ZosFiles_messages_1.ZosFilesMessages.ussFileDeletedSuccessfully.message }; } catch (error) { imperative_1.Logger.getAppLogger().error(error); throw error; } }); } /** * Deletes a z/OS file system * * @param {AbstractSession} session z/OSMF connection info * @param {string} fileSystemName The name of the ZFS to delete * * @throws {ImperativeError} File system name must be specified as a non-empty string * * @see https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.izua700/IZUHPINFO_API_DeleteUnixzFsFilesystem.htm */ static zfs(session, fileSystemName, options) { return __awaiter(this, void 0, void 0, function* () { // required imperative_1.ImperativeExpect.toNotBeNullOrUndefined(fileSystemName, ZosFiles_messages_1.ZosFilesMessages.missingFileSystemName.message); imperative_1.ImperativeExpect.toNotBeEqual(fileSystemName, "", ZosFiles_messages_1.ZosFilesMessages.missingFileSystemName.message); // Format the endpoint to send the request to const endpoint = ZosFiles_constants_1.ZosFilesConstants.RESOURCE + ZosFiles_constants_1.ZosFilesConstants.RES_ZFS_FILES + "/" + encodeURIComponent(fileSystemName); const reqHeaders = [core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING]; if (options && options.responseTimeout != null) { reqHeaders.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() }); } const data = yield core_for_zowe_sdk_1.ZosmfRestClient.deleteExpectString(session, endpoint, reqHeaders); return { success: true, commandResponse: ZosFiles_messages_1.ZosFilesMessages.zfsDeletedSuccessfully.message, apiResponse: data }; }); } } exports.Delete = Delete; //# sourceMappingURL=Delete.js.map