97 lines
No EOL
3.3 KiB
JavaScript
97 lines
No EOL
3.3 KiB
JavaScript
/*
|
|
* appConfig.js
|
|
*
|
|
* retrives configuration data from fylgja.yml file
|
|
*/
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const yaml = require('js-yaml');
|
|
|
|
// Load YAML configuration file
|
|
let yamlConfig = {};
|
|
try {
|
|
const configPath = path.join(__dirname, '..', '..', 'fylgja.yml');
|
|
const fileContents = fs.readFileSync(configPath, 'utf8');
|
|
yamlConfig = yaml.load(fileContents);
|
|
console.log('Successfully loaded fylgja.yml configuration');
|
|
} catch (error) {
|
|
console.error(`Error loading fylgja.yml: ${error.message}`);
|
|
console.log('Using default configuration values');
|
|
// Default values will be used if file cannot be loaded
|
|
}
|
|
|
|
// Base directory for resolving relative paths from config
|
|
const baseDir = path.join(__dirname, '..', '..');
|
|
|
|
// Configuration paths
|
|
module.exports = {
|
|
|
|
SLACK_CONFIG: {
|
|
botToken: yamlConfig?.slack?.bot_token || process.env.SLACK_BOT_TOKEN,
|
|
signingSecret: yamlConfig?.slack?.signing_secret || process.env.SLACK_SIGNING_SECRET
|
|
},
|
|
|
|
// Server configuration from YAML (with fallback to env vars)
|
|
SERVER_CONFIG: {
|
|
port: parseInt(yamlConfig?.server?.port || process.env.PORT || 3000)
|
|
},
|
|
|
|
// Path configurations
|
|
SIGMA_REPO_DIR: yamlConfig?.paths?.sigma_repo_dir
|
|
? path.resolve(baseDir, yamlConfig.paths.sigma_repo_dir)
|
|
: path.join(baseDir, 'sigma-repo'),
|
|
|
|
DB_PATH: yamlConfig?.paths?.db_path
|
|
? path.resolve(baseDir, yamlConfig.paths.db_path)
|
|
: path.resolve(baseDir, 'sigma.db'),
|
|
|
|
// Load SIGMA_CLI_PATH from YAML, env, or use default path
|
|
SIGMA_CLI_PATH: yamlConfig?.sigma?.['sigma-cli']?.path
|
|
? path.resolve(baseDir, yamlConfig.sigma['sigma-cli'].path)
|
|
: path.join(process.env.VIRTUAL_ENV || './.venv', 'bin', 'sigma'),
|
|
|
|
// Sigma CLI configuration from YAML
|
|
SIGMA_CLI_CONFIG: {
|
|
backend: yamlConfig?.sigma?.['sigma-cli']?.backend || "lucene",
|
|
target: yamlConfig?.sigma?.['sigma-cli']?.target || "ecs_windows",
|
|
format: yamlConfig?.sigma?.['sigma-cli']?.format || "siem_rule_ndjson"
|
|
},
|
|
|
|
// Sigma Repository configuration from YAML
|
|
SIGMA_REPO_CONFIG: {
|
|
url: yamlConfig?.sigma?.repo?.url || "https://github.com/SigmaHQ/sigma.git",
|
|
branch: yamlConfig?.sigma?.repo?.branch || "main"
|
|
},
|
|
|
|
// Elasticsearch configuration from YAML
|
|
ELASTICSEARCH_CONFIG: {
|
|
protocol: yamlConfig?.elasticsearch?.protocol || "http",
|
|
hosts: yamlConfig?.elasticsearch?.hosts || ["localhost:9200"],
|
|
username: yamlConfig?.elasticsearch?.username || process.env.ELASTIC_USERNAME || "elastic",
|
|
password: yamlConfig?.elasticsearch?.password || process.env.ELASTIC_PASSWORD || "changeme",
|
|
apiEndpoint: yamlConfig?.elasticsearch?.api_endpoint || "http://localhost:5601/api/detection_engine/rules",
|
|
spaces: yamlConfig?.elasticsearch?.spaces || [
|
|
{
|
|
name: "Default",
|
|
id: "default",
|
|
indexPattern: "logs-*",
|
|
emoji: "🔍"
|
|
}
|
|
]
|
|
},
|
|
|
|
// Logging configuration from YAML
|
|
LOGGING_CONFIG: {
|
|
level: yamlConfig?.logging?.level || "info",
|
|
file: yamlConfig?.logging?.file || "./logs/fylgja.log"
|
|
},
|
|
|
|
// Default configuration (fallback)
|
|
DEFAULT_CONFIG: {
|
|
siem: 'elasticsearch',
|
|
lang: 'lucene',
|
|
output: 'ndjson',
|
|
repoUrl: yamlConfig?.sigma?.repo?.url || "https://github.com/SigmaHQ/sigma.git",
|
|
repoBranch: yamlConfig?.sigma?.repo?.branch || "main"
|
|
}
|
|
}; |