Skip to content

Commit

Permalink
feat(oay): actually read configuration from oay.toml (#2615)
Browse files Browse the repository at this point in the history
  • Loading branch information
messense authored Jul 11, 2023
1 parent 869eecd commit 7617c2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 7 additions & 14 deletions bin/oay/src/bin/oay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions bin/oay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;

use serde::Deserialize;
use serde::Serialize;

Expand All @@ -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)]
Expand Down

0 comments on commit 7617c2f

Please sign in to comment.