This commit is contained in:
Diego Imbert
2025-08-06 16:10:55 +02:00
parent ad7f9e0f90
commit 65bf99e9f3
+14 -21
View File
@@ -3,7 +3,7 @@ use std::sync::Arc;
use axum::{
extract::{Path, Request},
response::{IntoResponse, Response},
routing::get,
routing::{get, put},
Extension, Router,
};
use windmill_common::{
@@ -19,14 +19,18 @@ use crate::{
};
pub fn workspaced_unauthed_service() -> Router {
// Most routes are duplicated to support the s3://storage/path syntax
Router::new()
.route("/s3%3A//:storage/*key", get(get_object))
.route("/:storage/*key", get(get_object))
.route("/s3%3A//:storage/*key", put(put_object))
.route("/:storage/*key", put(put_object))
}
async fn get_object(
Extension(db): Extension<DB>,
Path((w_id, storage, object_key)): Path<(String, String, String)>,
Extension(user_db): Extension<UserDB>,
Path((w_id, storage_str, object_key)): Path<(String, String, String)>,
Extension(auth_cache): Extension<Arc<AuthCache>>,
req: Request<axum::body::Body>,
) -> Result<Response> {
@@ -34,27 +38,16 @@ async fn get_object(
let Some(authed) = auth_cache.get_authed(Some(w_id.clone()), token).await else {
return Err(Error::NotAuthorized("Invalid token".to_string()));
};
let storage = if storage.is_empty() {
None
} else {
Some(storage)
};
// temp values
let user_db: Option<UserDB> = None;
let authed = ApiAuthed {
email: "s3_proxy".to_string(),
username: "s3_proxy".to_string(),
is_admin: true,
..Default::default()
};
let storage = Some(storage_str.clone()).filter(|s| !s.is_empty());
let (_, s3_resource) =
get_workspace_s3_resource(&authed, &db, user_db, token, &w_id, storage).await?;
let s3_resource = s3_resource.ok_or(Error::InternalErr(
"No files storage resource defined at the workspace level".to_string(),
))?;
get_workspace_s3_resource(&authed, &db, Some(user_db), token, &w_id, storage).await?;
let s3_resource = s3_resource.ok_or_else(|| {
Error::InternalErr(format!(
"Storage {} not found at the workspace level",
storage_str
))
})?;
let s3_client = build_object_store_client(&s3_resource).await?;
let result = read_object_streamable(s3_client, &object_key).await?;
let stream = result.into_stream();