1pub mod auth;
2pub mod config;
3pub mod dashboard;
4pub mod error;
5pub mod locks;
6pub mod metrics;
7pub mod model;
8pub mod namespace;
9pub mod range;
10pub mod routes;
11pub mod state;
12pub mod storage;
13
14use std::sync::Arc;
15
16use axum::Router;
17
18use crate::auth::Authorizer;
19use crate::config::Config;
20use crate::locks::LockStore;
21use crate::metrics::Metrics;
22use crate::state::AppState;
23use crate::storage::s3::{S3Config, S3Store};
24use crate::storage::{LocalStore, Store};
25
26pub fn app(config: Config) -> Router {
27 let local = LocalStore::new(config.storage_root.clone())
28 .with_max_object_size(config.max_object_size)
29 .with_compression(config.compression);
30
31 let store = match &config.storage {
32 crate::config::Storage::Local => Store::Local(local),
33 crate::config::Storage::Bucket {
34 endpoint,
35 bucket,
36 region,
37 access_key,
38 secret_key,
39 path_style,
40 } => {
41 let bucket = S3Store::new(&S3Config {
42 endpoint: endpoint.clone(),
43 bucket: bucket.clone(),
44 region: region.clone(),
45 access_key: access_key.clone(),
46 secret_key: secret_key.clone(),
47 path_style: *path_style,
48 })
49 .expect("the bucket configuration is not usable");
50
51 tracing::warn!(
52 "objects are stored in a bucket: collection, deduplication, compression and verification answer 501, and the lfsx_objects_stored and lfsx_store_bytes gauges are not measured — read capacity from the bucket itself"
53 );
54
55 Store::Bucket {
56 bucket: Box::new(bucket),
57 staging: local,
58 }
59 }
60 };
61 let locks = LockStore::new(config.storage_root.clone());
62 let authorizer = Authorizer::new(&config.auth);
63
64 routes::router(Arc::new(AppState {
65 store,
66 locks,
67 config,
68 authorizer,
69 metrics: Metrics::new(),
70 }))
71}