WIP: Add updates controller #5

Draft
dln wants to merge 1 commit from dln/push-zvvozlmpyvun into main
3 changed files with 41 additions and 0 deletions
Showing only changes of commit 80aa9d1547 - Show all commits

View file

@ -4,6 +4,7 @@ use dropshot::ApiDescription;
use std::sync::Arc;
use crate::context::ControllerContext;
use crate::updates;
use crate::version;
type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
@ -11,5 +12,6 @@ type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
pub fn api() -> Result<ControllerApiDescription> {
let mut api = ControllerApiDescription::new();
api.register(version::version)?;
api.register(updates::get_latest)?;
Ok(api)
}

View file

@ -1,4 +1,5 @@
pub mod api;
pub mod context;
mod updates;
mod version;

38
controller/src/updates.rs Normal file
View file

@ -0,0 +1,38 @@
use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext};
use schemars::JsonSchema;
use serde::Serialize;
use std::sync::Arc;
use crate::context::ControllerContext;
use trace_request::trace_request;
/// Update information
#[derive(Serialize, JsonSchema)]
struct UpdateInfo {
name: String,
}
/// Fetch update info
#[endpoint {
method = GET,
path = "/updates/latest",
}]
#[trace_request]
pub(crate) async fn get_latest(
rqctx: RequestContext<Arc<ControllerContext>>,
) -> Result<HttpResponseOk<UpdateInfo>, HttpError> {
let upd = UpdateInfo {
name: "Hello".to_string(),
};
tracing::info_span!("Hello, span!");
async move {
tracing::info!("Someone made a request to /updates/latest");
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
}
.instrument(tracing::info_span!("Let's do the thing...."))
.await;
Ok(HttpResponseOk(upd))
}