@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
168 lines (164 loc) • 8.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.testables = exports.gatewayConnectivity = exports.defaultLogFiles = exports.completeInstall = exports.askConfigType = exports.askBundleType = exports.ConfigFiles = exports.BackstageInstallMethods = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _snooplogg = _interopRequireDefault(require("snooplogg"));
var _basicPrompts = require("../../common/basicPrompts");
var _types = require("../../common/types");
var _utils = require("../../common/utils");
var helpers = _interopRequireWildcard(require("./helpers"));
var _backstageTemplates = require("./helpers/templates/backstageTemplates");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// @ts-ignore
const {
log
} = (0, _snooplogg.default)('engage: install: agents: backstage');
const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.BACKSTAGE_DA}`;
const defaultLogFiles = exports.defaultLogFiles = '/group-*_instance-*.log';
// ConfigFiles - all the config file that are used in the setup
const ConfigFiles = exports.ConfigFiles = {
DAEnvVars: `${helpers.configFiles.DA_ENV_VARS}`,
BackstageDABinaryFile: 'discovery_agent',
BackstageDAYaml: 'discovery_agent.yml'
};
const BackstagePrompts = {
enterUrlHost: 'Enter the host of the URL for connecting to Backstage',
selectUrlScheme: 'Select the scheme of the URL for connecting to Backstage',
enterBackendPort: '(Optional) Enter the backend port of the URL for connecting to Backstage',
enterUrlPath: '(Optional) Enter the path of the URL for connecting to Backstage',
selectAuthMode: 'Select the authentication type for connecting to Backstage',
enterStaticTokenValue: 'Enter the static token value',
enterJwksClientID: 'Enter the ClientID for the JWKS Auth Flow',
enterJwksClientSecret: 'Enter the ClientSecret for the JWKS Auth Flow',
enterJwksTokenURL: 'Enter TokenURL for the JWKS Auth Flow'
};
const askBundleType = async () => {
// Backstage agent has only DA
return _types.BundleType.DISCOVERY;
};
exports.askBundleType = askBundleType;
const askConfigType = async () => {
return _types.AgentConfigTypes.DOCKERIZED;
};
//
// Questions for the configuration of Backstage agent
//
exports.askConfigType = askConfigType;
const askBackstageUrlHost = async () => await (0, _basicPrompts.askInput)({
msg: BackstagePrompts.enterUrlHost
});
const askBackstageUrlScheme = async () => await (0, _basicPrompts.askList)({
msg: BackstagePrompts.selectUrlScheme,
choices: [_backstageTemplates.UrlScheme.HTTP, _backstageTemplates.UrlScheme.HTTPS]
});
const askBackstageUrlBackendPort = async () => await (0, _basicPrompts.askInput)({
msg: BackstagePrompts.enterBackendPort,
allowEmptyInput: true
});
const askBackstageUrlPath = async () => await (0, _basicPrompts.askInput)({
msg: BackstagePrompts.enterUrlPath,
allowEmptyInput: true
});
const askBackstageAuthMode = async () => await (0, _basicPrompts.askList)({
msg: BackstagePrompts.selectAuthMode,
choices: [{
name: "No auth",
value: _backstageTemplates.AuthMode.NoAuth
}, _backstageTemplates.AuthMode.Guest, _backstageTemplates.AuthMode.StaticToken, _backstageTemplates.AuthMode.Jwks]
});
const askBackstageAuthStaticToken = async () => await (0, _basicPrompts.askInput)({
msg: BackstagePrompts.enterStaticTokenValue
});
const askBaskstageAuthJwksClientID = async () => await (0, _basicPrompts.askInput)({
msg: BackstagePrompts.enterJwksClientID
});
const askBaskstageAuthJwksClientSecret = async () => await (0, _basicPrompts.askInput)({
msg: BackstagePrompts.enterJwksClientSecret
});
const askBaskstageAuthJwksTokenUrl = async () => await (0, _basicPrompts.askInput)({
msg: BackstagePrompts.enterJwksTokenURL
});
const gatewayConnectivity = async () => {
const backstageAgentValues = new _backstageTemplates.BackstageAgentValues();
console.log('\nCONNECTION TO Backstage:');
console.log(_chalk.default.gray(`The discovery agent needs to connect to Backstage to discover API's for publishing to Amplify.`));
await askPrompts(backstageAgentValues);
return backstageAgentValues;
};
exports.gatewayConnectivity = gatewayConnectivity;
const generateSuccessHelpMsg = installConfig => {
console.log(_chalk.default.yellow('\nPlease make sure to copy the "private_key.pem" and "public_key.pem" files for the existing service account you selected.'));
dockerSuccessMsg(installConfig);
console.log(_chalk.default.gray(`\nAdditional information about agent features can be found here:\n${helpers.agentsDocsUrl.BACKSTAGE}`));
};
const dockerSuccessMsg = installConfig => {
let dockerInfo;
const runDaLinuxMsg = `docker run -it --env-file ${helpers.pwd}/${helpers.configFiles.DA_ENV_VARS} -v ${helpers.pwd}:/keys ${helpers.eolChar}`;
const runDaWinMsg = `docker run -it --env-file ${helpers.pwdWin}/${helpers.configFiles.DA_ENV_VARS} -v ${helpers.pwdWin}:/keys ${helpers.eolCharWin}`;
const startDaLinuxMsg = `\nStart the Discovery Agent on a Linux based machine`;
const startDaWinMsg = `\nStart the Discovery Agent on a Windows machine`;
dockerInfo = `To utilize the agents, pull the latest Docker images and run them using the appropriate supplied environment files, (${helpers.configFiles.DA_ENV_VARS}:`;
console.log(_chalk.default.whiteBright(dockerInfo), '\n');
const daImageVersion = `${daImage}:${installConfig.daVersion}`;
console.log(_chalk.default.white('Pull the latest image of the Discovery Agent:'));
console.log(_chalk.default.cyan(`docker pull ${daImageVersion}`));
console.log(_chalk.default.white(_utils.isWindows ? startDaWinMsg : startDaLinuxMsg));
console.log(_chalk.default.cyan(_utils.isWindows ? runDaWinMsg : runDaLinuxMsg));
console.log('\t', _chalk.default.cyan(`-v /data ${daImageVersion}`), '\n');
};
async function askPrompts(values) {
values.host = await askBackstageUrlHost();
values.scheme = await askBackstageUrlScheme();
values.backendPort = await askBackstageUrlBackendPort();
values.urlPath = await askBackstageUrlPath();
values.authMode = await askBackstageAuthMode();
switch (values.authMode) {
case _backstageTemplates.AuthMode.StaticToken:
{
values.staticTokenValue = await askBackstageAuthStaticToken();
break;
}
case _backstageTemplates.AuthMode.Jwks:
{
values.jwksClientID = await askBaskstageAuthJwksClientID();
values.jwksClientSecret = await askBaskstageAuthJwksClientSecret();
values.jwksTokenURL = await askBaskstageAuthJwksTokenUrl();
break;
}
}
return values;
}
const completeInstall = async installConfig => {
/**
* Create agent resources
*/
const backstageAgentValues = installConfig.gatewayConfig;
// Add final settings
backstageAgentValues.centralConfig = installConfig.centralConfig;
console.log('Generating the configuration file(s)...');
(0, _utils.writeTemplates)(ConfigFiles.DAEnvVars, backstageAgentValues, _backstageTemplates.backstageDAEnvVarTemplate);
console.log('Configuration file(s) have been successfully created.\n');
generateSuccessHelpMsg(installConfig);
};
exports.completeInstall = completeInstall;
const BackstageInstallMethods = exports.BackstageInstallMethods = {
GetBundleType: askBundleType,
GetDeploymentType: askConfigType,
AskGatewayQuestions: gatewayConnectivity,
FinalizeGatewayInstall: completeInstall,
ConfigFiles: Object.values(ConfigFiles),
AgentNameMap: {
[_types.AgentTypes.da]: _types.AgentNames.BACKSTAGE_DA,
[_types.AgentTypes.ta]: _types.AgentNames.BACKSTAGE_DA
},
GatewayDisplay: _types.GatewayTypes.BACKSTAGE
};
const testables = exports.testables = {
BackstagePrompts,
ConfigFiles,
defaultLogFiles
};