Display the list of registered clients
This commit is contained in:
25
src/user.rs
25
src/user.rs
@@ -4,7 +4,8 @@ use s3::{Bucket, BucketConfiguration};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::utils::{curr_time, rand_str};
|
||||
use crate::constants::TOKEN_LEN;
|
||||
use crate::utils::{curr_time, format_time, rand_str};
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum UserError {
|
||||
@@ -42,16 +43,34 @@ pub struct APIClient {
|
||||
|
||||
/// Client secret
|
||||
pub secret: String,
|
||||
|
||||
/// Client creation time
|
||||
pub created: u64,
|
||||
|
||||
/// Client last usage time
|
||||
pub used: u64,
|
||||
}
|
||||
|
||||
impl APIClient {
|
||||
pub fn fmt_created(&self) -> String {
|
||||
format_time(self.created).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn fmt_used(&self) -> String {
|
||||
format_time(self.used).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl APIClient {
|
||||
/// Generate a new API client
|
||||
pub fn generate(description: String, network: Option<ipnet::IpNet>) -> Self {
|
||||
Self {
|
||||
id: Default::default(),
|
||||
id: uuid::Uuid::new_v4(),
|
||||
description,
|
||||
network,
|
||||
secret: rand_str(20),
|
||||
secret: rand_str(TOKEN_LEN),
|
||||
created: curr_time().unwrap(),
|
||||
used: curr_time().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user