pub struct AutoDetectPatterns;Expand description
Auto-detection patterns for identifying sensitive environment variables.
This utility helps determine which environment variables should be encrypted based on their names. It uses common patterns to identify secrets like tokens, passwords, and API keys.
§Examples
use dotenvage::AutoDetectPatterns;
assert!(AutoDetectPatterns::should_encrypt("API_TOKEN"));
assert!(AutoDetectPatterns::should_encrypt("DATABASE_PASSWORD"));
assert!(AutoDetectPatterns::should_encrypt("RECOVERY_PHRASE"));
assert!(!AutoDetectPatterns::should_encrypt("PORT"));
assert!(!AutoDetectPatterns::should_encrypt("AWS_REGION"));Implementations§
Source§impl AutoDetectPatterns
impl AutoDetectPatterns
Sourcepub const ENCRYPT_PATTERNS: &'static [&'static str]
pub const ENCRYPT_PATTERNS: &'static [&'static str]
Patterns indicating a variable should be encrypted.
Variables containing any of these substrings (case-insensitive) will be
automatically encrypted unless they match a pattern in
NEVER_ENCRYPT.
Sourcepub const NEVER_ENCRYPT: &'static [&'static str]
pub const NEVER_ENCRYPT: &'static [&'static str]
Variables that should never be encrypted.
These are typically configuration values that need to be plaintext for readability or compatibility reasons.
Sourcepub fn should_encrypt(key: &str) -> bool
pub fn should_encrypt(key: &str) -> bool
Returns true if an environment variable name should be encrypted.
This checks the variable name against
ENCRYPT_PATTERNS
and NEVER_ENCRYPT lists.
AGE key variables (like EKG_AGE_KEY_NAME, AGE_KEY_NAME, etc.) are
never encrypted as they are used for configuration.
§Examples
use dotenvage::AutoDetectPatterns;
assert!(AutoDetectPatterns::should_encrypt("STRIPE_API_KEY"));
assert!(AutoDetectPatterns::should_encrypt("github_token"));
assert!(!AutoDetectPatterns::should_encrypt("DATABASE_NAME"));
assert!(!AutoDetectPatterns::should_encrypt("EKG_AGE_KEY_NAME"));
assert!(!AutoDetectPatterns::should_encrypt("AGE_KEY_NAME"));Sourcepub fn is_age_key_variable(key: &str) -> bool
pub fn is_age_key_variable(key: &str) -> bool
Check if a variable name is an AGE key variable that should never be encrypted.
AGE key variables are used for configuration and must remain plaintext. This includes:
DOTENVAGE_AGE_KEYAGE_KEYEKG_AGE_KEYAGE_KEY_NAME- Any variable ending with
_AGE_KEY_NAME(e.g.,EKG_AGE_KEY_NAME)
§Examples
use dotenvage::AutoDetectPatterns;
assert!(AutoDetectPatterns::is_age_key_variable("EKG_AGE_KEY_NAME"));
assert!(AutoDetectPatterns::is_age_key_variable("AGE_KEY_NAME"));
assert!(AutoDetectPatterns::is_age_key_variable("DOTENVAGE_AGE_KEY"));
assert!(!AutoDetectPatterns::is_age_key_variable("API_KEY"));