@syntropysoft/praetorian
Version:
Praetorian CLI – A universal multi-environment configuration validator for DevSecOps teams. Validate, compare, and secure YAML/ENV files with ease.
53 lines • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvFileAdapter = void 0;
const AbstractFileAdapter_1 = require("../base/AbstractFileAdapter");
class EnvFileAdapter extends AbstractFileAdapter_1.AbstractFileAdapter {
canHandle(filePath) {
return filePath.endsWith('.env') || filePath.startsWith('env.');
}
async read(filePath) {
this.validateFileExists(filePath);
const content = await this.readFileContent(filePath);
return this.parseEnvContent(content);
}
parseEnvContent(content) {
const result = {};
const lines = content.split('\n');
for (const line of lines) {
const trimmed = line.trim();
// Skip empty lines and comments
if (!trimmed || trimmed.startsWith('#')) {
continue;
}
// Handle key=value format
const equalIndex = trimmed.indexOf('=');
if (equalIndex > 0) {
const key = trimmed.substring(0, equalIndex).trim();
const value = trimmed.substring(equalIndex + 1).trim();
// Remove quotes if present
const cleanValue = this.removeQuotes(value);
if (key) {
result[key] = cleanValue;
}
}
}
return result;
}
removeQuotes(value) {
// Remove single or double quotes from beginning and end
if ((value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))) {
return value.slice(1, -1);
}
return value;
}
getFormat() {
return 'env';
}
getSupportedExtensions() {
return ['.env'];
}
}
exports.EnvFileAdapter = EnvFileAdapter;
//# sourceMappingURL=EnvFileAdapter.js.map