mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-28 16:07:06 +00:00
admin api: update cors and lifecycle rules in UpdateBucket
This commit is contained in:
@@ -4285,6 +4285,24 @@
|
|||||||
"UpdateBucketRequestBody": {
|
"UpdateBucketRequestBody": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"corsRules": {
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/cors.Rule"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lifecycleRules": {
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/lifecycle.Rule"
|
||||||
|
}
|
||||||
|
},
|
||||||
"quotas": {
|
"quotas": {
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -949,6 +949,10 @@ pub struct UpdateBucketResponse(pub GetBucketInfoResponse);
|
|||||||
pub struct UpdateBucketRequestBody {
|
pub struct UpdateBucketRequestBody {
|
||||||
pub website_access: Option<UpdateBucketWebsiteAccess>,
|
pub website_access: Option<UpdateBucketWebsiteAccess>,
|
||||||
pub quotas: Option<ApiBucketQuotas>,
|
pub quotas: Option<ApiBucketQuotas>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub cors_rules: Option<Vec<xml::cors::CorsRule>>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub lifecycle_rules: Option<Vec<xml::lifecycle::LifecycleRule>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||||
|
|||||||
@@ -323,6 +323,38 @@ impl RequestHandler for UpdateBucketRequest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(cr) = self.body.cors_rules {
|
||||||
|
let cors_config = if cr.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let cc = xml::cors::CorsConfiguration {
|
||||||
|
xmlns: (),
|
||||||
|
cors_rules: cr,
|
||||||
|
};
|
||||||
|
cc.validate()?;
|
||||||
|
Some(cc.into_garage_cors_config()?)
|
||||||
|
};
|
||||||
|
|
||||||
|
state.cors_config.update(cors_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(lr) = self.body.lifecycle_rules {
|
||||||
|
let lifecycle_config = if lr.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let lc = xml::lifecycle::LifecycleConfiguration {
|
||||||
|
xmlns: (),
|
||||||
|
lifecycle_rules: lr,
|
||||||
|
};
|
||||||
|
Some(
|
||||||
|
lc.validate_into_garage_lifecycle_config()
|
||||||
|
.ok_or_bad_request("Invalid lifecycle configuration")?,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
state.lifecycle_config.update(lifecycle_config);
|
||||||
|
}
|
||||||
|
|
||||||
garage.bucket_table.insert(&bucket).await?;
|
garage.bucket_table.insert(&bucket).await?;
|
||||||
|
|
||||||
Ok(UpdateBucketResponse(
|
Ok(UpdateBucketResponse(
|
||||||
|
|||||||
@@ -324,6 +324,8 @@ impl Cli {
|
|||||||
body: UpdateBucketRequestBody {
|
body: UpdateBucketRequestBody {
|
||||||
website_access: Some(wa),
|
website_access: Some(wa),
|
||||||
quotas: None,
|
quotas: None,
|
||||||
|
cors_rules: None,
|
||||||
|
lifecycle_rules: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
@@ -374,6 +376,8 @@ impl Cli {
|
|||||||
body: UpdateBucketRequestBody {
|
body: UpdateBucketRequestBody {
|
||||||
website_access: None,
|
website_access: None,
|
||||||
quotas: Some(new_quotas),
|
quotas: Some(new_quotas),
|
||||||
|
cors_rules: None,
|
||||||
|
lifecycle_rules: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user