Skip to content

Commit

Permalink
adjust types
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Apr 10, 2024
1 parent 03e8eb4 commit 3e173fd
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 20 deletions.
Binary file added .DS_Store
Binary file not shown.
151 changes: 131 additions & 20 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_json::{Number, Value};
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug)]
pub struct TlsConfig {
pub certs: Value,
pub trusted_certs: Value,
pub enabled: bool,
pub loose: bool,
pub trust_all: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Backend {
pub id: String,
Expand All @@ -12,7 +21,7 @@ pub struct Backend {
pub protocol: String,
pub ip_address: Option<String>,
pub predicate: Value,
pub tls_config: Value,
pub tls_config: Option<TlsConfig>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -43,6 +52,7 @@ pub struct RawRequest {
pub tls: bool,
pub uri: String,
pub path: String,
pub query: HashMap<String, Vec<String>>,
pub version: String,
pub has_body: bool,
pub remote: String,
Expand All @@ -65,18 +75,42 @@ pub struct HealthCheck {
pub url: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Client {
pub retries: Number,
pub max_errors: Number,
pub retry_initial_delay: Number,
pub backoff_factor: Number,
pub call_timeout: Number,
pub call_and_stream_timeout: Number,
pub connection_timeout: Number,
pub idle_timeout: Number,
pub global_timeout: Number,
pub sample_interval: Number,
pub proxy: Value,
pub custom_timeouts: Value,
pub cache_connection_settings: Value,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct RouteBackend {
pub targets: Vec<Backend>,
pub root: String,
pub rewrite: bool,
pub load_balancing: Value,
pub client: Value,
pub client: Client,
pub health_check: Option<HealthCheck>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Location {
pub tenant: String,
pub teams: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Route {
pub _loc: Location,
pub id: String,
pub name: String,
pub description: String,
Expand All @@ -93,22 +127,36 @@ pub struct Route {
pub plugins: Value,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct OtoroshiResponse {
pub status: u32,
pub headers: HashMap<String, String>,
pub cookies: Value,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Cookie {
pub name: String,
pub value: String,
pub domain: Option<String>,
pub path: String,
#[serde(alias = "maxAge")]
pub max_age: Option<Number>,
pub secure: bool,
#[serde(alias = "httpOnly")]
pub http_only: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct OtoroshiRequest {
pub url: String,
pub method: String,
pub headers: HashMap<String, String>,
pub query: HashMap<String, Vec<String>>,
pub version: String,
pub client_cert_chain: Value,
pub backend: Option<Backend>,
pub cookies: Value,
pub cookies: Vec<Cookie>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -118,29 +166,92 @@ pub struct WasmBackendContext {
pub apikey: Option<Apikey>,
pub user: Option<User>,
pub raw_request: RawRequest,
pub config: Value,
pub config: Config,
pub global_config: Value,
pub attrs: Value,
pub route: Route,
pub request_body_bytes: Option<Vec<u8>>,
pub request: OtoroshiRequest,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Source {
kind: String,
path: String,
opts: Value,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthorizationRights {
pub read: bool,
pub write: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Authorizations {
#[serde(alias = "httpAccess")]
pub http_access: bool,
#[serde(alias = "proxyHttpCallTimeout")]
pub proxy_http_call_timeout: Number,
#[serde(alias = "globalDataStoreAccess")]
pub global_data_store_access: AuthorizationRights,
#[serde(alias = "pluginDataStoreAccess")]
pub plugin_data_store_access: AuthorizationRights,
#[serde(alias = "globalMapAccess")]
pub global_map_access: AuthorizationRights,
#[serde(alias = "pluginMapAccess")]
pub plugin_map_access: AuthorizationRights,
#[serde(alias = "proxyStateAccess")]
pub proxy_state_access: bool,
#[serde(alias = "configurationAccess")]
pub configuration_access: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct KillOptions {
#[serde(alias = "immortal")]
pub immortal: bool,
pub max_calls: Number,
pub max_memory_usage: Number,
pub max_avg_call_duration: Number,
pub max_unused_duration: Number,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub source: Source,
#[serde(alias = "memoryPages")]
pub memory_pages: Number,
#[serde(alias = "functionName")]
pub function_name: String,
pub config: Value,
#[serde(alias = "allowedHosts")]
pub allowed_hosts: Vec<String>,
#[serde(alias = "allowedPaths")]
pub allowed_paths: Value,
pub wasi: bool,
pub opa: bool,
pub authorizations: Authorizations,
pub instances: Number,
#[serde(alias = "killOptions")]
pub kill_options: KillOptions,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct WasmAccessValidatorContext {
pub snowflake: Option<String>,
pub apikey: Option<Apikey>,
pub user: Option<User>,
pub request: RawRequest,
pub config: Value,
pub config: Config,
pub global_config: Value,
pub attrs: Value,
pub route: Route,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmRequestTransformerContext {
pub snowflake: Option<String>,
pub snowflake: String,
pub raw_request: OtoroshiRequest,
pub otoroshi_request: OtoroshiRequest,
pub backend: Backend,
Expand All @@ -154,22 +265,22 @@ pub struct WasmRequestTransformerContext {
pub request_body_bytes: Option<Vec<u8>>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmResponseTransformerContext {
pub snowflake: Option<String>,
pub raw_response: OtoroshiResponse,
pub otoroshi_response: OtoroshiResponse,
pub apikey: Option<Apikey>,
pub user: Option<User>,
pub request: RawRequest,
pub config: Value,
pub config: Config,
pub global_config: Value,
pub attrs: Value,
pub route: Route,
pub response_body_bytes: Option<Vec<u8>>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmSinkContext {
pub snowflake: Option<String>,
pub request: RawRequest,
Expand All @@ -181,12 +292,12 @@ pub struct WasmSinkContext {
pub message: String,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct OtoroshiPluginResponse {
pub content: String,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmBackendResponse {
pub headers: Option<HashMap<String, String>>,
pub body_bytes: Option<Vec<u8>>,
Expand All @@ -196,19 +307,19 @@ pub struct WasmBackendResponse {
pub status: u32,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmAccessValidatorError {
pub message: String,
pub status: u32,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmAccessValidatorResponse {
pub result: bool,
pub error: Option<WasmAccessValidatorError>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmTransformerResponse {
pub headers: HashMap<String, String>,
pub cookies: Value,
Expand All @@ -218,12 +329,12 @@ pub struct WasmTransformerResponse {
pub body_str: Option<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmSinkMatchesResponse {
pub result: bool,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WasmSinkHandleResponse {
pub status: u32,
pub headers: HashMap<String, String>,
Expand Down

0 comments on commit 3e173fd

Please sign in to comment.