chore: update deps
This commit is contained in:
parent
59aafc037e
commit
a146386e68
4 changed files with 338 additions and 328 deletions
515
Cargo.lock
generated
515
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -11,13 +11,13 @@ build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-rt = "2.7"
|
actix-rt = "2.7"
|
||||||
config = "0.11.0"
|
config = "0.13.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
tera = "1.15"
|
tera = "1.15"
|
||||||
tokio = { version = "1.17", features = ["fs", "time"] }
|
tokio = { version = "1.17", features = ["fs", "time"] }
|
||||||
url = { version = "2.2.2", features = ["serde"] }
|
url = { version = "2.2.2", features = ["serde"] }
|
||||||
validator = { version = "0.14", features = ["derive"]}
|
validator = { version = "0.15", features = ["derive"]}
|
||||||
derive_more = "0.99.17"
|
derive_more = "0.99.17"
|
||||||
log = "0.4.16"
|
log = "0.4.16"
|
||||||
|
|
||||||
|
|
146
src/settings.rs
146
src/settings.rs
|
@ -180,51 +180,57 @@ impl Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Result<Self, ConfigError> {
|
pub fn new() -> Result<Self, ConfigError> {
|
||||||
let mut s = Config::new();
|
let mut s = Config::builder();
|
||||||
|
|
||||||
// setting default values
|
// setting default values
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
s.set_default("database.pool", 2.to_string())
|
{
|
||||||
.expect("Couldn't get the number of CPUs");
|
s = s
|
||||||
|
.set_default("database.pool", "2")
|
||||||
|
.expect("Couldn't get the number of CPUs");
|
||||||
|
}
|
||||||
|
|
||||||
const CURRENT_DIR: &str = "./config/default.toml";
|
const CURRENT_DIR: &str = "./config/default.toml";
|
||||||
const ETC: &str = "/etc/starchart/config.toml";
|
const ETC: &str = "/etc/starchart/config.toml";
|
||||||
|
|
||||||
if let Ok(path) = env::var("STARCHART_CONFIG") {
|
let mut read_file = false;
|
||||||
s.merge(File::with_name(&path))?;
|
if Path::new(CURRENT_DIR).exists() {
|
||||||
} else if Path::new(CURRENT_DIR).exists() {
|
|
||||||
// merging default config from file
|
// merging default config from file
|
||||||
s.merge(File::with_name(CURRENT_DIR))?;
|
s = s.add_source(File::with_name(CURRENT_DIR));
|
||||||
} else if Path::new(ETC).exists() {
|
read_file = true;
|
||||||
s.merge(File::with_name(ETC))?;
|
}
|
||||||
} else {
|
|
||||||
|
if Path::new(ETC).exists() {
|
||||||
|
s = s.add_source(File::with_name(ETC));
|
||||||
|
read_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(path) = env::var("STARCHART_CONFIG") {
|
||||||
|
s = s.add_source(File::with_name(&path));
|
||||||
|
read_file = true;
|
||||||
|
}
|
||||||
|
if !read_file {
|
||||||
log::warn!("configuration file not found");
|
log::warn!("configuration file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
s.merge(Environment::with_prefix("STARCHART").separator("__"))?;
|
s = s.add_source(Environment::with_prefix("STARCHART").separator("__"));
|
||||||
|
|
||||||
check_url(&s);
|
|
||||||
|
|
||||||
match env::var("PORT") {
|
match env::var("PORT") {
|
||||||
Ok(val) => {
|
Ok(val) => s = s.set_override("server.port", val).unwrap(),
|
||||||
s.set("server.port", val).unwrap();
|
|
||||||
}
|
|
||||||
Err(e) => warn!("couldn't interpret PORT: {}", e),
|
Err(e) => warn!("couldn't interpret PORT: {}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
match env::var("DATABASE_URL") {
|
match env::var("DATABASE_URL") {
|
||||||
Ok(val) => {
|
Ok(val) => s = s.set_override("database.url", val).unwrap(),
|
||||||
let url = Url::parse(&val).expect("couldn't parse Database URL");
|
//let url = Url::parse(&val).expect("couldn't parse Database URL");
|
||||||
s.set("database.url", url.to_string())
|
//TODO: sqlite fails Url::parse, figure out workarounds
|
||||||
.expect("unable to set database URL");
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("couldn't interpret DATABASE_URL: {}", e);
|
warn!("couldn't interpret DATABASE_URL: {}", e);
|
||||||
set_database_url(&mut s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut settings: Settings = s.try_into()?;
|
let mut settings = s.build()?.try_deserialize::<Settings>()?;
|
||||||
|
settings.check_url();
|
||||||
|
|
||||||
settings.log.set_log_level();
|
settings.log.set_log_level();
|
||||||
settings.repository.create_root_dir();
|
settings.repository.create_root_dir();
|
||||||
|
@ -234,58 +240,54 @@ impl Settings {
|
||||||
|
|
||||||
Ok(settings)
|
Ok(settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
|
fn check_url(&self) {
|
||||||
|
Url::parse(&self.source_code).expect("Please enter a URL for source_code in settings");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
//#[cfg(not(tarpaulin_include))]
|
||||||
fn check_url(s: &Config) {
|
//fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) {
|
||||||
let url = s
|
// s.set("database.username", database_conf.username.clone())
|
||||||
.get::<String>("source_code")
|
// .expect("Couldn't set database username");
|
||||||
.expect("Couldn't access source_code");
|
// s.set("database.password", database_conf.password.clone())
|
||||||
|
// .expect("Couldn't access database password");
|
||||||
|
// s.set("database.hostname", database_conf.hostname.clone())
|
||||||
|
// .expect("Couldn't access database hostname");
|
||||||
|
// s.set("database.port", database_conf.port as i64)
|
||||||
|
// .expect("Couldn't access database port");
|
||||||
|
// s.set("database.name", database_conf.name.clone())
|
||||||
|
// .expect("Couldn't access database name");
|
||||||
|
// s.set(
|
||||||
|
// "database.database_type",
|
||||||
|
// format!("{}", database_conf.database_type),
|
||||||
|
// )
|
||||||
|
// .expect("Couldn't access database type");
|
||||||
|
//}
|
||||||
|
|
||||||
Url::parse(&url).expect("Please enter a URL for source_code in settings");
|
//#[cfg(not(tarpaulin_include))]
|
||||||
}
|
//fn set_database_url(s: &mut Config) {
|
||||||
|
// s.set(
|
||||||
#[cfg(not(tarpaulin_include))]
|
// "database.url",
|
||||||
fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) {
|
// format!(
|
||||||
s.set("database.username", database_conf.username.clone())
|
// r"{}://{}:{}@{}:{}/{}",
|
||||||
.expect("Couldn't set database username");
|
// s.get::<String>("database.database_type")
|
||||||
s.set("database.password", database_conf.password.clone())
|
// .expect("Couldn't access database database_type"),
|
||||||
.expect("Couldn't access database password");
|
// s.get::<String>("database.username")
|
||||||
s.set("database.hostname", database_conf.hostname.clone())
|
// .expect("Couldn't access database username"),
|
||||||
.expect("Couldn't access database hostname");
|
// s.get::<String>("database.password")
|
||||||
s.set("database.port", database_conf.port as i64)
|
// .expect("Couldn't access database password"),
|
||||||
.expect("Couldn't access database port");
|
// s.get::<String>("database.hostname")
|
||||||
s.set("database.name", database_conf.name.clone())
|
// .expect("Couldn't access database hostname"),
|
||||||
.expect("Couldn't access database name");
|
// s.get::<String>("database.port")
|
||||||
s.set(
|
// .expect("Couldn't access database port"),
|
||||||
"database.database_type",
|
// s.get::<String>("database.name")
|
||||||
format!("{}", database_conf.database_type),
|
// .expect("Couldn't access database name")
|
||||||
)
|
// ),
|
||||||
.expect("Couldn't access database type");
|
// )
|
||||||
}
|
// .expect("Couldn't set databse url");
|
||||||
|
//}
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
fn set_database_url(s: &mut Config) {
|
|
||||||
s.set(
|
|
||||||
"database.url",
|
|
||||||
format!(
|
|
||||||
r"{}://{}:{}@{}:{}/{}",
|
|
||||||
s.get::<String>("database.database_type")
|
|
||||||
.expect("Couldn't access database database_type"),
|
|
||||||
s.get::<String>("database.username")
|
|
||||||
.expect("Couldn't access database username"),
|
|
||||||
s.get::<String>("database.password")
|
|
||||||
.expect("Couldn't access database password"),
|
|
||||||
s.get::<String>("database.hostname")
|
|
||||||
.expect("Couldn't access database hostname"),
|
|
||||||
s.get::<String>("database.port")
|
|
||||||
.expect("Couldn't access database port"),
|
|
||||||
s.get::<String>("database.name")
|
|
||||||
.expect("Couldn't access database name")
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.expect("Couldn't set databse url");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -44,6 +44,7 @@ pub mod sqlx_sqlite {
|
||||||
|
|
||||||
pub async fn get_data() -> (BoxDB, Arc<Data>) {
|
pub async fn get_data() -> (BoxDB, Arc<Data>) {
|
||||||
let url = env::var("SQLITE_DATABASE_URL").unwrap();
|
let url = env::var("SQLITE_DATABASE_URL").unwrap();
|
||||||
|
env::set_var("DATABASE_URL", &url);
|
||||||
println!("found db url: {url}");
|
println!("found db url: {url}");
|
||||||
let mut settings = Settings::new().unwrap();
|
let mut settings = Settings::new().unwrap();
|
||||||
settings.database.url = url.clone();
|
settings.database.url = url.clone();
|
||||||
|
|
Loading…
Reference in a new issue