@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
601 lines (594 loc) • 27.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.serviceAccountNameAlreadyExists = exports.selectServiceAccount = exports.selectIngestionProtocol = exports.selectAWSRegion = exports.secretAlreadyExists = exports.namespaceAlreadyExists = exports.k8sClusterMessages = exports.idpTestables = exports.idpMessages = exports.getCentralEnvironments = exports.envMessages = exports.enterServiceAccountName = exports.enterPublicKeyPath = exports.enterPrivateKeyPath = exports.enterNamespaceName = exports.enterAWSRegion = exports.createNamespace = exports.createGatewayAgentCredsSecret = exports.createAmplifyAgentKeysSecret = exports.askServiceAccountName = exports.askReferencedEnvironments = exports.askPublicKeyPath = exports.askPublicAndPrivateKeysPath = exports.askPrivateKeyPath = exports.askNamespace = exports.askKeyValuePairLoop = exports.askK8sClusterName = exports.askIngestionProtocol = exports.askForSecretName = exports.askForIDPConfiguration = exports.askForIDPAuthConfiguration = exports.askEnvironmentName = exports.askDosaClientId = exports.askBundleType = exports.askArrayLoop = exports.askAgentName = exports.askAWSRegion = exports.agentMessages = exports.addIdentityProvider = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _snooplogg = _interopRequireDefault(require("snooplogg"));
var _inquirer = _interopRequireDefault(require("inquirer"));
var _basicPrompts = require("../../../common/basicPrompts");
var _Kubectl = require("../../../common/Kubectl");
var _PlatformClient = require("../../../common/PlatformClient");
var _types = require("../../../common/types");
var _getters = require("./getters");
var _regex = require("./regex");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const {
log
} = (0, _snooplogg.default)('central: install: agents: saas');
const cliNowString = `cli-${Date.now()}`;
const envMessages = exports.envMessages = {
createNewEnvironment: 'Create a new environment',
enterEnvironmentName: 'Enter a new environment name',
isProduction: 'Is the environment used for production purpose?',
selectEnvironment: 'Select an environment',
selectReferencedEnvironment: 'Select a referenced environment',
selectMoreWithExistingRefEnv: "Selected environment already contains references, do you want to select more",
selectMoreRefEnv: "Do you want to select more referenced environment",
getEnvironmentsError: 'Get environments error.',
environmentAlreadyExists: 'Environment already exists. Please enter a new name.',
selectTeam: 'Select a team'
};
const k8sClusterMessages = exports.k8sClusterMessages = {
enterK8sClusterName: 'Enter a unique k8s cluster name'
};
const agentMessages = exports.agentMessages = {
enterDiscoveryAgentName: 'Enter a new discovery agent name',
enterTraceabilityAgentName: 'Enter a new traceability agent name',
enterComplianceAgentName: 'Enter a new compliance agent name',
getAgentsError: 'Error getting agents.',
agentAlreadyExists: 'Agent already exists. Please enter a new name.',
selectAgentType: 'Select the type of agent(s) you want to install'
};
const idpMessages = exports.idpMessages = {
addIDP: 'Choose if you want to add an IDP Configuration. Multiple Identity providers can be configured',
enterTitle: 'Enter the title of the IDP config',
selectType: 'Select the type of the IDP',
enterMetadataURL: 'Enter the metadata URL',
provideReqHeadersRegistration: 'Add request headers used for registration calls as key-value pairs. Stops when empty key is provided',
provideQueryParamsRegistration: 'Add query parameters used for registration calls as key-value pairs. Stops when empty key is provided',
provideClientProperties: "Enter additional client properties used for registration calls as key-value pairs. Stops when empty key is provided",
enterClientTimeout: "Enter client timeout (in seconds) for dynamic registration calls. Defaults to 60s. Minimum 30s",
selectAuthType: "Select the auth type",
enterToken: "Enter the access token",
selectClientSecretAuthMethod: "Select the auth method for ClientSecret based auth",
enterClientID: "Enter the clientID",
enterClientSecret: "Enter the clientSecret",
enterClientScopes: "Enter the list of scope names",
provideReqHeadersForTokenFetch: "Enter the request headers used for the token fetch call as key-value pairs. Stops when empty input is provided",
provideQueryParamsForTokenFetch: "Enter the query parameters used for the token fetch call as key-value pairs. Stops when empty input is provided"
};
const namespaceAlreadyExists = exports.namespaceAlreadyExists = 'Namespace already exists. Please enter a new name.';
const secretAlreadyExists = exports.secretAlreadyExists = 'Secret already exists. Please enter a new name.';
const enterNamespaceName = exports.enterNamespaceName = 'Enter a new namespace name';
const selectServiceAccount = exports.selectServiceAccount = 'Select a service account';
const enterServiceAccountName = exports.enterServiceAccountName = 'Enter a new service account name';
const enterPublicKeyPath = exports.enterPublicKeyPath = 'Enter the file path to the public key';
const enterPrivateKeyPath = exports.enterPrivateKeyPath = 'Enter the file path to the private key';
const selectIngestionProtocol = exports.selectIngestionProtocol = 'Select Traceability protocol';
const serviceAccountNameAlreadyExists = exports.serviceAccountNameAlreadyExists = 'Service account already exists. Please enter a new name.';
const selectAWSRegion = exports.selectAWSRegion = 'Select an AWS Region';
const enterAWSRegion = exports.enterAWSRegion = 'Enter an AWS Region';
const askAWSRegion = async (region = '') => {
let regions = Object.values(_types.AWSRegions).map(str => ({
name: str,
value: str
}));
let answer = await (0, _basicPrompts.askList)({
msg: selectAWSRegion,
default: region,
choices: [{
name: 'Enter an AWS Region not on the list',
value: 'CREATE_NEW'
}, ...regions]
});
if (answer === 'CREATE_NEW') {
return await (0, _basicPrompts.askInput)({
msg: enterAWSRegion
});
} else {
return answer;
}
};
exports.askAWSRegion = askAWSRegion;
const askServiceAccountName = async serviceAccountNames => {
console.warn(_chalk.default.yellow(`WARNING: Creating a new service account will overwrite any existing "private_key.pem" and "public_key.pem" files in this directory`));
const name = await (0, _basicPrompts.askInput)({
msg: enterServiceAccountName,
defaultValue: cliNowString,
validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(serviceAccountNames, serviceAccountNameAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.dosaRegex, _regex.invalidDosaName))
});
return name;
};
exports.askServiceAccountName = askServiceAccountName;
const askDosaClientId = async (client, showWarning = true) => {
// Fetch all existing service accounts.
const serviceAccounts = await client.getServiceAccounts(_PlatformClient.PlatformServiceAccountRole.ApiCentralAdmin);
const serviceAccountNames = serviceAccounts.map(nextAccount => nextAccount.name);
// Ask user to select an existing service account or create a new one.
const selectedName = await (0, _basicPrompts.askList)({
msg: selectServiceAccount,
choices: [{
name: 'Create a new service account',
value: 'CREATE_NEW'
}, new _inquirer.default.Separator(), ...serviceAccountNames, new _inquirer.default.Separator()]
});
if (selectedName === 'CREATE_NEW') {
// We're going to create a new service account. Ask for a unique name. (We'll create it later.)
const name = await askServiceAccountName(serviceAccountNames);
return {
clientId: null,
name,
isNew: true
};
} else {
// We're using an existing service account. Notify user to make its keys available to the agents.
if (showWarning) {
console.log(_chalk.default.yellow('Please make sure your "private_key.pem" and "public_key.pem" files for the selected service account are in this installation folder.'));
}
// Fetch selected service account's client ID and return info about it.
const selectedAccount = serviceAccounts.find(nextAccount => nextAccount.name === selectedName);
return {
clientId: selectedAccount === null || selectedAccount === void 0 ? void 0 : selectedAccount.client_id,
name: selectedName,
isNew: false
};
}
};
exports.askDosaClientId = askDosaClientId;
const askNamespace = async (msg, defaultValue) => {
const namespaces = await _Kubectl.kubectl.get('ns');
if (namespaces.error) throw Error(namespaces.error);
let answer = await (0, _basicPrompts.askList)({
msg,
choices: [{
name: 'Create a new namespace',
value: 'CREATE_NEW'
}, new _inquirer.default.Separator(), ...namespaces.data, new _inquirer.default.Separator()]
});
if (answer === 'CREATE_NEW') {
const name = await (0, _basicPrompts.askInput)({
msg: enterNamespaceName,
defaultValue,
validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(namespaces.data, namespaceAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.namespaceRegex, _regex.invalidNamespace))
});
return {
name,
isNew: true
};
} else {
return {
name: answer,
isNew: false
};
}
};
exports.askNamespace = askNamespace;
const askForSecretName = async (msg, defaultValue, options) => {
return await (0, _basicPrompts.askInput)({
msg,
defaultValue,
validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(options, secretAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.resourceRegex, (0, _regex.invalidResourceMsg)('Secret')))
});
};
exports.askForSecretName = askForSecretName;
const askIngestionProtocol = async () => {
return await (0, _basicPrompts.askList)({
msg: selectIngestionProtocol,
choices: Object.entries(_types.IngestionProtocol).reduce((accumulator, curr) => {
return accumulator.concat({
name: curr[0],
value: curr[1]
});
}, []),
default: _types.IngestionProtocol.Lumberjack
});
};
exports.askIngestionProtocol = askIngestionProtocol;
const askBundleType = async choices => await (0, _basicPrompts.askList)({
msg: agentMessages.selectAgentType,
choices: choices
});
exports.askBundleType = askBundleType;
const askEnvironmentName = async (client, defsManager, isAxwayManaged = null) => {
let envs;
if (isAxwayManaged == null) {
// do not filter any environments
const {
data: allEnvs
} = await (0, _getters.getListByResource)({
client,
defsManager,
resourceType: 'Environment',
resourceShortName: 'env'
});
if (!allEnvs) throw Error(envMessages.getEnvironmentsError);
envs = allEnvs;
} else {
// Get only the axway managed environments
const {
data: axwayManagedEnvs
} = await (0, _getters.getListByResource)({
client,
defsManager,
resourceType: 'Environment',
resourceShortName: 'env',
query: 'spec.axwayManaged==true'
});
if (!axwayManagedEnvs) throw Error(envMessages.getEnvironmentsError);
envs = axwayManagedEnvs;
if (!isAxwayManaged) {
const {
data: allEnvs
} = await (0, _getters.getListByResource)({
client,
defsManager,
resourceType: 'Environment',
resourceShortName: 'env'
});
if (!allEnvs) throw Error(envMessages.getEnvironmentsError);
// Remove any axway managed envs from the array when isAxwayManaged is false
envs = allEnvs.filter(env => {
return !envs.find(axwayManagedEnv => env.name == axwayManagedEnv.name);
});
}
}
let answer = await (0, _basicPrompts.askList)({
msg: envMessages.selectEnvironment,
choices: [{
name: envMessages.createNewEnvironment,
value: 'CREATE_NEW'
}, new _inquirer.default.Separator(), ...envs.map(e => e.name).sort((name1, name2) => name1.localeCompare(name2)), new _inquirer.default.Separator()]
});
if (answer === 'CREATE_NEW') {
const name = await (0, _basicPrompts.askInput)({
msg: envMessages.enterEnvironmentName,
defaultValue: cliNowString,
validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(envs.map(env => env.name), envMessages.environmentAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.resourceRegex, (0, _regex.invalidResourceMsg)('Environment')))
});
return {
name,
isNew: true
};
} else {
var _selectedEnv$referenc, _selectedEnv$referenc2, _selectedEnv$referenc3, _selectedEnv$referenc4;
const selectedEnv = envs.find(env => env.name == answer);
return {
name: answer,
isNew: false,
referencedEnvironments: selectedEnv !== null && selectedEnv !== void 0 && (_selectedEnv$referenc = selectedEnv.references) !== null && _selectedEnv$referenc !== void 0 && _selectedEnv$referenc.managedEnvironments ? selectedEnv === null || selectedEnv === void 0 ? void 0 : (_selectedEnv$referenc2 = selectedEnv.references) === null || _selectedEnv$referenc2 === void 0 ? void 0 : _selectedEnv$referenc2.managedEnvironments : [],
referencedIdentityProviders: selectedEnv !== null && selectedEnv !== void 0 && (_selectedEnv$referenc3 = selectedEnv.references) !== null && _selectedEnv$referenc3 !== void 0 && _selectedEnv$referenc3.identityProviders ? selectedEnv === null || selectedEnv === void 0 ? void 0 : (_selectedEnv$referenc4 = selectedEnv.references) === null || _selectedEnv$referenc4 === void 0 ? void 0 : _selectedEnv$referenc4.identityProviders : []
};
}
};
exports.askEnvironmentName = askEnvironmentName;
const getCentralEnvironments = async (client, defsManager) => {
let envs;
const {
data: allEnvs
} = await (0, _getters.getListByResource)({
client,
defsManager,
resourceType: 'Environment',
resourceShortName: 'env'
});
if (!allEnvs) throw Error(envMessages.getEnvironmentsError);
envs = allEnvs;
return envs;
};
exports.getCentralEnvironments = getCentralEnvironments;
const askReferencedEnvironments = async (client, defsManager, envInfo) => {
var _envInfo$referencedEn;
if (((_envInfo$referencedEn = envInfo.referencedEnvironments) === null || _envInfo$referencedEn === void 0 ? void 0 : _envInfo$referencedEn.length) > 0) {
const choice = (await (0, _basicPrompts.askList)({
msg: envMessages.selectMoreWithExistingRefEnv,
default: _types.YesNo.No,
choices: _types.YesNoChoices
})) === _types.YesNo.Yes;
if (!choice) {
return envInfo.referencedEnvironments;
}
}
// filter all environments not referencing other environment
const {
data: allEnvs
} = await (0, _getters.getListByResource)({
client,
defsManager,
resourceType: 'Environment',
resourceShortName: 'env',
query: "metadata.references.kind!=Environment"
});
if (!allEnvs) throw Error(envMessages.getEnvironmentsError);
let askReferencedEnvironments = true;
const selectedRefEnv = envInfo.referencedEnvironments ? [...envInfo.referencedEnvironments] : [];
const envFilter = name => {
return !(selectedRefEnv !== null && selectedRefEnv !== void 0 && selectedRefEnv.includes(name)) && name != envInfo.name;
};
while (askReferencedEnvironments) {
let selectedEnv = await (0, _basicPrompts.askList)({
msg: envMessages.selectReferencedEnvironment,
choices: [...allEnvs.filter(e => envFilter(e.name)).map(e => e.name).sort((n, m) => n.localeCompare(m))]
});
selectedRefEnv.push(selectedEnv);
askReferencedEnvironments = (await (0, _basicPrompts.askList)({
msg: envMessages.selectMoreRefEnv,
default: _types.YesNo.No,
choices: _types.YesNoChoices
})) === _types.YesNo.Yes;
}
return selectedRefEnv;
};
exports.askReferencedEnvironments = askReferencedEnvironments;
const askK8sClusterName = async () => {
const name = await (0, _basicPrompts.askInput)({
msg: k8sClusterMessages.enterK8sClusterName,
defaultValue: cliNowString,
validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateRegex)(_regex.resourceRegex, (0, _regex.invalidResourceMsg)('K8sCluster')))
});
return name;
};
exports.askK8sClusterName = askK8sClusterName;
const askAgentName = async (client, defsManager, agentType, scopeName) => {
var _agents;
let resourceType;
let resourceShortName;
let msg;
switch (agentType) {
case _types.AgentTypes.da:
{
resourceType = 'DiscoveryAgent';
resourceShortName = 'da';
msg = agentMessages.enterDiscoveryAgentName;
break;
}
case _types.AgentTypes.ta:
{
resourceType = 'TraceabilityAgent';
resourceShortName = 'ta';
msg = agentMessages.enterTraceabilityAgentName;
break;
}
case _types.AgentTypes.ca:
{
resourceType = 'ComplianceAgent';
resourceShortName = 'ca';
msg = agentMessages.enterComplianceAgentName;
break;
}
}
let {
data: agents
} = await (0, _getters.getListByResource)({
client,
defsManager,
resourceType,
resourceShortName,
scopeName
});
// if there are no agents scoped to the env, make the agents list blank to validate against
agents = (_agents = agents) !== null && _agents !== void 0 ? _agents : [];
const name = await (0, _basicPrompts.askInput)({
msg: msg,
defaultValue: cliNowString,
validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(agents.map(a => a.name), agentMessages.agentAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.resourceRegex, (0, _regex.invalidResourceMsg)(resourceType)))
});
return name;
};
/**
* @description Create a secret that contains a public & private key pair for agents to connect to central.
* If a user is creating a new service account, then the keys should be passed in as args.
* If they are using an existing account, then the user will be prompted for the keys that created the service account.
* @param namespace The namespace to create the secret in.
* @param secretName The name of the secret.
* @param publicKey The file path to the public key attached to the chosen service account.
* @param privateKey The file path to the corresponding private key.
*/
exports.askAgentName = askAgentName;
const createAmplifyAgentKeysSecret = async (namespace, secretName, publicKeyName, publicKey, privateKeyName, privateKey) => {
const {
error
} = await _Kubectl.kubectl.create('secret', `-n ${namespace} generic ${secretName} --from-file=${publicKeyName}=${publicKey} --from-file=${privateKeyName}=${privateKey} --from-literal=password=""`);
if (error) throw new Error(error);
console.log(`Created ${secretName} in the ${namespace} namespace.`);
};
exports.createAmplifyAgentKeysSecret = createAmplifyAgentKeysSecret;
const createNamespace = async namespace => {
const res = await _Kubectl.kubectl.create('ns', namespace);
if (res.error) throw new Error(res.error);
console.log(`Created namespace ${namespace}.`);
return namespace;
};
exports.createNamespace = createNamespace;
const createGatewayAgentCredsSecret = async (namespace, secretName, apiManagerAuthUser, apiManagerAuthPass, apiGatewayAuthUser, apiGatewayAuthPass) => {
const {
error
} = await _Kubectl.kubectl.create('secret', `-n ${namespace} generic ${secretName} \
--from-literal=APIMANAGER_AUTH_USERNAME=${apiManagerAuthUser} \
--from-literal=APIMANAGER_AUTH_PASSWORD=${apiManagerAuthPass} \
--from-literal=APIGATEWAY_AUTH_USERNAME=${apiGatewayAuthUser} \
--from-literal=APIGATEWAY_AUTH_PASSWORD=${apiGatewayAuthPass}`);
if (error) {
throw Error(error);
}
console.log(`Created ${secretName} in the ${namespace} namespace.`);
};
exports.createGatewayAgentCredsSecret = createGatewayAgentCredsSecret;
const askPublicKeyPath = async () => await (0, _basicPrompts.askInput)({
msg: enterPublicKeyPath,
defaultValue: 'public_key.pem'
});
exports.askPublicKeyPath = askPublicKeyPath;
const askPrivateKeyPath = async () => await (0, _basicPrompts.askInput)({
msg: enterPrivateKeyPath,
defaultValue: 'private_key.pem'
});
exports.askPrivateKeyPath = askPrivateKeyPath;
const askPublicAndPrivateKeysPath = async () => {
console.log(_chalk.default.yellow('Please provide the same "private_key.pem" and "public_key.pem" that was used to create the selected Service Account.'));
const publicKey = await askPublicKeyPath();
const privateKey = await askPrivateKeyPath();
return [publicKey, privateKey];
};
exports.askPublicAndPrivateKeysPath = askPublicAndPrivateKeysPath;
const askKeyValuePairLoop = async (msg, keyLabel, validateFunc) => {
let key = "non-empty";
let map = new Map();
console.log(_chalk.default.cyan(msg));
while (key != "") {
key = await (0, _basicPrompts.askInput)({
msg: `Enter the ${keyLabel} name`,
allowEmptyInput: true,
validate: validateFunc
});
if (key === "") {
return map;
}
let value = await (0, _basicPrompts.askInput)({
msg: `Enter the ${keyLabel} value`
});
map.set(key, value);
}
return map;
};
exports.askKeyValuePairLoop = askKeyValuePairLoop;
const askArrayLoop = async msg => {
let value = "non-empty";
let array = [];
console.log(_chalk.default.gray(msg));
while (value != "") {
value = await (0, _basicPrompts.askInput)({
msg: "Enter the value",
allowEmptyInput: true
});
if (value === "") {
return array;
}
array.push(value);
}
return array;
};
exports.askArrayLoop = askArrayLoop;
const addIdentityProvider = async () => {
let providedIDPs = [];
let providedIDPAuths = [];
while ((await (0, _basicPrompts.askList)({
msg: idpMessages.addIDP,
choices: _types.YesNoChoices,
default: _types.YesNo.Yes
})) === _types.YesNo.Yes) {
console.log("starting IDP Configuration process");
let idpConfig = new _types.IDPConfiguration();
idpConfig = await askForIDPConfiguration(idpConfig);
providedIDPs.push(idpConfig);
let idpAuthConfig = new _types.IDPAuthConfiguration();
idpAuthConfig = await askForIDPAuthConfiguration(idpAuthConfig);
providedIDPAuths.push(idpAuthConfig);
}
return [providedIDPs, providedIDPAuths];
};
exports.addIdentityProvider = addIdentityProvider;
const askForIDPAuthAccessToken = async idpAuth => {
console.log(_chalk.default.gray('gathering the access token auth configuration'));
idpAuth.token = await (0, _basicPrompts.askInput)({
msg: idpMessages.enterToken
});
return idpAuth;
};
const askForIDPAuthClientSecret = async idpAuth => {
console.log(_chalk.default.gray('gathering the client secret auth configuration'));
idpAuth.authMethod = await (0, _basicPrompts.askList)({
msg: idpMessages.selectClientSecretAuthMethod,
choices: [{
name: _types.IDPClientSecretAuthMethod.ClientSecretBasic,
value: _types.IDPClientSecretAuthMethod.ClientSecretBasic
}, {
name: _types.IDPClientSecretAuthMethod.ClientSecretPost,
value: _types.IDPClientSecretAuthMethod.ClientSecretPost
}, {
name: _types.IDPClientSecretAuthMethod.ClientSecretJWT,
value: _types.IDPClientSecretAuthMethod.ClientSecretJWT
}]
});
idpAuth.clientID = await (0, _basicPrompts.askInput)({
msg: idpMessages.enterClientID
});
idpAuth.clientSecret = await (0, _basicPrompts.askInput)({
msg: idpMessages.enterClientSecret
});
idpAuth.clientScopes = await idpTestables.askArrayLoop(idpMessages.enterClientScopes);
return idpAuth;
};
const askForIDPConfiguration = async idpConfigValues => {
console.log(_chalk.default.gray('gathering idp configuration for azure'));
idpConfigValues.title = await (0, _basicPrompts.askInput)({
msg: idpMessages.enterTitle
});
idpConfigValues.type = await (0, _basicPrompts.askList)({
msg: idpMessages.selectType,
choices: [{
name: _types.IDPType.Generic,
value: _types.IDPType.Generic
}, {
name: _types.IDPType.KeyCloak,
value: _types.IDPType.KeyCloak
}, {
name: _types.IDPType.Okta,
value: _types.IDPType.Okta
}]
});
idpConfigValues.metadataURL = await (0, _basicPrompts.askInput)({
msg: idpMessages.enterMetadataURL,
validate: (0, _basicPrompts.validateRegex)(_regex.GitLabRegexPatterns.gitLabBaseURLRegex, 'metadataURL must have a valid URL format')
});
idpConfigValues.requestHeaders = await idpTestables.askKeyValuePairLoop(idpMessages.provideReqHeadersRegistration, "request header", (0, _basicPrompts.validateRegex)(_regex.keyFromKeyValuePairRegex, 'Please enter a valid value'));
idpConfigValues.queryParameters = await idpTestables.askKeyValuePairLoop(idpMessages.provideQueryParamsRegistration, "query parameter", (0, _basicPrompts.validateRegex)(_regex.keyFromKeyValuePairRegex, 'Please enter a valid value'));
idpConfigValues.clientProperties = await idpTestables.askKeyValuePairLoop(idpMessages.provideClientProperties, "client property", (0, _basicPrompts.validateRegex)(_regex.keyFromKeyValuePairRegex, 'Please enter a valid value'));
idpConfigValues.clientTimeout = await (0, _basicPrompts.askInput)({
type: 'number',
msg: idpMessages.enterClientTimeout,
validate: (0, _basicPrompts.validateValueRange)(30, 600),
defaultValue: 60,
allowEmptyInput: true
});
return idpConfigValues;
};
exports.askForIDPConfiguration = askForIDPConfiguration;
const askForIDPAuthConfiguration = async idpConfigValues => {
console.log(_chalk.default.gray('gathering idp auth configuration for azure'));
idpConfigValues.authType = await (0, _basicPrompts.askList)({
msg: idpMessages.selectAuthType,
choices: [{
name: _types.IDPAuthType.AccessToken,
value: _types.IDPAuthType.AccessToken
}, {
name: _types.IDPAuthType.ClientSecret,
value: _types.IDPAuthType.ClientSecret
}]
});
log(idpConfigValues.authType);
switch (idpConfigValues.authType) {
case _types.IDPAuthType.AccessToken:
{
let auth = new _types.IDPAuthAccessToken();
idpConfigValues.authConfig = await askForIDPAuthAccessToken(auth);
break;
}
case _types.IDPAuthType.ClientSecret:
{
let auth = new _types.IDPAuthClientSecret();
idpConfigValues.authConfig = await askForIDPAuthClientSecret(auth);
break;
}
}
idpConfigValues.requestHeaders = await idpTestables.askKeyValuePairLoop(idpMessages.provideReqHeadersForTokenFetch, "request header", (0, _basicPrompts.validateRegex)(_regex.keyFromKeyValuePairRegex, 'Please enter a valid value'));
idpConfigValues.queryParameters = await idpTestables.askKeyValuePairLoop(idpMessages.provideQueryParamsForTokenFetch, "query parameter", (0, _basicPrompts.validateRegex)(_regex.keyFromKeyValuePairRegex, 'Please enter a valid value'));
return idpConfigValues;
};
// exported inside another object because we want to mock this function when testing
exports.askForIDPAuthConfiguration = askForIDPAuthConfiguration;
const idpTestables = exports.idpTestables = {
addIdentityProvider,
askKeyValuePairLoop,
askArrayLoop
};