Skip to content

Commit 1331678

Browse files
emilyalbinijclulow
andcommitted
user: implement user factory
Co-Authored-By: Joshua M. Clulow <jmc@oxide.computer>
1 parent ebcdc85 commit 1331678

23 files changed

Lines changed: 2350 additions & 4 deletions

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"download",
1111
"factory/aws",
1212
"factory/gimlet",
13+
"factory/user",
1314
"factory/lab",
1415
"factory/propolis",
1516
"github/client",
@@ -44,6 +45,7 @@ wrong_self_convention = "allow"
4445
[workspace.dependencies]
4546
ansi-to-html = { version = "0.2", features = [ "lazy-init" ] }
4647
anyhow = "1"
48+
async-compression = { version = "0.4", features = ["gzip", "tokio"] }
4749
aws-config = "1"
4850
aws-credential-types = "1"
4951
aws-runtime = "1"
@@ -58,6 +60,7 @@ devinfo = { version = "0.1", features = [ "private" ] }
5860
dialoguer = { version = "0.12.0", default-features = false }
5961
dirs-next = "2"
6062
dropshot = "0.16"
63+
expect-test = "1"
6164
futures = "0.3"
6265
futures-core = "0.3"
6366
getopts = "0.2"
@@ -80,6 +83,7 @@ percent-encoding = "2.1"
8083
progenitor = { version = "0.11" }
8184
progenitor-client = { version = "0.11" }
8285
rand = "0.10"
86+
rand_pcg = "0.10"
8387
regex = "1"
8488
reqwest = { version = "0.12", features = [ "json", "stream" ] }
8589
rust-toolchain-file = "0.1"

common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ chrono = { workspace = true }
1616
libc = { workspace = true }
1717
new_mime_guess = { workspace = true }
1818
rand = { workspace = true }
19+
rand_pcg = { workspace = true }
1920
regex = { workspace = true }
2021
rusty_ulid = { workspace = true }
2122
serde = { workspace = true }

common/src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use std::time::Duration;
1212
use anyhow::Result;
1313
use chrono::prelude::*;
1414
use rand::distr::Alphanumeric;
15-
use rand::{rng, RngExt as _};
15+
use rand::{rng, Rng, RngExt, SeedableRng as _};
16+
use rand_pcg::Pcg64;
1617
use regex::Regex;
1718
use rusty_ulid::Ulid;
1819
use serde::{Deserialize, Serialize};
@@ -63,6 +64,24 @@ pub fn make_log(name: &'static str) -> Logger {
6364
}
6465
}
6566

67+
pub fn make_test_log() -> Logger {
68+
let dec = slog_term::PlainSyncDecorator::new(slog_term::TestStdoutWriter);
69+
let dr = slog_term::FullFormat::new(dec).build().fuse();
70+
Logger::root(dr, o!())
71+
}
72+
73+
pub fn make_test_rng() -> Pcg64 {
74+
/*
75+
* This is a deterministic rng that is guaranteed not to change behavior
76+
* across version bumps. We can rely on its outputs in assertions.
77+
*/
78+
Pcg64::seed_from_u64(42)
79+
}
80+
81+
pub fn make_test_ulid<R: Rng>(rng: &mut R) -> Ulid {
82+
Ulid::from_timestamp_with_rng(0, rng)
83+
}
84+
6685
fn bool_env(var: &str) -> bool {
6786
if let Ok(content) = std::env::var(var) {
6887
let lower = content.to_ascii_lowercase();

common/src/unix.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
use anyhow::{anyhow, Result};
6+
use serde::{Deserialize, Serialize};
67
use std::ffi::{CStr, CString};
78
use std::io::{Error as IoError, ErrorKind};
89
use std::path::PathBuf;
@@ -60,10 +61,16 @@ pub fn getuid() -> Uid {
6061
Uid(unsafe { libc::getuid() })
6162
}
6263

63-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
64+
#[derive(
65+
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
66+
)]
67+
#[serde(transparent)]
6468
pub struct Uid(pub u32);
6569

66-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
70+
#[derive(
71+
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
72+
)]
73+
#[serde(transparent)]
6774
pub struct Gid(pub u32);
6875

6976
fn catch_errno<T, F: Fn() -> T>(f: F) -> Result<T, IoError> {

database/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ macro_rules! sqlite_ulid_new_type {
258258
PartialOrd,
259259
Ord,
260260
Hash,
261-
Debug,
262261
serde::Serialize,
263262
serde::Deserialize,
264263
$($derives),*
@@ -311,6 +310,12 @@ macro_rules! sqlite_ulid_new_type {
311310
}
312311
}
313312

313+
impl std::fmt::Debug for $name {
314+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
315+
write!(f, "{}({})", stringify!($name), self.0.to_string())
316+
}
317+
}
318+
314319
impl std::str::FromStr for $name {
315320
type Err = rusty_ulid::DecodingError;
316321

factory/user/Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
name = "buildomat-factory-user"
3+
version.workspace = true
4+
edition.workspace = true
5+
license.workspace = true
6+
7+
[lints]
8+
workspace = true
9+
10+
[dependencies]
11+
buildomat-common = { path = "../../common" }
12+
buildomat-database = { path = "../../database" }
13+
buildomat-client = { path = "../../client" }
14+
buildomat-types = { path = "../../types" }
15+
16+
anyhow = { workspace = true }
17+
async-compression = { workspace = true }
18+
base64 = { workspace = true }
19+
chrono = { workspace = true }
20+
getopts = { workspace = true }
21+
libc = { workspace = true }
22+
rand = { workspace = true }
23+
reqwest = { workspace = true }
24+
rusty_ulid = { workspace = true }
25+
schemars = { workspace = true }
26+
sea-query = { workspace = true }
27+
serde = { workspace = true }
28+
serde_json = { workspace = true }
29+
slog = { workspace = true }
30+
slog-term = { workspace = true }
31+
smf = { workspace = true }
32+
strum = { workspace = true }
33+
tempfile = { workspace = true }
34+
tokio = { workspace = true }
35+
toml = { workspace = true }
36+
usdt = { workspace = true }
37+
38+
[dev-dependencies]
39+
expect-test = { workspace = true }

0 commit comments

Comments
 (0)