Skip to content

Commit b0b6f36

Browse files
committed
wip
1 parent e0194d6 commit b0b6f36

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

Cargo.lock

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

objectstore-server/src/endpoints/batch.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use objectstore_service::id::{ObjectContext, ObjectId};
1313
use objectstore_service::{DeleteResult, GetResult, InsertResult};
1414

1515
use crate::auth::AuthAwareService;
16-
use crate::error::ApiResult;
16+
use crate::endpoints::common::ApiResult;
1717
use crate::extractors::Operation;
1818
use crate::extractors::{BatchRequest, Xt};
1919
use crate::multipart::{IntoBytesStream, Part};
@@ -177,11 +177,14 @@ impl IntoPart for DeleteResult {
177177

178178
#[cfg(test)]
179179
mod tests {
180+
use crate::auth::PublicKeyDirectory;
181+
180182
use super::*;
181183
use axum::body::Body;
182184
use axum::http::{Request, StatusCode};
183185
use bytes::Bytes;
184186
use objectstore_service::StorageConfig;
187+
use std::collections::BTreeMap;
185188
use std::sync::Arc;
186189
use tower::ServiceExt;
187190

@@ -201,6 +204,9 @@ mod tests {
201204
let state = Arc::new(crate::state::Services {
202205
config: crate::config::Config::default(),
203206
service: storage_service,
207+
key_directory: PublicKeyDirectory {
208+
keys: BTreeMap::new(),
209+
},
204210
});
205211

206212
// Build the router with state

objectstore-server/src/extractors/batch.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anyhow::Context;
44
use axum::{
55
extract::{FromRequest, Request},
66
http::StatusCode,
7-
response::IntoResponse,
7+
response::{IntoResponse, Response},
88
};
99
use bytes::Bytes;
1010
use futures::{StreamExt, stream::BoxStream};
@@ -14,8 +14,6 @@ use multer::{Constraints, Multipart, SizeLimit};
1414
use objectstore_service::id::ObjectKey;
1515
use objectstore_types::Metadata;
1616

17-
use crate::error::AnyhowResponse;
18-
1917
#[derive(Debug)]
2018
pub struct GetOperation {
2119
pub key: ObjectKey,
@@ -95,37 +93,37 @@ impl<S> FromRequest<S> for BatchRequest
9593
where
9694
S: Send + Sync,
9795
{
98-
type Rejection = AnyhowResponse;
96+
type Rejection = Response;
9997

10098
async fn from_request(request: Request, _: &S) -> Result<Self, Self::Rejection> {
10199
let Some(content_type) = request
102100
.headers()
103101
.get(CONTENT_TYPE)
104102
.and_then(|ct| ct.to_str().ok())
105103
else {
106-
return Err((StatusCode::BAD_REQUEST, "expected valid Content-Type")
107-
.into_response()
108-
.into());
104+
return Err((StatusCode::BAD_REQUEST, "expected valid Content-Type").into_response());
109105
};
110106

111107
let Ok(mime) = content_type.parse::<mime::Mime>() else {
112-
return Err((StatusCode::BAD_REQUEST, "expected valid Content-Type")
113-
.into_response()
114-
.into());
108+
return Err((StatusCode::BAD_REQUEST, "expected valid Content-Type").into_response());
115109
};
116110
if !(mime.type_() == mime::MULTIPART && mime.subtype() == "mixed") {
117111
return Err((
118112
StatusCode::BAD_REQUEST,
119113
"expected Content-Type: multipart/mixed",
120114
)
121-
.into_response()
122-
.into());
115+
.into_response());
123116
}
124117

125118
// XXX: `multer::parse_boundary` requires the content-type to be `multipart/form-data`
126119
let content_type = content_type.replace("multipart/mixed", "multipart/form-data");
127-
let boundary =
128-
multer::parse_boundary(content_type).context("failed to parse multipart boundary")?;
120+
let Ok(boundary) = multer::parse_boundary(content_type).context("") else {
121+
return Err((
122+
StatusCode::BAD_REQUEST,
123+
"failed to parse multipart boundary",
124+
)
125+
.into_response());
126+
};
129127
let mut parts = Multipart::with_constraints(
130128
request.into_body().into_data_stream(),
131129
boundary,

objectstore-server/src/multipart.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,29 @@ where
8080
let mut this = self.project();
8181
match std::mem::replace(this.state, State::Waiting) {
8282
State::Waiting => match this.parts.as_mut().poll_next(ctx) {
83-
Poll::Pending => return Poll::Pending,
83+
Poll::Pending => Poll::Pending,
8484
Poll::Ready(None) => {
8585
*this.state = State::SendClosingBoundary;
8686
ctx.waker().wake_by_ref();
87-
return Poll::Pending;
87+
Poll::Pending
8888
}
89-
Poll::Ready(Some(Err(e))) => return Poll::Ready(Some(Err(e))),
89+
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))),
9090
Poll::Ready(Some(Ok(p))) => {
9191
*this.state = State::SendHeaders(p);
92-
return Poll::Ready(Some(Ok(this.boundary.clone())));
92+
Poll::Ready(Some(Ok(this.boundary.clone())))
9393
}
9494
},
9595
State::SendHeaders(part) => {
9696
*this.state = State::SendBody(part.body);
9797
let headers = serialize_headers(part.headers);
98-
return Poll::Ready(Some(Ok(headers)));
98+
Poll::Ready(Some(Ok(headers)))
9999
}
100100
State::SendBody(body) => {
101101
// Add \r\n after the body
102102
let mut body_with_newline = BytesMut::with_capacity(body.len() + 2);
103103
body_with_newline.put(body);
104104
body_with_newline.put(&b"\r\n"[..]);
105-
return Poll::Ready(Some(Ok(body_with_newline.freeze())));
105+
Poll::Ready(Some(Ok(body_with_newline.freeze())))
106106
}
107107
State::SendClosingBoundary => {
108108
*this.state = State::Done;
@@ -114,10 +114,10 @@ where
114114
let mut closing = BytesMut::with_capacity(boundary_without_crlf.len() + 4);
115115
closing.put(boundary_without_crlf.as_bytes());
116116
closing.put(&b"--\r\n"[..]);
117-
return Poll::Ready(Some(Ok(closing.freeze())));
117+
Poll::Ready(Some(Ok(closing.freeze())))
118118
}
119119
State::Done => {
120-
return Poll::Ready(None);
120+
Poll::Ready(None)
121121
}
122122
}
123123
}

objectstore-service/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ mod backend;
1010
pub mod id;
1111

1212
use std::path::Path;
13-
use std::pin::Pin;
1413
use std::sync::Arc;
1514
use std::sync::atomic::{AtomicU64, Ordering};
1615
use std::time::Instant;
1716

1817
use bytes::{Bytes, BytesMut};
19-
use futures_util::Stream;
2018
use futures_util::{StreamExt, TryStreamExt, stream::BoxStream};
2119
use objectstore_types::Metadata;
2220

2321
use crate::backend::common::BoxedBackend;
24-
use crate::id::{ObjectContext, ObjectId, ObjectKey};
22+
use crate::id::{ObjectContext, ObjectId};
2523

2624
/// The threshold up until which we will go to the "high volume" backend.
2725
const BACKEND_SIZE_THRESHOLD: usize = 1024 * 1024; // 1 MiB

0 commit comments

Comments
 (0)