Can register new clients
This commit is contained in:
37
src/user.rs
37
src/user.rs
@ -1,10 +1,11 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::utils::curr_time;
|
||||
use s3::error::S3Error;
|
||||
use s3::request::ResponseData;
|
||||
use s3::{Bucket, BucketConfiguration};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::utils::{curr_time, rand_str};
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum UserError {
|
||||
#[error("failed to fetch user configuration: {0}")]
|
||||
@ -27,6 +28,34 @@ pub struct User {
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
/// Single API client information
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct APIClient {
|
||||
/// Client unique ID
|
||||
pub id: uuid::Uuid,
|
||||
|
||||
/// Client description
|
||||
pub description: String,
|
||||
|
||||
/// Restricted API network for token
|
||||
pub network: Option<ipnet::IpNet>,
|
||||
|
||||
/// Client secret
|
||||
pub secret: String,
|
||||
}
|
||||
|
||||
impl APIClient {
|
||||
/// Generate a new API client
|
||||
pub fn generate(description: String, network: Option<ipnet::IpNet>) -> Self {
|
||||
Self {
|
||||
id: Default::default(),
|
||||
description,
|
||||
network,
|
||||
secret: rand_str(20),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct UserConfig {
|
||||
/// Target user ID
|
||||
@ -40,6 +69,9 @@ pub struct UserConfig {
|
||||
|
||||
/// Current user matrix token
|
||||
pub matrix_token: String,
|
||||
|
||||
/// API clients
|
||||
pub clients: Vec<APIClient>,
|
||||
}
|
||||
|
||||
impl UserConfig {
|
||||
@ -97,6 +129,7 @@ impl UserConfig {
|
||||
created: curr_time()?,
|
||||
updated: curr_time()?,
|
||||
matrix_token: "".to_string(),
|
||||
clients: vec![],
|
||||
})
|
||||
}
|
||||
Err(e) => Err(UserError::FetchUserConfig(e).into()),
|
||||
|
Reference in New Issue
Block a user