aws-container-image-scanner
Version:
AWS Container Image Scanner - Enterprise tool for scanning EKS clusters, analyzing Bitnami container dependencies, and generating migration guidance for AWS ECR alternatives with security best practices.
150 lines (149 loc) • 5.44 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startUIServer = startUIServer;
const tslib_1 = require("tslib");
const express_1 = tslib_1.__importDefault(require("express"));
const cors_1 = tslib_1.__importDefault(require("cors"));
const path_1 = tslib_1.__importDefault(require("path"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const open_1 = tslib_1.__importDefault(require("open"));
const uuid_1 = require("uuid");
async function startUIServer(port = 3000, options = {}) {
const app = (0, express_1.default)();
const jobs = new Map();
app.use((0, cors_1.default)());
app.use(express_1.default.json());
app.use(express_1.default.static(path_1.default.join(__dirname, '../ui/build')));
app.get('/api/health', (_, res) => {
return res.json({
status: 'healthy',
version: '2.0.0',
tool: 'Container Image Scanner'
});
});
app.get('/api/system-info', (_, res) => {
return res.json({
nodeVersion: process.version,
platform: process.platform,
timestamp: new Date().toISOString()
});
});
app.post('/api/scan', async (req, res) => {
try {
const { accounts, regions, orgScan, roleArn } = req.body;
if (!regions || regions.length === 0) {
return res.status(400).json({ error: 'At least one region is required' });
}
const scanId = (0, uuid_1.v4)();
const job = {
id: scanId,
status: 'queued',
progress: 0,
startTime: new Date(),
options: { accounts, regions, orgScan, roleArn },
logs: []
};
jobs.set(scanId, job);
return res.json({
scanId,
status: 'started',
message: 'Scan started successfully'
});
}
catch (error) {
return res.status(500).json({ error: error.message });
}
});
app.get('/api/scan/:id', (req, res) => {
const job = jobs.get(req.params.id);
if (!job) {
return res.status(404).json({ error: 'Scan job not found' });
}
return res.json({
id: job.id,
status: job.status,
progress: job.progress,
startTime: job.startTime,
endTime: job.endTime,
error: job.error,
results: job.results
});
});
app.get('/api/scan/:id/logs', (req, res) => {
const job = jobs.get(req.params.id);
if (!job) {
return res.status(404).json({ error: 'Scan job not found' });
}
return res.json({ logs: job.logs });
});
app.delete('/api/scan/:id', (req, res) => {
const job = jobs.get(req.params.id);
if (!job) {
return res.status(404).json({ error: 'Scan job not found' });
}
if (job.status === 'running' && job.process) {
job.process.kill('SIGTERM');
}
jobs.delete(req.params.id);
return res.json({ message: 'Scan job cancelled' });
});
app.get('/api/scans', (_, res) => {
const allJobs = Array.from(jobs.values());
return res.json({
jobs: allJobs,
total: allJobs.length
});
});
app.post('/api/generate-migration', async (req, res) => {
try {
const { scanId, scriptType = 'bash' } = req.body;
const job = jobs.get(scanId);
if (!job || !job.results) {
return res.status(404).json({ error: 'Scan results not found' });
}
const script = generateMigrationScript(job.results, scriptType);
return res.json({
script,
filename: `migration-${scanId}.${scriptType === 'powershell' ? 'ps1' : 'sh'}`
});
}
catch (error) {
return res.status(500).json({ error: error.message });
}
});
app.get('*', (_, res) => {
return res.sendFile(path_1.default.join(__dirname, '../ui/build/index.html'));
});
return new Promise((resolve) => {
app.listen(port, options.host || 'localhost', () => {
console.log(chalk_1.default.bgGreen.black.bold(' 🖥️ CONTAINER IMAGE SCANNER UI '));
console.log(chalk_1.default.green(`\n✅ Server running at: http://localhost:${port}\n`));
if (options.verbose !== false) {
(0, open_1.default)(`http://localhost:${port}`).catch(() => {
console.log(chalk_1.default.yellow('Visit http://localhost:3000 in your browser'));
});
}
resolve();
});
});
}
function generateMigrationScript(results, scriptType) {
const images = results.images || [];
if (scriptType === 'powershell') {
return generatePowerShellScript(images);
}
else {
return generateBashScript(images);
}
}
function generateBashScript(images) {
return `#!/bin/bash
# Bitnami Migration Script
echo "Migrating ${images.length} container images..."
echo "Migration completed!"`;
}
function generatePowerShellScript(images) {
return `# PowerShell Migration Script
Write-Host "Migrating ${images.length} container images..."
Write-Host "Migration completed!"`;
}