chore: lints and update config 11.x -> 13.x
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Aravinth Manivannan 2022-12-11 19:27:59 +05:30
parent 1b40c44854
commit a4f4903120
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
6 changed files with 165 additions and 128 deletions

218
Cargo.lock generated
View file

@ -75,7 +75,7 @@ dependencies = [
"bytestring",
"http",
"regex",
"serde 1.0.149",
"serde",
"tracing",
]
@ -161,7 +161,7 @@ dependencies = [
"once_cell",
"pin-project-lite",
"regex",
"serde 1.0.149",
"serde",
"serde_json",
"serde_urlencoded",
"smallvec",
@ -249,12 +249,6 @@ dependencies = [
"alloc-no-stdlib",
]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "async-trait"
version = "0.1.59"
@ -272,7 +266,7 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e"
dependencies = [
"num-traits 0.2.15",
"num-traits",
]
[[package]]
@ -433,7 +427,7 @@ dependencies = [
"libconfig",
"log",
"pretty_env_logger",
"serde 1.0.149",
"serde",
"serde_json",
"sqlx",
"url",
@ -441,15 +435,18 @@ dependencies = [
[[package]]
name = "config"
version = "0.11.0"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369"
checksum = "d379af7f68bfc21714c6c7dea883544201741d2ce8274bb12fa54f89507f52a7"
dependencies = [
"async-trait",
"json5",
"lazy_static",
"nom 5.1.2",
"nom",
"pathdiff",
"ron",
"rust-ini",
"serde 1.0.149",
"serde-hjson",
"serde",
"serde_json",
"toml",
"yaml-rust",
@ -644,6 +641,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "dlv-list"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
[[package]]
name = "dotenvy"
version = "0.15.6"
@ -656,7 +659,7 @@ version = "0.1.0"
dependencies = [
"async-trait",
"libconductor",
"serde 1.0.149",
"serde",
"serde_json",
]
@ -666,7 +669,7 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
dependencies = [
"serde 1.0.149",
"serde",
]
[[package]]
@ -1027,6 +1030,17 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "json5"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1"
dependencies = [
"pest",
"pest_derive",
"serde",
]
[[package]]
name = "language-tags"
version = "0.3.2"
@ -1039,19 +1053,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]]
name = "libc"
version = "0.2.138"
@ -1064,16 +1065,16 @@ version = "0.1.0"
dependencies = [
"async-trait",
"libconfig",
"serde 1.0.149",
"serde",
"serde_json",
]
[[package]]
name = "libconfig"
version = "0.1.0"
source = "git+https://git.batsense.net/librepages/libconfig#76416ccdb622f48362502a24dbc4ba90ed054225"
source = "git+https://git.batsense.net/librepages/libconfig#f54290c4bae26b51a4945e0bf812e2b99856963b"
dependencies = [
"serde 1.0.149",
"serde",
]
[[package]]
@ -1173,17 +1174,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"lexical-core",
"memchr",
"version_check",
]
[[package]]
name = "nom"
version = "7.1.1"
@ -1194,15 +1184,6 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
dependencies = [
"num-traits 0.2.15",
]
[[package]]
name = "num-traits"
version = "0.2.15"
@ -1228,6 +1209,16 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
[[package]]
name = "ordered-multimap"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a"
dependencies = [
"dlv-list",
"hashbrown",
]
[[package]]
name = "os_str_bytes"
version = "6.4.1"
@ -1288,12 +1279,62 @@ version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1"
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "percent-encoding"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pest"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc8bed3549e0f9b0a2a78bf7c0018237a2cdf085eecbbc048e52612438e4e9d0"
dependencies = [
"thiserror",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdc078600d06ff90d4ed238f0119d84ab5d43dbaad278b0e33a8820293b32344"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28a1af60b1c4148bb269006a750cff8e2ea36aff34d2d96cf7be0b14d1bed23c"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pest_meta"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fec8605d59fc2ae0c6c1aefc0c7c7a9769732017c0ce07f7a9cfffa7b4404f20"
dependencies = [
"once_cell",
"pest",
"sha1",
]
[[package]]
name = "pin-project-lite"
version = "0.2.9"
@ -1453,10 +1494,25 @@ dependencies = [
]
[[package]]
name = "rust-ini"
version = "0.13.0"
name = "ron"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a"
dependencies = [
"base64",
"bitflags",
"serde",
]
[[package]]
name = "rust-ini"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df"
dependencies = [
"cfg-if",
"ordered-multimap",
]
[[package]]
name = "rustc_version"
@ -1530,12 +1586,6 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]]
name = "serde"
version = "1.0.149"
@ -1545,18 +1595,6 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-hjson"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
dependencies = [
"lazy_static",
"num-traits 0.1.43",
"regex",
"serde 0.8.23",
]
[[package]]
name = "serde_derive"
version = "1.0.149"
@ -1576,7 +1614,7 @@ checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
dependencies = [
"itoa",
"ryu",
"serde 1.0.149",
"serde",
]
[[package]]
@ -1588,7 +1626,7 @@ dependencies = [
"form_urlencoded",
"itoa",
"ryu",
"serde 1.0.149",
"serde",
]
[[package]]
@ -1660,7 +1698,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f87e292b4291f154971a43c3774364e2cbcaec599d3f5bf6fa9d122885dbc38a"
dependencies = [
"itertools",
"nom 7.1.1",
"nom",
"unicode_categories",
]
@ -1712,7 +1750,7 @@ dependencies = [
"rand",
"rustls",
"rustls-pemfile",
"serde 1.0.149",
"serde",
"serde_json",
"sha1",
"sha2",
@ -1741,7 +1779,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"serde 1.0.149",
"serde",
"serde_json",
"sha2",
"sqlx-core",
@ -1761,12 +1799,6 @@ dependencies = [
"tokio-rustls",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stringprep"
version = "0.1.2"
@ -1836,7 +1868,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"itoa",
"serde 1.0.149",
"serde",
"time-core",
"time-macros",
]
@ -1932,7 +1964,7 @@ version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
dependencies = [
"serde 1.0.149",
"serde",
]
[[package]]
@ -1962,6 +1994,12 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "ucd-trie"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
[[package]]
name = "unicode-bidi"
version = "0.3.8"
@ -2010,7 +2048,7 @@ dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"serde 1.0.149",
"serde",
]
[[package]]
@ -2101,9 +2139,9 @@ dependencies = [
[[package]]
name = "webpki-roots"
version = "0.22.5"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be"
checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87"
dependencies = [
"webpki",
]

View file

@ -20,7 +20,7 @@ serde = { version = "1", features=["derive"]}
actix-web-codegen-const-routes = { version = "0.1.0", tag = "0.1.0", git = "https://github.com/realaravinth/actix-web-codegen-const-routes" }
libconfig = { version = "0.1.0", git = "https://git.batsense.net/librepages/libconfig" }
derive_builder = "0.11.2"
config = "0.11"
config = "0.13"
derive_more = "0.99.17"
url = { version = "2.2.2", features = ["serde"]}
serde_json = { version ="1", features = ["raw_value"]}

View file

@ -57,6 +57,7 @@ async fn post_event(ctx: AppCtx, payload: web::Json<EventType>) -> ServiceResult
#[cfg(test)]
pub mod tests {
use actix_web::{http::StatusCode, test, App};
use libconductor::NewSite;
use super::*;
@ -77,7 +78,12 @@ pub mod tests {
base64::encode(format!("{}:{}", creds.username.clone(), creds.password))
);
let new_hostname = EventType::NewHostname("demo.librepages.org".into());
let msg = NewSite {
hostname: "demo.librepages.org".into(),
branch: "librepages".into(),
path: "/tmp/librepages".into(),
};
let new_hostname = EventType::NewSite(msg);
// upload json
let upload_json = test::call_service(

View file

@ -37,13 +37,9 @@ impl Ctx {
pub async fn new(s: &Settings) -> ArcCtx {
let source_code = {
let mut url = s.source_code.clone();
if !url.ends_with('/') {
url.push('/');
}
let mut base = url::Url::parse(&url).unwrap();
base = base.join("tree/").unwrap();
base = base.join(crate::GIT_COMMIT_HASH).unwrap();
base.into()
url = url.join("tree/").unwrap();
url = url.join(crate::GIT_COMMIT_HASH).unwrap();
url.into()
};
let conductor: Box<dyn Conductor> = match s.conductor {

View file

@ -17,7 +17,7 @@
use std::env;
use std::path::Path;
use config::{Config, ConfigError, Environment, File};
use config::{builder::DefaultState, Config, ConfigBuilder, ConfigError, Environment, File};
use derive_more::Display;
use log::info;
use log::warn;
@ -63,7 +63,7 @@ pub struct Settings {
pub debug: bool,
pub api_keys: Vec<Creds>,
pub server: Server,
pub source_code: String,
pub source_code: Url,
pub conductor: ConductorType,
}
@ -76,35 +76,34 @@ impl Settings {
}
pub fn new() -> Result<Self, ConfigError> {
let mut s = Config::new();
let mut s = Config::builder();
const CURRENT_DIR: &str = "./config/config.toml";
const ETC: &str = "/etc/lpconductor/config.toml";
if let Ok(path) = env::var("LPCONDUCTOR_CONFIG") {
s.merge(File::with_name(&path))?;
s = s.add_source(File::with_name(&path));
} else if Path::new(CURRENT_DIR).exists() {
// 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() {
s.merge(File::with_name(ETC))?;
s = s.add_source(File::with_name(ETC));
} else {
warn!("configuration file not found");
}
s.merge(Environment::with_prefix(PREFIX).separator(SEPARATOR))?;
set_separator_field(&mut s);
check_url(&s);
s = s.add_source(Environment::with_prefix(PREFIX).separator(SEPARATOR));
s = set_separator_field(s);
match env::var("PORT") {
Ok(val) => {
s.set("server.port", val).unwrap();
s = s.set_override("server.port", val).unwrap();
}
Err(e) => warn!("couldn't interpret PORT: {}", e),
}
match s.try_into::<Self>() {
let s = s.build()?;
match s.try_deserialize::<Self>() {
Ok(val) => {
Ok(val)
},
@ -114,36 +113,34 @@ impl Settings {
}
#[cfg(not(tarpaulin_include))]
fn set_separator_field(s: &mut Config) {
fn set_separator_field(mut s: ConfigBuilder<DefaultState>) -> ConfigBuilder<DefaultState> {
// ref: https://github.com/mehcode/config-rs/issues/391
fn from_env(s: &mut Config, env_name: &str, config_name: &str) {
fn from_env(
s: ConfigBuilder<DefaultState>,
env_name: &str,
config_name: &str,
) -> ConfigBuilder<DefaultState> {
if let Ok(val) = env::var(env_name) {
info!("Overriding {config_name} with data from env var {env_name}");
s.set(config_name, val)
.unwrap_or_else(|_| panic!("Couldn't set {config_name} from env var {env_name}"));
s.set_override(config_name, val)
.unwrap_or_else(|_| panic!("Couldn't set {config_name} from env var {env_name}"))
} else {
s
}
}
from_env(s, &format!("{PREFIX}{SEPARATOR}SOURCE_CODE"), "source_code");
from_env(
s = from_env(s, &format!("{PREFIX}{SEPARATOR}SOURCE_CODE"), "source_code");
s = from_env(
s,
&format!("{PREFIX}{SEPARATOR}SERVER{SEPARATOR}URL_PREFIX"),
"server.url_prefix",
);
from_env(
s = from_env(
s,
&format!("{PREFIX}{SEPARATOR}SERVER{SEPARATOR}PROXY_HAS_TLS"),
"server.proxy_has_tls",
);
}
#[cfg(not(tarpaulin_include))]
fn check_url(s: &Config) {
let url = s
.get::<String>("source_code")
.expect("Couldn't access source_code");
Url::parse(&url).expect("Please enter a URL for source_code in settings");
s
}
#[cfg(test)]