Skip to content

Commit 4148b76

Browse files
authored
[1/n] update tufaceous to pick up more changes (#7879)
Update tufaceous so that: * tufaceous-brand-metadata changes can be picked up * tufaceous-artifact now defines `ArtifactHashId` and `ArtifactHash`
1 parent 58f4fc3 commit 4148b76

File tree

54 files changed

+107
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+107
-163
lines changed

Cargo.lock

Lines changed: 25 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/api/external/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ mod error;
1111
pub mod http_pagination;
1212
pub use crate::api::internal::shared::AllowedSourceIps;
1313
pub use crate::api::internal::shared::SwitchLocation;
14-
use crate::update::ArtifactHash;
1514
use crate::update::ArtifactId;
1615
use anyhow::Context;
1716
use api_identity::ObjectIdentity;
@@ -45,6 +44,7 @@ use std::net::IpAddr;
4544
use std::net::Ipv4Addr;
4645
use std::num::{NonZeroU16, NonZeroU32};
4746
use std::str::FromStr;
47+
use tufaceous_artifact::ArtifactHash;
4848
use uuid::Uuid;
4949

5050
// The type aliases below exist primarily to ensure consistency among return

common/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ pub mod update;
3232
pub mod vlan;
3333
pub mod zpool_name;
3434

35-
pub use update::hex_schema;
36-
3735
/// A type that allows adding file and line numbers to log messages
3836
/// automatically. It should be instantiated at the root logger of each
3937
/// executable that desires this functionality, as in the following example.
@@ -84,3 +82,14 @@ impl<T> std::fmt::Debug for NoDebug<T> {
8482
write!(f, "..")
8583
}
8684
}
85+
86+
pub fn hex_schema<const N: usize>(
87+
gen: &mut schemars::SchemaGenerator,
88+
) -> schemars::schema::Schema {
89+
use schemars::JsonSchema;
90+
91+
let mut schema: schemars::schema::SchemaObject =
92+
<String>::json_schema(gen).into();
93+
schema.format = Some(format!("hex string ({N} bytes)"));
94+
schema.into()
95+
}

common/src/update.rs

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use std::{fmt, str::FromStr};
5+
use std::fmt;
66

7-
use hex::FromHexError;
8-
use schemars::{
9-
JsonSchema,
10-
gen::SchemaGenerator,
11-
schema::{Schema, SchemaObject},
12-
};
7+
use schemars::JsonSchema;
138
use serde::{Deserialize, Serialize};
149
use tufaceous_artifact::{Artifact, ArtifactKind, ArtifactVersion};
1510

1611
/// An identifier for an artifact.
1712
///
1813
/// The kind is [`ArtifactKind`], indicating that it might represent an artifact
1914
/// whose kind is unknown.
15+
// TODO: move this to tufaceous-artifact in the future
2016
#[derive(
2117
Debug,
2218
Clone,
@@ -56,84 +52,3 @@ impl From<Artifact> for ArtifactId {
5652
}
5753
}
5854
}
59-
60-
/// A hash-based identifier for an artifact.
61-
///
62-
/// Some places, e.g. the installinator, request artifacts by hash rather than
63-
/// by name and version. This type indicates that.
64-
#[derive(
65-
Debug,
66-
Clone,
67-
PartialEq,
68-
Eq,
69-
Hash,
70-
Ord,
71-
PartialOrd,
72-
Deserialize,
73-
Serialize,
74-
JsonSchema,
75-
)]
76-
pub struct ArtifactHashId {
77-
/// The kind of artifact this is.
78-
pub kind: ArtifactKind,
79-
80-
/// The hash of the artifact.
81-
pub hash: ArtifactHash,
82-
}
83-
84-
/// The hash of an artifact.
85-
#[derive(
86-
Copy,
87-
Clone,
88-
Eq,
89-
PartialEq,
90-
Ord,
91-
PartialOrd,
92-
Hash,
93-
Serialize,
94-
Deserialize,
95-
JsonSchema,
96-
)]
97-
#[serde(transparent)]
98-
#[cfg_attr(feature = "testing", derive(test_strategy::Arbitrary))]
99-
pub struct ArtifactHash(
100-
#[serde(with = "serde_human_bytes::hex_array")]
101-
#[schemars(schema_with = "hex_schema::<32>")]
102-
pub [u8; 32],
103-
);
104-
105-
impl AsRef<[u8]> for ArtifactHash {
106-
fn as_ref(&self) -> &[u8] {
107-
&self.0
108-
}
109-
}
110-
111-
impl fmt::Debug for ArtifactHash {
112-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113-
f.debug_tuple("ArtifactHash").field(&hex::encode(self.0)).finish()
114-
}
115-
}
116-
117-
impl fmt::Display for ArtifactHash {
118-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119-
f.write_str(&hex::encode(self.0))
120-
}
121-
}
122-
123-
impl FromStr for ArtifactHash {
124-
type Err = FromHexError;
125-
126-
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
127-
let mut out = [0u8; 32];
128-
hex::decode_to_slice(s, &mut out)?;
129-
Ok(Self(out))
130-
}
131-
}
132-
133-
/// Produce an OpenAPI schema describing a hex array of a specific length (e.g.,
134-
/// a hash digest).
135-
pub fn hex_schema<const N: usize>(gen: &mut SchemaGenerator) -> Schema {
136-
let mut schema: SchemaObject = <String>::json_schema(gen).into();
137-
schema.format = Some(format!("hex string ({N} bytes)"));
138-
schema.into()
139-
}

dev-tools/reconfigurator-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use nexus_types::deployment::{Blueprint, UnstableReconfiguratorState};
3636
use omicron_common::api::external::Generation;
3737
use omicron_common::api::external::Name;
3838
use omicron_common::policy::NEXUS_REDUNDANCY;
39-
use omicron_common::update::ArtifactHash;
4039
use omicron_uuid_kinds::BlueprintUuid;
4140
use omicron_uuid_kinds::CollectionUuid;
4241
use omicron_uuid_kinds::GenericUuid;
@@ -52,6 +51,7 @@ use std::io::BufRead;
5251
use std::io::IsTerminal;
5352
use swrite::{SWrite, swriteln};
5453
use tabled::Tabled;
54+
use tufaceous_artifact::ArtifactHash;
5555
use tufaceous_artifact::ArtifactVersion;
5656

5757
mod log_capture;

gateway-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ slog-term.workspace = true
2121
termios.workspace = true
2222
tokio = { workspace = true, features = [ "io-std", "rt-multi-thread", "macros", "time" ] }
2323
tokio-tungstenite.workspace = true
24+
tufaceous-artifact.workspace = true
2425
uuid.workspace = true
2526

2627
gateway-client.workspace = true

0 commit comments

Comments
 (0)