Skip to content

Commit 0bb3fa8

Browse files
committed
fingerprint
1 parent db3538e commit 0bb3fa8

File tree

19 files changed

+136
-136
lines changed

19 files changed

+136
-136
lines changed

Cargo.lock

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ bencher_adapter = { path = "lib/bencher_adapter" }
2626
bencher_boundary = { path = "lib/bencher_boundary" }
2727
bencher_client = { path = "lib/bencher_client" }
2828
bencher_comment = { path = "lib/bencher_comment" }
29-
bencher_fingerprint = { path = "lib/bencher_fingerprint" }
3029
bencher_github = { path = "lib/bencher_github" }
3130
bencher_json = { path = "lib/bencher_json" }
3231
bencher_logger = { path = "lib/bencher_logger" }

lib/bencher_client/src/lib.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl From<bencher_json::DateTimeMillis> for types::DateTimeMillis {
168168
}
169169
}
170170

171-
macro_rules! into_uuids {
171+
macro_rules! try_into_json_uuids {
172172
($($list:ident[$name:ident]),*) => {
173173
$(
174174
impl TryFrom<types::$list> for bencher_json::JsonUuids {
@@ -189,7 +189,7 @@ macro_rules! into_uuids {
189189
};
190190
}
191191

192-
into_uuids!(
192+
try_into_json_uuids!(
193193
JsonOrganizations[JsonOrganization],
194194
JsonMembers[JsonMember],
195195
JsonProjects[JsonProject],
@@ -203,7 +203,7 @@ into_uuids!(
203203
JsonAlerts[JsonAlert]
204204
);
205205

206-
macro_rules! into_uuid {
206+
macro_rules! try_into_json_uuid {
207207
($($name:ident),*) => {
208208
$(
209209
impl TryFrom<types::$name> for bencher_json::JsonUuid {
@@ -220,7 +220,7 @@ macro_rules! into_uuid {
220220
};
221221
}
222222

223-
into_uuid!(
223+
try_into_json_uuid!(
224224
JsonOrganization,
225225
JsonMember,
226226
JsonProject,
@@ -234,3 +234,17 @@ into_uuid!(
234234
JsonModel,
235235
JsonAlert
236236
);
237+
238+
macro_rules! from_uuid {
239+
($($name:ident),*) => {
240+
$(
241+
impl From<bencher_json::$name> for types::$name {
242+
fn from(json: bencher_json::$name) -> Self {
243+
Self::from(uuid::Uuid::from(json))
244+
}
245+
}
246+
)*
247+
};
248+
}
249+
250+
from_uuid!(Fingerprint);

lib/bencher_fingerprint/Cargo.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/bencher_fingerprint/src/lib.rs

Lines changed: 0 additions & 90 deletions
This file was deleted.

lib/bencher_json/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::sync::LazyLock;
22

33
pub use bencher_valid::{
4-
BenchmarkName, Boundary, BranchName, CdfBoundary, DateTime, DateTimeMillis, Email, GitHash,
5-
Index, IqrBoundary, Jwt, Model, ModelTest, NameId, NameIdKind, NonEmpty, PercentageBoundary,
6-
ResourceId, ResourceIdKind, ResourceName, SampleSize, Sanitize, Secret, Slug, Units, Url,
7-
UserName, ValidError, Window,
4+
BenchmarkName, Boundary, BranchName, CdfBoundary, DateTime, DateTimeMillis, Email, Fingerprint,
5+
GitHash, Index, IqrBoundary, Jwt, Model, ModelTest, NameId, NameIdKind, NonEmpty,
6+
PercentageBoundary, ResourceId, ResourceIdKind, ResourceName, SampleSize, Sanitize, Secret,
7+
Slug, Units, Url, UserName, ValidError, Window,
88
};
99
#[cfg(feature = "plus")]
1010
pub use bencher_valid::{

lib/bencher_valid/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ regex = { version = "1.11", optional = true }
4848
regex-lite = { version = "0.1", optional = true }
4949
wasm-bindgen = { version = "0.2", optional = true }
5050

51+
[target.'cfg(target_os = "windows")'.dependencies]
52+
windows = { version = "0.60", optional = true, features = [
53+
"System_Profile_SystemManufacturers",
54+
] }
55+
5156
[dev-dependencies]
5257
# Workspace
5358
pretty_assertions.workspace = true

lib/bencher_valid/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub enum ValidError {
5656
Index(u8),
5757
#[error("Failed to parse plot index: {0}")]
5858
IndexStr(std::num::ParseIntError),
59+
#[error("Failed to validate fingerprint: {0}")]
60+
Fingerprint(String),
5961

6062
#[cfg(feature = "plus")]
6163
#[error("Failed to validate plan level: {0}")]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::str::FromStr;
2+
3+
use derive_more::Display;
4+
#[cfg(feature = "schema")]
5+
use schemars::JsonSchema;
6+
use serde::{Deserialize, Serialize};
7+
use uuid::Uuid;
8+
#[cfg(feature = "wasm")]
9+
use wasm_bindgen::prelude::*;
10+
11+
use crate::ValidError;
12+
13+
#[cfg(feature = "lite")]
14+
mod target_os;
15+
16+
#[typeshare::typeshare]
17+
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
18+
#[cfg_attr(feature = "schema", derive(JsonSchema))]
19+
#[cfg_attr(feature = "db", derive(diesel::FromSqlRow, diesel::AsExpression))]
20+
#[cfg_attr(feature = "db", diesel(sql_type = diesel::sql_types::Text))]
21+
pub struct Fingerprint(Uuid);
22+
23+
impl FromStr for Fingerprint {
24+
type Err = ValidError;
25+
26+
fn from_str(fingerprint: &str) -> Result<Self, Self::Err> {
27+
Ok(Self(fingerprint.parse().map_err(|_e| {
28+
ValidError::Fingerprint(fingerprint.to_owned())
29+
})?))
30+
}
31+
}
32+
33+
impl From<Fingerprint> for Uuid {
34+
fn from(fingerprint: Fingerprint) -> Self {
35+
fingerprint.0
36+
}
37+
}

lib/bencher_fingerprint/src/linux.rs renamed to lib/bencher_valid/src/fingerprint/target_os/linux.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::fs;
22

3+
use uuid::Uuid;
4+
35
const HEX_BASE: u32 = 16;
46

57
impl crate::Fingerprint {
@@ -10,8 +12,9 @@ impl crate::Fingerprint {
1012
}
1113
}
1214

13-
fn parse_machine_id(path: &str) -> Option<u128> {
15+
fn parse_machine_id(path: &str) -> Option<Uuid> {
1416
fs::read_to_string(path)
1517
.ok()
1618
.and_then(|id| u128::from_str_radix(id.trim(), HEX_BASE).ok())
19+
.map(Uuid::from_u128)
1720
}

0 commit comments

Comments
 (0)