Generate random runner tokens
This commit is contained in:
parent
f84a5b288e
commit
8005718584
3 changed files with 15 additions and 12 deletions
|
|
@ -1,22 +1,10 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use gix::{actor::IdentityRef, date::Time};
|
||||
use rand::{rngs::OsRng, seq::IteratorRandom};
|
||||
use time::{macros::format_description, OffsetDateTime, UtcOffset};
|
||||
|
||||
use crate::somehow;
|
||||
|
||||
const RUN_ID_PREFIX: &str = "r-";
|
||||
const RUN_ID_CHARS: &str = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
const RUN_ID_LEN: usize = 30; // log(16^40, base=len(RUN_ID_CHARS)) ~ 31
|
||||
|
||||
pub fn new_run_id() -> String {
|
||||
RUN_ID_PREFIX
|
||||
.chars()
|
||||
.chain((0..RUN_ID_LEN).map(|_| RUN_ID_CHARS.chars().choose(&mut OsRng).unwrap()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn time_to_offset_datetime(time: Time) -> somehow::Result<OffsetDateTime> {
|
||||
Ok(OffsetDateTime::from_unix_timestamp(time.seconds)?
|
||||
.to_offset(UtcOffset::from_whole_seconds(time.offset)?))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue