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            presign,
42        } => {
43            let bucket = S3Store::new(&S3Config {
44                endpoint: endpoint.clone(),
45                bucket: bucket.clone(),
46                region: region.clone(),
47                access_key: access_key.clone(),
48                secret_key: secret_key.clone(),
49                path_style: *path_style,
50                redirect: *presign,
51                lifetime: std::time::Duration::from_secs(config.action_lifetime.into()),
52            })
53            .expect("the bucket configuration is not usable");
54
55            tracing::warn!(
56                "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"
57            );
58
59            if *presign {
60                tracing::warn!(
61                    "LFSX_S3_PRESIGN=true — downloads are redirected to the bucket, so                      lfsx_downloaded_bytes stops counting them and the bucket serves the ranges"
62                );
63            }
64
65            if config.compression.is_some() {
66                tracing::warn!(
67                    "LFSX_COMPRESSION is set and objects are stored in a bucket — the bucket                      holds them uncompressed, because a compressed object is only readable                      through the local file the codec opens"
68                );
69            }
70
71            Store::bucket(bucket, local)
72        }
73    };
74    let locks = LockStore::new(config.storage_root.clone());
75    let authorizer = Authorizer::new(&config.auth);
76
77    routes::router(Arc::new(AppState {
78        store,
79        locks,
80        config,
81        authorizer,
82        metrics: Metrics::new(),
83    }))
84}