From ea7fb901ebc316bba53d248a2f8bd7a3455f5791 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 7 Jan 2022 16:23:04 +0100 Subject: Implement {Put,Get,Delete}BucketCors and CORS in general - OPTIONS request against API endpoint - Returning corresponding CORS headers on API calls - Returning corresponding CORS headers on website GET's --- src/model/bucket_table.rs | 30 ++++++++++++++++++++++++------ src/model/migrate.rs | 3 ++- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src/model') diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index db7cec18..7c7b9f30 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -27,10 +27,7 @@ pub struct BucketParams { pub creation_date: u64, /// Map of key with access to the bucket, and what kind of access they give pub authorized_keys: crdt::Map, - /// Whether this bucket is allowed for website access - /// (under all of its global alias names), - /// and if so, the website configuration XML document - pub website_config: crdt::Lww>, + /// Map of aliases that are or have been given to this bucket /// in the global namespace /// (not authoritative: this is just used as an indication to @@ -40,6 +37,13 @@ pub struct BucketParams { /// in namespaces local to keys /// key = (access key id, alias name) pub local_aliases: crdt::LwwMap<(String, String), bool>, + + /// Whether this bucket is allowed for website access + /// (under all of its global alias names), + /// and if so, the website configuration XML document + pub website_config: crdt::Lww>, + /// CORS rules + pub cors_config: crdt::Lww>>, } #[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] @@ -48,15 +52,26 @@ pub struct WebsiteConfig { pub error_document: Option, } +#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] +pub struct CorsRule { + pub id: Option, + pub max_age_seconds: Option, + pub allow_origins: Vec, + pub allow_methods: Vec, + pub allow_headers: Vec, + pub expose_headers: Vec, +} + impl BucketParams { /// Create an empty BucketParams with no authorized keys and no website accesss pub fn new() -> Self { BucketParams { creation_date: now_msec(), authorized_keys: crdt::Map::new(), - website_config: crdt::Lww::new(None), aliases: crdt::LwwMap::new(), local_aliases: crdt::LwwMap::new(), + website_config: crdt::Lww::new(None), + cors_config: crdt::Lww::new(None), } } } @@ -65,9 +80,12 @@ impl Crdt for BucketParams { fn merge(&mut self, o: &Self) { self.creation_date = std::cmp::min(self.creation_date, o.creation_date); self.authorized_keys.merge(&o.authorized_keys); - self.website_config.merge(&o.website_config); + self.aliases.merge(&o.aliases); self.local_aliases.merge(&o.local_aliases); + + self.website_config.merge(&o.website_config); + self.cors_config.merge(&o.cors_config); } } diff --git a/src/model/migrate.rs b/src/model/migrate.rs index 65140c4b..7e61957a 100644 --- a/src/model/migrate.rs +++ b/src/model/migrate.rs @@ -69,9 +69,10 @@ impl Migrate { state: Deletable::Present(BucketParams { creation_date: now_msec(), authorized_keys: Map::new(), - website_config: Lww::new(website), aliases: LwwMap::new(), local_aliases: LwwMap::new(), + website_config: Lww::new(website), + cors_config: Lww::new(None), }), }) .await?; -- cgit v1.2.3