@broadcom/endevor-bridge-for-git-for-zowe-cli
Version:
Endevor Bridge for Git plug-in for Zowe CLI
166 lines (162 loc) • 6.41 kB
JavaScript
'use strict';
var imperative = require('@zowe/imperative');
require('../../api/constants/EBGConstants.js');
require('../../api/constants/PluginConstants.js');
require('../../api/doc/ebg/IMappingView.js');
require('../../api/doc/IBranchMetadata.js');
require('child_process');
require('../../api/utils/ChangeValidator.js');
require('fs');
var OptionUtils = require('../../api/utils/OptionUtils.js');
require('../../api/utils/OptionValidator.js');
/*
* 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.
*/
/**
* Utility Methods for Endevor Bridge for Git Session
*/
class EBGSession extends OptionUtils.OptionUtils {
/**
* Creates the Endevor Bridge for Git connection session if and only if all the required options are provided
*
* @param args command arguments
*/
createSession(args) {
const session = {
type: "basic",
protocol: this.getOption(true, EBGSession.EBG_OPTION_PROTOCOL, args, EBGSession.DEFAULT_PROTOCOL),
hostname: this.getOption(true, EBGSession.EBG_OPTION_HOST, args, null),
port: Number(this.getOption(true, EBGSession.EBG_OPTION_PORT, args, null)),
user: this.getOption(true, EBGSession.EBG_OPTION_USER, args, null),
password: this.getOption(true, EBGSession.EBG_OPTION_GIT_PERSONAL_ACCESS_TOKEN, args, null),
rejectUnauthorized: this.getOption(true, EBGSession.EBG_OPTION_REJECT_UNAUTHORIZED, args, EBGSession.DEFAULT_REJECT_UNAUTHORIZED),
};
const basePath = this.getOption(false, EBGSession.EBG_OPTION_BASE_PATH, args, undefined);
if (basePath) {
session.basePath = basePath.startsWith("/") ? basePath : `/${basePath}`;
}
if (!this.optionValidator.isMissingOptions(EBGSession.EBG_SESSION_OPTION_GROUP)) {
return new imperative.Session(session);
}
else {
throw new Error("Missing required options for Endevor Bridge for Git connection");
}
}
}
EBGSession.PROFILE_TYPE = "ebg";
EBGSession.EBG_SESSION_OPTION_GROUP = "Endevor Bridge for Git connection options (you can also use an 'ebg' profile)";
EBGSession.DEFAULT_PROTOCOL = imperative.AbstractSession.DEFAULT_PROTOCOL;
EBGSession.DEFAULT_REJECT_UNAUTHORIZED = false;
/**
* Option used in profile creation and commands for protocol for Endevor Bridge for Git
*/
EBGSession.EBG_OPTION_PROTOCOL = {
name: "protocol",
aliases: ["prot"],
description: "Endevor Bridge for Git SCM protocol. " +
OptionUtils.OptionUtils.defaultValueDescription(EBGSession.DEFAULT_PROTOCOL),
type: "string",
required: true,
group: EBGSession.EBG_SESSION_OPTION_GROUP,
defaultValue: EBGSession.DEFAULT_PROTOCOL,
allowableValues: { values: ["http", "https"], caseSensitive: false },
};
/**
* Option used in profile creation and commands for hostname for Endevor Bridge for Git
*/
EBGSession.EBG_OPTION_HOST = {
name: "host",
aliases: ["H"],
description: "Endevor Bridge for Git hostname.",
type: "string",
required: true,
group: EBGSession.EBG_SESSION_OPTION_GROUP,
};
/**
* Option used in profile creation and commands for port for Endevor Bridge for Git
*/
EBGSession.EBG_OPTION_PORT = {
name: "port",
aliases: ["P"],
description: "Endevor Bridge for Git port.",
type: "number",
required: true,
group: EBGSession.EBG_SESSION_OPTION_GROUP,
};
/**
* Option used in profile creation and commands for username / ID for Endevor Bridge for Git
*/
EBGSession.EBG_OPTION_USER = {
name: "user",
aliases: ["u"],
description: "Endevor Bridge for Git username (your git username).",
type: "string",
required: true,
group: EBGSession.EBG_SESSION_OPTION_GROUP,
};
/**
* Option used in profile creation and commands for password/passphrase for Endevor Bridge for Git
*/
EBGSession.EBG_OPTION_GIT_PERSONAL_ACCESS_TOKEN = {
name: "token",
aliases: ["t"],
description: "Git personal access token (Obtain the token from your Git Enterprise Server).",
type: "string",
required: true,
group: EBGSession.EBG_SESSION_OPTION_GROUP,
};
/**
* Option used in profile creation and commands for rejectUnauthorized setting for connecting to Endevor Bridge for Git
*/
EBGSession.EBG_OPTION_REJECT_UNAUTHORIZED = {
name: "reject-unauthorized",
aliases: ["ru"],
description: "Reject self-signed certificates. " +
OptionUtils.OptionUtils.defaultValueDescription(false),
type: "boolean",
group: EBGSession.EBG_SESSION_OPTION_GROUP,
};
/**
* Option used in profile creation and commands for base path for Endevor Bridge for Git
*/
EBGSession.EBG_OPTION_BASE_PATH = {
name: "ebg-base-path",
description: "The Endevor Bridge for Git Rest API base path.",
type: "string",
required: false,
group: EBGSession.EBG_SESSION_OPTION_GROUP,
defaultValue: undefined,
};
/**
* Options related to connecting to Endevor Bridge for Git
* These options can be filled in if the user creates a profile
*/
EBGSession.EBG_CONNECTION_OPTIONS = [
EBGSession.EBG_OPTION_PROTOCOL,
EBGSession.EBG_OPTION_HOST,
EBGSession.EBG_OPTION_PORT,
EBGSession.EBG_OPTION_USER,
EBGSession.EBG_OPTION_GIT_PERSONAL_ACCESS_TOKEN,
EBGSession.EBG_OPTION_REJECT_UNAUTHORIZED,
EBGSession.EBG_OPTION_BASE_PATH,
];
exports.EBGSession = EBGSession;