UNPKG

token-guardian

Version:

A comprehensive solution for protecting and managing API tokens and secrets

59 lines (58 loc) 1.68 kB
import { Logger } from '../utils/Logger'; import { TokenPattern } from '../interfaces/TokenPattern'; import { ScanResult } from '../interfaces/ScanResult'; export declare class GitScanner { private patterns; private ignorePatterns; private logger; constructor(patterns?: TokenPattern[], ignorePatterns?: string[], logger?: Logger); /** * Calculate Shannon entropy of a string * @param str String to calculate entropy for * @returns Entropy value */ private calculateEntropy; /** * Check if a file should be ignored * @param filepath File path to check * @returns Whether the file should be ignored */ private shouldIgnoreFile; /** * Get staged files for scanning * @returns List of staged file paths */ private getStagedFiles; /** * Scan a single line for potential tokens * @param line Line to scan * @param lineNumber Line number * @param filepath File path * @returns Array of found tokens */ private scanLine; /** * Scan a file for potential tokens * @param filepath File to scan * @returns Scan results */ private scanFile; /** * Run the pre-commit scan * @returns Scan results and whether the commit should be blocked */ runPreCommitScan(): Promise<{ results: ScanResult[]; shouldBlock: boolean; }>; /** * Add a custom token pattern * @param pattern Pattern to add */ addPattern(pattern: TokenPattern): void; /** * Add a custom ignore pattern * @param pattern Pattern to ignore */ addIgnorePattern(pattern: string): void; }