Skip to content

Commit 4e46032

Browse files
committed
use TypedUuid for session and token IDs
1 parent c3d1152 commit 4e46032

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

nexus/db-model/src/console_session.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44

55
use chrono::{DateTime, Utc};
66
use nexus_db_schema::schema::console_session;
7+
use omicron_uuid_kinds::ConsoleSessionKind;
8+
use omicron_uuid_kinds::TypedUuid;
79
use uuid::Uuid;
810

11+
use crate::typed_uuid::DbTypedUuid;
12+
913
// TODO: `struct SessionToken(String)` for session token
1014

1115
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
1216
#[diesel(table_name = console_session)]
1317
pub struct ConsoleSession {
14-
pub id: Uuid,
18+
pub id: DbTypedUuid<ConsoleSessionKind>,
1519
pub token: String,
1620
pub time_created: DateTime<Utc>,
1721
pub time_last_used: DateTime<Utc>,
@@ -22,7 +26,7 @@ impl ConsoleSession {
2226
pub fn new(token: String, silo_user_id: Uuid) -> Self {
2327
let now = Utc::now();
2428
Self {
25-
id: Uuid::new_v4(),
29+
id: TypedUuid::new_v4().into(),
2630
token,
2731
silo_user_id,
2832
time_last_used: now,

nexus/db-model/src/device_auth.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ use nexus_db_schema::schema::{device_access_token, device_auth_request};
1111

1212
use chrono::{DateTime, Duration, Utc};
1313
use nexus_types::external_api::views;
14+
use omicron_uuid_kinds::{AccessTokenKind, TypedUuid};
1415
use rand::{Rng, RngCore, SeedableRng, distributions::Slice, rngs::StdRng};
1516
use uuid::Uuid;
1617

18+
use crate::typed_uuid::DbTypedUuid;
19+
1720
/// Default timeout in seconds for client to authenticate for a token request.
1821
const CLIENT_AUTHENTICATION_TIMEOUT: i64 = 300;
1922

@@ -117,7 +120,7 @@ impl DeviceAuthRequest {
117120
#[derive(Clone, Debug, Insertable, Queryable, Selectable)]
118121
#[diesel(table_name = device_access_token)]
119122
pub struct DeviceAccessToken {
120-
pub id: Uuid,
123+
pub id: DbTypedUuid<AccessTokenKind>,
121124
pub token: String,
122125
pub client_id: Uuid,
123126
pub device_code: String,
@@ -137,7 +140,7 @@ impl DeviceAccessToken {
137140
let now = Utc::now();
138141
assert!(time_requested <= now);
139142
Self {
140-
id: Uuid::new_v4(),
143+
id: TypedUuid::new_v4().into(),
141144
token: generate_token(),
142145
client_id,
143146
device_code,

nexus/db-queries/src/db/datastore/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,12 @@ mod test {
482482
ByteCount, Error, IdentityMetadataCreateParams, LookupType, Name,
483483
};
484484
use omicron_test_utils::dev;
485-
use omicron_uuid_kinds::CollectionUuid;
486485
use omicron_uuid_kinds::DatasetUuid;
487486
use omicron_uuid_kinds::GenericUuid;
488487
use omicron_uuid_kinds::PhysicalDiskUuid;
489488
use omicron_uuid_kinds::SledUuid;
490489
use omicron_uuid_kinds::VolumeUuid;
490+
use omicron_uuid_kinds::{CollectionUuid, TypedUuid};
491491
use std::collections::HashMap;
492492
use std::collections::HashSet;
493493
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV6};
@@ -575,7 +575,7 @@ mod test {
575575
let silo_user_id = Uuid::new_v4();
576576

577577
let session = ConsoleSession {
578-
id: Uuid::new_v4(),
578+
id: TypedUuid::new_v4().into(),
579579
token: token.clone(),
580580
time_created: Utc::now() - Duration::minutes(5),
581581
time_last_used: Utc::now() - Duration::minutes(5),

uuid-kinds/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ macro_rules! impl_typed_uuid_kind {
5151
// Please keep this list in alphabetical order.
5252

5353
impl_typed_uuid_kind! {
54+
AccessToken => "access_token",
5455
AffinityGroup => "affinity_group",
5556
AntiAffinityGroup => "anti_affinity_group",
5657
Blueprint => "blueprint",
5758
Collection => "collection",
59+
ConsoleSession => "console_session",
5860
Dataset => "dataset",
5961
DemoSaga => "demo_saga",
6062
Downstairs => "downstairs",

0 commit comments

Comments
 (0)