Skip to main content

lfsx_server/
lib.rs

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 page;
10pub mod range;
11pub mod routes;
12pub mod state;
13pub mod storage;
14
15use std::sync::Arc;
16
17use axum::Router;
18
19use crate::auth::Authorizer;
20use crate::config::Config;
21use crate::locks::LockStore;
22use crate::metrics::Metrics;
23use crate::state::AppState;
24use crate::storage::s3::{S3Config, S3Store};
25use crate::storage::{LocalStore, Store};
26
27pub fn app(config: Config) -> Router {
28    let local = LocalStore::new(config.storage_root.clone())
29        .with_max_object_size(config.max_object_size)
30        .with_compression(config.compression);
31
32    let store = match &config.storage {
33        crate::config::Storage::Local => Store::Local(local),
34        crate::config::Storage::Bucket {
35            endpoint,
36            bucket,
37            region,
38            access_key,
39            secret_key,
40            path_style,
41        } => {
42            let bucket = S3Store::new(&S3Config {
43                endpoint: endpoint.clone(),
44                bucket: bucket.clone(),
45                region: region.clone(),
46                access_key: access_key.clone(),
47                secret_key: secret_key.clone(),
48                path_style: *path_style,
49            })
50            .expect("the bucket configuration is not usable");
51
52            tracing::warn!(
53                "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"
54            );
55
56            Store::Bucket {
57                bucket: Box::new(bucket),
58                staging: local,
59            }
60        }
61    };
62    let locks = LockStore::new(config.storage_root.clone());
63    let authorizer = Authorizer::new(&config.auth);
64
65    routes::router(Arc::new(AppState {
66        store,
67        locks,
68        config,
69        authorizer,
70        metrics: Metrics::new(),
71    }))
72}