aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-06-14 17:13:41 +0200
committerAlex Auvolat <alex@adnab.me>2023-06-14 17:19:25 +0200
commit8ef42c9609bcefc642cc9739acb921dffba49b89 (patch)
tree5d479c3ad3951d5d44cea5c2e033b506733c4f0f /src
parenta83a092c032058728f191119de99f38844aa74f5 (diff)
downloadgarage-8ef42c9609bcefc642cc9739acb921dffba49b89.tar.gz
garage-8ef42c9609bcefc642cc9739acb921dffba49b89.zip
admin docs: reformatting, key admin: add check
Diffstat (limited to 'src')
-rw-r--r--src/api/admin/cluster.rs18
-rw-r--r--src/api/admin/key.rs3
-rw-r--r--src/garage/admin/key.rs15
-rw-r--r--src/model/key_table.rs14
4 files changed, 25 insertions, 25 deletions
diff --git a/src/api/admin/cluster.rs b/src/api/admin/cluster.rs
index ae4a1cc3..c8107b82 100644
--- a/src/api/admin/cluster.rs
+++ b/src/api/admin/cluster.rs
@@ -1,7 +1,7 @@
use std::net::SocketAddr;
use std::sync::Arc;
-use hyper::{Body, Request, Response, StatusCode};
+use hyper::{Body, Request, Response};
use serde::{Deserialize, Serialize};
use garage_util::crdt::*;
@@ -161,8 +161,8 @@ struct GetClusterStatusResponse {
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct ApplyClusterLayoutResponse {
- message: Vec<String>,
- layout: GetClusterLayoutResponse,
+ message: Vec<String>,
+ layout: GetClusterLayoutResponse,
}
#[derive(Serialize)]
@@ -238,7 +238,7 @@ pub async fn handle_update_cluster_layout(
garage.system.update_cluster_layout(&layout).await?;
let res = format_cluster_layout(&layout);
- Ok(json_ok_response(&res)?)
+ Ok(json_ok_response(&res)?)
}
pub async fn handle_apply_cluster_layout(
@@ -253,10 +253,10 @@ pub async fn handle_apply_cluster_layout(
garage.system.update_cluster_layout(&layout).await?;
let res = ApplyClusterLayoutResponse {
- message: msg,
- layout: format_cluster_layout(&layout),
- };
- Ok(json_ok_response(&res)?)
+ message: msg,
+ layout: format_cluster_layout(&layout),
+ };
+ Ok(json_ok_response(&res)?)
}
pub async fn handle_revert_cluster_layout(
@@ -270,7 +270,7 @@ pub async fn handle_revert_cluster_layout(
garage.system.update_cluster_layout(&layout).await?;
let res = format_cluster_layout(&layout);
- Ok(json_ok_response(&res)?)
+ Ok(json_ok_response(&res)?)
}
// ----
diff --git a/src/api/admin/key.rs b/src/api/admin/key.rs
index 0d1f799b..8d1c6890 100644
--- a/src/api/admin/key.rs
+++ b/src/api/admin/key.rs
@@ -93,7 +93,8 @@ pub async fn handle_import_key(
&req.access_key_id,
&req.secret_access_key,
req.name.as_deref().unwrap_or("Imported key"),
- );
+ )
+ .ok_or_bad_request("Invalid key format")?;
garage.key_table.insert(&imported_key).await?;
key_info_results(garage, imported_key, false).await
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
diff --git a/src/model/key_table.rs b/src/model/key_table.rs
index bb5334a3..a9762f1b 100644
--- a/src/model/key_table.rs
+++ b/src/model/key_table.rs
@@ -149,11 +149,19 @@ impl Key {
}
/// Import a key from it's parts
- pub fn import(key_id: &str, secret_key: &str, name: &str) -> Self {
- Self {
+ pub fn import(key_id: &str, secret_key: &str, name: &str) -> Result<Self, &'static str> {
+ if key_id.len() != 26 || &key_id[..2] != "GK" || hex::decode(&key_id[2..]).is_err() {
+ return Err("The specified key ID is not a valid Garage key ID (starts with `GK`, followed by 12 hex-encoded bytes)");
+ }
+
+ if secret_key.len() != 64 || hex::decode(&secret_key).is_err() {
+ return Err("The specified secret key is not a valid Garage secret key (composed of 32 hex-encoded bytes)");
+ }
+
+ Ok(Self {
key_id: key_id.to_string(),
state: crdt::Deletable::present(KeyParams::new(secret_key, name)),
- }
+ })
}
/// Create a new Key which can me merged to mark an existing key deleted