Skip to main content

devops_armory/cloud/gcp/gke/route/
models.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize)]
4pub struct HTTPRoute {
5    pub kind: String,
6    pub apiVersion: String,
7    pub metadata: Metadata,
8    pub spec: HTTPRouteSpec,
9}
10
11#[derive(Debug, Serialize, Deserialize)]
12pub struct Metadata {
13    pub name: String,
14    pub namespace: String,
15    pub resourceVersion: Option<String>
16}
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct HTTPRouteSpec {
20    pub parentRefs: Vec<ParentRef>,
21    pub hostnames: Vec<String>,  
22    pub rules: Vec<Rule>,
23}
24
25#[derive(Debug, Serialize, Deserialize)]
26pub struct ParentRef {
27    pub kind: String,
28    pub name: String,
29}
30
31#[derive(Debug, Serialize, Deserialize)]
32pub struct Rule {
33    pub matches: Option<Vec<MatchCriteria>>,
34    pub filters: Option<Vec<Filter>>,
35    pub backendRefs: Vec<BackendRef>,
36}
37
38#[derive(Debug, Serialize, Deserialize)]
39pub struct MatchCriteria {
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub path: Option<Path>,
42    pub headers: Option<Vec<NameMatch>>,
43    #[serde(rename = "queryParams")]
44    pub query_params: Option<Vec<NameMatch>>,
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub method: Option<MethodMatch>,
47}
48
49#[derive(Debug, Serialize, Deserialize)]
50pub struct Path {
51    pub r#type: PathMatchType, 
52    pub value: String,
53}
54
55#[derive(Debug, Serialize, Deserialize)]
56pub struct Filter {    
57    #[serde(rename = "type")]    
58    pub filter_type: HttpRouteFilterType,    
59    #[serde(default, skip_serializing_if = "Option::is_none")]    
60    pub config: Option<FilterConfig>,
61}
62
63#[derive(Debug, Serialize, Deserialize)]
64pub struct URLRewrite {
65    pub hostname: String,
66    pub path: PathRewrite,
67}
68
69#[derive(Debug, Serialize, Deserialize)]
70pub struct PathRewrite {
71    pub r#type: String,
72    pub replacePrefixMatch: String,
73}
74
75#[derive(Debug, Serialize, Deserialize)]
76pub struct BackendRef {
77    pub name: String,
78    pub port: u16,
79}
80
81// Get resource version models
82
83#[derive(Debug, Serialize, Deserialize, Default)]
84pub struct HTTPRouteGetParent {
85    pub items: Vec<MetadataGet>,
86}
87
88#[derive(Debug, Serialize, Deserialize, Default)]
89pub struct HTTPRouteGet {
90    pub metadata: MetadataGet,
91}
92
93#[derive(Debug, Serialize, Deserialize, Default)]
94pub struct MetadataGet {
95    pub resourceVersion: String
96}
97
98#[derive(Debug, Serialize, Deserialize)]
99#[serde(tag = "type", content = "spec", rename_all = "PascalCase")]
100pub enum FilterConfig {
101    RequestHeaderModifier(RequestHeaderModifier),
102    ResponseHeaderModifier(ResponseHeaderModifier),
103    RequestMirror(RequestMirror),
104    RequestRedirect(RequestRedirect),
105    UrlRewrite(UrlRewrite),
106    FaultInjection(FaultInjection),
107    RateLimit(RateLimit),
108    Authentication(Authentication),
109}
110
111#[derive(Debug, Serialize, Deserialize)]
112#[serde(rename_all = "PascalCase")]
113pub enum HttpRouteFilterType {
114    RequestHeaderModifier,
115    ResponseHeaderModifier,
116    RequestMirror,
117    RequestRedirect,
118    UrlRewrite,
119    FaultInjection,
120    RateLimit,
121    Authentication,
122}
123
124#[derive(Debug, Serialize, Deserialize)]
125pub struct RequestHeaderModifier {
126    #[serde(default, skip_serializing_if = "Vec::is_empty")]
127    pub add: Vec<HeaderOp>,
128    #[serde(default, skip_serializing_if = "Vec::is_empty")]
129    pub remove: Vec<String>,
130    #[serde(default, skip_serializing_if = "Vec::is_empty")]
131    pub set: Vec<HeaderOp>,
132}
133
134#[derive(Debug, Serialize, Deserialize)]
135pub struct ResponseHeaderModifier {
136    #[serde(default, skip_serializing_if = "Vec::is_empty")]
137    pub add: Vec<HeaderOp>,
138    #[serde(default, skip_serializing_if = "Vec::is_empty")]
139    pub remove: Vec<String>,
140    #[serde(default, skip_serializing_if = "Vec::is_empty")]
141    pub set: Vec<HeaderOp>,
142}
143
144#[derive(Debug, Serialize, Deserialize)]
145pub struct HeaderOp {
146    pub name: String,
147    pub value: String,
148}
149
150#[derive(Debug, Serialize, Deserialize)]
151pub struct RequestMirror {
152    pub backend_service: String,
153    #[serde(default)]
154    pub percentage: Option<u8>,
155}
156
157#[derive(Debug, Serialize, Deserialize)]
158pub struct RequestRedirect {
159    pub scheme: Option<String>,
160    pub host: Option<String>,
161    pub path: Option<String>,
162    pub port: Option<u16>,
163    pub status_code: Option<u16>,
164}
165
166#[derive(Debug, Serialize, Deserialize)]
167pub struct UrlRewrite {
168    pub host: Option<String>,
169    pub path: Option<String>,
170}
171
172#[derive(Debug, Serialize, Deserialize)]
173pub struct FaultInjection {
174    pub delay_ms: Option<u64>,
175    pub abort_http_status: Option<u16>,
176    pub percentage: Option<u8>,
177}
178
179#[derive(Debug, Serialize, Deserialize)]
180pub struct RateLimit {
181    pub requests_per_unit: Option<u64>,
182    pub unit: Option<String>, // e.g., "second", "minute"
183}
184
185#[derive(Debug, Serialize, Deserialize)]
186pub struct Authentication {
187    pub provider: Option<String>,
188    pub jwt_audiences: Option<Vec<String>>,
189    pub jwks_uri: Option<String>,
190}
191
192/// HTTPRoute matches options
193
194#[derive(Debug, Serialize, Deserialize)]
195#[serde(rename_all = "PascalCase")]
196pub enum PathMatchType {
197    PathPrefix,
198    PathExact,
199    PathRegex,
200}
201
202#[derive(Debug, Serialize, Deserialize)]
203pub struct NameMatch {
204    #[serde(rename = "type")]
205    pub kind: MatchType,
206    pub name: String,
207    pub value: String,
208}
209
210#[derive(Debug, Serialize, Deserialize)]
211#[serde(rename_all = "PascalCase")]
212pub enum MatchType {
213    Exact,
214    Prefix,
215    RegularExpression,
216}
217
218// "GET", "POST" — keep as String for flexibility
219
220#[derive(Debug, Serialize, Deserialize)]
221pub struct MethodMatch {
222    pub method: String,
223}
224