mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
feat: Separate Docker config file location and email data storage location #81
This commit is contained in:
@@ -173,7 +173,44 @@ pub struct Settings {
|
|||||||
})
|
})
|
||||||
)]
|
)]
|
||||||
pub bichon_root_dir: String,
|
pub bichon_root_dir: String,
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
env,
|
||||||
|
help = "Set the file path for email index directory",
|
||||||
|
value_parser = ValueParser::new(|s: &str| {
|
||||||
|
let path = PathBuf::from(s);
|
||||||
|
if !path.is_absolute() {
|
||||||
|
return Err("Path must be an absolute directory path".to_string());
|
||||||
|
}
|
||||||
|
if !path.exists() {
|
||||||
|
return Err(format!("Path {:?} does not exist", path));
|
||||||
|
}
|
||||||
|
if !path.is_dir() {
|
||||||
|
return Err(format!("Path {:?} is not a directory", path));
|
||||||
|
}
|
||||||
|
Ok(s.to_string())
|
||||||
|
})
|
||||||
|
)]
|
||||||
|
pub bichon_index_dir: Option<String>,
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
env,
|
||||||
|
help = "Set the file path for email data directory",
|
||||||
|
value_parser = ValueParser::new(|s: &str| {
|
||||||
|
let path = PathBuf::from(s);
|
||||||
|
if !path.is_absolute() {
|
||||||
|
return Err("Path must be an absolute directory path".to_string());
|
||||||
|
}
|
||||||
|
if !path.exists() {
|
||||||
|
return Err(format!("Path {:?} does not exist", path));
|
||||||
|
}
|
||||||
|
if !path.is_dir() {
|
||||||
|
return Err(format!("Path {:?} is not a directory", path));
|
||||||
|
}
|
||||||
|
Ok(s.to_string())
|
||||||
|
})
|
||||||
|
)]
|
||||||
|
pub bichon_data_dir: Option<String>,
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
env,
|
env,
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
use crate::modules::context::Initialize;
|
use crate::modules::context::Initialize;
|
||||||
use crate::modules::settings::cli::SETTINGS;
|
use crate::modules::settings::cli::SETTINGS;
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -35,7 +34,6 @@ const LOG_DIR: &str = "logs";
|
|||||||
const TLS_CERT: &str = "cert.pem";
|
const TLS_CERT: &str = "cert.pem";
|
||||||
const TLS_KEY: &str = "key.pem";
|
const TLS_KEY: &str = "key.pem";
|
||||||
|
|
||||||
|
|
||||||
pub static DATA_DIR_MANAGER: LazyLock<DataDirManager> =
|
pub static DATA_DIR_MANAGER: LazyLock<DataDirManager> =
|
||||||
LazyLock::new(|| DataDirManager::new(PathBuf::from(&SETTINGS.bichon_root_dir)));
|
LazyLock::new(|| DataDirManager::new(PathBuf::from(&SETTINGS.bichon_root_dir)));
|
||||||
|
|
||||||
@@ -49,7 +47,7 @@ pub struct DataDirManager {
|
|||||||
pub tls_key: PathBuf,
|
pub tls_key: PathBuf,
|
||||||
pub envelope_dir: PathBuf,
|
pub envelope_dir: PathBuf,
|
||||||
pub eml_dir: PathBuf,
|
pub eml_dir: PathBuf,
|
||||||
pub log_dir: PathBuf
|
pub log_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Initialize for DataDirManager {
|
impl Initialize for DataDirManager {
|
||||||
@@ -66,6 +64,18 @@ impl Initialize for DataDirManager {
|
|||||||
|
|
||||||
impl DataDirManager {
|
impl DataDirManager {
|
||||||
pub fn new(root_dir: PathBuf) -> Self {
|
pub fn new(root_dir: PathBuf) -> Self {
|
||||||
|
let envelope_dir = if let Some(ref index_dir) = SETTINGS.bichon_index_dir {
|
||||||
|
PathBuf::from(index_dir)
|
||||||
|
} else {
|
||||||
|
root_dir.join(ENVELOPE_DIR)
|
||||||
|
};
|
||||||
|
|
||||||
|
let eml_dir = if let Some(ref data_dir) = SETTINGS.bichon_data_dir {
|
||||||
|
PathBuf::from(data_dir)
|
||||||
|
} else {
|
||||||
|
root_dir.join(EML_DIR)
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
root_dir: root_dir.clone(),
|
root_dir: root_dir.clone(),
|
||||||
meta_db: root_dir.join(META_FILE),
|
meta_db: root_dir.join(META_FILE),
|
||||||
@@ -73,9 +83,9 @@ impl DataDirManager {
|
|||||||
tls_key: root_dir.join(TLS_KEY),
|
tls_key: root_dir.join(TLS_KEY),
|
||||||
tls_cert: root_dir.join(TLS_CERT),
|
tls_cert: root_dir.join(TLS_CERT),
|
||||||
log_dir: root_dir.join(LOG_DIR),
|
log_dir: root_dir.join(LOG_DIR),
|
||||||
envelope_dir: root_dir.join(ENVELOPE_DIR),
|
envelope_dir,
|
||||||
temp_dir: root_dir.join(TMP_DIR),
|
temp_dir: root_dir.join(TMP_DIR),
|
||||||
eml_dir: root_dir.join(EML_DIR),
|
eml_dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user