edge-schema 0.1.0

Shared schema types for Wasmer Edge.
Documentation
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>;