configuration: Add smtp config values.
This commit is contained in:
committed by
nitnelave
parent
350fdcdf9b
commit
18e3892e55
@@ -21,7 +21,7 @@ pub enum Command {
|
||||
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
pub struct RunOpts {
|
||||
/// Change config file name
|
||||
/// Change config file name.
|
||||
#[clap(short, long, default_value = "lldap_config.toml")]
|
||||
pub config_file: String,
|
||||
|
||||
@@ -33,7 +33,11 @@ pub struct RunOpts {
|
||||
#[clap(long)]
|
||||
pub ldaps_port: Option<u16>,
|
||||
|
||||
/// Set verbose logging
|
||||
/// Change HTTP API port. Default: 17170
|
||||
#[clap(long)]
|
||||
pub http_port: Option<u16>,
|
||||
|
||||
/// Set verbose logging.
|
||||
#[clap(short, long)]
|
||||
pub verbose: bool,
|
||||
}
|
||||
|
||||
@@ -1,13 +1,39 @@
|
||||
use crate::infra::cli::RunOpts;
|
||||
use anyhow::{Context, Result};
|
||||
use figment::{
|
||||
providers::{Env, Format, Serialized, Toml},
|
||||
Figment,
|
||||
};
|
||||
use lettre::message::Mailbox;
|
||||
use lldap_auth::opaque::{server::ServerSetup, KeyPair};
|
||||
use log::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::infra::cli::RunOpts;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, derive_builder::Builder)]
|
||||
#[builder(pattern = "owned")]
|
||||
pub struct MailOptions {
|
||||
#[builder(default = "false")]
|
||||
pub enable_password_reset: bool,
|
||||
#[builder(default = "None")]
|
||||
pub from: Option<Mailbox>,
|
||||
#[builder(default = "None")]
|
||||
pub reply_to: Option<Mailbox>,
|
||||
#[builder(default = r#""localhost".to_string()"#)]
|
||||
pub server: String,
|
||||
#[builder(default = "587")]
|
||||
pub port: u16,
|
||||
#[builder(default = r#""admin".to_string()"#)]
|
||||
pub user: String,
|
||||
#[builder(default = r#""".to_string()"#)]
|
||||
pub password: String,
|
||||
#[builder(default = "true")]
|
||||
pub tls_required: bool,
|
||||
}
|
||||
|
||||
impl std::default::Default for MailOptions {
|
||||
fn default() -> Self {
|
||||
MailOptionsBuilder::default().build().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, derive_builder::Builder)]
|
||||
#[builder(
|
||||
@@ -35,11 +61,19 @@ pub struct Configuration {
|
||||
pub verbose: bool,
|
||||
#[builder(default = r#"String::from("server_key")"#)]
|
||||
pub key_file: String,
|
||||
#[builder(default)]
|
||||
pub smtp_options: MailOptions,
|
||||
#[serde(skip)]
|
||||
#[builder(field(private), setter(strip_option))]
|
||||
server_setup: Option<ServerSetup>,
|
||||
}
|
||||
|
||||
impl std::default::Default for Configuration {
|
||||
fn default() -> Self {
|
||||
ConfigurationBuilder::default().build().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfigurationBuilder {
|
||||
pub fn build(self) -> Result<Configuration> {
|
||||
let server_setup = get_server_setup(self.key_file.as_deref().unwrap_or("server_key"))?;
|
||||
@@ -77,6 +111,10 @@ impl Configuration {
|
||||
self.ldaps_port = port;
|
||||
}
|
||||
|
||||
if let Some(port) = cli_opts.http_port {
|
||||
self.http_port = port;
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -108,7 +146,7 @@ pub fn init(cli_opts: RunOpts) -> Result<Configuration> {
|
||||
ConfigurationBuilder::default().build().unwrap(),
|
||||
))
|
||||
.merge(Toml::file(config_file))
|
||||
.merge(Env::prefixed("LLDAP_"))
|
||||
.merge(Env::prefixed("LLDAP_").split("__"))
|
||||
.extract()?;
|
||||
|
||||
let mut config = config.merge_with_cli(cli_opts);
|
||||
|
||||
Reference in New Issue
Block a user