From 9d1dbfb2f5fc5f11cc680f723a996175352a1e74 Mon Sep 17 00:00:00 2001 From: naskya Date: Tue, 2 Jul 2024 00:16:58 +0900 Subject: [PATCH] WIP --- fishctl/src/command/config/update/v1.rs | 43 ++++++++++++++++++++++++- fishctl/src/config/server.rs | 18 +++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/fishctl/src/command/config/update/v1.rs b/fishctl/src/command/config/update/v1.rs index f9e8071..9c14a36 100644 --- a/fishctl/src/command/config/update/v1.rs +++ b/fishctl/src/command/config/update/v1.rs @@ -175,7 +175,7 @@ struct Meta { object_storage_region: Option, object_storage_access_key: Option, object_storage_secret_key: Option, - object_storage_port: Option, + // object_storage_port: Option, object_storage_use_ssl: bool, object_storage_set_public_read: bool, object_storage_s3_force_path_style: bool, @@ -352,11 +352,51 @@ fn create_new_server_config( None }; + let object_storage = match meta.use_object_storage { + false => None, + true => Some(server::ObjectStorage { + enabled: true, + base_url: meta + .object_storage_base_url + .to_owned() + .ok_or(Error::InvalidConfig("Object storage base url is not set"))?, + bucket: meta + .object_storage_bucket + .to_owned() + .ok_or(Error::InvalidConfig( + "Object storage bucket name is not set", + ))?, + prefix: meta + .object_storage_prefix + .to_owned() + .ok_or(Error::InvalidConfig("Object storage prefix is not set"))?, + endpoint: { + if meta.object_storage_endpoint.is_none() { + cprintln!("Warning: Since the object storage endpoint is not set, we assume that you are using AWS S3. If it's not the case, please fill in the `file.object_storage.endpoint` field in `config/server.toml`."); + } + meta.object_storage_endpoint.to_owned() + }, + region: meta.object_storage_region.to_owned(), + access_key: meta + .object_storage_access_key + .to_owned() + .ok_or(Error::InvalidConfig("Object storage access key is not set"))?, + access_secret: meta.object_storage_secret_key.to_owned().ok_or( + Error::InvalidConfig("Object storage access secret is not set"), + )?, + use_ssl: meta.object_storage_use_ssl, + use_proxy: meta.object_storage_use_proxy, + set_public_read: meta.object_storage_set_public_read, + use_path_based_url: meta.object_storage_s3_force_path_style, + }), + }; + let file = { let mut file = server::File { max_size: None, proxy_remote_file: None, cache_remote_file: None, + object_storage, }; if let Some(max_size) = default_yml.get("maxFileSize") { @@ -381,6 +421,7 @@ fn create_new_server_config( if file.max_size.is_none() && file.proxy_remote_file.is_none() && file.proxy_remote_file.is_none() + && file.object_storage.is_none() { None } else { diff --git a/fishctl/src/config/server.rs b/fishctl/src/config/server.rs index be85b06..ebe5e15 100644 --- a/fishctl/src/config/server.rs +++ b/fishctl/src/config/server.rs @@ -157,6 +157,24 @@ pub struct File { pub max_size: Option, pub proxy_remote_file: Option, pub cache_remote_file: Option, + pub object_storage: Option, +} + +#[derive(Deserialize, Serialize, Validate, Debug, Clone)] +pub struct ObjectStorage { + pub enabled: bool, + #[validate(url)] + pub base_url: String, + pub bucket: String, + pub prefix: String, + pub endpoint: Option, + pub region: Option, + pub access_key: String, + pub access_secret: String, + pub use_ssl: bool, + pub use_proxy: bool, + pub set_public_read: bool, + pub use_path_based_url: bool, } #[derive(Deserialize, Serialize, Validate, Debug, Clone)]