Skip to content

Commit

Permalink
add x-rust-type to ArtifactHash
Browse files Browse the repository at this point in the history
  • Loading branch information
iliana committed Oct 11, 2024
1 parent 4e8200a commit 4094dac
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions clients/gateway-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ workspace = true
base64.workspace = true
chrono.workspace = true
gateway-messages.workspace = true
omicron-common.workspace = true
progenitor.workspace = true
rand.workspace = true
reqwest = { workspace = true, features = ["rustls-tls", "stream"] }
Expand Down
3 changes: 3 additions & 0 deletions clients/gateway-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ progenitor::generate_api!(
slog::debug!(log, "client response"; "result" => ?result);
}),
derives = [schemars::JsonSchema],
crates = {
"omicron-common" = "0.1.0",
},
patch = {
HostPhase2RecoveryImageId = { derives = [PartialEq, Eq, PartialOrd, Ord] },
ImageVersion = { derives = [PartialEq, Eq, PartialOrd, Ord] },
Expand Down
3 changes: 3 additions & 0 deletions clients/installinator-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ progenitor::generate_api!(
slog::debug!(log, "client response"; "result" => ?result);
}),
derives = [schemars::JsonSchema],
crates = {
"omicron-common" = "0.1.0",
},
replace = {
Duration = std::time::Duration,
EventReportForInstallinatorSpec = installinator_common::EventReport,
Expand Down
3 changes: 3 additions & 0 deletions clients/wicketd-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ progenitor::generate_api!(
slog::debug!(log, "client response"; "result" => ?result);
}),
derives = [schemars::JsonSchema],
crates = {
"omicron-common" = "0.1.0",
},
patch = {
CurrentRssUserConfig = { derives = [PartialEq] },
CurrentRssUserConfigSensitive = { derives = [PartialEq, Eq, PartialOrd, Ord] },
Expand Down
15 changes: 14 additions & 1 deletion common/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl FromStr for ArtifactKind {
#[cfg_attr(feature = "testing", derive(test_strategy::Arbitrary))]
pub struct ArtifactHash(
#[serde(with = "serde_human_bytes::hex_array")]
#[schemars(schema_with = "hex_schema::<32>")]
#[schemars(schema_with = "artifact_hash_schema")]
pub [u8; 32],
);

Expand Down Expand Up @@ -328,6 +328,19 @@ pub fn hex_schema<const N: usize>(gen: &mut SchemaGenerator) -> Schema {
schema.into()
}

fn artifact_hash_schema(gen: &mut SchemaGenerator) -> Schema {
let mut schema: SchemaObject = hex_schema::<32>(gen).into();
schema.extensions.insert(
"x-rust-type".into(),
serde_json::json!({
"crate": env!("CARGO_PKG_NAME"),
"version": env!("CARGO_PKG_VERSION"),
"path": concat!(module_path!(), "::ArtifactHash"),
}),
);
schema.into()
}

#[cfg(test)]
mod tests {
use crate::api::internal::nexus::KnownArtifactKind;
Expand Down
4 changes: 2 additions & 2 deletions gateway-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ async fn main() -> Result<()> {
} else {
// clap guarantees these are not `None` when `clear` is false.
let update_id = update_id.unwrap();
let host_phase_2 = host_phase_2.unwrap().to_string();
let control_plane = control_plane.unwrap().to_string();
let host_phase_2 = host_phase_2.unwrap();
let control_plane = control_plane.unwrap();
client
.sp_installinator_image_id_set(
sp.type_,
Expand Down
2 changes: 1 addition & 1 deletion installinator/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl ArtifactClient {
.client
.get_artifact_by_hash(
artifact_hash_id.kind.as_str(),
&artifact_hash_id.hash.to_string(),
&artifact_hash_id.hash,
)
.await?;

Expand Down
15 changes: 15 additions & 0 deletions openapi/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,11 @@
"type": "object",
"properties": {
"sha256_hash": {
"x-rust-type": {
"crate": "omicron-common",
"path": "omicron_common::update::ArtifactHash",
"version": "0.1.0"
},
"type": "string",
"format": "hex string (32 bytes)"
}
Expand Down Expand Up @@ -1688,10 +1693,20 @@
"type": "object",
"properties": {
"control_plane": {
"x-rust-type": {
"crate": "omicron-common",
"path": "omicron_common::update::ArtifactHash",
"version": "0.1.0"
},
"type": "string",
"format": "hex string (32 bytes)"
},
"host_phase_2": {
"x-rust-type": {
"crate": "omicron-common",
"path": "omicron_common::update::ArtifactHash",
"version": "0.1.0"
},
"type": "string",
"format": "hex string (32 bytes)"
},
Expand Down
5 changes: 5 additions & 0 deletions openapi/installinator.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"description": "The hash of the artifact.",
"required": true,
"schema": {
"x-rust-type": {
"crate": "omicron-common",
"path": "omicron_common::update::ArtifactHash",
"version": "0.1.0"
},
"type": "string",
"format": "hex string (32 bytes)"
}
Expand Down
10 changes: 10 additions & 0 deletions openapi/wicketd.json
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,11 @@
"properties": {
"hash": {
"description": "The hash of the artifact.",
"x-rust-type": {
"crate": "omicron-common",
"path": "omicron_common::update::ArtifactHash",
"version": "0.1.0"
},
"type": "string",
"format": "hex string (32 bytes)"
},
Expand Down Expand Up @@ -983,6 +988,11 @@
},
"sha256": {
"description": "A SHA-256 digest of the key.",
"x-rust-type": {
"crate": "omicron-common",
"path": "omicron_common::update::ArtifactHash",
"version": "0.1.0"
},
"type": "string",
"format": "hex string (32 bytes)"
}
Expand Down
4 changes: 2 additions & 2 deletions wicketd/src/update_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,8 @@ impl UpdateDriver {
"Setting installinator image ID",
move |_cx| async move {
let installinator_image_id = InstallinatorImageId {
control_plane: plan.control_plane_hash.to_string(),
host_phase_2: plan.host_phase_2_hash.to_string(),
control_plane: plan.control_plane_hash,
host_phase_2: plan.host_phase_2_hash,
update_id: update_cx.update_id,
};
update_cx
Expand Down

0 comments on commit 4094dac

Please sign in to comment.