Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | /**
* CI/CD Integration Command
* Generate CI/CD workflow templates and setup automation
*/
const { Command } = require('commander')
const chalk = require('chalk')
const inquirer = require('inquirer')
const fs = require('fs-extra')
const path = require('path')
const ora = require('ora')
const ciCommand = new Command('ci')
.description('CI/CD integration for automated security scanning')
// Setup CI workflow
ciCommand
.command('setup')
.description('Setup CI/CD integration')
.option('-p, --platform <platform>', 'CI platform (github|gitlab|jenkins|circleci)', 'github')
.option('-f, --framework <framework>', 'project framework (react|nextjs|fastapi|django|nodejs)')
.action(async (options) => {
console.log(chalk.bold.cyan('š§ Setting up Vaultace CI/CD Integration\n'))
try {
// Detect platform if not specified
let platform = options.platform
if (!platform) {
if (await fs.exists('.github/workflows')) platform = 'github'
else if (await fs.exists('.gitlab-ci.yml')) platform = 'gitlab'
else if (await fs.exists('Jenkinsfile')) platform = 'jenkins'
else if (await fs.exists('.circleci/config.yml')) platform = 'circleci'
}
// Detect framework if not specified
let framework = options.framework
if (!framework && await fs.exists('package.json')) {
const pkg = await fs.readJSON('package.json')
if (pkg.dependencies?.next) framework = 'nextjs'
else if (pkg.dependencies?.react) framework = 'react'
else framework = 'nodejs'
} else if (!framework && await fs.exists('requirements.txt')) {
const requirements = await fs.readFile('requirements.txt', 'utf8')
if (requirements.includes('fastapi')) framework = 'fastapi'
else if (requirements.includes('django')) framework = 'django'
else framework = 'python'
}
const answers = await inquirer.prompt([
{
type: 'list',
name: 'platform',
message: 'Select CI/CD platform:',
choices: [
{ name: 'GitHub Actions', value: 'github' },
{ name: 'GitLab CI', value: 'gitlab' },
{ name: 'Jenkins', value: 'jenkins' },
{ name: 'CircleCI', value: 'circleci' }
],
default: platform
},
{
type: 'list',
name: 'framework',
message: 'Select project framework:',
choices: [
{ name: 'React', value: 'react' },
{ name: 'Next.js', value: 'nextjs' },
{ name: 'Node.js', value: 'nodejs' },
{ name: 'FastAPI', value: 'fastapi' },
{ name: 'Django', value: 'django' },
{ name: 'Other/Generic', value: 'generic' }
],
default: framework
},
{
type: 'confirm',
name: 'failOnVuln',
message: 'Fail build on high/critical vulnerabilities?',
default: true
},
{
type: 'input',
name: 'scanPath',
message: 'Path to scan (relative to repo root):',
default: '.'
}
])
const spinner = ora('Generating CI/CD workflow...').start()
// Generate workflow file
const workflowContent = generateWorkflow(answers)
const workflowPath = getWorkflowPath(answers.platform)
// Create directory if needed
await fs.ensureDir(path.dirname(workflowPath))
// Write workflow file
await fs.writeFile(workflowPath, workflowContent)
spinner.succeed('CI/CD workflow generated successfully!')
console.log(chalk.green('\nā
Integration Setup Complete'))
console.log(`${chalk.bold('Platform:')} ${answers.platform}`)
console.log(`${chalk.bold('Framework:')} ${answers.framework}`)
console.log(`${chalk.bold('Workflow file:')} ${workflowPath}`)
console.log(chalk.blue('\nš Next steps:'))
console.log('1. Commit and push the workflow file to your repository')
console.log('2. Set VAULTACE_API_KEY secret in your CI environment')
console.log('3. Get API key from: https://app.vaultace.com/settings')
if (answers.platform === 'github') {
console.log(chalk.gray('4. Go to Settings > Secrets and variables > Actions'))
console.log(chalk.gray('5. Add new repository secret: VAULTACE_API_KEY'))
}
} catch (error) {
console.error(chalk.red(`CI setup failed: ${error.message}`))
process.exit(1)
}
})
// Generate API key
ciCommand
.command('token')
.description('Generate API token for CI/CD')
.action(async () => {
console.log(chalk.cyan('š CI/CD API Token Generation'))
console.log(chalk.gray('Note: API tokens are managed through the web dashboard\n'))
console.log(chalk.bold('To generate a CI/CD token:'))
console.log('1. Go to https://app.vaultace.com/settings')
console.log('2. Navigate to API Keys section')
console.log('3. Click "Generate CI/CD Token"')
console.log('4. Copy the token and add it to your CI secrets')
console.log(chalk.yellow('\nā ļø Security reminder:'))
console.log('⢠Keep API tokens secure and rotate them regularly')
console.log('⢠Use environment-specific tokens for different stages')
console.log('⢠Never commit tokens to your repository')
})
function getWorkflowPath(platform) {
switch (platform) {
case 'github':
return '.github/workflows/vaultace-security-scan.yml'
case 'gitlab':
return '.gitlab-ci.yml'
case 'jenkins':
return 'Jenkinsfile.vaultace'
case 'circleci':
return '.circleci/vaultace-config.yml'
default:
return 'vaultace-workflow.yml'
}
}
function generateWorkflow(config) {
const { platform, framework, failOnVuln, scanPath } = config
switch (platform) {
case 'github':
return generateGitHubWorkflow(framework, failOnVuln, scanPath)
case 'gitlab':
return generateGitLabWorkflow(framework, failOnVuln, scanPath)
case 'jenkins':
return generateJenkinsfile(framework, failOnVuln, scanPath)
case 'circleci':
return generateCircleCIWorkflow(framework, failOnVuln, scanPath)
default:
return generateGenericWorkflow(framework, failOnVuln, scanPath)
}
}
function generateGitHubWorkflow(framework, failOnVuln, scanPath) {
return `name: Vaultace Security Scan
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install Vaultace CLI
run: npm install -g @vaultace/cli
- name: Run Vaultace Security Scan
env:
VAULTACE_API_KEY: \${{ secrets.VAULTACE_API_KEY }}
run: |
vaultace scan ${scanPath} \\
--remote \\
--format sarif \\
--output vaultace-results.sarif \\
${framework !== 'generic' ? `--framework ${framework}` : ''} \\
${failOnVuln ? '--ci' : ''}
- name: Upload SARIF to GitHub
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: vaultace-results.sarif
- name: Upload Scan Results
if: always()
uses: actions/upload-artifact@v4
with:
name: vaultace-scan-results
path: vaultace-results.sarif`
}
function generateGitLabWorkflow(framework, failOnVuln, scanPath) {
return `# Vaultace Security Scan Integration
vaultace-scan:
stage: test
image: node:18-alpine
before_script:
- npm install -g @vaultace/cli
script:
- |
vaultace scan ${scanPath} \\
--remote \\
--format json \\
--output vaultace-results.json \\
${framework !== 'generic' ? `--framework ${framework}` : ''} \\
${failOnVuln ? '--ci' : ''}
artifacts:
reports:
junit: vaultace-results.json
paths:
- vaultace-results.json
expire_in: 1 week
only:
- main
- merge_requests`
}
function generateJenkinsfile(framework, failOnVuln, scanPath) {
return `pipeline {
agent any
environment {
VAULTACE_API_KEY = credentials('vaultace-api-key')
}
stages {
stage('Security Scan') {
steps {
sh 'npm install -g @vaultace/cli'
sh '''
vaultace scan ${scanPath} \\
--remote \\
--format json \\
--output vaultace-results.json \\
${framework !== 'generic' ? `--framework ${framework}` : ''} \\
${failOnVuln ? '--ci' : ''}
'''
}
post {
always {
archiveArtifacts artifacts: 'vaultace-results.json', fingerprint: true
}
}
}
}
}`
}
function generateCircleCIWorkflow(framework, failOnVuln, scanPath) {
return `version: 2.1
orbs:
node: circleci/node@5.1.0
jobs:
vaultace-scan:
docker:
- image: cimg/node:18.0
steps:
- checkout
- run:
name: Install Vaultace CLI
command: npm install -g @vaultace/cli
- run:
name: Run Security Scan
command: |
vaultace scan ${scanPath} \\
--remote \\
--format json \\
--output vaultace-results.json \\
${framework !== 'generic' ? `--framework ${framework}` : ''} \\
${failOnVuln ? '--ci' : ''}
- store_artifacts:
path: vaultace-results.json
destination: scan-results
workflows:
security-check:
jobs:
- vaultace-scan`
}
function generateGenericWorkflow(framework, failOnVuln, scanPath) {
return `# Vaultace Security Scan
# Add this to your CI/CD pipeline
# Install Vaultace CLI
npm install -g @vaultace/cli
# Run security scan
vaultace scan ${scanPath} \\
--remote \\
--format json \\
--output vaultace-results.json \\
${framework !== 'generic' ? `--framework ${framework}` : ''} \\
${failOnVuln ? '--ci' : ''}
# The scan will:
# - Detect AI-generated security vulnerabilities
# - Upload results to Vaultace dashboard
# - ${failOnVuln ? 'Fail the build if critical/high vulnerabilities found' : 'Report vulnerabilities without failing build'}
# - Generate scan artifact for download`
}
module.exports = ciCommand |