From c9b733a4a667c82c665d84352624902dcba093a7 Mon Sep 17 00:00:00 2001 From: trinity-1686a Date: Sat, 14 Dec 2024 17:46:27 +0100 Subject: support redirection on s3 endpoint --- src/model/bucket_table.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/model/bucket_table.rs') diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index 1dbdfac2..625c177d 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -60,6 +60,60 @@ mod v08 { pub struct WebsiteConfig { pub index_document: String, pub error_document: Option, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub routing_rules: Vec, + } + + #[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] + pub struct RoutingRule { + pub condition: Option, + pub redirect: Redirect, + } + + #[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] + pub struct Condition { + pub http_error_code: Option, + pub prefix: Option, + } + + #[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] + pub struct Redirect { + pub hostname: Option, + pub http_redirect_code: u16, + pub protocol: Option, + pub replace_key_prefix: Option, + pub replace_key: Option, + } + + impl Redirect { + pub fn compute_target(&self, suffix: Option<&str>) -> String { + let mut res = String::new(); + if let Some(hostname) = &self.hostname { + if let Some(protocol) = &self.protocol { + res.push_str(&protocol); + res.push_str("://"); + } else { + res.push_str("//"); + } + res.push_str(&hostname); + } + res.push('/'); + if let Some(replace_key_prefix) = &self.replace_key_prefix { + res.push_str(&replace_key_prefix); + if let Some(suffix) = suffix { + res.push_str(suffix) + } + } else if let Some(replace_key) = &self.replace_key { + res.push_str(&replace_key) + } + res + } + } + + #[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] + pub struct RedirectAll { + pub hostname: String, + pub protoco: String, } #[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] -- cgit v1.2.3