Generate random runner tokens

This commit is contained in:
Joscha 2023-08-10 16:58:28 +02:00
parent f84a5b288e
commit 8005718584
3 changed files with 15 additions and 12 deletions

14
src/id.rs Normal file
View file

@ -0,0 +1,14 @@
use rand::{rngs::OsRng, seq::IteratorRandom};
const ID_CHARS: &str = "0123456789abcdefghijklmnopqrstuvwxyz";
fn random_id(prefix: &str, length: usize) -> String {
prefix
.chars()
.chain((0..length).map(|_| ID_CHARS.chars().choose(&mut OsRng).unwrap()))
.collect()
}
pub fn random_runner_token() -> String {
random_id("t", 30)
}