Add tokens routes
This commit is contained in:
@@ -8,15 +8,45 @@ pub async fn robots_txt() -> HttpResponse {
|
||||
.body("User-agent: *\nDisallow: /\n")
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct LenConstraints {
|
||||
min: usize,
|
||||
max: usize,
|
||||
}
|
||||
|
||||
impl LenConstraints {
|
||||
pub fn new(min: usize, max: usize) -> Self {
|
||||
Self { min, max }
|
||||
}
|
||||
pub fn not_empty(max: usize) -> Self {
|
||||
Self { min: 1, max }
|
||||
}
|
||||
pub fn max_only(max: usize) -> Self {
|
||||
Self { min: 0, max }
|
||||
}
|
||||
|
||||
pub fn check_str(&self, s: &str) -> bool {
|
||||
s.len() >= self.min && s.len() <= self.max
|
||||
}
|
||||
|
||||
pub fn check_u32(&self, v: u32) -> bool {
|
||||
v >= self.min as u32 && v <= self.max as u32
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct ServerConstraints {
|
||||
// TODO
|
||||
pub token_name: LenConstraints,
|
||||
pub token_ip_net: LenConstraints,
|
||||
pub token_max_inactivity: LenConstraints,
|
||||
}
|
||||
|
||||
impl Default for ServerConstraints {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
// TODO
|
||||
token_name: LenConstraints::new(5, 255),
|
||||
token_ip_net: LenConstraints::max_only(44),
|
||||
token_max_inactivity: LenConstraints::new(3600, 3600 * 24 * 365),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user