server: update clap and add LDAPS options
This commit is contained in:
committed by
nitnelave
parent
f1b86a16ee
commit
6b6f11db1b
@@ -1,8 +1,8 @@
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use lettre::message::Mailbox;
|
||||
|
||||
/// lldap is a lightweight LDAP server
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
#[clap(version, author)]
|
||||
pub struct CLIOpts {
|
||||
/// Export
|
||||
@@ -11,7 +11,7 @@ pub struct CLIOpts {
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
pub enum Command {
|
||||
/// Export the GraphQL schema to *.graphql.
|
||||
#[clap(name = "export_graphql_schema")]
|
||||
@@ -24,7 +24,7 @@ pub enum Command {
|
||||
SendTestEmail(TestEmailOpts),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
pub struct GeneralConfigOpts {
|
||||
/// Change config file name.
|
||||
#[clap(
|
||||
@@ -40,7 +40,7 @@ pub struct GeneralConfigOpts {
|
||||
pub verbose: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
pub struct RunOpts {
|
||||
#[clap(flatten)]
|
||||
pub general_config: GeneralConfigOpts,
|
||||
@@ -54,10 +54,6 @@ pub struct RunOpts {
|
||||
#[clap(long, env = "LLDAP_LDAP_PORT")]
|
||||
pub ldap_port: Option<u16>,
|
||||
|
||||
/// Change ldap ssl port. Default: 6360
|
||||
#[clap(long, env = "LLDAP_LDAPS_PORT")]
|
||||
pub ldaps_port: Option<u16>,
|
||||
|
||||
/// Change HTTP API port. Default: 17170
|
||||
#[clap(long, env = "LLDAP_HTTP_PORT")]
|
||||
pub http_port: Option<u16>,
|
||||
@@ -68,9 +64,12 @@ pub struct RunOpts {
|
||||
|
||||
#[clap(flatten)]
|
||||
pub smtp_opts: SmtpOpts,
|
||||
|
||||
#[clap(flatten)]
|
||||
pub ldaps_opts: LdapsOpts,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
pub struct TestEmailOpts {
|
||||
#[clap(flatten)]
|
||||
pub general_config: GeneralConfigOpts,
|
||||
@@ -83,10 +82,30 @@ pub struct TestEmailOpts {
|
||||
pub smtp_opts: SmtpOpts,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
#[clap(next_help_heading = Some("LDAPS"), setting = clap::AppSettings::DeriveDisplayOrder)]
|
||||
pub struct LdapsOpts {
|
||||
/// Enable LDAPS. Default: false.
|
||||
#[clap(long, env = "LLDAP_LDAPS_OPTIONS__ENABLED")]
|
||||
pub ldaps_enabled: Option<bool>,
|
||||
|
||||
/// Change ldap ssl port. Default: 6360
|
||||
#[clap(long, env = "LLDAP_LDAPS_OPTIONS__PORT")]
|
||||
pub ldaps_port: Option<u16>,
|
||||
|
||||
/// Ldaps certificate file. Default: cert.pem
|
||||
#[clap(long, env = "LLDAP_LDAPS_OPTIONS__CERT_FILE")]
|
||||
pub ldaps_cert_file: Option<String>,
|
||||
|
||||
/// Ldaps certificate key file. Default: key.pem
|
||||
#[clap(long, env = "LLDAP_LDAPS_OPTIONS__KEY_FILE")]
|
||||
pub ldaps_key_file: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
#[clap(next_help_heading = Some("SMTP"), setting = clap::AppSettings::DeriveDisplayOrder)]
|
||||
pub struct SmtpOpts {
|
||||
/// Sender email address.
|
||||
#[clap(long)]
|
||||
#[clap(long, env = "LLDAP_SMTP_OPTIONS__FROM")]
|
||||
pub smtp_from: Option<Mailbox>,
|
||||
|
||||
@@ -115,7 +134,7 @@ pub struct SmtpOpts {
|
||||
pub smtp_tls_required: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap, Clone)]
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
pub struct ExportGraphQLSchemaOpts {
|
||||
/// Output to a file. If not specified, the config is printed to the standard output.
|
||||
#[clap(short, long)]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
domain::handler::UserId,
|
||||
infra::cli::{GeneralConfigOpts, RunOpts, SmtpOpts, TestEmailOpts},
|
||||
infra::cli::{GeneralConfigOpts, LdapsOpts, RunOpts, SmtpOpts, TestEmailOpts},
|
||||
};
|
||||
use anyhow::{Context, Result};
|
||||
use figment::{
|
||||
@@ -39,13 +39,30 @@ impl std::default::Default for MailOptions {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, derive_builder::Builder)]
|
||||
#[builder(pattern = "owned")]
|
||||
pub struct LdapsOptions {
|
||||
#[builder(default = "false")]
|
||||
pub enabled: bool,
|
||||
#[builder(default = "6360")]
|
||||
pub port: u16,
|
||||
#[builder(default = r#"String::from("cert.pem")"#)]
|
||||
pub cert_file: String,
|
||||
#[builder(default = r#"String::from("key.pem")"#)]
|
||||
pub key_file: String,
|
||||
}
|
||||
|
||||
impl std::default::Default for LdapsOptions {
|
||||
fn default() -> Self {
|
||||
LdapsOptionsBuilder::default().build().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, derive_builder::Builder)]
|
||||
#[builder(pattern = "owned", build_fn(name = "private_build"))]
|
||||
pub struct Configuration {
|
||||
#[builder(default = "3890")]
|
||||
pub ldap_port: u16,
|
||||
#[builder(default = "6360")]
|
||||
pub ldaps_port: u16,
|
||||
#[builder(default = "17170")]
|
||||
pub http_port: u16,
|
||||
#[builder(default = r#"SecUtf8::from("secretjwtsecret")"#)]
|
||||
@@ -64,6 +81,8 @@ pub struct Configuration {
|
||||
pub key_file: String,
|
||||
#[builder(default)]
|
||||
pub smtp_options: MailOptions,
|
||||
#[builder(default)]
|
||||
pub ldaps_options: LdapsOptions,
|
||||
#[builder(default = r#"String::from("http://localhost")"#)]
|
||||
pub http_url: String,
|
||||
#[serde(skip)]
|
||||
@@ -144,10 +163,6 @@ impl ConfigOverrider for RunOpts {
|
||||
config.ldap_port = port;
|
||||
}
|
||||
|
||||
if let Some(port) = self.ldaps_port {
|
||||
config.ldaps_port = port;
|
||||
}
|
||||
|
||||
if let Some(port) = self.http_port {
|
||||
config.http_port = port;
|
||||
}
|
||||
@@ -156,6 +171,7 @@ impl ConfigOverrider for RunOpts {
|
||||
config.http_url = url.to_string();
|
||||
}
|
||||
self.smtp_opts.override_config(config);
|
||||
self.ldaps_opts.override_config(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +182,23 @@ impl ConfigOverrider for TestEmailOpts {
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfigOverrider for LdapsOpts {
|
||||
fn override_config(&self, config: &mut Configuration) {
|
||||
if let Some(enabled) = self.ldaps_enabled {
|
||||
config.ldaps_options.enabled = enabled;
|
||||
}
|
||||
if let Some(port) = self.ldaps_port {
|
||||
config.ldaps_options.port = port;
|
||||
}
|
||||
if let Some(path) = self.ldaps_cert_file.as_ref() {
|
||||
config.ldaps_options.cert_file = path.clone();
|
||||
}
|
||||
if let Some(path) = self.ldaps_key_file.as_ref() {
|
||||
config.ldaps_options.key_file = path.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfigOverrider for GeneralConfigOpts {
|
||||
fn override_config(&self, config: &mut Configuration) {
|
||||
if self.verbose {
|
||||
|
||||
Reference in New Issue
Block a user