mirror of https://github.com/realaravinth/gitpad
feat: get admin_email in settings and validate admin_email and source_code
SUMMARY New field is added to settings to receive email of the admin of the instance. source_code is a link to the repository of the source code of a GitPad instance, set_source_code is defined to build a HTTP link to the exact commit from which the instance binary was built. NOTE Current Settings::set_source_code assumes the provided HTTP link to point to a forge belonging to the GitHub-family(GitHub, Gitea and GitLab), provisions must be made to accommodate other forges as well.master
parent
b7fe7ea5d5
commit
fc40706ca9
|
@ -2,6 +2,7 @@ log = "info" # possible values: "info", "warn", "trace", "error", "debug"
|
||||||
source_code = "https://github.com/realaravinth/gitpad"
|
source_code = "https://github.com/realaravinth/gitpad"
|
||||||
allow_registration = true # allow registration on server
|
allow_registration = true # allow registration on server
|
||||||
allow_demo = true # allow demo on server
|
allow_demo = true # allow demo on server
|
||||||
|
admin_email = "admin@gitpad.example.com"
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
# The port at which you want authentication to listen to
|
# The port at which you want authentication to listen to
|
||||||
|
|
|
@ -22,6 +22,7 @@ use derive_more::Display;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
|
@ -137,19 +138,32 @@ pub struct Database {
|
||||||
pub database_type: DBType,
|
pub database_type: DBType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Validate, Clone, Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub log: LogLevel,
|
pub log: LogLevel,
|
||||||
pub database: Database,
|
pub database: Database,
|
||||||
pub allow_registration: bool,
|
pub allow_registration: bool,
|
||||||
pub allow_demo: bool,
|
pub allow_demo: bool,
|
||||||
pub server: Server,
|
pub server: Server,
|
||||||
|
#[validate(url)]
|
||||||
pub source_code: String,
|
pub source_code: String,
|
||||||
pub repository: Repository,
|
pub repository: Repository,
|
||||||
|
#[validate(email)]
|
||||||
|
pub admin_email: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
fn set_source_code(&mut self) {
|
||||||
|
if !self.source_code.ends_with('/') {
|
||||||
|
self.source_code.push('/');
|
||||||
|
}
|
||||||
|
let mut base = url::Url::parse(&self.source_code).unwrap();
|
||||||
|
base = base.join("tree/").unwrap();
|
||||||
|
base = base.join(crate::GIT_COMMIT_HASH).unwrap();
|
||||||
|
self.source_code = base.into();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new() -> Result<Self, ConfigError> {
|
pub fn new() -> Result<Self, ConfigError> {
|
||||||
let mut s = Config::new();
|
let mut s = Config::new();
|
||||||
|
|
||||||
|
@ -194,10 +208,13 @@ impl Settings {
|
||||||
|
|
||||||
set_database_url(&mut s);
|
set_database_url(&mut s);
|
||||||
|
|
||||||
let settings: Settings = s.try_into()?;
|
let mut settings: Settings = s.try_into()?;
|
||||||
|
|
||||||
settings.log.set_log_level();
|
settings.log.set_log_level();
|
||||||
settings.repository.create_root_dir();
|
settings.repository.create_root_dir();
|
||||||
|
settings.validate().unwrap();
|
||||||
|
settings.set_source_code();
|
||||||
|
settings.validate().unwrap();
|
||||||
|
|
||||||
Ok(settings)
|
Ok(settings)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue