Skip to content

Commit

Permalink
refactor: Update dropshot from 0.11 to 0.15
Browse files Browse the repository at this point in the history
This is a bit of a forced chore since there are some features I wanted
to use in the newer versions of dropshot.
  • Loading branch information
clintjedwards committed Jan 24, 2025
1 parent 4126873 commit 50b109e
Show file tree
Hide file tree
Showing 22 changed files with 652 additions and 761 deletions.
562 changes: 250 additions & 312 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ cleanup-integration-tests:

## run-tailwind: Run the tailwind compiler
run-tailwind:
> npx tailwindcss -i ./gofer/src/main.css -o ./gofer/public/css/main.css --watch >/dev/null 2>&1
> npx tailwindcss@3.4.17 -i ./gofer/src/main.css -o ./gofer/public/css/main.css --watch >/dev/null 2>&1

## clippy-pedantic: Let clippy nitpick your code.
clippy-pedantic:
Expand Down
7 changes: 4 additions & 3 deletions gofer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ crossbeam = "0.8.4"
dashmap = "5.5.3"
derive_builder = "0.20.0"
dirs = "5.0.1"
dropshot = { git = "https://github.com/clintjedwards/dropshot.git", tag = "v0.11.1-dev" }
dropshot_endpoint = { git = "https://github.com/clintjedwards/dropshot.git", tag = "v0.11.1-dev" }
dropshot = { git = "https://github.com/clintjedwards/dropshot.git", tag = "v0.15.1" }
dropshot_endpoint = { git = "https://github.com/clintjedwards/dropshot.git", tag = "v0.15.1" }
figment = { version = "0.10.16", features = ["env", "toml"] }
futures = "0.3.30"
gofer_sdk = { path = "../sdk/rust" }
http = "0.2.12"
human-panic = "2.0.1"
hyper = { version = "0.14", features = ["server", "full"] }
hyper = { version = "1.5.2", features = ["server", "full"] }
lazy-regex = "3.1.0"
mime_guess = "2.0.4"
polyfmt = { git = "https://github.com/clintjedwards/polyfmt-rs.git", tag = "v0.0.13" }
Expand Down Expand Up @@ -61,6 +61,7 @@ tungstenite = "0.21.0"
uuid = { version = "1.8.0", features = ["v7"] }
console-subscriber = "0.1"
termion = "4.0.3"
semver = "1.0.25"

[dev-dependencies]
lazy_static = "1.4.0"
Expand Down
12 changes: 6 additions & 6 deletions gofer/src/api/deployments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ pub async fn list_deployments(
Err(e) => {
return Err(http_error!(
"Could not open connection to database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand All @@ -339,7 +339,7 @@ pub async fn list_deployments(
Err(e) => {
return Err(http_error!(
"Could not get objects from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
));
Expand All @@ -352,7 +352,7 @@ pub async fn list_deployments(
let deployment = Deployment::try_from(storage_deployment).map_err(|e| {
http_error!(
"Could not parse object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
)
Expand Down Expand Up @@ -405,7 +405,7 @@ pub async fn get_deployment(
Err(e) => {
return Err(http_error!(
"Could not open connection to database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand Down Expand Up @@ -439,7 +439,7 @@ pub async fn get_deployment(
_ => {
return Err(http_error!(
"Could not get object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand All @@ -450,7 +450,7 @@ pub async fn get_deployment(
let deployment = Deployment::try_from(storage_deployment).map_err(|e| {
http_error!(
"Could not parse object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
)
Expand Down
10 changes: 5 additions & 5 deletions gofer/src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub async fn get_event(
Err(e) => {
return Err(http_error!(
"Could not open connection to database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand All @@ -320,7 +320,7 @@ pub async fn get_event(
_ => {
return Err(http_error!(
"Could not get objects from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
));
Expand All @@ -331,7 +331,7 @@ pub async fn get_event(
let event = Event::try_from(storage_event).map_err(|e| {
http_error!(
"Could not parse object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
)
Expand Down Expand Up @@ -373,7 +373,7 @@ pub async fn delete_event(
Err(e) => {
return Err(http_error!(
"Could not open connection to database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand All @@ -391,7 +391,7 @@ pub async fn delete_event(
_ => {
return Err(http_error!(
"Could not delete object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
));
Expand Down
24 changes: 12 additions & 12 deletions gofer/src/api/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ pub async fn install_extension(
if !err_str.contains("already exists") {
return Err(http_error!(
"Could not install extension",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into()),
id = registration.extension_id
Expand All @@ -925,7 +925,7 @@ pub async fn install_extension(
.map_err(|err| {
http_error!(
"Could not start extension",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(err.into()),
id = registration.extension_id
Expand Down Expand Up @@ -978,7 +978,7 @@ pub async fn update_extension(
Err(e) => {
return Err(http_error!(
"Could not open connection to database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand Down Expand Up @@ -1014,7 +1014,7 @@ pub async fn update_extension(
_ => {
return Err(http_error!(
"Could not update object in database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
));
Expand Down Expand Up @@ -1077,7 +1077,7 @@ pub async fn uninstall_extension(
Err(e) => {
return Err(http_error!(
"Could not open connection to database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand All @@ -1089,7 +1089,7 @@ pub async fn uninstall_extension(
.map_err(|err| {
http_error!(
"Could not delete object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(err.into())
)
Expand All @@ -1100,7 +1100,7 @@ pub async fn uninstall_extension(
.map_err(|err| {
http_error!(
"Could not delete object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(err.into())
)
Expand Down Expand Up @@ -1336,7 +1336,7 @@ pub async fn list_extension_subscriptions(
Err(e) => {
return Err(http_error!(
"Could not open connection to database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
));
Expand All @@ -1351,7 +1351,7 @@ pub async fn list_extension_subscriptions(
Err(e) => {
return Err(http_error!(
"Could not get objects from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
));
Expand All @@ -1365,7 +1365,7 @@ pub async fn list_extension_subscriptions(
subscriptions::Subscription::try_from(storage_subscription).map_err(|e| {
http_error!(
"Could not parse object from database",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
)
Expand Down Expand Up @@ -1426,7 +1426,7 @@ pub async fn get_extension_debug_info(
.map_err(|e| {
http_error!(
"Could not establish extension client",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id.clone(),
Some(e.into())
)
Expand All @@ -1438,7 +1438,7 @@ pub async fn get_extension_debug_info(
.map_err(|e| {
http_error!(
"Could not query extension's debug endpoint",
http::StatusCode::INTERNAL_SERVER_ERROR,
hyper::StatusCode::INTERNAL_SERVER_ERROR,
rqctx.request_id,
Some(e.into())
)
Expand Down
50 changes: 23 additions & 27 deletions gofer/src/api/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::conf;
use anyhow::{anyhow, Context, Result};
use dropshot::{
endpoint, ApiDescription, ConfigDropshot, ConfigTls, HandlerTaskMode, HttpError,
HttpResponseUpdatedNoContent, HttpServerStarter, Path, RequestContext, UntypedBody,
HttpResponseUpdatedNoContent, Path, RequestContext, ServerBuilder, UntypedBody,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -22,7 +22,7 @@ pub async fn start_web_service(conf: conf::api::ApiConfig, api_state: Arc<ApiSta

let dropshot_conf = ConfigDropshot {
bind_address,
request_body_max_bytes: 524288000, // 500MB to allow for extra large objects.
default_request_body_max_bytes: 524288000, // 500MB to allow for extra large objects.

// If a client disconnects run the handler to completion still. Eventually we'll want to save resources
// by allowing the handler to early cancel, but until this is more developed lets just run it to completion.
Expand All @@ -34,32 +34,28 @@ pub async fn start_web_service(conf: conf::api::ApiConfig, api_state: Arc<ApiSta
/* /api/external/{extension_id} */
api.register(external_event_handler).unwrap();

let server = if !conf.server.use_tls {
HttpServerStarter::new(&dropshot_conf, api, Some(Arc::new(Middleware)), api_state)
.map_err(|error| anyhow!("failed to create server: {}", error))?
.start()
} else {
let (tls_cert, tls_key) = load_tls(
conf.external_events.use_tls,
conf.external_events.tls_cert_path,
conf.external_events.tls_key_path,
)?;

let tls_config = Some(ConfigTls::AsBytes {
certs: tls_cert,
key: tls_key,
});

HttpServerStarter::new_with_tls(
&dropshot_conf,
api,
Some(Arc::new(Middleware)),
api_state,
tls_config,
)
.map_err(|error| anyhow!("failed to create server: {}", error))?
.start()
let tls_config = match conf.server.use_tls {
true => {
let (tls_cert, tls_key) = load_tls(
conf.external_events.use_tls,
conf.external_events.tls_cert_path,
conf.external_events.tls_key_path,
)?;

Some(ConfigTls::AsBytes {
certs: tls_cert,
key: tls_key,
})
}
false => None,
};

let server = ServerBuilder::new(api, api_state, Some(Arc::new(Middleware)))
.config(dropshot_conf)
.tls(tls_config)
.start()
.map_err(|error| anyhow!("failed to create server: {}", error))?;

let shutdown = server.wait_for_shutdown();

tokio::spawn(wait_for_shutdown_signal(server));
Expand Down
Loading

0 comments on commit 50b109e

Please sign in to comment.