From 6b67f8bcfd9e80a1f98ae2bce1342068526a4b35 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Mon, 13 Mar 2023 16:48:46 -0300 Subject: [PATCH] Support non-persistent configuration with DELTACHAT_* env #3986 This way we can test some recently added config options that we don't want to expose in UI like DeleteToTrash or SignUnencrypted. Note that persistent config options like DeleteToTrash should remain anyway because they allow fine-grained (per-account) control. Having them matters for tests also. --- CHANGELOG.md | 1 + src/config.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68d6667d3..76b768dc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Drop unused SQL columns #4141 - "full message view" not needed because of footers that go to contact status #4151 - Pick up system's light/dark mode in generated message HTML #4150 +- Support non-persistent configuration with DELTACHAT_* env ### Fixes - Fix segmentation fault if `dc_context_unref()` is called during diff --git a/src/config.rs b/src/config.rs index 2fa64ae96..39cd00877 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,6 @@ //! # Key-value configuration management. +use std::env; use std::str::FromStr; use anyhow::{ensure, Context as _, Result}; @@ -317,6 +318,11 @@ impl Context { /// Get a configuration key. Returns `None` if no value is set, and no default value found. pub async fn get_config(&self, key: Config) -> Result> { + let env_key = format!("DELTACHAT_{}", key.as_ref().to_uppercase()); + if let Ok(value) = env::var(env_key) { + return Ok(Some(value)); + } + let value = match key { Config::Selfavatar => { let rel_path = self.sql.get_raw_config(key.as_ref()).await?;