@broadcom/ops-for-zowe-cli
Version:
OPS/MVS® Plug-in for Zowe CLI
142 lines • 5.84 kB
JavaScript
;
/*
* 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.RuleUtils = void 0;
const constants_1 = require("../constants");
const OpsRestClient_1 = require("./OpsRestClient");
class RuleUtils {
/**
*
*
* @static
* @param {Session} session
* @param {string} ruleSetName
* @param {string} ruleName
* @param {string} newState
* @param {boolean} restApi
* @param {string} [subSystem]
* @return {*} {Promise<{}>}
* @memberof RuleUtils
*/
static setRuleStatus(session, ruleSetName, ruleName, newState, restApi, subSystem) {
return __awaiter(this, void 0, void 0, function* () {
const ruleUrl = this.getRuleURL(session, ruleSetName, ruleName, restApi, subSystem);
const postBody = {
status: newState
};
return OpsRestClient_1.OpsRestClient.postExpectJSON(session, ruleUrl, constants_1.OpsConstants.headers, postBody);
});
}
/**
*
*
* @static
* @param {Session} session
* @param {string} ruleSetName
* @param {string} ruleName
* @param {boolean} restApi
* @param {string} [subSystem]
* @return {*} {Promise<{}>}
* @memberof RuleUtils
*/
static showRuleStatus(session, ruleSetName, ruleName, restApi, subSystem) {
return __awaiter(this, void 0, void 0, function* () {
const ruleUrl = this.getRuleURL(session, ruleSetName, ruleName, restApi, subSystem);
return OpsRestClient_1.OpsRestClient.getExpectJSON(session, ruleUrl, constants_1.OpsConstants.headers);
});
}
/**
*
*
* @static
* @param {Session} session
* @param {string} ruleSetName
* @param {string} ruleName
* @param {boolean} restApi
* @param {string} subSystem
* @return {*} {string}
* @memberof RuleUtils
*/
static getRuleURL(session, ruleSetName, ruleName, restApi, subSystem) {
ruleSetName = encodeURIComponent(ruleSetName);
ruleName = encodeURIComponent(ruleName);
let subsystemQueryString = "";
if (subSystem != null) {
subsystemQueryString = "?sub=" + encodeURIComponent(subSystem);
}
// Endpoint formatted based on restApi value
if (restApi === false) {
// web services
return `${constants_1.OpsConstants.BASE_URL}${constants_1.OpsConstants.RULESET_URL}/${ruleSetName}` +
`${constants_1.OpsConstants.RULE_URL}/${ruleName}${constants_1.OpsConstants.STATUS_URL}${subsystemQueryString}`;
}
else {
return this.getRuleURLForRestApi(session, ruleSetName, ruleName, subsystemQueryString);
}
}
/**
*
*
* @static
* @param {Session} session
* @param {string} ruleSetName
* @param {string} ruleName
* @param {string} subsystemQueryString
* @return {*} {string}
* @memberof RuleUtils
*/
static getRuleURLForRestApi(session, ruleSetName, ruleName, subsystemQueryString) {
let resource = "";
if (session.ISession.basePath == null || session.ISession.basePath === "") {
resource = constants_1.OpsConstants.DEFAULT_BASEPATH;
}
// Don't allow ruleSetName * and ruleName with value (this is validated in processOps of Rule.handler.ts)
if ((ruleSetName === "*") || (ruleName === "*")) {
if (ruleSetName === "*") {
if (ruleName !== "*") {
return null;
}
ruleSetName = "%2A";
}
if (ruleName === "*") {
ruleName = "%2A";
}
return `${resource}${constants_1.OpsConstants.RULES_URL}${subsystemQueryString}&ruleset=${ruleSetName}&rulename=${ruleName}`;
}
else {
return `${resource}${constants_1.OpsConstants.RULES_URL}/${ruleSetName}.${ruleName}${subsystemQueryString}`;
}
}
}
exports.RuleUtils = RuleUtils;
//# sourceMappingURL=RuleUtils.js.map