feat: add loading config data
Diff
Cargo.lock | 71 +++++++++++++++++++++++++++++++--
Cargo.toml | 1 +-
rgit.conf.example | 30 ++++++++++++++-
src/configuration/mod.rs | 104 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/main.rs | 9 ++++-
5 files changed, 211 insertions(+), 4 deletions(-)
@@ -446,9 +446,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "bytemuck"
version = "1.15.0"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15"
checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5"
[[package]]
name = "byteorder"
@@ -605,6 +605,18 @@ dependencies = [
]
[[package]]
name = "confy"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e37668cb35145dcfaa1931a5f37fde375eeae8068b4c0d2f289da28a270b2d2c"
dependencies = [
"directories",
"serde",
"thiserror",
"toml",
]
[[package]]
name = "console"
version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -820,9 +832,9 @@ dependencies = [
[[package]]
name = "deunicode"
version = "1.4.4"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "322ef0094744e63628e6f0eb2295517f79276a5b342a4c2ff3042566ca181d4e"
checksum = "339544cc9e2c4dc3fc7149fd630c5f22263a4fdf18a98afd0075784968b5cf00"
[[package]]
name = "digest"
@@ -835,6 +847,26 @@ dependencies = [
]
[[package]]
name = "directories"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "dlv-list"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1476,6 +1508,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.5.0",
"libc",
]
[[package]]
name = "librocksdb-sys"
version = "0.16.0+8.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2043,6 +2085,17 @@ dependencies = [
]
[[package]]
name = "redox_users"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]]
name = "regex"
version = "1.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2108,6 +2161,7 @@ dependencies = [
"bytes",
"clap",
"comrak",
"confy",
"console-subscriber",
"flate2",
"futures",
@@ -2668,6 +2722,15 @@ dependencies = [
]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]]
name = "tonic"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -53,6 +53,7 @@ uuid = { version = "1.7", features = ["v4"] }
httparse = "1.7"
yoke = { version = "0.7.1", features = ["derive"] }
rand = "0.8.5"
confy = "0.5.1"
[build-dependencies]
anyhow = "1.0"
@@ -0,0 +1,30 @@
# Set the title and heading of the repository index page
root_title = 'Git repository browser'
# Set a subtitle for the repository index page
root_description = 'Open-source projects available at mydomain.tld'
# Include some more info about example.com on the index page
root_readme = '/config/rgit_about.md'
# Allow download of source tarballs
snapshots = [
'tar.gz',
'tar.bz2',
'zip',
]
# Add a favicon
favicon = '/config/favicon.ico'
# Use a custom logo image
logo = '/config/logo.png'
# Alt text for the custom logo image
logo_alt = '🏔️'
# Url loaded when clicking on the logo
logo_link = '/'
# Allow http transport git clone
enable_http_clone = true
# Show extra links for each repository on the index page
enable_index_links = false
# Show owner on the index page
enable_index_owner = true
# Generate HTTPS clone urls
clone_prefix = 'https://git.mydomain.tld'
# Generate SSH clone urls
ssh_clone_prefix = 'ssh://git.mydomain.tld:/srv/git'
\ No newline at end of file
@@ -0,0 +1,104 @@
use std::vec;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct AppConfig {
pub root_title: String,
pub root_description: String,
pub root_readme: String,
pub snapshots: Vec<String>,
pub favicon: String,
pub logo: String,
pub logo_alt: String,
pub logo_link: String,
pub enable_http_clone: bool,
pub enable_index_links: bool,
pub enable_index_owner: bool,
pub clone_prefix: String,
pub ssh_clone_prefix: String,
}
impl ::std::default::Default for AppConfig {
fn default() -> Self {
Self {
root_title: String::from("Git repository browser"),
root_description: String::new(),
root_readme: String::new(),
snapshots: vec![
String::from("tar.gz"),
String::from("tar.bz2"),
String::from("zip"),
],
favicon: String::new(),
logo: String::new(),
logo_alt: String::from("🏡"),
logo_link: String::from("/"),
enable_http_clone: true,
enable_index_links: false,
enable_index_owner: true,
clone_prefix: String::new(),
ssh_clone_prefix: String::new(),
}
}
}
impl AppConfig {
pub fn load(path: String) -> Self {
confy::load_path(path).unwrap_or_default()
}
}
@@ -47,6 +47,7 @@ use crate::{
layers::logger::LoggingMiddleware,
};
mod configuration;
mod database;
mod git;
mod layers;
@@ -79,6 +80,13 @@ pub struct Args {
#[clap(long, default_value_t = Duration::from_secs(10).into())]
request_timeout: humantime::Duration,
#[clap(long, default_value_t = String::new())]
config: String,
}
#[derive(Debug, Clone, Copy)]
@@ -212,6 +220,7 @@ async fn main() -> Result<(), anyhow::Error> {
.layer(Extension(Arc::new(Git::new(syntax_set))))
.layer(Extension(db))
.layer(Extension(Arc::new(args.scan_path)))
.layer(Extension(configuration::AppConfig::load(args.config)))
.layer(CorsLayer::new());
let listener = TcpListener::bind(&args.bind_address).await?;