Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oay): actually read configuration from oay.toml #2615

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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