diff --git a/dev-tools/omdb/src/bin/omdb/db.rs b/dev-tools/omdb/src/bin/omdb/db.rs index ff65784de80..1529fceaf9d 100644 --- a/dev-tools/omdb/src/bin/omdb/db.rs +++ b/dev-tools/omdb/src/bin/omdb/db.rs @@ -2432,7 +2432,20 @@ async fn cmd_db_disk_info( datastore: &DataStore, args: &DiskInfoArgs, ) -> Result<(), anyhow::Error> { - match datastore.disk_get(opctx, args.uuid).await? { + let disk = { + use nexus_db_schema::schema::disk::dsl; + + let conn = datastore.pool_connection_for_tests().await?; + + dsl::disk + .filter(dsl::id.eq(args.uuid)) + .select(nexus_db_model::Disk::as_select()) + .get_result_async(&*conn) + .await + .unwrap() + }; + + match datastore.disk_get_with_model(opctx, disk).await? { Disk::Crucible(disk) => { crucible_disk_info(opctx, datastore, disk).await } diff --git a/nexus/db-queries/src/db/datastore/disk.rs b/nexus/db-queries/src/db/datastore/disk.rs index 23907422b79..14e02cac072 100644 --- a/nexus/db-queries/src/db/datastore/disk.rs +++ b/nexus/db-queries/src/db/datastore/disk.rs @@ -302,6 +302,9 @@ impl Into for Disk { } impl DataStore { + /// Return a `datastore::Disk` given a disk's UUID. Will perform a + /// LookupPath in order to retrive the `model::Disk`, then call + /// `disk_get_with_model`. pub async fn disk_get( &self, opctx: &OpContext, @@ -310,6 +313,21 @@ impl DataStore { let (.., disk) = LookupPath::new(opctx, self).disk_id(disk_id).fetch().await?; + self.disk_get_with_model(opctx, disk).await + } + + /// Return a `datastore::Disk` given a `model::Disk` + /// + /// Prefer to use `disk_get` instead: this version of the function bypasses + /// the LookupPath induced permissions check and is (currently) only called + /// from omdb. + pub async fn disk_get_with_model( + &self, + opctx: &OpContext, + disk: model::Disk, + ) -> LookupResult { + let disk_id = disk.id(); + let conn = self.pool_connection_authorized(opctx).await?; let disk = match disk.disk_type {