secretshield
Version:
š”ļø SecretShield is a CLI tool that detects API keys and sensitive credentials before you commit code.
35 lines (28 loc) ⢠1.05 kB
JavaScript
const { execSync } = require('child_process');
const scanFilesForSecrets = require('../scripts/scan');
const chalk = require('chalk');
console.log("ā
SecretShield CLI is working!");
console.log('š SecretShield scanning staged files...');
let files = [];
try {
files = execSync('git diff --cached --name-only', { encoding: 'utf-8' })
.split('\n')
.filter(f => f.trim().length > 0);
} catch (err) {
console.error(chalk.red("ā ļø Failed to scan files. Make sure Git is initialized and you have staged files."));
process.exit(1);
}
if (files.length === 0) {
console.log(chalk.yellow("ā ļø No staged files to scan."));
process.exit(0);
}
const path = require('path');
const absolutePaths = files.map(file => path.resolve(process.cwd(), file));
const secretsFound = scanFilesForSecrets(absolutePaths);
if (secretsFound) {
console.log('\nš Commit blocked: Secrets detected!');
process.exit(1);
} else {
console.log('ā
No secrets found. You are good to commit.');
}