@broadcom/sysview-for-zowe-cli
Version:
Zowe CLI plugin for SYSVIEW
166 lines • 7.5 kB
JavaScript
;
/*
* Copyright (c) 2020 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.SysviewSession = void 0;
const imperative_1 = require("@zowe/imperative");
const Constants_1 = require("../Constants");
class SysviewSession extends imperative_1.Session {
/**
* Given a SYSVIEW profile, create a SYSVIEW REST Session.
* @static
* @param {IProfile} profile - The SYSVIEW profile contents
* @returns {Session} - A session for usage in the SYSVIEW REST Client
*/
static createSysviewSession(profile) {
const config = {
hostname: profile.host,
port: profile.port,
protocol: "https",
rejectUnauthorized: profile.rejectUnauthorized != null ? profile.rejectUnauthorized : SysviewSession.REJECT_UNAUTHORIZED_OPTION.defaultValue,
basePath: profile.basePath || SysviewSession.BASE_PATH_OPTION.defaultValue,
};
if (profile.user && profile.password) {
imperative_1.Logger.getAppLogger().debug("Using basic authentication");
config.type = imperative_1.SessConstants.AUTH_TYPE_BASIC;
config.user = profile.user;
config.password = profile.password;
}
else if (profile.tokenType && profile.tokenValue) {
imperative_1.Logger.getAppLogger().debug("Using token authentication");
config.type = imperative_1.SessConstants.AUTH_TYPE_TOKEN;
config.tokenType = profile.tokenType;
config.tokenValue = profile.tokenValue;
}
else
imperative_1.Logger.getAppLogger().debug("No authentication found");
return new imperative_1.Session(config);
}
/**
* Given command line arguments, create a SYSVIEW REST Session.
* @static
* @param {ICommandArguments} args - The arguments specified by the user
* @param {boolean} [doPrompting=true] - Indicates that we want imperative to prompt for user name and password
* when no form of credentials are supplied.
* @returns {Session} - A session for usage in the SYSVIEW REST Client
*/
static createSysviewSessionFromArguments(args_1) {
return __awaiter(this, arguments, void 0, function* (args, doPrompting = true) {
let config = {
hostname: args.host,
port: args.port,
protocol: "https",
rejectUnauthorized: args.rejectUnauthorized,
basePath: args.basePath,
};
if (args.user && args.password) {
imperative_1.Logger.getAppLogger().debug("Using basic authentication");
config.type = imperative_1.SessConstants.AUTH_TYPE_BASIC;
config.user = args.user;
config.password = args.password;
}
else if (args.tokenType && args.tokenValue) {
imperative_1.Logger.getAppLogger().debug("Using token authentication");
config.type = imperative_1.SessConstants.AUTH_TYPE_TOKEN;
config.tokenType = args.tokenType;
config.tokenValue = args.tokenValue;
}
else
imperative_1.Logger.getAppLogger().debug("No authentication found");
// If credentials are missing, prompt the user
config = yield imperative_1.ConnectionPropsForSessCfg.addPropsOrPrompt(config, args, { doPrompting });
return new imperative_1.Session(config);
});
}
}
exports.SysviewSession = SysviewSession;
SysviewSession.HOST_OPTION = {
description: "The hostname of the SYSVIEW REST API",
type: "string",
name: "host", aliases: ["H"],
// required: true, // support base profiles
group: "sysview connection options"
};
SysviewSession.PORT_OPTION = {
description: "The port number of the SYSVIEW REST API",
type: "number",
name: "port", aliases: ["P"],
// required: true, // support base profiles
group: "sysview connection options"
};
SysviewSession.USER_OPTION = {
description: "Your z/OS username used to authenticate to the SYSVIEW REST API",
type: "string",
name: "user", aliases: ["u"],
// required: true, // support base profiles
group: "sysview connection options"
};
SysviewSession.PASSWORD_OPTION = {
description: "Your z/OS password used to authenticate to the SYSVIEW REST API",
type: "string",
name: "password", aliases: ["pass", "pw"],
// required: true, // support base profiles
group: "sysview connection options"
};
SysviewSession.REJECT_UNAUTHORIZED_OPTION = {
description: "If set, the server certificate is verified against the list of supplied CAs",
type: "boolean",
name: "reject-unauthorized", aliases: ["ru"],
// defaultValue: true, // support base profiles
group: "sysview connection options"
};
SysviewSession.SSID_OPTION = {
description: "SSID of the SYSVIEW instance. Default value: GSVX",
type: "string",
name: "ssid",
defaultValue: "GSVX",
group: "sysview connection options"
};
SysviewSession.BASE_PATH_OPTION = {
description: "The base path for your API mediation layer instance." +
" Do not specify this option if you are not using an API mediation layer.",
type: "string",
name: "base-path", aliases: ["bp"],
defaultValue: Constants_1.Constants.DEFAULT_BASE_PATH,
group: "sysview connection options"
};
SysviewSession.SYSVIEW_CONNECTION_OPTIONS = [
SysviewSession.HOST_OPTION,
SysviewSession.PORT_OPTION,
SysviewSession.USER_OPTION,
SysviewSession.PASSWORD_OPTION,
SysviewSession.REJECT_UNAUTHORIZED_OPTION,
SysviewSession.SSID_OPTION,
SysviewSession.BASE_PATH_OPTION
];
//# sourceMappingURL=SysviewSession.js.map