aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-01-29 12:46:20 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-01-29 19:26:16 +0100
commit1c03941b192dc1c8418618166293c3fb5b9732a9 (patch)
tree7c3120594bab4eff6db36e217931669c16d4664c /src
parent4f0b923c4f2bc9be80bf1e7ca61cc66c354cc7e0 (diff)
downloadgarage-1c03941b192dc1c8418618166293c3fb5b9732a9.tar.gz
garage-1c03941b192dc1c8418618166293c3fb5b9732a9.zip
admin api: fix panic on GetKeyInfo with no args
Diffstat (limited to 'src')
-rw-r--r--src/api/admin/key.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/api/admin/key.rs b/src/api/admin/key.rs
index 3e4201d9..d2f449ed 100644
--- a/src/api/admin/key.rs
+++ b/src/api/admin/key.rs
@@ -43,15 +43,19 @@ impl EndpointHandler for GetKeyInfoRequest {
type Response = GetKeyInfoResponse;
async fn handle(self, garage: &Arc<Garage>) -> Result<GetKeyInfoResponse, Error> {
- let key = if let Some(id) = self.id {
- garage.key_helper().get_existing_key(&id).await?
- } else if let Some(search) = self.search {
- garage
- .key_helper()
- .get_existing_matching_key(&search)
- .await?
- } else {
- unreachable!();
+ let key = match (self.id, self.search) {
+ (Some(id), None) => garage.key_helper().get_existing_key(&id).await?,
+ (None, Some(search)) => {
+ garage
+ .key_helper()
+ .get_existing_matching_key(&search)
+ .await?
+ }
+ _ => {
+ return Err(Error::bad_request(
+ "Either id or search must be provided (but not both)",
+ ));
+ }
};
Ok(key_info_results(garage, key, self.show_secret_key).await?)