1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::net::IpAddr;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::entity::EntityDescriptorConst;

#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
pub enum BanScope {
    /// Prevent all traffic on a network level.
    #[serde(rename = "all_network_traffic")]
    AllNetworkTraffic,
}

#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
pub struct IpBlacklistEntrySpec {
    pub ips: Vec<IpAddr>,
    pub scope: BanScope,
    #[serde(
        deserialize_with = "time::serde::timestamp::option::deserialize",
        serialize_with = "time::serde::timestamp::option::serialize"
    )]
    #[schemars(with = "Option<u64>")]
    pub valid_until: Option<time::OffsetDateTime>,
}

impl EntityDescriptorConst for IpBlacklistEntrySpec {
    const NAMESPACE: &'static str = "edge.io";
    const NAME: &'static str = "IpBlacklistEntry";
    const VERSION: &'static str = "1";
    const KIND: &'static str = "edge.io/IpBlacklistEntry.v1";

    type Spec = Self;
    type State = ();
}

pub type IpBlacklistEntry = super::entity::Entity<IpBlacklistEntrySpec>;