Skip to content
Clone

refactor(dvcs): migrate per-crate config to central lib/config crate (git, gitauth, gitlfs, gitsmart, gitssh, gitsync)

zhenyi committed
parent 139e88a commit 223a973 Browse files

31 files changed

+54 −149

File tree 31
Modified dvcs/codesearch/lib.rs View dvcs/codesearch/lib.rs
@@ -0,0 +1 @@
1
Modified dvcs/git/archive/usecase.rs View dvcs/git/archive/usecase.rs
@@ -93,11 +93,11 @@
9393 use crate::GitRepository;
9494 use crate::object::cache::ObjectCache;
9595 use cache::CacheBuilder;
96 use storage::config::StorageSettings;
96 use config::storage::StorageSettings;
9797 use storage::local::LocalStorage;
9898
9999 fn make_repo(dir: &std::path::Path, name: &str) -> GitRepository {
100 let cache_cfg = cache::config::cache::AppCacheSettings::default();
100 let cache_cfg = config::cache::AppCacheSettings::default();
101101 let cache = block_on(CacheBuilder::from_config(cache_cfg).build())
102102 .expect("cache build")
103103 .expect("cache enabled");
@@ -109,7 +109,7 @@
109109 };
110110 let mut settings = StorageSettings::default();
111111 settings.set_local(
112 storage::config::LocalStorageSettings::builder()
112 config::storage::LocalStorageSettings::builder()
113113 .root_dir(dir.join("storage").to_path_buf())
114114 .build(),
115115 );
Modified dvcs/git/lfs/usecase.rs View dvcs/git/lfs/usecase.rs
@@ -161,8 +161,8 @@
161161 use super::*;
162162 use crate::object::cache::ObjectCache;
163163 use cache::CacheBuilder;
164 use config::storage::StorageSettings;
164165 use std::sync::Arc;
165 use storage::config::StorageSettings;
166166 use storage::local::LocalStorage;
167167
168168 fn block_on<F: std::future::Future>(f: F) -> F::Output {
@@ -174,7 +174,7 @@
174174 }
175175
176176 fn make_repo(dir: &std::path::Path) -> GitRepository {
177 let cache_cfg = cache::config::cache::AppCacheSettings::default();
177 let cache_cfg = config::cache::AppCacheSettings::default();
178178 let cache = Arc::new(
179179 block_on(CacheBuilder::from_config(cache_cfg).build())
180180 .expect("cache build")
@@ -187,7 +187,7 @@
187187 };
188188 let mut settings = StorageSettings::default();
189189 settings.set_local(
190 storage::config::LocalStorageSettings::builder()
190 config::storage::LocalStorageSettings::builder()
191191 .root_dir(dir.join("storage").to_path_buf())
192192 .build(),
193193 );
Modified dvcs/git/tree/usecase.rs View dvcs/git/tree/usecase.rs
@@ -310,7 +310,7 @@
310310 use crate::GitRepository;
311311 use crate::object::cache::ObjectCache;
312312 use cache::CacheBuilder;
313 use storage::config::StorageSettings;
313 use config::storage::StorageSettings;
314314 use storage::local::LocalStorage;
315315
316316 fn block_on<F: std::future::Future>(f: F) -> F::Output {
@@ -322,7 +322,7 @@
322322 }
323323
324324 fn make_repo(dir: &std::path::Path, name: &str) -> GitRepository {
325 let cache_cfg = cache::config::cache::AppCacheSettings::default();
325 let cache_cfg = config::cache::AppCacheSettings::default();
326326 let cache = block_on(CacheBuilder::from_config(cache_cfg).build())
327327 .expect("cache build")
328328 .expect("cache enabled");
@@ -334,7 +334,7 @@
334334 };
335335 let mut settings = StorageSettings::default();
336336 settings.set_local(
337 storage::config::LocalStorageSettings::builder()
337 config::storage::LocalStorageSettings::builder()
338338 .root_dir(dir.join("storage").to_path_buf())
339339 .build(),
340340 );
Modified dvcs/git/Cargo.toml View dvcs/git/Cargo.toml
@@ -25,4 +25,8 @@
2525bytes.workspace = true
2626async-trait.workspace = true
2727async-graphql.workspace = true
28base64.workspace = true
No newline at end of file
28base64.workspace = true
29
30[dev-dependencies]
31config.workspace = true
32tempfile.workspace = true
No newline at end of file
Modified dvcs/gitauth/Cargo.toml View dvcs/gitauth/Cargo.toml
@@ -14,6 +14,7 @@
1414auth.workspace = true
1515base64.workspace = true
1616cache.workspace = true
17config.workspace = true
1718db.workspace = true
1819jwt.workspace = true
1920metrics.workspace = true
@@ -27,4 +28,5 @@
2728
2829[dev-dependencies]
2930argon2.workspace = true
31config.workspace = true
3032password-hash.workspace = true
No newline at end of file
Deleted dvcs/gitauth/config.rs
@@ -1,12 +0,0 @@
1#[derive(Debug, Clone)]
2pub struct GitAuthConfig {
3 pub allow_anonymous_read: bool,
4}
5
6impl Default for GitAuthConfig {
7 fn default() -> Self {
8 Self {
9 allow_anonymous_read: true,
10 }
11 }
12}
Modified dvcs/gitauth/lib.rs View dvcs/gitauth/lib.rs
@@ -1,5 +1,4 @@
11pub mod basic;
2pub mod config;
32pub mod error;
43pub mod metrics;
54pub mod permission;
@@ -10,7 +9,6 @@
109pub mod testing;
1110
1211pub use basic::{BasicCredentials, parse_authorization};
13pub use config::GitAuthConfig;
1412pub use error::{GitAuthError, GitAuthResult};
1513pub use resolve::ResolvedRepo;
1614pub use service::{AuthenticatedUser, GitAuthService};
Modified dvcs/gitauth/service.rs View dvcs/gitauth/service.rs
@@ -8,11 +8,11 @@
88use repo::actor::{ActorContext, RepoAccess};
99use uuid::Uuid;
1010
11use crate::config::GitAuthConfig;
1211use crate::error::{GitAuthError, GitAuthResult};
1312use crate::metrics;
1413use crate::permission;
1514use crate::resolve::{self, ResolvedRepo};
15use config::git::GitAuthConfig;
1616
1717#[derive(Clone)]
1818pub struct GitAuthService {
@@ -153,11 +153,12 @@
153153#[cfg(test)]
154154mod tests {
155155 use super::*;
156 use config::jwt::JwtSettings;
156157 use db::channel::channels;
157158 use db::conn::sea_orm::{ActiveModelTrait, ConnectionTrait, DatabaseConnection, Set};
158159 use db::repo::{repo_collaborations, repos};
159160 use db::space::spaces;
160 use jwt::{JwtSettings, SigningKeyCache};
161 use jwt::SigningKeyCache;
161162 use std::sync::Arc;
162163 use time::OffsetDateTime;
163164 use tokio::sync::RwLock;
Modified dvcs/gitlfs/Cargo.toml View dvcs/gitlfs/Cargo.toml
@@ -24,5 +24,6 @@
2424url.workspace = true
2525
2626[dev-dependencies]
27config.workspace = true
2728tokio.workspace = true
2829tempfile.workspace = true
No newline at end of file
Modified dvcs/gitlfs/store.rs View dvcs/gitlfs/store.rs
@@ -284,7 +284,7 @@
284284#[cfg(test)]
285285mod tests {
286286 use super::*;
287 use storage::config::{LocalStorageSettings, StorageSettings};
287 use config::storage::{LocalStorageSettings, StorageSettings};
288288
289289 fn make_store() -> (tempfile::TempDir, DefaultLfsStore) {
290290 let dir = tempfile::tempdir().expect("tempdir");
Modified dvcs/gitsmart/tests/smart.rs View dvcs/gitsmart/tests/smart.rs
@@ -3,6 +3,9 @@
33use std::sync::Arc;
44use std::time::Duration;
55
6use config::git::SmartConfig;
7use config::jwt::JwtSettings;
8use config::storage::{LocalStorageSettings, StorageSettings};
69use db::channel::channels;
710use db::conn::Db;
811use db::conn::sea_orm::{
@@ -13,12 +16,11 @@
1316use db::space::spaces;
1417use db::user::users;
1518use gitauth::GitAuthService;
19use gitsmart::SmartService;
1620use gitsmart::handler::router;
17use gitsmart::{SmartConfig, SmartService};
18use jwt::{JwtSettings, JwtState, SigningKeyCache};
21use jwt::{JwtState, SigningKeyCache};
1922use password_hash::rand_core::OsRng;
2023use password_hash::{PasswordHasher, SaltString};
21use storage::config::{LocalStorageSettings, StorageSettings};
2224use tempfile::TempDir;
2325use time::OffsetDateTime;
2426use tokio::sync::RwLock;
Modified dvcs/gitsmart/Cargo.toml View dvcs/gitsmart/Cargo.toml
@@ -18,6 +18,7 @@
1818base64.workspace = true
1919bytes.workspace = true
2020cache.workspace = true
21config.workspace = true
2122flate2.workspace = true
2223futures.workspace = true
2324gitauth.workspace = true
Deleted dvcs/gitsmart/config.rs
@@ -1,18 +0,0 @@
1#[derive(Debug, Clone)]
2pub struct SmartConfig {
3 pub git_storage_root: String,
4 pub lfs_storage_root: String,
5 pub object_cache_prefix: String,
6 pub object_cache_ttl: u64,
7}
8
9impl Default for SmartConfig {
10 fn default() -> Self {
11 Self {
12 git_storage_root: "/var/lib/repo/git".to_string(),
13 lfs_storage_root: "/var/lib/repo/lfs".to_string(),
14 object_cache_prefix: "gitsmart".to_string(),
15 object_cache_ttl: 300,
16 }
17 }
18}
Modified dvcs/gitsmart/lib.rs View dvcs/gitsmart/lib.rs
@@ -1,4 +1,3 @@
1pub mod config;
21pub mod error;
32pub mod handler;
43pub mod metrics;
@@ -6,7 +5,6 @@
65pub mod push;
76pub mod service;
87
9pub use config::SmartConfig;
108pub use error::{SmartError, SmartResult};
119pub use push::{NoopPushBackend, PushCoordinator, PushOperations, RedisPushBackend};
1210pub use service::{SmartService, SmartState};
Modified dvcs/gitsmart/service.rs View dvcs/gitsmart/service.rs
@@ -5,8 +5,8 @@
55use gitauth::GitAuthService;
66use storage::StorageRepository;
77
8use crate::config::SmartConfig;
98use crate::push::{NoopPushBackend, PushCoordinator, PushOperations, RedisPushBackend};
9use config::git::SmartConfig;
1010
1111pub use gitauth::ResolvedRepo;
1212
@@ -18,7 +18,7 @@
1818 pub cache: Arc<cache::Cache>,
1919 pub kv: Option<Arc<RedisCache>>,
2020 pub queue: Option<Arc<queue::Queue>>,
21 pub sync_settings: gitsync::SyncSettings,
21 pub sync_settings: config::git::SyncSettings,
2222}
2323
2424impl SmartService {
@@ -27,7 +27,7 @@
2727 config: SmartConfig,
2828 storage: Arc<dyn StorageRepository>,
2929 ) -> crate::SmartResult<Self> {
30 let cache_cfg = cache::config::cache::AppCacheSettings::default();
30 let cache_cfg = config::cache::AppCacheSettings::default();
3131 let cache = cache::CacheBuilder::from_config(cache_cfg)
3232 .build()
3333 .await
@@ -40,7 +40,7 @@
4040 cache: Arc::new(cache),
4141 kv: None,
4242 queue: None,
43 sync_settings: gitsync::SyncSettings::default(),
43 sync_settings: config::git::SyncSettings::default(),
4444 })
4545 }
4646
@@ -54,7 +54,7 @@
5454 self
5555 }
5656
57 pub fn with_sync_settings(mut self, settings: gitsync::SyncSettings) -> Self {
57 pub fn with_sync_settings(mut self, settings: config::git::SyncSettings) -> Self {
5858 self.sync_settings = settings;
5959 self
6060 }
Modified dvcs/gitssh/handler/mod.rs View dvcs/gitssh/handler/mod.rs
@@ -10,9 +10,9 @@
1010
1111use db::user::users;
1212
13use crate::config::GitSshConfig;
1413use crate::handler::git_op::GitOperation;
1514use crate::service::GitSshService;
15use config::git::GitSshConfig;
1616
1717pub(crate) mod git_op;
1818
Modified dvcs/gitssh/tests/ssh_roundtrip.rs View dvcs/gitssh/tests/ssh_roundtrip.rs
@@ -4,6 +4,8 @@
44use std::sync::Arc;
55use std::time::Duration;
66
7use config::git::GitSshConfig;
8use config::jwt::JwtSettings;
79use db::channel::channels;
810use db::conn::Db;
911use db::conn::sea_orm::{
@@ -15,9 +17,9 @@
1517use db::user::user_ssh_keys;
1618use db::user::users;
1719use gitauth::GitAuthService;
20use gitssh::GitSshService;
1821use gitssh::server::{generate_host_key, serve_on_listener};
19use gitssh::{GitSshConfig, GitSshService};
20use jwt::{JwtSettings, JwtState, SigningKeyCache};
22use jwt::{JwtState, SigningKeyCache};
2123use sha2::{Digest, Sha256};
2224use tempfile::TempDir;
2325use time::OffsetDateTime;
Modified dvcs/gitssh/Cargo.toml View dvcs/gitssh/Cargo.toml
@@ -12,6 +12,7 @@
1212name = "gitssh"
1313[dependencies]
1414russh.workspace = true
15config.workspace = true
1516ssh-key.workspace = true
1617bytes.workspace = true
1718futures.workspace = true
@@ -31,6 +32,7 @@
3132repo = { path = "../../lib/repo" }
3233sea-orm.workspace = true
3334[dev-dependencies]
35config.workspace = true
3436rand.workspace = true
3537tempfile.workspace = true
3638time.workspace = true
Deleted dvcs/gitssh/config.rs
@@ -1,32 +0,0 @@
1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4pub struct GitSshConfig {
5 pub bind_addr: String,
6 pub port: u16,
7 pub host_key_path: String,
8 pub git_storage_root: String,
9 pub max_sessions: usize,
10 pub banner: Option<String>,
11 pub auth_rejection_time: Duration,
12 pub inactivity_timeout: Option<Duration>,
13 pub keepalive_interval: Duration,
14 pub keepalive_max: u32,
15}
16
17impl Default for GitSshConfig {
18 fn default() -> Self {
19 Self {
20 bind_addr: "0.0.0.0".to_string(),
21 port: 2222,
22 host_key_path: "/etc/gitssh/ssh_host_ed25519_key".to_string(),
23 git_storage_root: "/var/lib/repo/git".to_string(),
24 max_sessions: 32,
25 banner: None,
26 auth_rejection_time: Duration::from_secs(1),
27 inactivity_timeout: Some(Duration::from_secs(300)),
28 keepalive_interval: Duration::from_secs(30),
29 keepalive_max: 3,
30 }
31 }
32}
Modified dvcs/gitssh/lib.rs View dvcs/gitssh/lib.rs
@@ -1,4 +1,3 @@
1pub mod config;
21pub mod error;
32pub mod git_service;
43mod handler;
@@ -6,7 +5,6 @@
65pub mod server;
76pub mod service;
87
9pub use config::GitSshConfig;
108pub use error::{SshError, SshResult};
119pub use git_service::GitService;
1210pub use server::run_ssh;
Modified dvcs/gitssh/server.rs View dvcs/gitssh/server.rs
@@ -7,10 +7,10 @@
77use russh::{MethodKind, MethodSet, SshId, server};
88use tokio::sync::Semaphore;
99
10use crate::config::GitSshConfig;
1110use crate::error::{SshError, SshResult};
1211use crate::handler::GitSshHandler;
1312use crate::service::GitSshService;
13use config::git::GitSshConfig;
1414
1515pub struct GitSshServer {
1616 service: Arc<GitSshService>,
Modified dvcs/gitssh/service.rs View dvcs/gitssh/service.rs
@@ -5,7 +5,7 @@
55use gitauth::{GitAuthService, ResolvedRepo};
66use gitsmart::push::{NoopPushBackend, PushCoordinator, RedisPushBackend};
77
8use crate::config::GitSshConfig;
8use config::git::GitSshConfig;
99
1010#[derive(Clone)]
1111pub struct GitSshService {
@@ -13,7 +13,7 @@
1313 pub config: GitSshConfig,
1414 pub kv: Option<Arc<RedisCache>>,
1515 pub queue: Option<Arc<queue::Queue>>,
16 pub sync_settings: gitsync::SyncSettings,
16 pub sync_settings: config::git::SyncSettings,
1717}
1818
1919impl GitSshService {
@@ -23,7 +23,7 @@
2323 config,
2424 kv: None,
2525 queue: None,
26 sync_settings: gitsync::SyncSettings::default(),
26 sync_settings: config::git::SyncSettings::default(),
2727 }
2828 }
2929
@@ -37,7 +37,7 @@
3737 self
3838 }
3939
40 pub fn with_sync_settings(mut self, settings: gitsync::SyncSettings) -> Self {
40 pub fn with_sync_settings(mut self, settings: config::git::SyncSettings) -> Self {
4141 self.sync_settings = settings;
4242 self
4343 }
Modified dvcs/gitsync/Cargo.toml View dvcs/gitsync/Cargo.toml
@@ -15,6 +15,7 @@
1515[dependencies]
1616async-trait.workspace = true
1717cache.workspace = true
18config.workspace = true
1819db.workspace = true
1920futures.workspace = true
2021git.workspace = true
Modified dvcs/gitsync/event.rs View dvcs/gitsync/event.rs
@@ -66,7 +66,7 @@
6666
6767pub async fn enqueue_post_receive(
6868 queue: &queue::Queue,
69 settings: &crate::SyncSettings,
69 settings: &config::git::SyncSettings,
7070 task: &PostReceiveTask,
7171) -> Result<(), queue::QueueError> {
7272 let payload = serde_json::to_vec(task)?;
@@ -81,7 +81,7 @@
8181
8282pub async fn enqueue_post_receive_dlq(
8383 queue: &queue::Queue,
84 settings: &crate::SyncSettings,
84 settings: &config::git::SyncSettings,
8585 task: &PostReceiveTask,
8686) -> Result<(), queue::QueueError> {
8787 let payload = serde_json::to_vec(task)?;
Modified dvcs/gitsync/languages.rs View dvcs/gitsync/languages.rs
@@ -8,7 +8,7 @@
88use uuid::Uuid;
99
1010use crate::error::{SyncError, SyncResult};
11use crate::settings::SyncSettings;
11use config::git::SyncSettings;
1212
1313/// swallowed (non-fatal).
1414pub async fn sync_repo_languages(
Modified dvcs/gitsync/lib.rs View dvcs/gitsync/lib.rs
@@ -6,7 +6,6 @@
66pub mod languages;
77pub mod lock;
88pub mod post_receive;
9pub mod settings;
109pub mod stats;
1110pub mod sync;
1211pub mod tags;
@@ -17,7 +16,6 @@
1716pub use event::{PostReceiveRefUpdate, PostReceiveTask, enqueue_post_receive};
1817pub use lock::{SyncLock, acquire_lock};
1918pub use post_receive::{enqueue_post_receive_push, prepare_post_receive};
20pub use settings::SyncSettings;
2119pub use sync::RepoSync;
2220pub use webhook::{NoopWebhookTx, WebhookTx};
2321pub use worker::{RunningWorker, SyncWorker};
Modified dvcs/gitsync/post_receive.rs View dvcs/gitsync/post_receive.rs
@@ -5,8 +5,8 @@
55
66use uuid::Uuid;
77
8use crate::SyncSettings;
98use crate::event::{PostReceiveRefUpdate, PostReceiveTask, enqueue_post_receive};
9use config::git::SyncSettings;
1010
1111pub const POST_RECEIVE_HOOK: &str = "post-receive";
1212pub const CAPTURE_FILE: &str = "_gta_post_receive";
Deleted dvcs/gitsync/settings.rs
@@ -1,42 +0,0 @@
1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4pub struct SyncSettings {
5 pub queue_topic: String,
6 pub dlq_topic: String,
7 pub group_id: String,
8 pub concurrency: usize,
9 pub lock_ttl_secs: u64,
10 pub max_commits_per_sync: usize,
11 pub max_lock_retries: u32,
12 pub language_timeout_secs: u64,
13 pub max_languages: usize,
14}
15
16impl Default for SyncSettings {
17 fn default() -> Self {
18 Self {
19 queue_topic: "gta.git.sync".to_string(),
20 dlq_topic: "gta.git.sync.dlq".to_string(),
21 group_id: "git-sync-workers".to_string(),
22 concurrency: 4,
23 lock_ttl_secs: 300,
24 max_commits_per_sync: 10_000,
25 max_lock_retries: 5,
26 language_timeout_secs: 30,
27 max_languages: 50,
28 }
29 }
30}
31
32impl SyncSettings {
33 #[must_use]
34 pub fn lock_ttl(&self) -> Duration {
35 Duration::from_secs(self.lock_ttl_secs)
36 }
37
38 #[must_use]
39 pub fn language_timeout(&self) -> Duration {
40 Duration::from_secs(self.language_timeout_secs)
41 }
42}
Modified dvcs/gitsync/sync.rs View dvcs/gitsync/sync.rs
@@ -1,10 +1,10 @@
11use std::sync::Arc;
22
33use cache::{Cache, RedisCache};
4use config::repo::SharedRepoConfig;
45use db::conn::Db;
56use db::repo::repos;
67use git::{GitRepository, gitcli};
7use repo::config::SharedRepoConfig;
88use repo::path::git_bare_path;
99use sea_orm::{DatabaseTransaction, TransactionTrait};
1010use storage::StorageRepository;
@@ -13,8 +13,8 @@
1313use crate::commits::{self, CommitData};
1414use crate::error::{SyncError, SyncResult};
1515use crate::lock;
16use crate::settings::SyncSettings;
1716use crate::{branches, languages, stats, tags};
17use config::git::SyncSettings;
1818
1919#[derive(Clone)]
2020pub struct RepoSync {
Modified dvcs/gitsync/worker.rs View dvcs/gitsync/worker.rs
@@ -1,18 +1,18 @@
11use std::sync::Arc;
22
33use cache::{Cache, RedisCache};
4use config::repo::SharedRepoConfig;
45use db::conn::Db;
56use db::repo::repos;
67use queue::{AutoOffsetReset, Queue, QueueError, RawMessage, SubscriptionMode};
7use repo::config::SharedRepoConfig;
88use sea_orm::EntityTrait;
99use storage::StorageRepository;
1010
1111use crate::event::PostReceiveTask;
12use crate::settings::SyncSettings;
1312use crate::sync::RepoSync;
1413use crate::webhook::WebhookTx;
1514use crate::{SyncError, SyncResult};
15use config::git::SyncSettings;
1616
1717const ATTEMPT_KEY_PREFIX: &str = "git:sync:attempts:";
1818const ATTEMPT_TTL_SECS: u64 = 3600;