zlayer_types/api/proxy.rs
1//! Reverse proxy API DTOs.
2//!
3//! Wire types for the read-only reverse proxy status endpoints: routes,
4//! load-balancer backend groups, TLS certificates, and L4 stream proxies.
5
6use serde::{Deserialize, Serialize};
7use utoipa::ToSchema;
8
9/// Information about a single registered route.
10#[derive(Debug, Serialize, Deserialize, ToSchema)]
11pub struct RouteInfo {
12 /// Owning service name.
13 pub service: String,
14 /// Endpoint name within the service.
15 pub endpoint: String,
16 /// Host pattern (e.g. `*.example.com`), or `null` for any host.
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub host: Option<String>,
19 /// Path prefix matched by this route.
20 pub path_prefix: String,
21 /// Whether the matched prefix is stripped before forwarding.
22 pub strip_prefix: bool,
23 /// Protocol (http, https, tcp, etc.).
24 pub protocol: String,
25 /// Exposure type (public / internal).
26 pub expose: String,
27 /// Backend addresses currently assigned to this route.
28 pub backends: Vec<String>,
29 /// Container target port.
30 pub target_port: u16,
31}
32
33/// Response for `GET /api/v1/proxy/routes`.
34#[derive(Debug, Serialize, Deserialize, ToSchema)]
35pub struct RoutesResponse {
36 /// Total number of routes.
37 pub total: usize,
38 /// Route details.
39 pub routes: Vec<RouteInfo>,
40}
41
42/// Information about a single backend in a load-balancer group.
43#[derive(Debug, Serialize, Deserialize, ToSchema)]
44pub struct BackendInfo {
45 /// Backend address (`ip:port`).
46 pub address: String,
47 /// Whether the backend is currently healthy.
48 pub healthy: bool,
49 /// Number of in-flight connections.
50 pub active_connections: u64,
51 /// Number of consecutive health-check failures.
52 pub consecutive_failures: u64,
53}
54
55/// A load-balancer backend group for one service.
56#[derive(Debug, Serialize, Deserialize, ToSchema)]
57pub struct BackendGroupInfo {
58 /// Service name.
59 pub service: String,
60 /// Load-balancing strategy (`round_robin` or `least_connections`).
61 pub strategy: String,
62 /// Backends in this group.
63 pub backends: Vec<BackendInfo>,
64 /// Number of healthy backends.
65 pub healthy_count: usize,
66 /// Total number of backends.
67 pub total_count: usize,
68}
69
70/// Response for `GET /api/v1/proxy/backends`.
71#[derive(Debug, Serialize, Deserialize, ToSchema)]
72pub struct BackendsResponse {
73 /// Total number of backend groups.
74 pub total_groups: usize,
75 /// Backend group details.
76 pub groups: Vec<BackendGroupInfo>,
77}
78
79/// Information about a loaded TLS certificate.
80#[derive(Debug, Serialize, Deserialize, ToSchema)]
81pub struct CertInfo {
82 /// Domain the certificate covers.
83 pub domain: String,
84 /// Certificate validity start (ISO-8601), if metadata is available.
85 #[serde(skip_serializing_if = "Option::is_none")]
86 pub not_before: Option<String>,
87 /// Certificate expiry (ISO-8601), if metadata is available.
88 #[serde(skip_serializing_if = "Option::is_none")]
89 pub not_after: Option<String>,
90 /// SHA-256 fingerprint, if metadata is available.
91 #[serde(skip_serializing_if = "Option::is_none")]
92 pub fingerprint: Option<String>,
93 /// Whether the certificate needs renewal (within 30 days of expiry).
94 pub needs_renewal: bool,
95}
96
97/// Response for `GET /api/v1/proxy/tls`.
98#[derive(Debug, Serialize, Deserialize, ToSchema)]
99pub struct TlsResponse {
100 /// Total number of cached certificates.
101 pub total: usize,
102 /// ACME email address, if configured.
103 #[serde(skip_serializing_if = "Option::is_none")]
104 pub acme_email: Option<String>,
105 /// Whether ACME auto-provisioning is available.
106 pub acme_available: bool,
107 /// Certificate details.
108 pub certificates: Vec<CertInfo>,
109}
110
111/// Information about a single L4 stream proxy backend.
112#[derive(Debug, Serialize, Deserialize, ToSchema)]
113pub struct StreamBackendInfo {
114 /// Backend address (`ip:port`).
115 pub address: String,
116}
117
118/// Information about a single L4 stream proxy.
119#[derive(Debug, Serialize, Deserialize, ToSchema)]
120pub struct StreamInfo {
121 /// Listen port on this node.
122 pub port: u16,
123 /// Transport protocol (`tcp` or `udp`).
124 pub protocol: String,
125 /// Service name.
126 pub service: String,
127 /// Number of backends.
128 pub backend_count: usize,
129 /// Backend addresses.
130 pub backends: Vec<StreamBackendInfo>,
131}
132
133/// Response for `GET /api/v1/proxy/streams`.
134#[derive(Debug, Serialize, Deserialize, ToSchema)]
135pub struct StreamsResponse {
136 /// Total number of stream proxies.
137 pub total: usize,
138 /// TCP stream count.
139 pub tcp_count: usize,
140 /// UDP stream count.
141 pub udp_count: usize,
142 /// Stream details.
143 pub streams: Vec<StreamInfo>,
144}