Support alternative S3-compatible crate stores
Diff
.env | 1 -
.gitignore | 2 ++
Cargo.lock | 1 +
chartered-fs/Cargo.toml | 1 +
chartered-fs/src/lib.rs | 22 ++++++++++++++++++----
chartered-frontend/src/components/FeaturedCrate.svelte | 2 +-
6 files changed, 21 insertions(+), 8 deletions(-)
@@ -1,1 +1,0 @@
DATABASE_URL=chartered.db
@@ -1,4 +1,6 @@
/target
.idea/
/chartered.db
.DS_Store
.env
@@ -669,6 +669,7 @@
"async-trait",
"aws-config",
"aws-sdk-s3",
"base64",
"bytes",
"http",
"itertools",
@@ -9,6 +9,7 @@
async-trait = "0.1"
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", tag = "release-2022-08-08", package = "aws-config" }
aws-sdk-s3 = { git = "https://github.com/awslabs/aws-sdk-rust", tag = "release-2022-08-08", package = "aws-sdk-s3" }
base64 = "0.13"
bytes = "1.1"
http = "0.2"
itertools = "0.10"
@@ -10,6 +10,7 @@
model::ObjectCannedAcl,
presigning::config::PresigningConfig,
types::{ByteStream, SdkError},
Endpoint,
};
use bytes::Bytes;
use itertools::Itertools;
@@ -36,8 +37,8 @@
UuidParse(#[from] uuid::Error),
#[error("path missing from uri")]
MissingPath,
#[error("host missing from uri")]
MissingHost,
#[error("invalid uri: {0}")]
InvalidUri(http::uri::InvalidUri),
#[error("bucket missing from uri")]
MissingBucket,
#[error("invalid aws presigning config: {0}")]
@@ -56,13 +57,23 @@
Ok(match uri.scheme() {
"s3" => {
let shared_config = aws_config::load_from_env().await;
let mut shared_config = aws_config::from_env();
if let Some(host) = uri.host() {
shared_config = shared_config.endpoint_resolver(Endpoint::immutable(
format!("https://{}", host)
.parse()
.map_err(Error::InvalidUri)?,
));
}
let shared_config = shared_config.load().await;
let client = aws_sdk_s3::Client::new(&shared_config);
let mut path = uri.path_segments().ok_or(Error::MissingPath)?;
Self::S3(S3 {
host: uri.host().ok_or(Error::MissingHost)?.to_string(),
bucket: path.next().ok_or(Error::MissingBucket)?.to_string(),
path: Itertools::intersperse(path, "/").collect(),
client,
@@ -198,7 +209,6 @@
#[derive(Debug)]
#[allow(dead_code)]
pub struct S3 {
host: String,
bucket: String,
path: String,
client: aws_sdk_s3::Client,
@@ -227,7 +237,7 @@
self.client
.put_object()
.key(format!("{}/{}", self.path, file_ref.reference))
.content_md5(format!("{:x}", md5::compute(&data)))
.content_md5(base64::encode(&*md5::compute(&data)))
.body(ByteStream::new(data.into()))
.bucket(&self.bucket)
.acl(ObjectCannedAcl::Private)
@@ -8,7 +8,7 @@
export let crate: Crate;
</script>
<a href={`/crates/${crate.organisation}/${crate.name}`} class="card flex items-center">
<a href={`/crates/${crate.organisation}/${crate.name}`} class="card flex items-center mb-3">
<div class="flex-grow">
<div class="font-semibold">
{crate.organisation}/<span class="text-highlight">{crate.name}</span>