UNPKG

@broadcom/ops-for-zowe-cli

Version:

OPS/MVS® Plug-in for Zowe CLI

134 lines 6.59 kB
"use strict"; /* * Copyright (c) 2024 Broadcom. All Rights Reserved. The term * "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This software and all information contained therein is * confidential and proprietary and shall not be duplicated, * used, disclosed, or disseminated in any way except as * authorized by the applicable license agreement, without the * express written permission of Broadcom. All authorized * reproductions must be marked with this language. * * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO * THE EXTENT PERMITTED BY APPLICABLE LAW, BROADCOM PROVIDES THIS * SOFTWARE WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT * LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL BROADCOM * BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR * DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE, * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS * INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF BROADCOM IS * EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE. */ 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.SSMResourceUtils = void 0; const OpsRestClient_1 = require("./OpsRestClient"); const OpsRestUtils_1 = require("./OpsRestUtils"); const constants_1 = require("../constants"); class SSMResourceUtils { /** * setResourceState */ static setResourceState(session, resource, restApi, desiredState, subsystem, table) { return __awaiter(this, void 0, void 0, function* () { const resourceUrl = this.getResourceURL(session, resource, restApi, table, subsystem); const postBody = { desired: desiredState }; return OpsRestClient_1.OpsRestClient.postExpectJSON(session, resourceUrl, SSMResourceUtils.headers, postBody); }); } static showResourceState(session, resourceName, restApi, subsystem, table) { return __awaiter(this, void 0, void 0, function* () { const resourceUrl = this.getResourceURL(session, resourceName, restApi, table, subsystem); return OpsRestClient_1.OpsRestClient.getExpectJSON(session, resourceUrl, SSMResourceUtils.headers); }); } static getResourceURL(session, resourceName, restApi, table, subSystem) { let resource = ""; let tableQueryString = ""; let subsystemQueryString = ""; let resourceQueryString = ""; // Endpoint formatted based on restApi value if (restApi === false) { // web services return SSMResourceUtils.getNonRestApiResourceURL(resourceName, table, subSystem); } else { // REST API if (session.ISession.basePath == null || session.ISession.basePath === "") { resource = constants_1.OpsConstants.DEFAULT_BASEPATH; } if (resourceName === "*") { // convert resourceQueryString = "?resource=" + "%2A"; } else { resourceQueryString = "?resource=" + encodeURIComponent(resourceName); } if (table != null) { tableQueryString = "&table=" + encodeURIComponent(table); } if (subSystem != null) { subsystemQueryString = "&sub=" + encodeURIComponent(subSystem); } return `${resource}${constants_1.OpsConstants.RESOURCES_URL}${resourceQueryString}${tableQueryString}${subsystemQueryString}`; } } static getResourceURLWithQueryParms(session, resourceName, restApi, table, subSystem) { let resource = ""; let tableQueryString = ""; let subsystemQueryString = ""; let resourceQueryString = ""; // Endpoint formatted based on restApi value if (restApi === false) { // web services return SSMResourceUtils.getNonRestApiResourceURL(resourceName, table, subSystem); } else { // REST API if (session.ISession.basePath == null || session.ISession.basePath === "") { resource = constants_1.OpsConstants.DEFAULT_BASEPATH; } resourceQueryString = encodeURIComponent(resourceName); if (table != null) { tableQueryString = encodeURIComponent(table); } if (subSystem != null) { subsystemQueryString = "?sub=" + encodeURIComponent(subSystem); } return `${resource}${constants_1.OpsConstants.RESOURCES_URL}/${tableQueryString}.${resourceQueryString}${subsystemQueryString}`; } } static getNonRestApiResourceURL(resourceName, table, subSystem) { let tableQueryString = ""; let subsystemQueryString = ""; // Endpoint formatted for restApi value = false resourceName = encodeURIComponent(resourceName); let resourceURL = `${this.RESOURCES_URL}/${resourceName}${this.STATE_URL}`; if (table != null) { tableQueryString = "table=" + encodeURIComponent(table); } if (subSystem != null) { subsystemQueryString = "sub=" + encodeURIComponent(subSystem); } if ((table != null) && (subSystem != null)) { resourceURL += `?${tableQueryString}&${subsystemQueryString}`; } else if ((table != null) || (subSystem != null)) { resourceURL += `?${tableQueryString}${subsystemQueryString}`; } return resourceURL; } } exports.SSMResourceUtils = SSMResourceUtils; SSMResourceUtils.SSM_URL = OpsRestUtils_1.OpsRestUtils.BASE_URL + "/ssm"; SSMResourceUtils.RESOURCES_URL = SSMResourceUtils.SSM_URL + "/resources"; SSMResourceUtils.STATE_URL = "/state"; SSMResourceUtils.headers = [{ "Content-Type": "application/json" }, { Accept: "application/json" }]; //# sourceMappingURL=SSMResourceUtils.js.map