forked from Deuxfleurs/garage
Add PutBucketWebsite and DeleteBucketWebsite to admin api
This commit is contained in:
parent
2ce3513c10
commit
5072dbd228
4 changed files with 94 additions and 0 deletions
|
@ -457,6 +457,26 @@ Deletes a storage bucket. A bucket cannot be deleted if it is not empty.
|
||||||
|
|
||||||
Warning: this will delete all aliases associated with the bucket!
|
Warning: this will delete all aliases associated with the bucket!
|
||||||
|
|
||||||
|
### PutBucketWebsite `PUT /bucket/website?id=<bucket id>`
|
||||||
|
|
||||||
|
Sets the website configuration for a bucket (this also enables website access for this bucket).
|
||||||
|
|
||||||
|
Request body format:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"indexDocument": "index.html",
|
||||||
|
"errorDocument": "404.html",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The field `errorDocument` is optional, if no error document is set a generic error message is displayed when errors happen.
|
||||||
|
|
||||||
|
|
||||||
|
### DeleteBucketWebsite `DELETE /bucket/website?id=<bucket id>`
|
||||||
|
|
||||||
|
Deletes the website configuration for a bucket (disables website access for this bucket).
|
||||||
|
|
||||||
|
|
||||||
## Operations on permissions for keys on buckets
|
## Operations on permissions for keys on buckets
|
||||||
|
|
||||||
|
@ -502,6 +522,7 @@ Request body format:
|
||||||
Flags in `permissions` which have the value `true` will be deactivated.
|
Flags in `permissions` which have the value `true` will be deactivated.
|
||||||
Other flags will remain unchanged.
|
Other flags will remain unchanged.
|
||||||
|
|
||||||
|
|
||||||
## Operations on bucket aliases
|
## Operations on bucket aliases
|
||||||
|
|
||||||
### GlobalAliasBucket `PUT /bucket/alias/global?id=<bucket id>&alias=<global alias>`
|
### GlobalAliasBucket `PUT /bucket/alias/global?id=<bucket id>&alias=<global alias>`
|
||||||
|
|
|
@ -144,6 +144,12 @@ impl ApiHandler for AdminApiServer {
|
||||||
}
|
}
|
||||||
Endpoint::CreateBucket => handle_create_bucket(&self.garage, req).await,
|
Endpoint::CreateBucket => handle_create_bucket(&self.garage, req).await,
|
||||||
Endpoint::DeleteBucket { id } => handle_delete_bucket(&self.garage, id).await,
|
Endpoint::DeleteBucket { id } => handle_delete_bucket(&self.garage, id).await,
|
||||||
|
Endpoint::PutBucketWebsite { id } => {
|
||||||
|
handle_put_bucket_website(&self.garage, id, req).await
|
||||||
|
}
|
||||||
|
Endpoint::DeleteBucketWebsite { id } => {
|
||||||
|
handle_delete_bucket_website(&self.garage, id).await
|
||||||
|
}
|
||||||
// Bucket-key permissions
|
// Bucket-key permissions
|
||||||
Endpoint::BucketAllowKey => {
|
Endpoint::BucketAllowKey => {
|
||||||
handle_bucket_change_key_perm(&self.garage, req, true).await
|
handle_bucket_change_key_perm(&self.garage, req, true).await
|
||||||
|
|
|
@ -374,6 +374,61 @@ pub async fn handle_delete_bucket(
|
||||||
.body(Body::empty())?)
|
.body(Body::empty())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- BUCKET WEBSITE CONFIGURATION ----
|
||||||
|
|
||||||
|
pub async fn handle_put_bucket_website(
|
||||||
|
garage: &Arc<Garage>,
|
||||||
|
id: String,
|
||||||
|
req: Request<Body>,
|
||||||
|
) -> Result<Response<Body>, Error> {
|
||||||
|
let req = parse_json_body::<PutBucketWebsiteRequest>(req).await?;
|
||||||
|
let bucket_id = parse_bucket_id(&id)?;
|
||||||
|
|
||||||
|
let mut bucket = garage
|
||||||
|
.bucket_helper()
|
||||||
|
.get_existing_bucket(bucket_id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let state = bucket.state.as_option_mut().unwrap();
|
||||||
|
state.website_config.update(Some(WebsiteConfig {
|
||||||
|
index_document: req.index_document,
|
||||||
|
error_document: req.error_document,
|
||||||
|
}));
|
||||||
|
|
||||||
|
garage.bucket_table.insert(&bucket).await?;
|
||||||
|
|
||||||
|
bucket_info_results(garage, bucket_id).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct PutBucketWebsiteRequest {
|
||||||
|
index_document: String,
|
||||||
|
#[serde(default)]
|
||||||
|
error_document: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn handle_delete_bucket_website(
|
||||||
|
garage: &Arc<Garage>,
|
||||||
|
id: String,
|
||||||
|
) -> Result<Response<Body>, Error> {
|
||||||
|
let bucket_id = parse_bucket_id(&id)?;
|
||||||
|
|
||||||
|
let mut bucket = garage
|
||||||
|
.bucket_helper()
|
||||||
|
.get_existing_bucket(bucket_id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let state = bucket.state.as_option_mut().unwrap();
|
||||||
|
state.website_config.update(None);
|
||||||
|
|
||||||
|
garage.bucket_table.insert(&bucket).await?;
|
||||||
|
|
||||||
|
bucket_info_results(garage, bucket_id).await
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- BUCKET/KEY PERMISSIONS ----
|
||||||
|
|
||||||
pub async fn handle_bucket_change_key_perm(
|
pub async fn handle_bucket_change_key_perm(
|
||||||
garage: &Arc<Garage>,
|
garage: &Arc<Garage>,
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
|
@ -426,6 +481,8 @@ struct BucketKeyPermChangeRequest {
|
||||||
permissions: ApiBucketKeyPerm,
|
permissions: ApiBucketKeyPerm,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- BUCKET ALIASES ----
|
||||||
|
|
||||||
pub async fn handle_global_alias_bucket(
|
pub async fn handle_global_alias_bucket(
|
||||||
garage: &Arc<Garage>,
|
garage: &Arc<Garage>,
|
||||||
bucket_id: String,
|
bucket_id: String,
|
||||||
|
@ -488,6 +545,8 @@ pub async fn handle_local_unalias_bucket(
|
||||||
bucket_info_results(garage, bucket_id).await
|
bucket_info_results(garage, bucket_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- HELPER ----
|
||||||
|
|
||||||
fn parse_bucket_id(id: &str) -> Result<Uuid, Error> {
|
fn parse_bucket_id(id: &str) -> Result<Uuid, Error> {
|
||||||
let id_hex = hex::decode(&id).ok_or_bad_request("Invalid bucket id")?;
|
let id_hex = hex::decode(&id).ok_or_bad_request("Invalid bucket id")?;
|
||||||
Ok(Uuid::try_from(&id_hex).ok_or_bad_request("Invalid bucket id")?)
|
Ok(Uuid::try_from(&id_hex).ok_or_bad_request("Invalid bucket id")?)
|
||||||
|
|
|
@ -46,6 +46,12 @@ pub enum Endpoint {
|
||||||
DeleteBucket {
|
DeleteBucket {
|
||||||
id: String,
|
id: String,
|
||||||
},
|
},
|
||||||
|
PutBucketWebsite {
|
||||||
|
id: String,
|
||||||
|
},
|
||||||
|
DeleteBucketWebsite {
|
||||||
|
id: String,
|
||||||
|
},
|
||||||
// Bucket-Key Permissions
|
// Bucket-Key Permissions
|
||||||
BucketAllowKey,
|
BucketAllowKey,
|
||||||
BucketDenyKey,
|
BucketDenyKey,
|
||||||
|
@ -103,6 +109,8 @@ impl Endpoint {
|
||||||
GET "/bucket" => ListBuckets,
|
GET "/bucket" => ListBuckets,
|
||||||
POST "/bucket" => CreateBucket,
|
POST "/bucket" => CreateBucket,
|
||||||
DELETE "/bucket" if id => DeleteBucket (query::id),
|
DELETE "/bucket" if id => DeleteBucket (query::id),
|
||||||
|
PUT "/bucket/website" if id => PutBucketWebsite (query::id),
|
||||||
|
DELETE "/bucket/website" if id => DeleteBucketWebsite (query::id),
|
||||||
// Bucket-key permissions
|
// Bucket-key permissions
|
||||||
POST "/bucket/allow" => BucketAllowKey,
|
POST "/bucket/allow" => BucketAllowKey,
|
||||||
POST "/bucket/deny" => BucketDenyKey,
|
POST "/bucket/deny" => BucketDenyKey,
|
||||||
|
|
Loading…
Reference in a new issue