Skip to content

Commit 77e2894

Browse files
uuid for api key
1 parent de26abf commit 77e2894

3 files changed

Lines changed: 3 additions & 21 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ semver = "1.0"
158158
static-files = "0.2"
159159
thiserror = "2.0"
160160
ulid = { version = "1.0", features = ["serde"] }
161+
uuid = { version = "1", features = ["v4"] }
161162
xxhash-rust = { version = "0.8", features = ["xxh3"] }
162163
futures-core = "0.3.31"
163164
tempfile = "3.20.0"

src/apikeys.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::collections::HashMap;
2020

2121
use chrono::{DateTime, Utc};
2222
use once_cell::sync::Lazy;
23-
use rand::Rng;
2423
use serde::{Deserialize, Serialize};
2524
use tokio::sync::RwLock;
2625
use ulid::Ulid;
@@ -77,7 +76,7 @@ impl ApiKey {
7776
let now = Utc::now();
7877
Self {
7978
key_id: Ulid::new(),
80-
api_key: generate_uuid_v4(),
79+
api_key: uuid::Uuid::new_v4().to_string(),
8180
key_name,
8281
created_by,
8382
created_at: now,
@@ -114,25 +113,6 @@ impl MetastoreObject for ApiKey {
114113
}
115114
}
116115

117-
/// Generate a UUID v4 formatted string using rand
118-
fn generate_uuid_v4() -> String {
119-
let mut rng = rand::thread_rng();
120-
let mut bytes = [0u8; 16];
121-
rng.fill(&mut bytes);
122-
// Set version 4 (bits 12-15 of time_hi_and_version)
123-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
124-
// Set variant 1 (bits 6-7 of clock_seq_hi_and_reserved)
125-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
126-
format!(
127-
"{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
128-
bytes[0], bytes[1], bytes[2], bytes[3],
129-
bytes[4], bytes[5],
130-
bytes[6], bytes[7],
131-
bytes[8], bytes[9],
132-
bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]
133-
)
134-
}
135-
136116
impl ApiKeyStore {
137117
/// Load API keys from object store into memory
138118
pub async fn load(&self) -> anyhow::Result<()> {

0 commit comments

Comments
 (0)