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 18, 2024
1 parent 95af64f commit 6b962d4
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 17 deletions.
127 changes: 117 additions & 10 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ where
/// Gets an OV
fn get_ov(guid: &str, conn: &mut T) -> Result<OwnerOV>;

/// Returns all the OVs in the DB
fn get_all_ovs(conn: &mut T) -> Result<Vec<OwnerOV>>;

/// Deletes an OV
fn delete_ov(guid: &str, conn: &mut T) -> Result<()>;

Expand Down Expand Up @@ -101,6 +104,9 @@ where
/// Gets an OV
fn get_ov(guid: &str, conn: &mut T) -> Result<RendezvousOV>;

/// Returns all the OVs in the DB
fn get_all_ovs(conn: &mut T) -> Result<Vec<RendezvousOV>>;

/// Deletes an OV
fn delete_ov(guid: &str, conn: &mut T) -> Result<()>;

Expand Down
14 changes: 14 additions & 0 deletions db/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ impl DBStoreOwner<PgConnection> for PostgresOwnerDB {
Ok(result)
}

fn get_all_ovs(conn: &mut PgConnection) -> Result<Vec<OwnerOV>> {
let result = super::schema::owner_vouchers::dsl::owner_vouchers
.select(OwnerOV::as_select())
.load(conn)?;
Ok(result)
}

fn delete_ov(guid: &str, conn: &mut PgConnection) -> Result<()> {
diesel::delete(owner_vouchers::dsl::owner_vouchers)
.filter(super::schema::owner_vouchers::guid.eq(guid))
Expand Down Expand Up @@ -222,6 +229,13 @@ impl DBStoreRendezvous<PgConnection> for PostgresRendezvousDB {
Ok(result)
}

fn get_all_ovs(conn: &mut PgConnection) -> Result<Vec<RendezvousOV>> {
let result = super::schema::rendezvous_vouchers::dsl::rendezvous_vouchers
.select(RendezvousOV::as_select())
.load(conn)?;
Ok(result)
}

fn delete_ov(guid: &str, conn: &mut PgConnection) -> Result<()> {
diesel::delete(rendezvous_vouchers::dsl::rendezvous_vouchers)
.filter(super::schema::rendezvous_vouchers::guid.eq(guid))
Expand Down
14 changes: 14 additions & 0 deletions db/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ impl DBStoreOwner<SqliteConnection> for SqliteOwnerDB {
Ok(result)
}

fn get_all_ovs(conn: &mut SqliteConnection) -> Result<Vec<OwnerOV>> {
let result = super::schema::owner_vouchers::dsl::owner_vouchers
.select(OwnerOV::as_select())
.load(conn)?;
Ok(result)
}

fn delete_ov(guid: &str, conn: &mut SqliteConnection) -> Result<()> {
diesel::delete(owner_vouchers::dsl::owner_vouchers)
.filter(super::schema::owner_vouchers::guid.eq(guid))
Expand Down Expand Up @@ -224,6 +231,13 @@ impl DBStoreRendezvous<SqliteConnection> for SqliteRendezvousDB {
Ok(result)
}

fn get_all_ovs(conn: &mut SqliteConnection) -> Result<Vec<RendezvousOV>> {
let result = super::schema::rendezvous_vouchers::dsl::rendezvous_vouchers
.select(RendezvousOV::as_select())
.load(conn)?;
Ok(result)
}

fn delete_ov(guid: &str, conn: &mut SqliteConnection) -> Result<()> {
diesel::delete(rendezvous_vouchers::dsl::rendezvous_vouchers)
.filter(super::schema::rendezvous_vouchers::guid.eq(guid))
Expand Down
3 changes: 3 additions & 0 deletions manufacturing-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ warp = "0.3.6"
log = "0.4"
hex = "0.4"
serde_yaml = "0.9"
tar = "0.4.41"
flate2 = "1.0.31"
tempdir = "0.3.7"

fdo-data-formats = { path = "../data-formats", version = "0.5.0" }
fdo-http-wrapper = { path = "../http-wrapper", version = "0.5.0", features = ["server"] }
Expand Down
Loading

0 comments on commit 6b962d4

Please sign in to comment.