Skip to content

Commit

Permalink
feat(manufacturing-server): implement an export OVs endpoint
Browse files Browse the repository at this point in the history
Just serving an archive with all the OVs the manufacturer knows about.
It'd be handy to just give this away to whoever needs these credentials
and/or create a nice UI where you click a button to have them all.
The post-MVP, with a UI, would be to just have a UI that is able to list
all the device credentials, let you select which one you want, download
them in an archive, profit. Not there yet.

Signed-off-by: Antonio Murdaca <[email protected]>
  • Loading branch information
runcom committed Sep 11, 2024
1 parent 0d1541e commit 4e867cc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions manufacturing-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ warp = "0.3.6"
log = "0.4"
hex = "0.4"
serde_yaml = "0.9"
tar = "0.4.41"
flate2 = "1.0.31"

fdo-data-formats = { path = "../data-formats", version = "0.5.0" }
fdo-http-wrapper = { path = "../http-wrapper", version = "0.5.0", features = ["server"] }
Expand Down
31 changes: 28 additions & 3 deletions manufacturing-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use std::convert::{TryFrom, TryInto};
use std::fs;
use std::fs::{self, File};
use std::io::Read;
use std::str::FromStr;
use std::sync::Arc;

Expand All @@ -11,6 +12,7 @@ use openssl::{
};
use serde_yaml::Value;
use tokio::signal::unix::{signal, SignalKind};
use warp::reply::Response;
use warp::Filter;

use fdo_data_formats::{
Expand Down Expand Up @@ -268,7 +270,29 @@ async fn main() -> Result<()> {

// Initialize handlers
let hello = warp::get().map(|| "Hello from the manufacturing server");
let handler_ping = fdo_http_wrapper::server::ping_handler();
let handler_export = warp::get().and(warp::path("export").map(|| {
let tar_gz = File::create("/tmp/archive.tar.gz").unwrap();
//let enc = flate2::write::GzEncoder::new(tar_gz, flate2::Compression::default());
let mut tar = tar::Builder::new(tar_gz);
tar.append_dir_all(".", "/home/amurdaca/testovs").unwrap();
tar.finish().unwrap();
let mut file = File::open("/tmp/archive.tar.gz").unwrap();
let mut data: Vec<u8> = Vec::new();
match file.read_to_end(&mut data) {
Err(why) => {
println!("Error: {:?}", why);
return Response::new(String::new().into());
}
Ok(_) => {
let mut res = Response::new(data.into());
res.headers_mut().insert(
"Content-Type",
warp::http::header::HeaderValue::from_static("application/x-tar"),
);
return res;
}
}
}));

// DI
let handler_di_app_start = fdo_http_wrapper::server::fdo_request_filter(
Expand Down Expand Up @@ -307,7 +331,7 @@ async fn main() -> Result<()> {
let routes = warp::post()
.and(
hello
.or(handler_ping)
.or(fdo_http_wrapper::server::ping_handler())
// DI
.or(handler_di_app_start)
.or(handler_di_set_hmac)
Expand All @@ -316,6 +340,7 @@ async fn main() -> Result<()> {
.or(handler_diun_request_key_parameters)
.or(handler_diun_provide_key),
)
.or(handler_export)
.recover(fdo_http_wrapper::server::handle_rejection)
.with(warp::log("manufacturing-server"));

Expand Down

0 comments on commit 4e867cc

Please sign in to comment.