From 65bf99e9f3d4bd345d0ff3ee391a50f434d84447 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Wed, 6 Aug 2025 16:10:55 +0200 Subject: [PATCH] nit --- backend/windmill-api/src/s3_proxy.rs | 35 +++++++++++----------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/backend/windmill-api/src/s3_proxy.rs b/backend/windmill-api/src/s3_proxy.rs index 5d4bdb7b1a..9e1c9d23f6 100644 --- a/backend/windmill-api/src/s3_proxy.rs +++ b/backend/windmill-api/src/s3_proxy.rs @@ -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, - Path((w_id, storage, object_key)): Path<(String, String, String)>, + Extension(user_db): Extension, + Path((w_id, storage_str, object_key)): Path<(String, String, String)>, Extension(auth_cache): Extension>, req: Request, ) -> Result { @@ -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 = 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();