mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-29 08:27:07 +00:00
admin api: allow updating website routing rules
This commit is contained in:
@@ -4348,6 +4348,15 @@
|
|||||||
"string",
|
"string",
|
||||||
"null"
|
"null"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"routingRules": {
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/website.RoutingRule"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -961,6 +961,8 @@ pub struct UpdateBucketWebsiteAccess {
|
|||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub index_document: Option<String>,
|
pub index_document: Option<String>,
|
||||||
pub error_document: Option<String>,
|
pub error_document: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub routing_rules: Option<Vec<xml::website::RoutingRule>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- DeleteBucket ----
|
// ---- DeleteBucket ----
|
||||||
|
|||||||
+21
-3
@@ -294,10 +294,28 @@ impl RequestHandler for UpdateBucketRequest {
|
|||||||
|
|
||||||
if let Some(wa) = self.body.website_access {
|
if let Some(wa) = self.body.website_access {
|
||||||
if wa.enabled {
|
if wa.enabled {
|
||||||
let (redirect_all, routing_rules) = match state.website_config.get() {
|
let redirect_all = state
|
||||||
Some(wc) => (wc.redirect_all.clone(), wc.routing_rules.clone()),
|
.website_config
|
||||||
None => (None, Vec::new()),
|
.get()
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|wc| wc.redirect_all.clone());
|
||||||
|
|
||||||
|
let routing_rules = if let Some(rr) = wa.routing_rules {
|
||||||
|
for r in rr.iter() {
|
||||||
|
r.validate()?;
|
||||||
|
}
|
||||||
|
rr.into_iter()
|
||||||
|
.map(xml::website::RoutingRule::into_garage_routing_rule)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
} else {
|
||||||
|
state
|
||||||
|
.website_config
|
||||||
|
.get()
|
||||||
|
.as_ref()
|
||||||
|
.map(|wc| wc.routing_rules.clone())
|
||||||
|
.unwrap_or_default()
|
||||||
};
|
};
|
||||||
|
|
||||||
state.website_config.update(Some(WebsiteConfig {
|
state.website_config.update(Some(WebsiteConfig {
|
||||||
index_document: wa.index_document.ok_or_bad_request(
|
index_document: wa.index_document.ok_or_bad_request(
|
||||||
"Please specify indexDocument when enabling website access.",
|
"Please specify indexDocument when enabling website access.",
|
||||||
|
|||||||
@@ -149,30 +149,7 @@ impl WebsiteConfiguration {
|
|||||||
.routing_rules
|
.routing_rules
|
||||||
.rules
|
.rules
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|rule| {
|
.map(RoutingRule::into_garage_routing_rule)
|
||||||
bucket_table::RoutingRule {
|
|
||||||
condition: rule.condition.map(|condition| {
|
|
||||||
bucket_table::RedirectCondition {
|
|
||||||
http_error_code: condition.http_error_code.map(|c| c.0 as u16),
|
|
||||||
prefix: condition.prefix.map(|p| p.0),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
redirect: bucket_table::Redirect {
|
|
||||||
hostname: rule.redirect.hostname.map(|h| h.0),
|
|
||||||
protocol: rule.redirect.protocol.map(|p| p.0),
|
|
||||||
// aws default to 301, which i find punitive in case of
|
|
||||||
// misconfiguration (can be permanently cached on the
|
|
||||||
// user agent)
|
|
||||||
http_redirect_code: rule
|
|
||||||
.redirect
|
|
||||||
.http_redirect_code
|
|
||||||
.map(|c| c.0 as u16)
|
|
||||||
.unwrap_or(302),
|
|
||||||
replace_key_prefix: rule.redirect.replace_prefix.map(|k| k.0),
|
|
||||||
replace_key: rule.redirect.replace_full.map(|k| k.0),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -237,6 +214,31 @@ impl RoutingRule {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_garage_routing_rule(self) -> bucket_table::RoutingRule {
|
||||||
|
bucket_table::RoutingRule {
|
||||||
|
condition: self
|
||||||
|
.condition
|
||||||
|
.map(|condition| bucket_table::RedirectCondition {
|
||||||
|
http_error_code: condition.http_error_code.map(|c| c.0 as u16),
|
||||||
|
prefix: condition.prefix.map(|p| p.0),
|
||||||
|
}),
|
||||||
|
redirect: bucket_table::Redirect {
|
||||||
|
hostname: self.redirect.hostname.map(|h| h.0),
|
||||||
|
protocol: self.redirect.protocol.map(|p| p.0),
|
||||||
|
// aws default to 301, which i find punitive in case of
|
||||||
|
// misconfiguration (can be permanently cached on the
|
||||||
|
// user agent)
|
||||||
|
http_redirect_code: self
|
||||||
|
.redirect
|
||||||
|
.http_redirect_code
|
||||||
|
.map(|c| c.0 as u16)
|
||||||
|
.unwrap_or(302),
|
||||||
|
replace_key_prefix: self.redirect.replace_prefix.map(|k| k.0),
|
||||||
|
replace_key: self.redirect.replace_full.map(|k| k.0),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Condition {
|
impl Condition {
|
||||||
|
|||||||
@@ -309,12 +309,14 @@ impl Cli {
|
|||||||
error_document: opt
|
error_document: opt
|
||||||
.error_document
|
.error_document
|
||||||
.or_else(|| bucket_website_config.and_then(|x| x.error_document.clone())),
|
.or_else(|| bucket_website_config.and_then(|x| x.error_document.clone())),
|
||||||
|
routing_rules: None,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UpdateBucketWebsiteAccess {
|
UpdateBucketWebsiteAccess {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
index_document: None,
|
index_document: None,
|
||||||
error_document: None,
|
error_document: None,
|
||||||
|
routing_rules: None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user