Skip to main content

ipscanner/types/
gate.rs

1use serde::{Deserialize, Serialize};
2
3/// Body of `POST /v1/gate/verify`.
4#[derive(Debug, Clone, Default, PartialEq, Serialize)]
5pub struct GateVerifyRequest {
6    /// The site secret (`gs_...`).
7    pub secret: String,
8    pub token: String,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub remote_ip: Option<String>,
11    /// The address the form submitted. Adds an email check (one request).
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub email: Option<String>,
14}
15
16impl GateVerifyRequest {
17    pub fn new(secret: impl Into<String>, token: impl Into<String>) -> Self {
18        GateVerifyRequest {
19            secret: secret.into(),
20            token: token.into(),
21            remote_ip: None,
22            email: None,
23        }
24    }
25}
26
27/// Response of `POST /v1/gate/verify`. Wire names are snake_case.
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29#[serde(default)]
30pub struct GateVerification {
31    pub success: bool,
32    /// Traffic class, as on an edge check.
33    pub class: String,
34    /// `allow`, `flag` or `block`.
35    pub action: String,
36    /// `monitor` or `enforce`.
37    pub mode: String,
38    pub confidence: f64,
39    pub network: GateNetwork,
40    pub signals: Vec<String>,
41    pub hostname: String,
42    pub issued_at: String,
43    pub ip_match: bool,
44    /// Present when `email` was sent. `action` is then the stricter of the network and email actions.
45    pub email: Option<GateEmail>,
46    pub locked: Vec<String>,
47    #[serde(rename = "planRequired")]
48    pub plan_required: Option<String>,
49}
50
51/// The email check of a gate verification.
52#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
53#[serde(default)]
54pub struct GateEmail {
55    pub status: String,
56    pub reason: Option<String>,
57    pub suggestion: Option<String>,
58    pub domain: String,
59    /// The site's email policy for this outcome.
60    pub action: String,
61}
62
63/// The network part of a gate verification.
64#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
65#[serde(default)]
66pub struct GateNetwork {
67    pub classification: String,
68    pub anonymized: bool,
69    /// The network owner. Null when unknown or on the site owner's Free plan.
70    pub provider: Option<String>,
71    /// The VPN brand. Null when unknown or on the site owner's Free plan.
72    pub vpn_provider: Option<String>,
73}