Generate random runner tokens
This commit is contained in:
parent
f84a5b288e
commit
8005718584
3 changed files with 15 additions and 12 deletions
14
src/id.rs
Normal file
14
src/id.rs
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue