This is an automated email from the ASF dual-hosted git repository.
koushiro pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new e426859fe refactor: split swift service into a separate crate (#7054)
e426859fe is described below
commit e426859fe9d0593f237c265f396678629f11584f
Author: Sahil Shadwal <[email protected]>
AuthorDate: Thu Dec 18 09:26:46 2025 +0530
refactor: split swift service into a separate crate (#7054)
* refactored core split swift
* style: reorder SwiftConfig import, reformat Swift endpoint error message,
and remove blank lines.
* Update core/core/Cargo.toml
Co-authored-by: Qinxuan Chen <[email protected]>
* resolving behavioral issues
---------
Co-authored-by: Qinxuan Chen <[email protected]>
---
core/Cargo.lock | 18 ++++++++
core/Cargo.toml | 3 +-
core/core/Cargo.toml | 1 -
core/core/src/services/mod.rs | 5 ---
core/services/swift/Cargo.toml | 51 ++++++++++++++++++++++
.../swift => services/swift/src}/backend.rs | 6 +--
.../swift/src}/compatible_services.md | 0
.../swift => services/swift/src}/config.rs | 21 ++++-----
.../services/swift => services/swift/src}/core.rs | 4 +-
.../swift => services/swift/src}/deleter.rs | 4 +-
.../services/swift => services/swift/src}/docs.md | 2 +-
.../services/swift => services/swift/src}/error.rs | 4 +-
.../swift/mod.rs => services/swift/src/lib.rs} | 11 +++--
.../swift => services/swift/src}/lister.rs | 4 +-
.../swift => services/swift/src}/writer.rs | 4 +-
core/src/lib.rs | 2 +
16 files changed, 106 insertions(+), 34 deletions(-)
diff --git a/core/Cargo.lock b/core/Cargo.lock
index d0ba13b6a..1a3749aee 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -5591,6 +5591,7 @@ dependencies = [
"opendal-service-sled",
"opendal-service-sqlite",
"opendal-service-surrealdb",
+ "opendal-service-swift",
"opendal-service-tikv",
"opendal-service-upyun",
"opendal-service-vercel-blob",
@@ -6450,6 +6451,23 @@ dependencies = [
"surrealdb",
]
+[[package]]
+name = "opendal-service-swift"
+version = "0.55.0"
+dependencies = [
+ "anyhow",
+ "bytes",
+ "ctor",
+ "http 1.4.0",
+ "log",
+ "opendal-core",
+ "pretty_assertions",
+ "quick-xml",
+ "serde",
+ "serde_json",
+ "tokio",
+]
+
[[package]]
name = "opendal-service-tikv"
version = "0.55.0"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index faaf0527c..b5c63c0fb 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -156,7 +156,7 @@ services-sftp = ["opendal-core/services-sftp"]
services-sled = ["dep:opendal-service-sled"]
services-sqlite = ["dep:opendal-service-sqlite"]
services-surrealdb = ["dep:opendal-service-surrealdb"]
-services-swift = ["opendal-core/services-swift"]
+services-swift = ["dep:opendal-service-swift"]
services-tikv = ["dep:opendal-service-tikv"]
services-upyun = ["dep:opendal-service-upyun"]
services-vercel-artifacts = ["opendal-core/services-vercel-artifacts"]
@@ -242,6 +242,7 @@ opendal-service-s3 = { path = "services/s3", version =
"0.55.0", optional = true
opendal-service-sled = { path = "services/sled", version = "0.55.0", optional
= true, default-features = false }
opendal-service-sqlite = { path = "services/sqlite", version = "0.55.0",
optional = true, default-features = false }
opendal-service-surrealdb = { path = "services/surrealdb", version = "0.55.0",
optional = true, default-features = false }
+opendal-service-swift = { path = "services/swift", version = "0.55.0",
optional = true, default-features = false }
opendal-service-tikv = { path = "services/tikv", version = "0.55.0", optional
= true, default-features = false }
opendal-service-upyun = { path = "services/upyun", version = "0.55.0",
optional = true, default-features = false }
opendal-service-vercel-blob = { path = "services/vercel-blob", version =
"0.55.0", optional = true, default-features = false }
diff --git a/core/core/Cargo.toml b/core/core/Cargo.toml
index 93fdf5686..6bcc144db 100644
--- a/core/core/Cargo.toml
+++ b/core/core/Cargo.toml
@@ -72,7 +72,6 @@ services-redis-native-tls = ["services-redis",
"redis?/tokio-native-tls-comp"]
services-rocksdb = ["dep:rocksdb", "internal-tokio-rt"]
services-seafile = []
services-sftp = ["dep:openssh", "dep:openssh-sftp-client", "dep:fastpool"]
-services-swift = []
services-vercel-artifacts = []
services-webdav = []
services-webhdfs = []
diff --git a/core/core/src/services/mod.rs b/core/core/src/services/mod.rs
index 3df095ffb..0db8b6f17 100644
--- a/core/core/src/services/mod.rs
+++ b/core/core/src/services/mod.rs
@@ -89,11 +89,6 @@ mod sftp;
#[cfg(feature = "services-sftp")]
pub use sftp::*;
-#[cfg(feature = "services-swift")]
-mod swift;
-#[cfg(feature = "services-swift")]
-pub use self::swift::*;
-
#[cfg(feature = "services-vercel-artifacts")]
mod vercel_artifacts;
#[cfg(feature = "services-vercel-artifacts")]
diff --git a/core/services/swift/Cargo.toml b/core/services/swift/Cargo.toml
new file mode 100644
index 000000000..d80ed7269
--- /dev/null
+++ b/core/services/swift/Cargo.toml
@@ -0,0 +1,51 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+description = "Apache OpenDAL Swift service implementation"
+name = "opendal-service-swift"
+
+authors = { workspace = true }
+edition = { workspace = true }
+homepage = { workspace = true }
+license = { workspace = true }
+repository = { workspace = true }
+rust-version = { workspace = true }
+version = { workspace = true }
+
+[package.metadata.docs.rs]
+all-features = true
+
+[dependencies]
+opendal-core = { path = "../../core", version = "0.55.0", default-features =
false }
+
+bytes = { workspace = true }
+ctor = { workspace = true }
+http = { workspace = true }
+log = { workspace = true }
+quick-xml = { workspace = true, features = ["serialize", "overlapped-lists"] }
+serde = { workspace = true, features = ["derive"] }
+serde_json = { workspace = true }
+tokio = { workspace = true, features = [
+ "macros",
+ "rt-multi-thread",
+ "io-util",
+] }
+
+[dev-dependencies]
+anyhow = "1"
+pretty_assertions = "1"
diff --git a/core/core/src/services/swift/backend.rs
b/core/services/swift/src/backend.rs
similarity index 99%
rename from core/core/src/services/swift/backend.rs
rename to core/services/swift/src/backend.rs
index 35cb829fe..0073cf9cd 100644
--- a/core/core/src/services/swift/backend.rs
+++ b/core/services/swift/src/backend.rs
@@ -23,14 +23,14 @@ use http::StatusCode;
use log::debug;
use super::SWIFT_SCHEME;
+use super::SwiftConfig;
use super::core::*;
use super::deleter::SwfitDeleter;
use super::error::parse_error;
use super::lister::SwiftLister;
use super::writer::SwiftWriter;
-use crate::raw::*;
-use crate::services::SwiftConfig;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
/// [OpenStack Swift](https://docs.openstack.org/api-ref/object-store/#)'s
REST API support.
/// For more information about swift-compatible services, refer to [Compatible
Services](#compatible-services).
diff --git a/core/core/src/services/swift/compatible_services.md
b/core/services/swift/src/compatible_services.md
similarity index 100%
rename from core/core/src/services/swift/compatible_services.md
rename to core/services/swift/src/compatible_services.md
diff --git a/core/core/src/services/swift/config.rs
b/core/services/swift/src/config.rs
similarity index 87%
rename from core/core/src/services/swift/config.rs
rename to core/services/swift/src/config.rs
index 14fd0c58e..63e928aac 100644
--- a/core/core/src/services/swift/config.rs
+++ b/core/services/swift/src/config.rs
@@ -48,20 +48,21 @@ impl Debug for SwiftConfig {
}
}
-impl crate::Configurator for SwiftConfig {
+impl opendal_core::Configurator for SwiftConfig {
type Builder = SwiftBuilder;
- fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
+ fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self>
{
let mut map = uri.options().clone();
if let Some(authority) = uri.authority() {
map.entry("endpoint".to_string())
.or_insert_with(|| format!("https://{authority}"));
} else if !map.contains_key("endpoint") {
- return Err(
- crate::Error::new(crate::ErrorKind::ConfigInvalid, "endpoint
is required")
- .with_context("service", SWIFT_SCHEME),
- );
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "endpoint is required",
+ )
+ .with_context("service", SWIFT_SCHEME));
}
if let Some(path) = uri.root() {
@@ -78,8 +79,8 @@ impl crate::Configurator for SwiftConfig {
}
if !map.contains_key("container") {
- return Err(crate::Error::new(
- crate::ErrorKind::ConfigInvalid,
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
"container is required",
)
.with_context("service", SWIFT_SCHEME));
@@ -96,8 +97,8 @@ impl crate::Configurator for SwiftConfig {
#[cfg(test)]
mod tests {
use super::*;
- use crate::Configurator;
- use crate::types::OperatorUri;
+ use opendal_core::Configurator;
+ use opendal_core::OperatorUri;
#[test]
fn from_uri_sets_endpoint_container_and_root() {
diff --git a/core/core/src/services/swift/core.rs
b/core/services/swift/src/core.rs
similarity index 99%
rename from core/core/src/services/swift/core.rs
rename to core/services/swift/src/core.rs
index acff08ec6..df521fcf2 100644
--- a/core/core/src/services/swift/core.rs
+++ b/core/services/swift/src/core.rs
@@ -23,8 +23,8 @@ use http::Response;
use http::header;
use serde::Deserialize;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
pub struct SwiftCore {
pub info: Arc<AccessorInfo>,
diff --git a/core/core/src/services/swift/deleter.rs
b/core/services/swift/src/deleter.rs
similarity index 96%
rename from core/core/src/services/swift/deleter.rs
rename to core/services/swift/src/deleter.rs
index 8f8cd3035..095c69b8b 100644
--- a/core/core/src/services/swift/deleter.rs
+++ b/core/services/swift/src/deleter.rs
@@ -21,8 +21,8 @@ use http::StatusCode;
use super::core::*;
use super::error::parse_error;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
pub struct SwfitDeleter {
core: Arc<SwiftCore>,
diff --git a/core/core/src/services/swift/docs.md
b/core/services/swift/src/docs.md
similarity index 96%
rename from core/core/src/services/swift/docs.md
rename to core/services/swift/src/docs.md
index 1a9c97889..1a3e67064 100644
--- a/core/core/src/services/swift/docs.md
+++ b/core/services/swift/src/docs.md
@@ -28,7 +28,7 @@ Refer to [`SwiftBuilder`]'s public API docs for more
information.
use std::sync::Arc;
use anyhow::Result;
-use opendal_core::services::Swift;
+use opendal_service_swift::Swift;
use opendal_core::Operator;
#[tokio::main]
diff --git a/core/core/src/services/swift/error.rs
b/core/services/swift/src/error.rs
similarity index 98%
rename from core/core/src/services/swift/error.rs
rename to core/services/swift/src/error.rs
index 3bbb25f88..a062ac6d9 100644
--- a/core/core/src/services/swift/error.rs
+++ b/core/services/swift/src/error.rs
@@ -22,8 +22,8 @@ use http::StatusCode;
use quick_xml::de;
use serde::Deserialize;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
diff --git a/core/core/src/services/swift/mod.rs
b/core/services/swift/src/lib.rs
similarity index 87%
rename from core/core/src/services/swift/mod.rs
rename to core/services/swift/src/lib.rs
index 506de54d5..1d6d04025 100644
--- a/core/core/src/services/swift/mod.rs
+++ b/core/services/swift/src/lib.rs
@@ -15,10 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-/// Default scheme for swift service.
-pub const SWIFT_SCHEME: &str = "swift";
+//! Swift service implementation for Apache OpenDAL.
+
+#![cfg_attr(docsrs, feature(doc_cfg))]
+#![deny(missing_docs)]
-use crate::types::DEFAULT_OPERATOR_REGISTRY;
+use opendal_core::DEFAULT_OPERATOR_REGISTRY;
mod backend;
mod config;
@@ -31,6 +33,9 @@ mod writer;
pub use backend::SwiftBuilder as Swift;
pub use config::SwiftConfig;
+/// Default scheme for swift service.
+pub const SWIFT_SCHEME: &str = "swift";
+
#[ctor::ctor]
fn register_swift_service() {
DEFAULT_OPERATOR_REGISTRY.register::<Swift>(SWIFT_SCHEME);
diff --git a/core/core/src/services/swift/lister.rs
b/core/services/swift/src/lister.rs
similarity index 98%
rename from core/core/src/services/swift/lister.rs
rename to core/services/swift/src/lister.rs
index 6cbde6223..a1e802abf 100644
--- a/core/core/src/services/swift/lister.rs
+++ b/core/services/swift/src/lister.rs
@@ -21,8 +21,8 @@ use bytes::Buf;
use super::core::*;
use super::error::parse_error;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
pub struct SwiftLister {
core: Arc<SwiftCore>,
diff --git a/core/core/src/services/swift/writer.rs
b/core/services/swift/src/writer.rs
similarity index 97%
rename from core/core/src/services/swift/writer.rs
rename to core/services/swift/src/writer.rs
index 2ff104163..3f8c63864 100644
--- a/core/core/src/services/swift/writer.rs
+++ b/core/services/swift/src/writer.rs
@@ -21,8 +21,8 @@ use http::StatusCode;
use super::core::SwiftCore;
use super::error::parse_error;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
pub struct SwiftWriter {
core: Arc<SwiftCore>,
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 2b2bce19d..d09ae794c 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -110,6 +110,8 @@ pub mod services {
pub use opendal_service_sqlite::*;
#[cfg(feature = "services-surrealdb")]
pub use opendal_service_surrealdb::*;
+ #[cfg(feature = "services-swift")]
+ pub use opendal_service_swift::*;
#[cfg(feature = "services-tikv")]
pub use opendal_service_tikv::*;
#[cfg(feature = "services-upyun")]