mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
feat: add multi-user support and role-based access control #31
This commit is contained in:
@@ -144,6 +144,15 @@ pub struct Settings {
|
||||
)]
|
||||
pub bichon_encrypt_password_file: Option<String>,
|
||||
|
||||
/// WebUI token expiration time in seconds (default: 7 days)
|
||||
#[clap(
|
||||
long,
|
||||
default_value = "168",
|
||||
env,
|
||||
help = "Set the WebUI token expiration time in hours"
|
||||
)]
|
||||
pub bichon_webui_token_expiration_hours: u32,
|
||||
|
||||
#[clap(
|
||||
long,
|
||||
env,
|
||||
@@ -180,19 +189,6 @@ pub struct Settings {
|
||||
)]
|
||||
pub bichon_envelope_cache_size: Option<usize>,
|
||||
|
||||
/// Enables or disables the access token mechanism for HTTP endpoints.
|
||||
///
|
||||
/// When set to `true`, HTTP requests will be subject to access token validation.
|
||||
/// If the `Authorization` header is missing or the token is invalid, the service will return a 401 Unauthorized response.
|
||||
/// When set to `false`, access token validation will be skipped.
|
||||
#[clap(
|
||||
long,
|
||||
default_value = "false",
|
||||
env,
|
||||
help = "Enables or disables the access token mechanism for HTTP endpoints."
|
||||
)]
|
||||
pub bichon_enable_access_token: bool,
|
||||
|
||||
/// Enables or disables HTTPS for REST API endpoints.
|
||||
///
|
||||
/// When set to `true`, the REST API will use HTTPS with a valid SSL/TLS certificate for secure communication.
|
||||
|
||||
@@ -16,8 +16,68 @@
|
||||
// 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/>.
|
||||
|
||||
use poem_openapi::Object;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::modules::settings::cli::Settings;
|
||||
|
||||
pub mod cli;
|
||||
pub mod dir;
|
||||
pub mod proxy;
|
||||
pub mod system;
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize, Object)]
|
||||
pub struct SystemConfigurations {
|
||||
pub bichon_log_level: String,
|
||||
pub bichon_http_port: i32,
|
||||
pub bichon_bind_ip: Option<String>,
|
||||
pub bichon_public_url: String,
|
||||
|
||||
pub bichon_cors_origins: Option<Vec<String>>,
|
||||
pub bichon_cors_max_age: i32,
|
||||
|
||||
pub bichon_ansi_logs: bool,
|
||||
pub bichon_log_to_file: bool,
|
||||
pub bichon_json_logs: bool,
|
||||
pub bichon_max_server_log_files: usize,
|
||||
|
||||
pub bichon_encrypt_password_set: bool,
|
||||
pub bichon_webui_token_expiration_hours: u32,
|
||||
|
||||
pub bichon_root_dir: String,
|
||||
pub bichon_metadata_cache_size: Option<usize>,
|
||||
pub bichon_envelope_cache_size: Option<usize>,
|
||||
|
||||
pub bichon_enable_rest_https: bool,
|
||||
pub bichon_http_compression_enabled: bool,
|
||||
pub bichon_sync_concurrency: Option<u16>,
|
||||
}
|
||||
|
||||
impl From<&Settings> for SystemConfigurations {
|
||||
fn from(s: &Settings) -> Self {
|
||||
Self {
|
||||
bichon_log_level: s.bichon_log_level.clone(),
|
||||
bichon_http_port: s.bichon_http_port,
|
||||
bichon_bind_ip: s.bichon_bind_ip.clone(),
|
||||
bichon_public_url: s.bichon_public_url.clone(),
|
||||
bichon_cors_origins: s
|
||||
.bichon_cors_origins
|
||||
.as_ref()
|
||||
.map(|set| set.iter().cloned().collect()),
|
||||
bichon_cors_max_age: s.bichon_cors_max_age,
|
||||
bichon_ansi_logs: s.bichon_ansi_logs,
|
||||
bichon_log_to_file: s.bichon_log_to_file,
|
||||
bichon_json_logs: s.bichon_json_logs,
|
||||
bichon_max_server_log_files: s.bichon_max_server_log_files,
|
||||
bichon_encrypt_password_set: s.bichon_encrypt_password.is_some()
|
||||
|| s.bichon_encrypt_password_file.is_some(),
|
||||
bichon_webui_token_expiration_hours: s.bichon_webui_token_expiration_hours,
|
||||
bichon_root_dir: s.bichon_root_dir.clone(),
|
||||
bichon_metadata_cache_size: s.bichon_metadata_cache_size,
|
||||
bichon_envelope_cache_size: s.bichon_envelope_cache_size,
|
||||
bichon_enable_rest_https: s.bichon_enable_rest_https,
|
||||
bichon_http_compression_enabled: s.bichon_http_compression_enabled,
|
||||
bichon_sync_concurrency: s.bichon_sync_concurrency,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
// 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/>.
|
||||
|
||||
|
||||
use native_db::*;
|
||||
use native_model::{native_model, Model};
|
||||
use poem_openapi::Object;
|
||||
@@ -132,10 +131,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_proxy_urls() {
|
||||
let urls = vec![
|
||||
"socks5://127.0.0.1:1080",
|
||||
"http://127.0.0.1:8080",
|
||||
];
|
||||
let urls = vec!["socks5://127.0.0.1:1080", "http://127.0.0.1:8080"];
|
||||
|
||||
for url in urls {
|
||||
let proxy = Proxy::new(url.to_string());
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
use crate::modules::database::manager::DB_MANAGER;
|
||||
use crate::modules::database::{find_impl, upsert_impl};
|
||||
use crate::modules::error::BichonResult;
|
||||
use crate::utc_now;
|
||||
// use crate::modules::database::manager::DB_MANAGER;
|
||||
// use crate::modules::database::{find_impl, upsert_impl};
|
||||
// use crate::modules::error::BichonResult;
|
||||
// use crate::utc_now;
|
||||
use native_db::*;
|
||||
use native_model::{native_model, Model};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -37,34 +37,34 @@ pub struct SystemSetting {
|
||||
}
|
||||
|
||||
impl SystemSetting {
|
||||
pub fn new(key: String, value: String) -> Self {
|
||||
Self {
|
||||
key,
|
||||
value,
|
||||
created_at: utc_now!(),
|
||||
updated_at: utc_now!(),
|
||||
}
|
||||
}
|
||||
// pub fn new(key: String, value: String) -> Self {
|
||||
// Self {
|
||||
// key,
|
||||
// value,
|
||||
// created_at: utc_now!(),
|
||||
// updated_at: utc_now!(),
|
||||
// }
|
||||
// }
|
||||
//overwrite
|
||||
pub async fn set(&self) -> BichonResult<()> {
|
||||
upsert_impl(DB_MANAGER.meta_db(), self.to_owned()).await
|
||||
}
|
||||
// pub async fn set(&self) -> BichonResult<()> {
|
||||
// upsert_impl(DB_MANAGER.meta_db(), self.to_owned()).await
|
||||
// }
|
||||
|
||||
pub fn get(key: &str) -> BichonResult<Option<SystemSetting>> {
|
||||
find_impl(DB_MANAGER.meta_db(), key)
|
||||
}
|
||||
// pub fn get(key: &str) -> BichonResult<Option<SystemSetting>> {
|
||||
// find_impl(DB_MANAGER.meta_db(), key)
|
||||
// }
|
||||
|
||||
// pub async fn list() -> RustMailerResult<Vec<SystemSetting>> {
|
||||
// list_all_impl(DB_MANAGER.metadata_db()).await
|
||||
// }
|
||||
|
||||
pub fn get_existing_value(key: &str) -> BichonResult<Option<String>> {
|
||||
let setting = Self::get(key)?;
|
||||
Ok(setting.map(|s| s.value))
|
||||
}
|
||||
// pub fn get_existing_value(key: &str) -> BichonResult<Option<String>> {
|
||||
// let setting = Self::get(key)?;
|
||||
// Ok(setting.map(|s| s.value))
|
||||
// }
|
||||
|
||||
pub async fn set_value(key: &str, value: String) -> BichonResult<()> {
|
||||
let setting = Self::new(key.to_string(), value);
|
||||
setting.set().await
|
||||
}
|
||||
// pub async fn set_value(key: &str, value: String) -> BichonResult<()> {
|
||||
// let setting = Self::new(key.to_string(), value);
|
||||
// setting.set().await
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user