diff options
author | Alex <alex@adnab.me> | 2023-08-29 08:55:46 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2023-08-29 08:55:46 +0000 |
commit | 32e5686ad8354a2b2b37807ba6d7add73a6d23ee (patch) | |
tree | e1396dc9ddb11ec6728c3db94f71e349f3db10a8 /src/api | |
parent | 2bbe2da5adb044d3dfd7be22052cb2962318f9d5 (diff) | |
parent | 06369c8f4abcdedc1ae68e13f1045367674b5b45 (diff) | |
download | garage-0.8.3.tar.gz garage-0.8.3.zip |
Merge pull request 'Garage v0.8.3' (#619) from next-0.8 into mainv0.8.3
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/619
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/Cargo.toml | 2 | ||||
-rw-r--r-- | src/api/admin/api_server.rs | 39 |
2 files changed, 23 insertions, 18 deletions
diff --git a/src/api/Cargo.toml b/src/api/Cargo.toml index c2155eb9..a9279c37 100644 --- a/src/api/Cargo.toml +++ b/src/api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "garage_api" -version = "0.8.2" +version = "0.8.3" authors = ["Alex Auvolat <alex@adnab.me>"] edition = "2018" license = "AGPL-3.0" diff --git a/src/api/admin/api_server.rs b/src/api/admin/api_server.rs index 8bf467dc..50c79120 100644 --- a/src/api/admin/api_server.rs +++ b/src/api/admin/api_server.rs @@ -100,6 +100,20 @@ impl AdminApiServer { .get("domain") .ok_or_internal_error("Could not parse domain query string")?; + if self.check_domain(domain).await? { + Ok(Response::builder() + .status(StatusCode::OK) + .body(Body::from(format!( + "Domain '{domain}' is managed by Garage" + )))?) + } else { + Err(Error::bad_request(format!( + "Domain '{domain}' is not managed by Garage" + ))) + } + } + + async fn check_domain(&self, domain: &str) -> Result<bool, Error> { // Resolve bucket from domain name, inferring if the website must be activated for the // domain to be valid. let (bucket_name, must_check_website) = if let Some(bname) = self @@ -123,19 +137,18 @@ impl AdminApiServer { (domain.to_string(), true) }; - let bucket_id = self + let bucket_id = match self .garage .bucket_helper() .resolve_global_bucket_name(&bucket_name) .await? - .ok_or(HelperError::NoSuchBucket(bucket_name.to_string()))?; + { + Some(bucket_id) => bucket_id, + None => return Ok(false), + }; if !must_check_website { - return Ok(Response::builder() - .status(StatusCode::OK) - .body(Body::from(format!( - "Domain '{domain}' is managed by Garage" - )))?); + return Ok(true); } let bucket = self @@ -148,16 +161,8 @@ impl AdminApiServer { let bucket_website_config = bucket_state.website_config.get(); match bucket_website_config { - Some(_v) => { - Ok(Response::builder() - .status(StatusCode::OK) - .body(Body::from(format!( - "Domain '{domain}' is managed by Garage" - )))?) - } - None => Err(Error::bad_request(format!( - "Domain '{domain}' is not managed by Garage" - ))), + Some(_v) => Ok(true), + None => Ok(false), } } |