@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
147 lines (143 loc) • 7.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.testables = exports.gatewayConnectivity = exports.completeInstall = exports.askConfigType = exports.askBundleType = exports.amplifyAgentsNs = exports.GraylogInstallMethods = exports.ConfigFiles = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _snooplogg = _interopRequireDefault(require("snooplogg"));
var _Kubectl = require("../../common/Kubectl");
var _basicPrompts = require("../../common/basicPrompts");
var _inputs = require("./helpers/inputs");
var _types = require("../../common/types");
var _utils = require("../../common/utils");
var helpers = _interopRequireWildcard(require("./helpers"));
var _graylogTemplates = require("./helpers/templates/graylogTemplates");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// @ts-ignore
const {
log
} = (0, _snooplogg.default)('engage: install: agents: graylog');
const amplifyAgentsNs = exports.amplifyAgentsNs = 'amplify-agents';
// ConfigFiles - all the config file that are used in the setup
const ConfigFiles = exports.ConfigFiles = {
helmOverride: 'agent-overrides.yaml'
};
// GraylogPrompts - prompts for user inputs
const prompts = {
agentNamespace: 'Enter the namespace to use for the Amplify Graylog Agents',
enterUrl: 'Enter the Graylog base URL that the agent will use',
enterUsername: 'Enter the Graylog user name',
enterPassword: 'Enter the password for Graylog user',
enterBasePathSegmentLen: 'Enter the base path segment length that agent will use for lookup'
};
const askBundleType = async () => {
return _types.BundleType.TRACEABILITY;
};
exports.askBundleType = askBundleType;
const askConfigType = async () => {
return _types.AgentConfigTypes.HELM;
};
//
// Questions for the configuration of Graylog agent
//
exports.askConfigType = askConfigType;
const askURL = async () => await (0, _basicPrompts.askInput)({
msg: prompts.enterUrl,
allowEmptyInput: false,
validate: (0, _basicPrompts.validateRegex)(helpers.GitLabRegexPatterns.gitLabBaseURLRegex, helpers.invalidValueExampleErrMsg('BaseURL', 'https://www.testdomain.com'))
});
const askUsername = async () => await (0, _basicPrompts.askInput)({
msg: prompts.enterUsername,
allowEmptyInput: false
});
const askPassword = async () => await (0, _basicPrompts.askInput)({
msg: prompts.enterPassword
});
const askBasePathSegmentLen = async () => await (0, _basicPrompts.askInput)({
msg: prompts.enterBasePathSegmentLen,
type: 'number',
defaultValue: 2
});
const gatewayConnectivity = async _installConfig => {
console.log(_chalk.default.gray(`The Amplify Graylog Agent needs to be deployed to your Kubernetes cluster to discover APIs for publishing to Amplify Engage.`));
const {
error
} = await _Kubectl.kubectl.isInstalled();
if (error) {
throw new Error(`Kubectl is required to fill out the following prompts. It appears to be missing or misconfigured.\n${error}`);
}
const graylogAgentValues = new _graylogTemplates.GraylogAgentValues();
graylogAgentValues.namespace = await (0, _inputs.askNamespace)(prompts.agentNamespace, amplifyAgentsNs);
graylogAgentValues.url = await askURL();
graylogAgentValues.userName = await askUsername();
graylogAgentValues.password = await askPassword();
graylogAgentValues.basePathSegmentLen = await askBasePathSegmentLen();
return graylogAgentValues;
};
exports.gatewayConnectivity = gatewayConnectivity;
const generateSuccessHelpMsg = namespace => {
console.log(`Graylog Agent override file has been placed at ${process.cwd()}/${ConfigFiles.helmOverride}`);
helpers.helmImageSecretInfo(namespace);
let agentHelmInfo = new Set();
agentHelmInfo.add({
helmReleaseName: 'graylog-agent',
helmChartName: 'axway/graylog-agent',
overrideFileName: ConfigFiles.helmOverride,
imageSecretOverrides: `--set image.pullSecret=<image-pull-secret-name>`
});
helpers.helmInstallInfo('Graylog', namespace, agentHelmInfo);
console.log('Configuration file(s) have been successfully created.\n');
console.log(_chalk.default.gray(`\nAdditional information about agent features can be found here:\n${helpers.agentsDocsUrl.GRAYLOG}`));
};
const completeInstall = async installConfig => {
// Add final settings to graylogAgentValues
const graylogAgentValues = installConfig.gatewayConfig;
if (graylogAgentValues.namespace.isNew) {
await helpers.createNamespace(graylogAgentValues.namespace.name);
}
graylogAgentValues.centralConfig = installConfig.centralConfig;
graylogAgentValues.graylogSecret = helpers.amplifyAgentsCredsSecret;
graylogAgentValues.agentKeysSecret = helpers.amplifyAgentsKeysSecret;
// read file content
await helpers.createSecret(graylogAgentValues.namespace.name, helpers.amplifyAgentsKeysSecret, async () => {
if (installConfig.centralConfig.ampcDosaInfo.isNew) {
console.log(_chalk.default.yellow(`The secret '${helpers.amplifyAgentsKeysSecret}' will be created with the same "private_key.pem" and "public_key.pem" that was auto generated to create the Service Account.`));
}
await helpers.createAmplifyAgentKeysSecret(graylogAgentValues.namespace.name, helpers.amplifyAgentsKeysSecret, 'publicKey', graylogAgentValues.centralConfig.dosaAccount.publicKey, 'privateKey', graylogAgentValues.centralConfig.dosaAccount.privateKey);
});
await helpers.createSecret(graylogAgentValues.namespace.name, helpers.amplifyAgentsCredsSecret, async () => {
await createGraylogCredsSecret(graylogAgentValues.namespace.name, helpers.amplifyAgentsCredsSecret, graylogAgentValues.userName, graylogAgentValues.password);
});
graylogAgentValues.traceabilityConfig = installConfig.traceabilityConfig;
console.log('Generating the configuration file(s)...');
(0, _utils.writeTemplates)(ConfigFiles.helmOverride, graylogAgentValues, helpers.graylogHelmOverrideTemplate);
generateSuccessHelpMsg(graylogAgentValues.namespace.name);
};
exports.completeInstall = completeInstall;
const createGraylogCredsSecret = async (namespace, secretName, user, password) => {
const {
error
} = await _Kubectl.kubectl.create('secret', `-n ${namespace} generic ${secretName} \
--from-literal=username=${user} \
--from-literal=password=${password}`);
if (error) {
throw Error(error);
}
console.log(`Created ${secretName} in the ${namespace} namespace.`);
};
const GraylogInstallMethods = exports.GraylogInstallMethods = {
GetBundleType: askBundleType,
GetDeploymentType: askConfigType,
AskGatewayQuestions: gatewayConnectivity,
FinalizeGatewayInstall: completeInstall,
ConfigFiles: Object.values(ConfigFiles),
AgentNameMap: {
[_types.AgentTypes.ca]: _types.AgentNames.GRAYLOG_CA
},
GatewayDisplay: _types.GatewayTypes.GRAYLOG
};
const testables = exports.testables = {
prompts,
ConfigFiles
};