Skip to content

Commit

Permalink
S3 storage backend
Browse files Browse the repository at this point in the history
  • Loading branch information
tinybeachthor committed Jul 5, 2023
1 parent b9476ee commit c441ff5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use async_compression::Level as CompressionLevel;

use common::signing::Keypair;
use auth::{HS256Key, decode_token_hs256_secret_base64};
use crate::storage::local::LocalStorageConfig;
use crate::narinfo::Compression as NixCompression;
use crate::storage::local::LocalStorageConfig;
use crate::storage::s3::S3StorageConfig;

const CONFIG_PATH: &str = "/trestripes/nixcache/config.toml";

Expand Down Expand Up @@ -113,6 +114,9 @@ pub enum StorageConfig {
/// Local file storage.
#[serde(rename = "local")]
Local(LocalStorageConfig),
/// S3 file storage.
#[serde(rename = "s3")]
S3(S3StorageConfig),
}

/// Compression configuration.
Expand Down
24 changes: 16 additions & 8 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use tower_http::trace::TraceLayer;

use crate::config::{Config, StorageConfig};
use crate::error::{ErrorKind, ServerResult};
use crate::storage::{StorageBackend, local::LocalBackend};
use crate::storage::{
StorageBackend,
local::LocalBackend, s3::S3Backend,
};
use crate::access::RequireAuth;

/// Global server state.
Expand All @@ -30,13 +33,18 @@ pub struct State {
}
impl State {
async fn new(config: Config) -> Result<Arc<Self>> {
let storage = match &config.storage {
StorageConfig::Local(local_config) => {
let local = LocalBackend::new(local_config.clone()).await?;
let boxed: Box<dyn StorageBackend> = Box::new(local);
Arc::new(boxed)
}
};
let storage = Arc::new(match &config.storage {
StorageConfig::Local(config) => {
let backend = LocalBackend::new(config.clone()).await?;
let boxed: Box<dyn StorageBackend> = Box::new(backend);
boxed
},
StorageConfig::S3(config) => {
let backend = S3Backend::new(config.clone()).await?;
let boxed: Box<dyn StorageBackend> = Box::new(backend);
boxed
},
});

Ok(Arc::new(Self {
config,
Expand Down

0 comments on commit c441ff5

Please sign in to comment.