diff options
author | Alex Auvolat <alex@adnab.me> | 2023-06-14 17:13:41 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-06-14 17:19:25 +0200 |
commit | 8ef42c9609bcefc642cc9739acb921dffba49b89 (patch) | |
tree | 5d479c3ad3951d5d44cea5c2e033b506733c4f0f /src/garage/admin/key.rs | |
parent | a83a092c032058728f191119de99f38844aa74f5 (diff) | |
download | garage-8ef42c9609bcefc642cc9739acb921dffba49b89.tar.gz garage-8ef42c9609bcefc642cc9739acb921dffba49b89.zip |
admin docs: reformatting, key admin: add check
Diffstat (limited to 'src/garage/admin/key.rs')
-rw-r--r-- | src/garage/admin/key.rs | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/src/garage/admin/key.rs b/src/garage/admin/key.rs index 908986fa..1c92670c 100644 --- a/src/garage/admin/key.rs +++ b/src/garage/admin/key.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use garage_table::*; -use garage_model::helper::error::Error; +use garage_model::helper::error::*; use garage_model::key_table::*; use crate::cli::*; @@ -127,22 +127,13 @@ impl AdminRpcHandler { return Err(Error::BadRequest("This command is intended to re-import keys that were previously generated by Garage. If you want to create a new key, use `garage key new` instead. Add the --yes flag if you really want to re-import a key.".to_string())); } - if query.key_id.len() != 26 - || &query.key_id[..2] != "GK" - || hex::decode(&query.key_id[2..]).is_err() - { - return Err(Error::BadRequest(format!("The specified key ID is not a valid Garage key ID (starts with `GK`, followed by 12 hex-encoded bytes)"))); - } - if query.secret_key.len() != 64 || hex::decode(&query.secret_key).is_err() { - return Err(Error::BadRequest(format!("The specified secret key is not a valid Garage secret key (composed of 32 hex-encoded bytes)"))); - } - let prev_key = self.garage.key_table.get(&EmptyKey, &query.key_id).await?; if prev_key.is_some() { return Err(Error::BadRequest(format!("Key {} already exists in data store. Even if it is deleted, we can't let you create a new key with the same ID. Sorry.", query.key_id))); } - let imported_key = Key::import(&query.key_id, &query.secret_key, &query.name); + let imported_key = Key::import(&query.key_id, &query.secret_key, &query.name) + .ok_or_bad_request("Invalid key format")?; self.garage.key_table.insert(&imported_key).await?; self.key_info_result(imported_key).await |