You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by ti...@apache.org on 2024/08/22 09:19:00 UTC
(opendal) 01/01: feat: expose configs always
This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch expose-configs-always
in repository https://gitbox.apache.org/repos/asf/opendal.git
commit 5b55921fe172f2f9ef0dc904ba162b6616bf5524
Author: tison <wa...@gmail.com>
AuthorDate: Thu Aug 22 17:18:45 2024 +0800
feat: expose configs always
Signed-off-by: tison <wa...@gmail.com>
---
core/src/services/aliyun_drive/backend.rs | 57 ++--------------
core/src/services/aliyun_drive/mod.rs | 1 -
core/src/services/alluxio/backend.rs | 29 +-------
core/src/services/alluxio/mod.rs | 1 -
core/src/services/atomicserver/backend.rs | 31 +--------
core/src/services/atomicserver/mod.rs | 1 -
core/src/services/config.rs | 108 ++++++++++++++++++++++++++++++
core/src/services/mod.rs | 9 +--
8 files changed, 117 insertions(+), 120 deletions(-)
diff --git a/core/src/services/aliyun_drive/backend.rs b/core/src/services/aliyun_drive/backend.rs
index 7dc5ba5c21..77440dbf47 100644
--- a/core/src/services/aliyun_drive/backend.rs
+++ b/core/src/services/aliyun_drive/backend.rs
@@ -36,58 +36,9 @@ use super::lister::AliyunDriveLister;
use super::lister::AliyunDriveParent;
use super::writer::AliyunDriveWriter;
use crate::raw::*;
+use crate::services::AliyunDriveConfig;
use crate::*;
-/// Aliyun Drive services support.
-#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
-#[serde(default)]
-#[non_exhaustive]
-pub struct AliyunDriveConfig {
- /// The Root of this backend.
- ///
- /// All operations will happen under this root.
- ///
- /// Default to `/` if not set.
- pub root: Option<String>,
- /// The access_token of this backend.
- ///
- /// Solution for client-only purpose. #4733
- ///
- /// Required if no client_id, client_secret and refresh_token are provided.
- pub access_token: Option<String>,
- /// The client_id of this backend.
- ///
- /// Required if no access_token is provided.
- pub client_id: Option<String>,
- /// The client_secret of this backend.
- ///
- /// Required if no access_token is provided.
- pub client_secret: Option<String>,
- /// The refresh_token of this backend.
- ///
- /// Required if no access_token is provided.
- pub refresh_token: Option<String>,
- /// The drive_type of this backend.
- ///
- /// All operations will happen under this type of drive.
- ///
- /// Available values are `default`, `backup` and `resource`.
- ///
- /// Fallback to default if not set or no other drives can be found.
- pub drive_type: String,
-}
-
-impl Debug for AliyunDriveConfig {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- let mut d = f.debug_struct("AliyunDriveConfig");
-
- d.field("root", &self.root)
- .field("drive_type", &self.drive_type);
-
- d.finish_non_exhaustive()
- }
-}
-
impl Configurator for AliyunDriveConfig {
type Builder = AliyunDriveBuilder;
fn into_builder(self) -> Self::Builder {
@@ -205,12 +156,12 @@ impl Builder for AliyunDriveBuilder {
self.config.refresh_token.clone(),
) {
(Some(client_id), Some(client_secret), Some(refresh_token)) if
- !client_id.is_empty() && !client_secret.is_empty() && !refresh_token.is_empty() => {
+ !client_id.is_empty() && !client_secret.is_empty() && !refresh_token.is_empty() => {
AliyunDriveSign::Refresh(client_id, client_secret, refresh_token, None, 0)
}
_ => return Err(Error::new(
- ErrorKind::ConfigInvalid,
- "access_token and a set of client_id, client_secret, and refresh_token are both missing.")
+ ErrorKind::ConfigInvalid,
+ "access_token and a set of client_id, client_secret, and refresh_token are both missing.")
.with_operation("Builder::build")
.with_context("service", Scheme::AliyunDrive)),
},
diff --git a/core/src/services/aliyun_drive/mod.rs b/core/src/services/aliyun_drive/mod.rs
index efdc2b8eef..970f726b47 100644
--- a/core/src/services/aliyun_drive/mod.rs
+++ b/core/src/services/aliyun_drive/mod.rs
@@ -20,6 +20,5 @@ mod error;
mod lister;
mod writer;
pub use backend::AliyunDriveBuilder as AliyunDrive;
-pub use backend::AliyunDriveConfig;
mod core;
diff --git a/core/src/services/alluxio/backend.rs b/core/src/services/alluxio/backend.rs
index bd998430b1..e3f905ccd1 100644
--- a/core/src/services/alluxio/backend.rs
+++ b/core/src/services/alluxio/backend.rs
@@ -30,36 +30,9 @@ use super::lister::AlluxioLister;
use super::writer::AlluxioWriter;
use super::writer::AlluxioWriters;
use crate::raw::*;
+use crate::services::AlluxioConfig;
use crate::*;
-/// Config for alluxio services support.
-#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
-#[serde(default)]
-#[non_exhaustive]
-pub struct AlluxioConfig {
- /// root of this backend.
- ///
- /// All operations will happen under this root.
- ///
- /// default to `/` if not set.
- pub root: Option<String>,
- /// endpoint of this backend.
- ///
- /// Endpoint must be full uri, mostly like `http://127.0.0.1:39999`.
- pub endpoint: Option<String>,
-}
-
-impl Debug for AlluxioConfig {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- let mut d = f.debug_struct("AlluxioConfig");
-
- d.field("root", &self.root)
- .field("endpoint", &self.endpoint);
-
- d.finish_non_exhaustive()
- }
-}
-
impl Configurator for AlluxioConfig {
type Builder = AlluxioBuilder;
fn into_builder(self) -> Self::Builder {
diff --git a/core/src/services/alluxio/mod.rs b/core/src/services/alluxio/mod.rs
index 95e0216d34..2eecbf0b92 100644
--- a/core/src/services/alluxio/mod.rs
+++ b/core/src/services/alluxio/mod.rs
@@ -17,7 +17,6 @@
mod backend;
pub use backend::AlluxioBuilder as Alluxio;
-pub use backend::AlluxioConfig;
mod core;
mod error;
diff --git a/core/src/services/atomicserver/backend.rs b/core/src/services/atomicserver/backend.rs
index eb61f61283..8dc0be9813 100644
--- a/core/src/services/atomicserver/backend.rs
+++ b/core/src/services/atomicserver/backend.rs
@@ -30,38 +30,9 @@ use serde::Serialize;
use crate::raw::adapters::kv;
use crate::raw::*;
+use crate::services::AtomicserverConfig;
use crate::*;
-/// Atomicserver service support.
-
-/// Config for Atomicserver services support
-#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
-#[serde(default)]
-#[non_exhaustive]
-pub struct AtomicserverConfig {
- /// work dir of this backend
- pub root: Option<String>,
- /// endpoint of this backend
- pub endpoint: Option<String>,
- /// private_key of this backend
- pub private_key: Option<String>,
- /// public_key of this backend
- pub public_key: Option<String>,
- /// parent_resource_id of this backend
- pub parent_resource_id: Option<String>,
-}
-
-impl Debug for AtomicserverConfig {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("AtomicserverConfig")
- .field("root", &self.root)
- .field("endpoint", &self.endpoint)
- .field("public_key", &self.public_key)
- .field("parent_resource_id", &self.parent_resource_id)
- .finish_non_exhaustive()
- }
-}
-
impl Configurator for AtomicserverConfig {
type Builder = AtomicserverBuilder;
fn into_builder(self) -> Self::Builder {
diff --git a/core/src/services/atomicserver/mod.rs b/core/src/services/atomicserver/mod.rs
index 45b4185640..d341c4d099 100644
--- a/core/src/services/atomicserver/mod.rs
+++ b/core/src/services/atomicserver/mod.rs
@@ -18,4 +18,3 @@
mod backend;
pub use backend::AtomicserverBuilder as Atomicserver;
-pub use backend::AtomicserverConfig;
diff --git a/core/src/services/config.rs b/core/src/services/config.rs
new file mode 100644
index 0000000000..ee383453fa
--- /dev/null
+++ b/core/src/services/config.rs
@@ -0,0 +1,108 @@
+use serde::{Deserialize, Serialize};
+use std::fmt::{Debug, Formatter};
+
+/// Config for Aliyun Drive services support.
+#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
+#[serde(default)]
+#[non_exhaustive]
+pub struct AliyunDriveConfig {
+ /// The Root of this backend.
+ ///
+ /// All operations will happen under this root.
+ ///
+ /// Default to `/` if not set.
+ pub root: Option<String>,
+ /// The access_token of this backend.
+ ///
+ /// Solution for client-only purpose. #4733
+ ///
+ /// Required if no client_id, client_secret and refresh_token are provided.
+ pub access_token: Option<String>,
+ /// The client_id of this backend.
+ ///
+ /// Required if no access_token is provided.
+ pub client_id: Option<String>,
+ /// The client_secret of this backend.
+ ///
+ /// Required if no access_token is provided.
+ pub client_secret: Option<String>,
+ /// The refresh_token of this backend.
+ ///
+ /// Required if no access_token is provided.
+ pub refresh_token: Option<String>,
+ /// The drive_type of this backend.
+ ///
+ /// All operations will happen under this type of drive.
+ ///
+ /// Available values are `default`, `backup` and `resource`.
+ ///
+ /// Fallback to default if not set or no other drives can be found.
+ pub drive_type: String,
+}
+
+impl Debug for AliyunDriveConfig {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ let mut d = f.debug_struct("AliyunDriveConfig");
+
+ d.field("root", &self.root)
+ .field("drive_type", &self.drive_type);
+
+ d.finish_non_exhaustive()
+ }
+}
+
+/// Config for alluxio services support.
+#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
+#[serde(default)]
+#[non_exhaustive]
+pub struct AlluxioConfig {
+ /// root of this backend.
+ ///
+ /// All operations will happen under this root.
+ ///
+ /// default to `/` if not set.
+ pub root: Option<String>,
+ /// endpoint of this backend.
+ ///
+ /// Endpoint must be full uri, mostly like `http://127.0.0.1:39999`.
+ pub endpoint: Option<String>,
+}
+
+impl Debug for AlluxioConfig {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ let mut d = f.debug_struct("AlluxioConfig");
+
+ d.field("root", &self.root)
+ .field("endpoint", &self.endpoint);
+
+ d.finish_non_exhaustive()
+ }
+}
+
+/// Config for Atomicserver services support
+#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
+#[serde(default)]
+#[non_exhaustive]
+pub struct AtomicserverConfig {
+ /// work dir of this backend
+ pub root: Option<String>,
+ /// endpoint of this backend
+ pub endpoint: Option<String>,
+ /// private_key of this backend
+ pub private_key: Option<String>,
+ /// public_key of this backend
+ pub public_key: Option<String>,
+ /// parent_resource_id of this backend
+ pub parent_resource_id: Option<String>,
+}
+
+impl Debug for AtomicserverConfig {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("AtomicserverConfig")
+ .field("root", &self.root)
+ .field("endpoint", &self.endpoint)
+ .field("public_key", &self.public_key)
+ .field("parent_resource_id", &self.parent_resource_id)
+ .finish_non_exhaustive()
+ }
+}
diff --git a/core/src/services/mod.rs b/core/src/services/mod.rs
index 10e9aa7f2e..e8fcc8bf24 100644
--- a/core/src/services/mod.rs
+++ b/core/src/services/mod.rs
@@ -19,12 +19,13 @@
//!
//! More ongoing services support is tracked at [opendal#5](https://github.com/apache/opendal/issues/5). Please feel free to submit issues if there are services not covered.
+mod config;
+pub use config::*;
+
#[cfg(feature = "services-aliyun-drive")]
mod aliyun_drive;
#[cfg(feature = "services-aliyun-drive")]
pub use aliyun_drive::AliyunDrive;
-#[cfg(feature = "services-aliyun-drive")]
-pub use aliyun_drive::AliyunDriveConfig;
#[cfg(feature = "services-azblob")]
mod azblob;
@@ -331,8 +332,6 @@ pub use self::postgresql::PostgresqlConfig;
mod atomicserver;
#[cfg(feature = "services-atomicserver")]
pub use self::atomicserver::Atomicserver;
-#[cfg(feature = "services-atomicserver")]
-pub use self::atomicserver::AtomicserverConfig;
#[cfg(feature = "services-mysql")]
mod mysql;
@@ -387,8 +386,6 @@ pub use self::swift::SwiftConfig;
mod alluxio;
#[cfg(feature = "services-alluxio")]
pub use alluxio::Alluxio;
-#[cfg(feature = "services-alluxio")]
-pub use alluxio::AlluxioConfig;
#[cfg(feature = "services-b2")]
mod b2;