-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
53 lines (43 loc) · 1.84 KB
/
config.ts
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
/**
* Configuration module for the ExploitDB MCP server
* Loads configuration from environment variables with sensible defaults
*/
import * as path from 'path';
import * as fs from 'fs-extra';
import * as dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();
// Default configuration
const defaultConfig = {
// Repository configuration
cloneRepository: false,
repositoryUrl: 'https://gitlab.com/exploit-database/exploitdb.git',
csvUrl: 'https://gitlab.com/exploit-database/exploitdb/-/raw/main/files_exploits.csv',
// Local storage paths
dataDir: path.join(process.cwd(), 'data'),
dbPath: path.join(process.cwd(), 'data', 'exploitdb.sqlite'),
// Update frequency in hours (0 to disable automatic updates)
updateInterval: 24,
// Maximum number of results to return per query
maxResults: 10
};
// Load configuration from environment variables
export const config = {
cloneRepository: process.env.CLONE_REPOSITORY === 'true' ? true : defaultConfig.cloneRepository,
repositoryUrl: process.env.REPOSITORY_URL || defaultConfig.repositoryUrl,
csvUrl: process.env.CSV_URL || defaultConfig.csvUrl,
dataDir: process.env.DATA_DIR ? path.resolve(process.env.DATA_DIR) : defaultConfig.dataDir,
dbPath: process.env.DB_PATH ? path.resolve(process.env.DB_PATH) : defaultConfig.dbPath,
updateInterval: process.env.UPDATE_INTERVAL ? parseInt(process.env.UPDATE_INTERVAL, 10) : defaultConfig.updateInterval,
maxResults: process.env.MAX_RESULTS ? parseInt(process.env.MAX_RESULTS, 10) : defaultConfig.maxResults
};
// Ensure data directory exists
export const ensureDataDir = async (): Promise<void> => {
await fs.ensureDir(config.dataDir);
// Create subdirectories if needed
if (config.cloneRepository) {
await fs.ensureDir(path.join(config.dataDir, 'exploitdb'));
}
};
// Export configuration
export default config;