Remove S3 + encryption
All checks were successful
All checks were successful
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
use mime::Mime;
|
||||
use pile_config::Label;
|
||||
use pile_io::{SyncReadBridge, chacha::ChaChaReaderv1Async};
|
||||
use pile_io::SyncReadBridge;
|
||||
use smartstring::{LazyCompact, SmartString};
|
||||
use std::{collections::HashMap, fs::File, path::PathBuf, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
source::{DirDataSource, S3DataSource, encrypt_path},
|
||||
value::ItemReader,
|
||||
};
|
||||
use crate::{source::DirDataSource, value::ItemReader};
|
||||
|
||||
//
|
||||
// MARK: item
|
||||
@@ -23,58 +20,19 @@ pub enum Item {
|
||||
path: PathBuf,
|
||||
group: Arc<HashMap<Label, Box<Item>>>,
|
||||
},
|
||||
|
||||
S3 {
|
||||
source: Arc<S3DataSource>,
|
||||
mime: Mime,
|
||||
|
||||
key: SmartString<LazyCompact>,
|
||||
group: Arc<HashMap<Label, Box<Item>>>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Item {
|
||||
/// Open the item for reading. For S3, performs a HEAD request to determine
|
||||
/// the object size.
|
||||
/// Open the item for reading.
|
||||
pub async fn read(&self) -> Result<ItemReader, std::io::Error> {
|
||||
Ok(match self {
|
||||
Self::File { path, .. } => ItemReader::File(File::open(path)?),
|
||||
|
||||
Self::S3 { source, key, .. } => {
|
||||
let logical_key = key.as_str();
|
||||
|
||||
let s3_key_part: SmartString<LazyCompact> = match &source.encryption_key {
|
||||
None => logical_key.into(),
|
||||
Some(enc_key) => encrypt_path(enc_key, logical_key).into(),
|
||||
};
|
||||
|
||||
let full_key: SmartString<LazyCompact> = match &source.prefix {
|
||||
None => s3_key_part,
|
||||
Some(p) => {
|
||||
if p.ends_with('/') {
|
||||
format!("{p}{s3_key_part}").into()
|
||||
} else {
|
||||
format!("{p}/{s3_key_part}").into()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let reader = source.client.get(&full_key).await?;
|
||||
|
||||
match source.encryption_key {
|
||||
None => ItemReader::S3(reader),
|
||||
Some(enc_key) => {
|
||||
ItemReader::EncryptedS3(ChaChaReaderv1Async::new(reader, enc_key).await?)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn source_name(&self) -> &pile_config::Label {
|
||||
match self {
|
||||
Self::File { source, .. } => &source.name,
|
||||
Self::S3 { source, .. } => &source.name,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +45,6 @@ impl Item {
|
||||
.to_str()
|
||||
.expect("path is not utf-8")
|
||||
.into(),
|
||||
Self::S3 { key, .. } => key.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,14 +63,12 @@ impl Item {
|
||||
pub fn mime(&self) -> &Mime {
|
||||
match self {
|
||||
Self::File { mime, .. } => mime,
|
||||
Self::S3 { mime, .. } => mime,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn group(&self) -> &HashMap<Label, Box<Self>> {
|
||||
match self {
|
||||
Self::File { group, .. } => group,
|
||||
Self::S3 { group, .. } => group,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use pile_io::{AsyncReader, AsyncSeekReader, S3Reader, chacha::ChaChaReaderv1Async};
|
||||
use pile_io::{AsyncReader, AsyncSeekReader};
|
||||
use std::{fs::File, io::Seek};
|
||||
|
||||
//
|
||||
@@ -7,16 +7,12 @@ use std::{fs::File, io::Seek};
|
||||
|
||||
pub enum ItemReader {
|
||||
File(File),
|
||||
S3(S3Reader),
|
||||
EncryptedS3(ChaChaReaderv1Async<S3Reader>),
|
||||
}
|
||||
|
||||
impl AsyncReader for ItemReader {
|
||||
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
||||
match self {
|
||||
Self::File(x) => std::io::Read::read(x, buf),
|
||||
Self::S3(x) => x.read(buf).await,
|
||||
Self::EncryptedS3(x) => x.read(buf).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +21,6 @@ impl AsyncSeekReader for ItemReader {
|
||||
async fn seek(&mut self, pos: std::io::SeekFrom) -> Result<u64, std::io::Error> {
|
||||
match self {
|
||||
Self::File(x) => x.seek(pos),
|
||||
Self::S3(x) => x.seek(pos).await,
|
||||
Self::EncryptedS3(x) => x.seek(pos).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user