Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/fakecloud-cloudfront/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true }

[target.'cfg(unix)'.dependencies]
libc = "0.2"
32 changes: 17 additions & 15 deletions crates/fakecloud-cloudfront/src/cfunctions_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl CloudFrontService {
Ok(xml_with_etag(StatusCode::OK, body, &snap.etag, None))
}

pub(crate) fn test_connection_function(
pub(crate) async fn test_connection_function(
&self,
req: &AwsRequest,
route: &Route,
Expand All @@ -288,19 +288,21 @@ impl CloudFrontService {
let event_bytes = base64::engine::general_purpose::STANDARD
.decode(parsed.connection_object.trim().as_bytes())
.map_err(|e| invalid_argument(format!("ConnectionObject is not valid base64: {e}")))?;
let state = self.state.read();
let f = state
.accounts
.get(DEFAULT_ACCOUNT)
.and_then(|a| a.connection_functions.get(&name).cloned())
.ok_or_else(|| {
aws_error(
StatusCode::NOT_FOUND,
"EntityNotFound",
format!("ConnectionFunction {name} does not exist"),
)
})?;
drop(state);
// Scoped so the lock guard is gone before the await below.
let f = {
let state = self.state.read();
state
.accounts
.get(DEFAULT_ACCOUNT)
.and_then(|a| a.connection_functions.get(&name).cloned())
.ok_or_else(|| {
aws_error(
StatusCode::NOT_FOUND,
"EntityNotFound",
format!("ConnectionFunction {name} does not exist"),
)
})?
};
if f.etag != if_match {
return Err(precondition_failed());
}
Expand All @@ -317,7 +319,7 @@ impl CloudFrontService {
};
let code = std::str::from_utf8(source)
.map_err(|e| invalid_argument(format!("function code is not valid UTF-8: {e}")))?;
let exec = crate::js_runtime::run_handler(code, &event_bytes);
let exec = crate::js_runtime::run_handler_off_runtime(code.to_owned(), event_bytes).await;

let mut body = String::with_capacity(1024);
body.push_str(XML_DECL);
Expand Down
32 changes: 17 additions & 15 deletions crates/fakecloud-cloudfront/src/functions_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl CloudFrontService {
Ok(xml_with_etag(StatusCode::OK, body, &snap.etag, None))
}

pub(crate) fn test_function(
pub(crate) async fn test_function(
&self,
req: &AwsRequest,
route: &Route,
Expand All @@ -269,19 +269,21 @@ impl CloudFrontService {
.decode(parsed.event_object.trim().as_bytes())
.map_err(|e| invalid_argument(format!("EventObject is not valid base64: {e}")))?;

let state = self.state.read();
let f = state
.accounts
.get(DEFAULT_ACCOUNT)
.and_then(|a| a.functions.get(&name).cloned())
.ok_or_else(|| {
aws_error(
StatusCode::NOT_FOUND,
"NoSuchFunctionExists",
format!("The specified function does not exist: {name}"),
)
})?;
drop(state);
// Scoped so the lock guard is gone before the await below.
let f = {
let state = self.state.read();
state
.accounts
.get(DEFAULT_ACCOUNT)
.and_then(|a| a.functions.get(&name).cloned())
.ok_or_else(|| {
aws_error(
StatusCode::NOT_FOUND,
"NoSuchFunctionExists",
format!("The specified function does not exist: {name}"),
)
})?
};
if f.etag != if_match {
return Err(precondition_failed());
}
Expand All @@ -303,7 +305,7 @@ impl CloudFrontService {
.unwrap_or_else(|_| source_b64.as_bytes().to_vec());
let code = String::from_utf8(code_bytes)
.map_err(|e| invalid_argument(format!("function code is not valid UTF-8: {e}")))?;
let exec = crate::js_runtime::run_handler(&code, &event_bytes);
let exec = crate::js_runtime::run_handler_off_runtime(code, event_bytes).await;

let mut body = String::with_capacity(1024);
body.push_str(XML_DECL);
Expand Down
Loading
Loading