vaultace-cli
Version:
AI-powered security scanner that detects vulnerabilities in AI-generated code. Proactive scanning, autonomous fixing, and emergency response for modern development teams.
204 lines (178 loc) ⢠6.05 kB
JavaScript
/**
* Configuration Command
* Manage CLI configuration settings
*/
const { Command } = require('commander')
const chalk = require('chalk')
const inquirer = require('inquirer')
const { table } = require('table')
const ConfigManager = require('../utils/config-manager')
const configCommand = new Command('config')
.description('Manage CLI configuration')
// Set configuration
configCommand
.command('set')
.description('Set configuration value')
.argument('<key>', 'configuration key')
.argument('<value>', 'configuration value')
.action(async (key, value) => {
try {
ConfigManager.set(key, value)
console.log(chalk.green(`ā
Set ${key} = ${value}`))
} catch (error) {
console.error(chalk.red(`Failed to set config: ${error.message}`))
process.exit(1)
}
})
// Get configuration
configCommand
.command('get')
.description('Get configuration value')
.argument('[key]', 'configuration key (optional)')
.action(async (key) => {
try {
if (key) {
const value = ConfigManager.get(key)
if (value !== undefined) {
console.log(value)
} else {
console.log(chalk.gray(`${key} is not set`))
}
} else {
// Show all config
const config = ConfigManager.getConfig()
if (Object.keys(config).length === 0) {
console.log(chalk.gray('No configuration found'))
return
}
console.log(chalk.bold('š§ Vaultace Configuration\n'))
const tableData = [[chalk.bold('Key'), chalk.bold('Value')]]
// Flatten config and hide sensitive data
const flatConfig = flattenConfig(config)
Object.entries(flatConfig).forEach(([k, v]) => {
let displayValue = v
// Hide sensitive values
if (k.includes('token') || k.includes('secret') || k.includes('key')) {
displayValue = v ? '***hidden***' : chalk.gray('not set')
}
tableData.push([k, displayValue])
})
console.log(table(tableData))
}
} catch (error) {
console.error(chalk.red(`Failed to get config: ${error.message}`))
process.exit(1)
}
})
// Reset configuration
configCommand
.command('reset')
.description('Reset configuration to defaults')
.option('-f, --force', 'skip confirmation prompt')
.action(async (options) => {
try {
if (!options.force) {
const { confirm } = await inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: 'Reset all configuration to defaults?',
default: false
}])
if (!confirm) {
console.log(chalk.gray('Operation cancelled'))
return
}
}
ConfigManager.reset()
console.log(chalk.green('ā
Configuration reset to defaults'))
console.log(chalk.gray('You will need to login again: vaultace auth login'))
} catch (error) {
console.error(chalk.red(`Failed to reset config: ${error.message}`))
process.exit(1)
}
})
// Configure interactive setup
configCommand
.command('setup')
.description('Interactive configuration setup')
.action(async () => {
console.log(chalk.bold.cyan('āļø Vaultace CLI Setup\n'))
try {
const answers = await inquirer.prompt([
{
type: 'input',
name: 'apiUrl',
message: 'Vaultace API URL:',
default: 'https://api.vaultace.com',
validate: (input) => {
try {
new URL(input)
return true
} catch {
return 'Please enter a valid URL'
}
}
},
{
type: 'list',
name: 'defaultSeverity',
message: 'Default minimum severity for scans:',
choices: [
{ name: 'Low (show all vulnerabilities)', value: 'low' },
{ name: 'Medium (recommended)', value: 'medium' },
{ name: 'High (critical issues only)', value: 'high' },
{ name: 'Critical (only critical vulnerabilities)', value: 'critical' }
],
default: 'medium'
},
{
type: 'list',
name: 'defaultFormat',
message: 'Default output format:',
choices: [
{ name: 'Table (human readable)', value: 'table' },
{ name: 'JSON (machine readable)', value: 'json' },
{ name: 'CSV (spreadsheet)', value: 'csv' },
{ name: 'SARIF (security tools)', value: 'sarif' }
],
default: 'table'
},
{
type: 'confirm',
name: 'aiPatterns',
message: 'Enable AI pattern detection by default?',
default: true
},
{
type: 'confirm',
name: 'autoUpdate',
message: 'Enable automatic CLI updates?',
default: true
}
])
// Save configuration
ConfigManager.set('apiUrl', answers.apiUrl)
ConfigManager.set('defaults.severity', answers.defaultSeverity)
ConfigManager.set('defaults.format', answers.defaultFormat)
ConfigManager.set('defaults.aiPatterns', answers.aiPatterns)
ConfigManager.set('preferences.autoUpdate', answers.autoUpdate)
console.log(chalk.green('\nā
Configuration saved successfully!'))
console.log(chalk.gray('Use vaultace auth login to authenticate'))
} catch (error) {
console.error(chalk.red(`Setup failed: ${error.message}`))
process.exit(1)
}
})
function flattenConfig(obj, prefix = '') {
const result = {}
for (const key in obj) {
const newKey = prefix ? `${prefix}.${key}` : key
if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
Object.assign(result, flattenConfig(obj[key], newKey))
} else {
result[newKey] = obj[key]
}
}
return result
}
module.exports = configCommand