This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 7617c2fb7 feat(oay): actually read configuration from `oay.toml` 
(#2615)
7617c2fb7 is described below

commit 7617c2fb73f60142fab5eeca1230cb6cec6c40e4
Author: messense <[email protected]>
AuthorDate: Tue Jul 11 19:47:53 2023 +0800

    feat(oay): actually read configuration from `oay.toml` (#2615)
---
 bin/oay/src/bin/oay.rs | 21 +++++++--------------
 bin/oay/src/config.rs  |  4 ++++
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/bin/oay/src/bin/oay.rs b/bin/oay/src/bin/oay.rs
index cc35055b5..93d846fe1 100644
--- a/bin/oay/src/bin/oay.rs
+++ b/bin/oay/src/bin/oay.rs
@@ -15,13 +15,15 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::str::FromStr;
 use std::sync::Arc;
 
+use anyhow::Context;
 use anyhow::Result;
 use oay::services::S3Service;
 use oay::Config;
-use opendal::services::Memory;
 use opendal::Operator;
+use opendal::Scheme;
 use tracing_subscriber::fmt;
 use tracing_subscriber::prelude::*;
 use tracing_subscriber::EnvFilter;
@@ -33,19 +35,10 @@ async fn main() -> Result<()> {
         .with(EnvFilter::from_default_env())
         .init();
 
-    let cfg: Config = Config {
-        backend: oay::BackendConfig {
-            typ: "memory".to_string(),
-        },
-        frontends: oay::FrontendsConfig {
-            s3: oay::S3Config {
-                enable: true,
-                addr: "127.0.0.1:3000".to_string(),
-            },
-        },
-    };
-
-    let op = Operator::new(Memory::default())?.finish();
+    let cfg: Config =
+        toml::from_str(&std::fs::read_to_string("oay.toml").context("failed to 
open oay.toml")?)?;
+    let scheme = Scheme::from_str(&cfg.backend.typ).context("unsupported 
scheme")?;
+    let op = Operator::via_map(scheme, cfg.backend.map.clone())?;
 
     let s3 = S3Service::new(Arc::new(cfg), op);
 
diff --git a/bin/oay/src/config.rs b/bin/oay/src/config.rs
index 64ab51c36..f306ed9fa 100644
--- a/bin/oay/src/config.rs
+++ b/bin/oay/src/config.rs
@@ -15,6 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::collections::HashMap;
+
 use serde::Deserialize;
 use serde::Serialize;
 
@@ -28,6 +30,8 @@ pub struct Config {
 pub struct BackendConfig {
     #[serde(rename = "type")]
     pub typ: String,
+    #[serde(flatten)]
+    pub map: HashMap<String, String>,
 }
 
 #[derive(Serialize, Deserialize)]

Reply via email to