diff options
Diffstat (limited to 'src/garage')
-rw-r--r-- | src/garage/Cargo.toml | 1 | ||||
-rw-r--r-- | src/garage/admin_rpc.rs | 30 | ||||
-rw-r--r-- | src/garage/main.rs | 18 | ||||
-rw-r--r-- | src/garage/server.rs | 6 |
4 files changed, 53 insertions, 2 deletions
diff --git a/src/garage/Cargo.toml b/src/garage/Cargo.toml index cb16bcd4..39288f40 100644 --- a/src/garage/Cargo.toml +++ b/src/garage/Cargo.toml @@ -19,6 +19,7 @@ garage_rpc = { version = "0.1", path = "../rpc" } garage_table = { version = "0.1.1", path = "../table" } garage_model = { version = "0.1.1", path = "../model" } garage_api = { version = "0.1.1", path = "../api" } +garage_web = { version = "0.1", path = "../web" } bytes = "0.4" rand = "0.7" diff --git a/src/garage/admin_rpc.rs b/src/garage/admin_rpc.rs index a23d3e95..e1981e3a 100644 --- a/src/garage/admin_rpc.rs +++ b/src/garage/admin_rpc.rs @@ -89,7 +89,7 @@ impl AdminRpcHandler { } bucket .state - .update(BucketState::Present(crdt::LWWMap::new())); + .update(BucketState::Present(BucketParams::new())); bucket } None => Bucket::new(query.name.clone()), @@ -155,6 +155,29 @@ impl AdminRpcHandler { &query.key_id, &query.bucket, allow_read, allow_write ))) } + BucketOperation::Website(query) => { + let mut bucket = self.get_existing_bucket(&query.bucket).await?; + + if !(query.allow ^ query.deny) { + return Err(Error::Message(format!( + "You must specify exactly one flag, either --allow or --deny" + ))); + } + + if let BucketState::Present(state) = bucket.state.get_mut() { + state.website.update(query.allow); + self.garage.bucket_table.insert(&bucket).await?; + let msg = if query.allow { + format!("Website access allowed for {}", &query.bucket) + } else { + format!("Website access denied for {}", &query.bucket) + }; + + Ok(AdminRPC::Ok(msg.to_string())) + } else { + unreachable!(); + } + } } } @@ -237,6 +260,7 @@ impl AdminRpcHandler { .unwrap_or(Err(Error::BadRPC(format!("Key {} does not exist", id)))) } + /// Update **bucket table** to inform of the new linked key async fn update_bucket_key( &self, mut bucket: Bucket, @@ -244,7 +268,8 @@ impl AdminRpcHandler { allow_read: bool, allow_write: bool, ) -> Result<(), Error> { - if let BucketState::Present(ak) = bucket.state.get_mut() { + if let BucketState::Present(params) = bucket.state.get_mut() { + let ak = &mut params.authorized_keys; let old_ak = ak.take_and_clear(); ak.merge(&old_ak.update_mutator( key_id.to_string(), @@ -262,6 +287,7 @@ impl AdminRpcHandler { Ok(()) } + /// Update **key table** to inform of the new linked bucket async fn update_key_bucket( &self, mut key: Key, diff --git a/src/garage/main.rs b/src/garage/main.rs index 1185871f..7c8899a0 100644 --- a/src/garage/main.rs +++ b/src/garage/main.rs @@ -141,6 +141,24 @@ pub enum BucketOperation { /// Allow key to read or write to bucket #[structopt(name = "deny")] Deny(PermBucketOpt), + + /// Expose as website or not + #[structopt(name = "website")] + Website(WebsiteOpt), +} + +#[derive(Serialize, Deserialize, StructOpt, Debug)] +pub struct WebsiteOpt { + /// Create + #[structopt(long = "allow")] + pub allow: bool, + + /// Delete + #[structopt(long = "deny")] + pub deny: bool, + + /// Bucket name + pub bucket: String, } #[derive(Serialize, Deserialize, StructOpt, Debug)] diff --git a/src/garage/server.rs b/src/garage/server.rs index 6caea5eb..ec78c067 100644 --- a/src/garage/server.rs +++ b/src/garage/server.rs @@ -11,6 +11,7 @@ use garage_util::error::Error; use garage_api::api_server; use garage_model::garage::Garage; use garage_rpc::rpc_server::RpcServer; +use garage_web::web_server; use crate::admin_rpc::*; @@ -56,6 +57,7 @@ pub async fn run_server(config_file: PathBuf) -> Result<(), Error> { info!("Initializing RPC and API servers..."); let run_rpc_server = Arc::new(rpc_server).run(wait_from(watch_cancel.clone())); let api_server = api_server::run_api_server(garage.clone(), wait_from(watch_cancel.clone())); + let web_server = web_server::run_web_server(garage.clone(), wait_from(watch_cancel.clone())); futures::try_join!( garage @@ -78,6 +80,10 @@ pub async fn run_server(config_file: PathBuf) -> Result<(), Error> { info!("API server exited"); rv }), + web_server.map(|rv| { + info!("Web server exited"); + rv + }), background.run().map(|rv| { info!("Background runner exited"); Ok(rv) |