-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigLoader.js
More file actions
36 lines (31 loc) · 1.34 KB
/
configLoader.js
File metadata and controls
36 lines (31 loc) · 1.34 KB
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
const fs = require('fs').promises;
const path = require('path');
const loadConfig = async () => {
const configPath = path.join(__dirname, 'config.json');
try {
const configData = await fs.readFile(configPath, 'utf8');
const config = JSON.parse(configData);
validateConfig(config); // Call to validateConfig function to ensure all necessary configurations are present
console.log('Configuration successfully loaded');
return config;
} catch (error) {
console.error('Failed to load configuration:', error.stack);
process.exit(1); // Exit the process if configuration cannot be loaded
}
};
// Function to validate the presence of necessary configurations for DynamoDB and CosmosDB
function validateConfig(config) {
const requiredAwsConfig = ['accessKeyId', 'secretAccessKey', 'region'];
const requiredAzureConfig = ['endpoint', 'key'];
let missingConfig = requiredAwsConfig.filter(key => !config.aws || !config.aws[key]);
if (missingConfig.length > 0) {
console.error(`Missing AWS configuration: ${missingConfig.join(', ')}`);
process.exit(1);
}
missingConfig = requiredAzureConfig.filter(key => !config.azure || !config.azure[key]);
if (missingConfig.length > 0) {
console.error(`Missing Azure CosmosDB configuration: ${missingConfig.join(', ')}`);
process.exit(1);
}
}
module.exports = loadConfig;