@broadcom/endevor-bridge-for-git-for-zowe-cli
Version:
Endevor Bridge for Git plug-in for Zowe CLI
178 lines • 8.87 kB
JavaScript
"use strict";
/*
* Copyright (c) 2019 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.BaseHandler = void 0;
const imperative_1 = require("@zowe/imperative");
const EBGSession_1 = require("./sessions/EBGSession");
const api_1 = require("../api");
const EndevorSession_1 = require("./sessions/EndevorSession");
const ZosmfSession_1 = require("./sessions/ZosmfSession");
const object_1 = require("../utils/object");
const BaseProfileDefinitions_1 = require("./sessions/BaseProfileDefinitions");
const endevor_bridge_for_git_rest_api_1 = require("@broadcom/endevor-bridge-for-git-rest-api");
const EBGClient_1 = require("../api/EBGClient");
/**
* This class is used by the various handlers in the project as the base class for their implementation.
*/
class BaseHandler {
/**
* This will grab the arguments and create a session before calling the subclass
* {@link BaseHandler#processWithSession} method.
*
* @param {IHandlerParameters} params Command parameters sent by imperative.
*
* @returns {Promise<void>}
*/
process(params) {
var _a, _b, _c, _d, _e, _f, _g;
return __awaiter(this, void 0, void 0, function* () {
// Initialize options validator
this.optionValidator = new api_1.OptionValidator();
this.optionUtils = new api_1.OptionUtils(this.optionValidator);
this.endevorProfileUtils = new EndevorSession_1.EndevorSession(this.optionValidator);
this.zosmfProfileUtils = new ZosmfSession_1.ZosmfSession(this.optionValidator);
const conf = imperative_1.ImperativeConfig.instance.config;
// Load profiles
// The EBG profile is loaded automatically in the arguments
// For the rest of profiles only the specified profiles are loaded in params.profiles
// so it is not necessary to specify the name in params.profiles.get()
const usingTeamConfig = ((_a = imperative_1.ImperativeConfig.instance.config) === null || _a === void 0 ? void 0 : _a.exists) || false;
if (usingTeamConfig) {
if (this.profileExists(conf.properties.profiles, "endevor")) {
this.endevorProfile = Object.assign({}, (_b = conf.properties.profiles[conf.properties.defaults.endevor]) === null || _b === void 0 ? void 0 : _b.properties);
}
if (this.profileExists(conf.properties.profiles, "base")) {
this.baseProfile = Object.assign({}, (_c = conf.properties.profiles[conf.properties.defaults.base]) === null || _c === void 0 ? void 0 : _c.properties);
}
if (this.profileExists(conf.properties.profiles, "zosmf")) {
this.zosmfProfile = Object.assign({}, (_d = conf.properties.profiles[conf.properties.defaults.zosmf]) === null || _d === void 0 ? void 0 : _d.properties);
}
}
else {
// for V1 compatibility
if ((0, object_1.isNotNil)(params.definition.profile)) {
// Load Endevor profile if needed
if (params.definition.profile.optional.includes(EndevorSession_1.EndevorSession.PROFILE_TYPE)) {
this.endevorProfile = params.profiles.get(EndevorSession_1.EndevorSession.PROFILE_TYPE, false);
}
if (params.definition.profile.optional.includes(BaseProfileDefinitions_1.BaseProfileDefinitions.PROFILE_TYPE)) {
this.baseProfile = params.profiles.get(BaseProfileDefinitions_1.BaseProfileDefinitions.PROFILE_TYPE, false);
}
// Load z/OSMF profile if needed
if (params.definition.profile.optional.includes(ZosmfSession_1.ZosmfSession.PROFILE_TYPE)) {
this.zosmfProfile = params.profiles.get(ZosmfSession_1.ZosmfSession.PROFILE_TYPE, false);
}
}
}
this.params = params;
if ((_g = (_f = (_e = params.definition) === null || _e === void 0 ? void 0 : _e.profile) === null || _f === void 0 ? void 0 : _f.optional) === null || _g === void 0 ? void 0 : _g.includes(EBGSession_1.EBGSession.PROFILE_TYPE)) {
this.ebgService = this.createEbgService(this.createEbgSession());
}
yield this.processWithSession();
// end any progress bar
this.progress.endBar();
});
}
validateRequiredOptions() {
return this.optionValidator.validateRequiredOptions();
}
getOption(optionDefinition, isRequired) {
return this.optionUtils.getOption(isRequired !== undefined ? isRequired : optionDefinition.required !== undefined ?
optionDefinition.required : false, optionDefinition, this.arguments);
}
getOptionFromArgument(optionDefinition) {
return this.optionUtils.getOptionFromArgument(optionDefinition, this.arguments);
}
getEndevorSessionOption(optionDefinition, isRequired = true) {
return this.endevorProfileUtils.getOption(isRequired, optionDefinition, this.arguments, this.endevorProfile);
}
createEbgSession() {
return new EBGSession_1.EBGSession(this.optionValidator).createSession(this.arguments);
}
createEbgService(ebgSession) {
return new endevor_bridge_for_git_rest_api_1.EBGRestService(new EBGClient_1.EBGClient(ebgSession));
}
createEndevorSession() {
return this.endevorProfileUtils.createSession(this.arguments, this.endevorProfile, this.baseProfile);
}
createZosmfSession() {
return this.zosmfProfileUtils.getSession(this.arguments, this.zosmfProfile, this.baseProfile);
}
/**
* Returns the command line arguments passed
*/
get arguments() {
return this.params.arguments;
}
/**
* Fail the command with an imperative error
* @param {IImperativeError} err - the imperative error parameters
*/
fail(err) {
throw new imperative_1.ImperativeError(err);
}
/**
* Returns the console interface for the command handler
* @returns {IHandlerResponseConsoleApi}
*/
get console() {
return this.params.response.console;
}
/**
* Returns the format interface for the command handler
* @returns {IHandlerFormatOutputApi}
*/
get format() {
return this.params.response.format;
}
/**
* Returns the format interface for the command handler
* @returns {IHandlerResponseDataApi}
*/
get data() {
return this.params.response.data;
}
/**
* Returns the format interface for the command handler
* @returns {IHandlerProgressApi}
*/
get progress() {
return this.params.response.progress;
}
profileExists(profiles, profileName) {
const filteredProfiles = Object.values(profiles).filter(value => value.type === profileName);
return filteredProfiles.length > 0;
}
}
exports.BaseHandler = BaseHandler;
//# sourceMappingURL=BaseHandler.js.map