use std::future::Future;
use std::path::Path;
use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_s3::types::Object;
use multihash::Multihash;
use tokio::io::AsyncRead;
use tokio_stream::Stream;
use crate::uri::Host;
use crate::uri::S3Uri;
use crate::Res;
mod s3;
mod workflow;
pub use s3::RemoteS3;
pub use workflow::resolve_workflow;
#[cfg(test)]
pub mod mocks;
#[derive(Debug)]
pub struct S3Attributes {
pub listing_uri: S3Uri,
pub object_uri: S3Uri,
pub hash: Multihash<256>,
pub size: u64,
}
pub struct RemoteObjectStream {
pub body: ByteStream,
pub uri: S3Uri,
}
pub type StreamObjectChunk = Vec<Res<Object>>;
pub type StreamItem = Res<StreamObjectChunk>;
pub trait ObjectsStream: Stream<Item = StreamItem> {}
impl<T: Stream<Item = StreamItem>> ObjectsStream for T {}
pub trait Remote {
fn exists(&self, host: &Option<Host>, s3_uri: &S3Uri)
-> impl Future<Output = Res<bool>> + Send;
fn get_object(
&self,
host: &Option<Host>,
s3_uri: &S3Uri,
) -> impl Future<Output = Res<impl AsyncRead + Send + Unpin>> + Send;
fn get_object_attributes(
&self,
host: &Option<Host>,
listing_uri: &S3Uri,
object: &Object,
) -> impl Future<Output = Res<S3Attributes>>;
fn get_object_stream(
&self,
host: &Option<Host>,
s3_uri: &S3Uri,
) -> impl Future<Output = Res<RemoteObjectStream>> + Send;
fn list_objects(
&self,
host: &Option<Host>,
listing_uri: &S3Uri,
) -> impl Future<Output = impl ObjectsStream> + Send;
fn resolve_url(
&self,
host: &Option<Host>,
s3_uri: &S3Uri,
) -> impl Future<Output = Res<S3Uri>> + Send;
fn put_object(
&self,
host: &Option<Host>,
s3_uri: &S3Uri,
contents: impl Into<ByteStream>,
) -> impl Future<Output = Res>;
fn upload_file(
&self,
host: &Option<Host>,
source_path: impl AsRef<Path>,
dest_uri: &S3Uri,
size: u64,
) -> impl Future<Output = Res<(S3Uri, Multihash<256>)>>;
}