more complete admin API #298
3 changed files with 67 additions and 55 deletions
|
@ -67,17 +67,16 @@ pub async fn handle_list_buckets(garage: &Arc<Garage>) -> Result<Response<Body>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct ListBucketResultItem {
|
struct ListBucketResultItem {
|
||||||
id: String,
|
id: String,
|
||||||
#[serde(rename = "globalAliases")]
|
|
||||||
global_aliases: Vec<String>,
|
global_aliases: Vec<String>,
|
||||||
#[serde(rename = "localAliases")]
|
|
||||||
local_aliases: Vec<BucketLocalAlias>,
|
local_aliases: Vec<BucketLocalAlias>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct BucketLocalAlias {
|
struct BucketLocalAlias {
|
||||||
#[serde(rename = "accessKeyId")]
|
|
||||||
access_key_id: String,
|
access_key_id: String,
|
||||||
alias: String,
|
alias: String,
|
||||||
}
|
}
|
||||||
|
@ -156,7 +155,8 @@ async fn bucket_info_results(
|
||||||
|
|
||||||
let state = bucket.state.as_option().unwrap();
|
let state = bucket.state.as_option().unwrap();
|
||||||
|
|
||||||
let res = GetBucketInfoResult {
|
let res =
|
||||||
|
GetBucketInfoResult {
|
||||||
id: hex::encode(&bucket.id),
|
id: hex::encode(&bucket.id),
|
||||||
global_aliases: state
|
global_aliases: state
|
||||||
.aliases
|
.aliases
|
||||||
|
@ -165,6 +165,13 @@ async fn bucket_info_results(
|
||||||
.filter(|(_, _, a)| *a)
|
.filter(|(_, _, a)| *a)
|
||||||
.map(|(n, _, _)| n.to_string())
|
.map(|(n, _, _)| n.to_string())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
|
website_access: state.website_config.get().is_some(),
|
||||||
|
website_config: state.website_config.get().clone().map(|wsc| {
|
||||||
|
GetBucketInfoWebsiteResult {
|
||||||
|
index_document: wsc.index_document,
|
||||||
|
error_document: wsc.error_document,
|
||||||
|
}
|
||||||
|
}),
|
||||||
keys: relevant_keys
|
keys: relevant_keys
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, key)| {
|
.map(|(_, key)| {
|
||||||
|
@ -200,21 +207,29 @@ async fn bucket_info_results(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct GetBucketInfoResult {
|
struct GetBucketInfoResult {
|
||||||
id: String,
|
id: String,
|
||||||
#[serde(rename = "globalAliases")]
|
|
||||||
global_aliases: Vec<String>,
|
global_aliases: Vec<String>,
|
||||||
|
website_access: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
website_config: Option<GetBucketInfoWebsiteResult>,
|
||||||
keys: Vec<GetBucketInfoKey>,
|
keys: Vec<GetBucketInfoKey>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct GetBucketInfoWebsiteResult {
|
||||||
|
index_document: String,
|
||||||
|
error_document: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct GetBucketInfoKey {
|
struct GetBucketInfoKey {
|
||||||
#[serde(rename = "accessKeyId")]
|
|
||||||
access_key_id: String,
|
access_key_id: String,
|
||||||
#[serde(rename = "name")]
|
|
||||||
name: String,
|
name: String,
|
||||||
permissions: ApiBucketKeyPerm,
|
permissions: ApiBucketKeyPerm,
|
||||||
#[serde(rename = "bucketLocalAliases")]
|
|
||||||
bucket_local_aliases: Vec<String>,
|
bucket_local_aliases: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,19 +308,18 @@ pub async fn handle_create_bucket(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct CreateBucketRequest {
|
struct CreateBucketRequest {
|
||||||
#[serde(rename = "globalAlias")]
|
|
||||||
global_alias: Option<String>,
|
global_alias: Option<String>,
|
||||||
#[serde(rename = "localAlias")]
|
|
||||||
local_alias: Option<CreateBucketLocalAlias>,
|
local_alias: Option<CreateBucketLocalAlias>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct CreateBucketLocalAlias {
|
struct CreateBucketLocalAlias {
|
||||||
#[serde(rename = "accessKeyId")]
|
|
||||||
access_key_id: String,
|
access_key_id: String,
|
||||||
alias: String,
|
alias: String,
|
||||||
#[serde(rename = "allPermissions", default)]
|
#[serde(default)]
|
||||||
all_permissions: bool,
|
all_permissions: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,10 +434,9 @@ pub async fn handle_bucket_change_key_perm(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct BucketKeyPermChangeRequest {
|
struct BucketKeyPermChangeRequest {
|
||||||
#[serde(rename = "bucketId")]
|
|
||||||
bucket_id: String,
|
bucket_id: String,
|
||||||
#[serde(rename = "accessKeyId")]
|
|
||||||
access_key_id: String,
|
access_key_id: String,
|
||||||
permissions: ApiBucketKeyPerm,
|
permissions: ApiBucketKeyPerm,
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,19 +76,19 @@ fn get_cluster_layout(garage: &Arc<Garage>) -> GetClusterLayoutResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct GetClusterStatusResponse {
|
struct GetClusterStatusResponse {
|
||||||
node: String,
|
node: String,
|
||||||
garage_version: &'static str,
|
garage_version: &'static str,
|
||||||
#[serde(rename = "knownNodes")]
|
|
||||||
known_nodes: HashMap<String, KnownNodeResp>,
|
known_nodes: HashMap<String, KnownNodeResp>,
|
||||||
layout: GetClusterLayoutResponse,
|
layout: GetClusterLayoutResponse,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct GetClusterLayoutResponse {
|
struct GetClusterLayoutResponse {
|
||||||
version: u64,
|
version: u64,
|
||||||
roles: HashMap<String, Option<NodeRole>>,
|
roles: HashMap<String, Option<NodeRole>>,
|
||||||
#[serde(rename = "stagedRoleChanges")]
|
|
||||||
staged_role_changes: HashMap<String, Option<NodeRole>>,
|
staged_role_changes: HashMap<String, Option<NodeRole>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,28 +203,27 @@ async fn key_info_results(garage: &Arc<Garage>, key: Key) -> Result<Response<Bod
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct GetKeyInfoResult {
|
struct GetKeyInfoResult {
|
||||||
name: String,
|
name: String,
|
||||||
#[serde(rename = "accessKeyId")]
|
|
||||||
access_key_id: String,
|
access_key_id: String,
|
||||||
#[serde(rename = "secretAccessKey")]
|
|
||||||
secret_access_key: String,
|
secret_access_key: String,
|
||||||
permissions: KeyPerm,
|
permissions: KeyPerm,
|
||||||
buckets: Vec<KeyInfoBucketResult>,
|
buckets: Vec<KeyInfoBucketResult>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct KeyPerm {
|
struct KeyPerm {
|
||||||
#[serde(rename = "createBucket", default)]
|
#[serde(default)]
|
||||||
create_bucket: bool,
|
create_bucket: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct KeyInfoBucketResult {
|
struct KeyInfoBucketResult {
|
||||||
id: String,
|
id: String,
|
||||||
#[serde(rename = "globalAliases")]
|
|
||||||
global_aliases: Vec<String>,
|
global_aliases: Vec<String>,
|
||||||
#[serde(rename = "localAliases")]
|
|
||||||
local_aliases: Vec<String>,
|
local_aliases: Vec<String>,
|
||||||
permissions: ApiBucketKeyPerm,
|
permissions: ApiBucketKeyPerm,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue