envilder
Version:
A CLI and GitHub Action that securely centralizes your environment variables from AWS SSM or Azure Key Vault as a single source of truth
68 lines • 1.99 kB
JavaScript
/**
* Represents an environment variable with validation and business rules.
*/
export class EnvironmentVariable {
/**
* Creates a new environment variable
*
* @param name - The name of the environment variable
* @param value - The value of the environment variable
* @param isSecret - Whether this variable should be treated as sensitive information
*/
constructor(name, value, isSecret = false) {
this.validate(name, value);
this._name = name;
this._value = value;
this._isSecret = isSecret;
}
/**
* Gets the name of the environment variable
*/
get name() {
return this._name;
}
/**
* Gets the value of the environment variable
*/
get value() {
return this._value;
}
/**
* Gets whether this variable is sensitive information
*/
get isSecret() {
return this._isSecret;
}
/**
* Returns a masked representation of the value for logging
*/
get maskedValue() {
if (!this._isSecret) {
return this._value;
}
return EnvironmentVariable.mask(this._value, 10);
}
/**
* Returns a masked representation of a secret path for safe logging.
*/
static maskSecretPath(path) {
return EnvironmentVariable.mask(path, 3);
}
static mask(value, minLengthToShowTail) {
return value.length > minLengthToShowTail
? '*'.repeat(value.length - 3) + value.slice(-3)
: '*'.repeat(value.length);
}
/**
* Validates the environment variable
*/
validate(name, value) {
if (!name || name.trim() === '') {
throw new Error('Environment variable name cannot be empty');
}
if (value === undefined || value === null) {
throw new Error(`Value for environment variable ${name} cannot be null or undefined`);
}
}
}
//# sourceMappingURL=EnvironmentVariable.js.map