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/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new fde54d34f7 feat(services/s3): add Huawei Cloud OBS preset (#9070)
fde54d34f7 is described below
commit fde54d34f7a950e44975992db8e598299957ea3b
Author: Xuanwo <[email protected]>
AuthorDate: Wed Nov 25 22:12:43 2026 +0800
feat(services/s3): add Huawei Cloud OBS preset (#9070)
---
bindings/dart/rust/Cargo.toml | 1 +
bindings/dotnet/Cargo.toml | 1 +
.../OpenDAL/ServiceConfig/ObsS3ServiceConfig.cs | 97 ++++++++++++++++++
bindings/haskell/Cargo.toml | 1 +
bindings/java/Cargo.toml | 1 +
.../java/org/apache/opendal/ServiceConfig.java | 65 ++++++++++++
bindings/lua/Cargo.toml | 1 +
bindings/nodejs/Cargo.toml | 2 +
bindings/ocaml/Cargo.toml | 1 +
bindings/php/Cargo.toml | 1 +
bindings/python/Cargo.toml | 2 +
bindings/python/python/opendal/config.py | 23 +++++
bindings/python/python/opendal/services.pyi | 1 +
bindings/python/src/services.rs | 4 +
bindings/ruby/Cargo.toml | 1 +
core/Cargo.toml | 1 +
core/fuzz/Cargo.toml | 1 +
core/services/s3/README.md | 1 +
core/services/s3/src/compatible_services.md | 1 +
core/services/s3/src/lib.rs | 2 +
core/services/s3/src/obs-s3.md | 40 ++++++++
core/services/s3/src/obs_s3_config.rs | 94 ++++++++++++++++++
core/services/s3/src/preset_tests.rs | 109 +++++++++++++++++++++
core/src/lib.rs | 39 ++++++++
website/data/capabilities.json | 87 ++++++++++++++++
website/data/services.json | 95 ++++++++++++++++++
26 files changed, 672 insertions(+)
diff --git a/bindings/dart/rust/Cargo.toml b/bindings/dart/rust/Cargo.toml
index 254dc7fa63..b34afb00d4 100644
--- a/bindings/dart/rust/Cargo.toml
+++ b/bindings/dart/rust/Cargo.toml
@@ -64,6 +64,7 @@ opendal = { path = "../../../core", features = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/bindings/dotnet/Cargo.toml b/bindings/dotnet/Cargo.toml
index 9a99981bac..0061bb94c7 100644
--- a/bindings/dotnet/Cargo.toml
+++ b/bindings/dotnet/Cargo.toml
@@ -87,6 +87,7 @@ opendal = { version = ">=0", path = "../../core", features = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/bindings/dotnet/OpenDAL/ServiceConfig/ObsS3ServiceConfig.cs
b/bindings/dotnet/OpenDAL/ServiceConfig/ObsS3ServiceConfig.cs
new file mode 100644
index 0000000000..2f03916389
--- /dev/null
+++ b/bindings/dotnet/OpenDAL/ServiceConfig/ObsS3ServiceConfig.cs
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+// DO NOT EDIT IT MANUALLY. This file is generated by
opendal/dev/src/generate/dotnet.rs.
+
+using OpenDAL.ServiceConfig.Abstractions;
+
+namespace OpenDAL.ServiceConfig
+{
+ /// <summary>
+ /// Configuration for service obs-s3.
+ /// </summary>
+ public sealed class ObsS3ServiceConfig : IServiceConfig
+ {
+ /// <summary>
+ /// Huawei Cloud access key ID (AK).
+ /// </summary>
+ public string? AccessKeyId { get; init; }
+ /// <summary>
+ /// OBS bucket name as a single lowercase DNS label.
+ /// </summary>
+ public string? Bucket { get; init; }
+ /// <summary>
+ /// HTTP(S) base endpoint override. OpenDAL prepends the bucket to the
host.
+ /// </summary>
+ public string? Endpoint { get; init; }
+ /// <summary>
+ /// OBS bucket region. Also used to sign requests.
+ /// </summary>
+ public string? Region { get; init; }
+ /// <summary>
+ /// Root within the bucket. The default is `/`.
+ /// </summary>
+ public string? Root { get; init; }
+ /// <summary>
+ /// Huawei Cloud secret access key (SK).
+ /// </summary>
+ public string? SecretAccessKey { get; init; }
+ /// <summary>
+ /// Session token for temporary Huawei Cloud credentials. Requires
both keys.
+ /// </summary>
+ public string? SessionToken { get; init; }
+
+ public string Scheme => "obs-s3";
+
+ public IReadOnlyDictionary<string, string> ToOptions()
+ {
+ var map = new Dictionary<string, string>();
+ if (AccessKeyId is not null)
+ {
+ map["access_key_id"] = Utilities.ToOptionString(AccessKeyId);
+ }
+ if (Bucket is not null)
+ {
+ map["bucket"] = Utilities.ToOptionString(Bucket);
+ }
+ if (Endpoint is not null)
+ {
+ map["endpoint"] = Utilities.ToOptionString(Endpoint);
+ }
+ if (Region is not null)
+ {
+ map["region"] = Utilities.ToOptionString(Region);
+ }
+ if (Root is not null)
+ {
+ map["root"] = Utilities.ToOptionString(Root);
+ }
+ if (SecretAccessKey is not null)
+ {
+ map["secret_access_key"] =
Utilities.ToOptionString(SecretAccessKey);
+ }
+ if (SessionToken is not null)
+ {
+ map["session_token"] = Utilities.ToOptionString(SessionToken);
+ }
+ return map;
+ }
+ }
+
+}
diff --git a/bindings/haskell/Cargo.toml b/bindings/haskell/Cargo.toml
index 9379cdb25c..ad759dfafe 100644
--- a/bindings/haskell/Cargo.toml
+++ b/bindings/haskell/Cargo.toml
@@ -73,6 +73,7 @@ opendal = { version = ">=0", path = "../../core", features = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/bindings/java/Cargo.toml b/bindings/java/Cargo.toml
index 4665660b09..82ce09a763 100644
--- a/bindings/java/Cargo.toml
+++ b/bindings/java/Cargo.toml
@@ -97,6 +97,7 @@ opendal = { version = ">=0", path = "../../core",
default-features = false, feat
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java
b/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java
index 095bd6a561..ea66669fd0 100644
--- a/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java
+++ b/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java
@@ -3486,6 +3486,71 @@ public interface ServiceConfig {
}
}
+ /**
+ * Configuration for service obs-s3.
+ */
+ @Builder
+ @Data
+ @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+ class ObsS3 implements ServiceConfig {
+ /**
+ * <p>Huawei Cloud access key ID (AK).</p>
+ */
+ public final String accessKeyId;
+ /**
+ * <p>OBS bucket name as a single lowercase DNS label.</p>
+ */
+ public final @NonNull String bucket;
+ /**
+ * <p>HTTP(S) base endpoint override. OpenDAL prepends the bucket to
the host.</p>
+ */
+ public final String endpoint;
+ /**
+ * <p>OBS bucket region. Also used to sign requests.</p>
+ */
+ public final @NonNull String region;
+ /**
+ * <p>Root within the bucket. The default is <code>/</code>.</p>
+ */
+ public final String root;
+ /**
+ * <p>Huawei Cloud secret access key (SK).</p>
+ */
+ public final String secretAccessKey;
+ /**
+ * <p>Session token for temporary Huawei Cloud credentials. Requires
both keys.</p>
+ */
+ public final String sessionToken;
+
+ @Override
+ public String scheme() {
+ return "obs-s3";
+ }
+
+ @Override
+ public Map<String, String> configMap() {
+ final HashMap<String, String> map = new HashMap<>();
+ if (accessKeyId != null) {
+ map.put("access_key_id", accessKeyId);
+ }
+ map.put("bucket", bucket);
+ if (endpoint != null) {
+ map.put("endpoint", endpoint);
+ }
+ map.put("region", region);
+ if (root != null) {
+ map.put("root", root);
+ }
+ if (secretAccessKey != null) {
+ map.put("secret_access_key", secretAccessKey);
+ }
+ if (sessionToken != null) {
+ map.put("session_token", sessionToken);
+ }
+ return map;
+ }
+ }
+
/**
* Configuration for service oci.
*/
diff --git a/bindings/lua/Cargo.toml b/bindings/lua/Cargo.toml
index fec5bc919c..5bbfac99e3 100644
--- a/bindings/lua/Cargo.toml
+++ b/bindings/lua/Cargo.toml
@@ -79,6 +79,7 @@ opendal = { version = ">=0", path = "../../core", features = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/bindings/nodejs/Cargo.toml b/bindings/nodejs/Cargo.toml
index 3e23ccb489..c8d8f818b8 100644
--- a/bindings/nodejs/Cargo.toml
+++ b/bindings/nodejs/Cargo.toml
@@ -65,6 +65,7 @@ default = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
@@ -147,6 +148,7 @@ services-memory = ["opendal/services-memory"]
services-minio = ["opendal/services-minio"]
services-neon = ["opendal/services-neon"]
services-obs = ["opendal/services-obs"]
+services-obs-s3 = ["opendal/services-obs-s3"]
services-oci = ["opendal/services-oci"]
services-oss = ["opendal/services-oss"]
services-oss-s3 = ["opendal/services-oss-s3"]
diff --git a/bindings/ocaml/Cargo.toml b/bindings/ocaml/Cargo.toml
index b374a69adf..bd92879b5b 100644
--- a/bindings/ocaml/Cargo.toml
+++ b/bindings/ocaml/Cargo.toml
@@ -74,6 +74,7 @@ opendal = { version = ">=0", path = "../../core", features = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/bindings/php/Cargo.toml b/bindings/php/Cargo.toml
index 8744439d78..49ec152bb7 100644
--- a/bindings/php/Cargo.toml
+++ b/bindings/php/Cargo.toml
@@ -72,6 +72,7 @@ opendal = { version = ">=0", path = "../../core", features = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml
index 7eba0f38ed..978aeba92c 100644
--- a/bindings/python/Cargo.toml
+++ b/bindings/python/Cargo.toml
@@ -68,6 +68,7 @@ default = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
@@ -201,6 +202,7 @@ services-monoiofs = [
services-mysql = ["opendal/services-mysql"]
services-neon = ["opendal/services-neon"]
services-obs = ["opendal/services-obs"]
+services-obs-s3 = ["opendal/services-obs-s3"]
services-oci = ["opendal/services-oci"]
services-onedrive = ["opendal/services-onedrive"]
services-opfs = [
diff --git a/bindings/python/python/opendal/config.py
b/bindings/python/python/opendal/config.py
index e81d282ff4..b2c2aa1560 100644
--- a/bindings/python/python/opendal/config.py
+++ b/bindings/python/python/opendal/config.py
@@ -943,6 +943,27 @@ class ObsConfig(TypedDict):
"""Skip signature will skip loading credentials and signing requests."""
+class ObsS3Config(TypedDict):
+ """Configuration for the `obs-s3` service."""
+
+ scheme: Required[Literal["obs-s3"]]
+ """The service scheme; fixed to `"obs-s3"`."""
+ access_key_id: NotRequired[str]
+ """Huawei Cloud access key ID (AK)."""
+ bucket: Required[str]
+ """OBS bucket name as a single lowercase DNS label."""
+ endpoint: NotRequired[str]
+ """HTTP(S) base endpoint override. OpenDAL prepends the bucket to the
host."""
+ region: Required[str]
+ """OBS bucket region. Also used to sign requests."""
+ root: NotRequired[str | os.PathLike[str]]
+ """Root within the bucket. The default is `/`."""
+ secret_access_key: NotRequired[str]
+ """Huawei Cloud secret access key (SK)."""
+ session_token: NotRequired[str]
+ """Session token for temporary Huawei Cloud credentials. Requires both
keys."""
+
+
class OciConfig(TypedDict):
"""Configuration for the `oci` service."""
@@ -1747,6 +1768,7 @@ ServiceConfig = (
| MysqlConfig
| NeonConfig
| ObsConfig
+ | ObsS3Config
| OciConfig
| OnedriveConfig
| OssConfig
@@ -1831,6 +1853,7 @@ __all__ = [
"MysqlConfig",
"NeonConfig",
"ObsConfig",
+ "ObsS3Config",
"OciConfig",
"OnedriveConfig",
"OssConfig",
diff --git a/bindings/python/python/opendal/services.pyi
b/bindings/python/python/opendal/services.pyi
index 09be7d254a..0eb1001a83 100644
--- a/bindings/python/python/opendal/services.pyi
+++ b/bindings/python/python/opendal/services.pyi
@@ -67,6 +67,7 @@ class Scheme:
Mysql: Final[Scheme]
Neon: Final[Scheme]
Obs: Final[Scheme]
+ ObsS3: Final[Scheme]
Oci: Final[Scheme]
Onedrive: Final[Scheme]
Oss: Final[Scheme]
diff --git a/bindings/python/src/services.rs b/bindings/python/src/services.rs
index f81a6aee89..7e7bb19e76 100644
--- a/bindings/python/src/services.rs
+++ b/bindings/python/src/services.rs
@@ -121,6 +121,8 @@ pub enum Scheme {
Neon,
#[cfg(feature = "services-obs")]
Obs,
+ #[cfg(feature = "services-obs-s3")]
+ ObsS3,
#[cfg(feature = "services-oci")]
Oci,
#[cfg(feature = "services-onedrive")]
@@ -321,6 +323,8 @@ impl_enum_to_str!(
Neon => "neon",
#[cfg(feature = "services-obs")]
Obs => "obs",
+ #[cfg(feature = "services-obs-s3")]
+ ObsS3 => "obs-s3",
#[cfg(feature = "services-oci")]
Oci => "oci",
#[cfg(feature = "services-onedrive")]
diff --git a/bindings/ruby/Cargo.toml b/bindings/ruby/Cargo.toml
index 0961ac0b26..41ab4e0fa0 100644
--- a/bindings/ruby/Cargo.toml
+++ b/bindings/ruby/Cargo.toml
@@ -80,6 +80,7 @@ opendal = { version = ">=0", path = "../../core", features = [
"services-cos-s3",
"services-gcs-s3",
"services-lakefs-s3",
+ "services-obs-s3",
"services-oss-s3",
"services-swift-s3api",
"services-tos-s3",
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 86aea42ae4..149f29f7ef 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -225,6 +225,7 @@ services-monoiofs = ["dep:opendal-service-monoiofs"]
services-mysql = ["dep:opendal-service-mysql"]
services-neon = ["dep:opendal-service-s3"]
services-obs = ["dep:opendal-service-obs"]
+services-obs-s3 = ["dep:opendal-service-s3"]
services-oci = ["dep:opendal-service-s3"]
services-onedrive = ["dep:opendal-service-onedrive"]
services-opfs = ["dep:opendal-service-opfs"]
diff --git a/core/fuzz/Cargo.toml b/core/fuzz/Cargo.toml
index d50a1e1ee3..425655f8c9 100644
--- a/core/fuzz/Cargo.toml
+++ b/core/fuzz/Cargo.toml
@@ -75,6 +75,7 @@ services-mongodb = ["opendal/services-mongodb"]
services-mysql = ["opendal/services-mysql"]
services-neon = ["opendal/services-neon"]
services-obs = ["opendal/services-obs"]
+services-obs-s3 = ["opendal/services-obs-s3"]
services-oci = ["opendal/services-oci"]
services-onedrive = ["opendal/services-onedrive"]
services-oss = ["opendal/services-oss"]
diff --git a/core/services/s3/README.md b/core/services/s3/README.md
index 44c31ca251..b8fa1b3d18 100644
--- a/core/services/s3/README.md
+++ b/core/services/s3/README.md
@@ -86,6 +86,7 @@ Services that send HTTP requests also require an HTTP
transport in
- [Volcengine and BytePlus TOS S3
preset](https://opendal.apache.org/services/tos-s3)
- [OpenStack Swift s3api
preset](https://opendal.apache.org/services/swift-s3api)
- [lakeFS S3 Gateway preset](https://opendal.apache.org/services/lakefs-s3)
+- [Huawei Cloud OBS S3 preset](https://opendal.apache.org/services/obs-s3)
- [Rust API documentation](https://docs.rs/opendal-service-s3)
- [Apache OpenDAL documentation](https://opendal.apache.org/docs/)
diff --git a/core/services/s3/src/compatible_services.md
b/core/services/s3/src/compatible_services.md
index f66da42572..269a959aa7 100644
--- a/core/services/s3/src/compatible_services.md
+++ b/core/services/s3/src/compatible_services.md
@@ -53,6 +53,7 @@ corresponding preset feature to select an S3 API explicitly.
- Use [`crate::CosS3`] or the `cos-s3` scheme for Tencent Cloud COS.
- Use [`crate::GcsS3`] or the `gcs-s3` scheme for Google Cloud Storage.
- Use [`crate::LakefsS3`] or the `lakefs-s3` scheme for the lakeFS S3 Gateway.
+- Use [`crate::ObsS3`] or the `obs-s3` scheme for Huawei Cloud OBS in the
China public cloud.
- Use [`crate::OssS3`] or the `oss-s3` scheme for Alibaba Cloud OSS.
- Use [`crate::SwiftS3api`] or the `swift-s3api` scheme for OpenStack Swift
s3api.
- Use [`crate::TosS3`] or the `tos-s3` scheme for Volcengine and BytePlus TOS.
diff --git a/core/services/s3/src/lib.rs b/core/services/s3/src/lib.rs
index 947a31a669..217896f577 100644
--- a/core/services/s3/src/lib.rs
+++ b/core/services/s3/src/lib.rs
@@ -47,6 +47,7 @@ mod idrive_e2_config;
mod ionos_config;
mod lakefs_s3_config;
mod neon_config;
+mod obs_s3_config;
mod oci_config;
mod oss_s3_config;
mod ovhcloud_config;
@@ -86,6 +87,7 @@ pub use lakefs_s3_config::{
pub use minio::MinioBuilder as Minio;
pub use minio_config::MinioConfig;
pub use neon_config::{NEON_SCHEME, Neon, NeonConfig, register_neon_service};
+pub use obs_s3_config::{OBS_S3_SCHEME, ObsS3, ObsS3Config,
register_obs_s3_service};
pub use oci_config::{OCI_SCHEME, Oci, OciConfig, register_oci_service};
pub use oss_s3_config::{OSS_S3_SCHEME, OssS3, OssS3Config,
register_oss_s3_service};
pub use ovhcloud_config::{OVHCLOUD_SCHEME, Ovhcloud, OvhcloudConfig,
register_ovhcloud_service};
diff --git a/core/services/s3/src/obs-s3.md b/core/services/s3/src/obs-s3.md
new file mode 100644
index 0000000000..4dcf627417
--- /dev/null
+++ b/core/services/s3/src/obs-s3.md
@@ -0,0 +1,40 @@
+# Huawei Cloud OBS S3-compatible API
+
+Enable `services-obs-s3` to use `obs-s3://bucket/prefix?region=cn-north-1`
+for a Huawei Cloud OBS bucket in the China public cloud. Set `region` to
+the bucket's region. OpenDAL derives the base endpoint
+`https://obs.<region>.myhuaweicloud.com` and uses the same region for S3
+Signature Version 4 with `UNSIGNED-PAYLOAD`.
+
+OpenDAL uses virtual-hosted-style addressing, so requests go to
+`https://<bucket>.obs.<region>.myhuaweicloud.com`. The bucket name must
+be a single lowercase DNS label. To override the endpoint, set `endpoint`
+to the base URL before the bucket name is added. Use `services-obs` and
+`obs://` for the native OBS API.
+
+Use Huawei Cloud-issued keys as `access_key_id` and `secret_access_key`.
+For temporary credentials, pass the security token as `session_token`
+along with both keys. The shared preset also reads these credentials from
+the standard AWS environment variables or shared profile files.
+
+See Huawei Cloud's [Boto3
FAQ](https://support.huaweicloud.com/obs_faq/obs_faq_0274.html)
+and [Terraform S3 backend
guide](https://github.com/huaweicloud/terraform-provider-huaweicloud/blob/b1d3ca6ee6e383aacfa5a82d1440d6a3fa3c6ca9/docs/guides/remote_state_backend.md).
+
+## Example
+
+```rust
+# fn main() -> opendal_core::Result<()> {
+use opendal_core::Operator;
+use opendal_service_s3::ObsS3;
+
+let op = Operator::new(
+ ObsS3::default()
+ .bucket("example-bucket")
+ .root("prefix")
+ .region("cn-north-1")
+ .access_key_id("example-access-key")
+ .secret_access_key("example-secret-key"),
+)?;
+# Ok(())
+# }
+```
diff --git a/core/services/s3/src/obs_s3_config.rs
b/core/services/s3/src/obs_s3_config.rs
new file mode 100644
index 0000000000..42685780c7
--- /dev/null
+++ b/core/services/s3/src/obs_s3_config.rs
@@ -0,0 +1,94 @@
+// 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.
+
+use opendal_core::Result;
+use serde::{Deserialize, Serialize};
+
+use crate::preset::{self, Connection};
+
+/// Configuration for Huawei Cloud OBS access through its S3-compatible API.
+#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
+#[serde(default, deny_unknown_fields)]
+#[non_exhaustive]
+pub struct ObsS3Config {
+ /// Root within the bucket. The default is `/`.
+ ///
+ /// <!-- @group General -->
+ /// <!-- @default / -->
+ pub root: Option<String>,
+ /// OBS bucket name as a single lowercase DNS label.
+ ///
+ /// <!-- @group General -->
+ /// <!-- @example example-bucket -->
+ pub bucket: String,
+ /// OBS bucket region. Also used to sign requests.
+ ///
+ /// <!-- @group General -->
+ /// <!-- @example cn-north-1 -->
+ pub region: String,
+ /// HTTP(S) base endpoint override. OpenDAL prepends the bucket to the
host.
+ ///
+ /// <!-- @group General -->
+ /// <!-- @example https://obs.cn-north-1.myhuaweicloud.com -->
+ pub endpoint: Option<String>,
+ /// Huawei Cloud access key ID (AK).
+ ///
+ /// <!-- @group Credentials -->
+ pub access_key_id: Option<String>,
+ /// Huawei Cloud secret access key (SK).
+ ///
+ /// <!-- @group Credentials -->
+ pub secret_access_key: Option<String>,
+ /// Session token for temporary Huawei Cloud credentials. Requires both
keys.
+ ///
+ /// <!-- @group Credentials -->
+ pub session_token: Option<String>,
+}
+
+impl ObsS3Config {
+ fn connection(&self) -> Result<Connection> {
+ let endpoint = match &self.endpoint {
+ Some(endpoint) => endpoint.clone(),
+ None => {
+ let region = preset::dns_label(&self.region, OBS_S3_SCHEME,
"region")?;
+ format!("https://obs.{region}.myhuaweicloud.com")
+ }
+ };
+ Ok(Connection {
+ endpoint,
+ region: self.region.clone(),
+ virtual_host_style: true,
+ })
+ }
+}
+
+preset::provider_preset! {
+ ObsS3Config, ObsS3, OBS_S3_SCHEME = "obs-s3", register_obs_s3_service,
"obs-s3.md";
+ required {
+ bucket: "Set the OBS bucket name.",
+ region: "Set the OBS bucket region used to sign requests.",
+ }
+ optional {
+ root: "Set the root within the bucket.",
+ endpoint: "Set the HTTP(S) base endpoint.",
+ access_key_id: "Set the Huawei Cloud access key ID.",
+ secret_access_key: "Set the Huawei Cloud secret access key.",
+ session_token: "Set the session token for temporary credentials.",
+ }
+ flags {}
+ token: session_token;
+}
diff --git a/core/services/s3/src/preset_tests.rs
b/core/services/s3/src/preset_tests.rs
index 203fb3841d..e5de152d6d 100644
--- a/core/services/s3/src/preset_tests.rs
+++ b/core/services/s3/src/preset_tests.rs
@@ -17,9 +17,11 @@
use std::time::Duration;
+use http::{Method, Request, Response, StatusCode};
use opendal_core::Configurator;
use opendal_core::ErrorKind;
use opendal_core::OperatorRegistry;
+use opendal_core::{Buffer, HttpBody, HttpTransport, HttpTransporter,
OperationContext, Result};
use url::Url;
use super::*;
@@ -34,6 +36,7 @@ fn registry() -> &'static OperatorRegistry {
register_cos_s3_service,
register_gcs_s3_service,
register_lakefs_s3_service,
+ register_obs_s3_service,
register_oss_s3_service,
register_swift_s3api_service,
register_tos_s3_service,
@@ -255,6 +258,20 @@ async fn
provider_uris_use_documented_endpoints_and_signing_regions() {
"/bucket.example.com/root/file",
"auto",
),
+ (
+ "obs-s3://bucket/root?region=cn-north-1",
+ &[],
+ "bucket.obs.cn-north-1.myhuaweicloud.com",
+ "/root/file",
+ "cn-north-1",
+ ),
+ (
+ "obs-s3://bucket/root",
+ &[("region", "cn-north-4")],
+ "bucket.obs.cn-north-4.myhuaweicloud.com",
+ "/root/file",
+ "cn-north-4",
+ ),
(
"oss-s3://bucket/root",
&[("region", "cn-hangzhou")],
@@ -349,6 +366,16 @@ async fn
explicit_endpoint_addressing_and_signing_options_take_precedence() {
.await;
assert_eq!(url.host_str(), Some("s3.example.test"));
assert_eq!(region, "custom-region");
+
+ let (url, region) = presign(
+ "obs-s3://bucket/root?region=cn-north-4",
+ &[("endpoint", "https://obs.example.test:8443")],
+ )
+ .await;
+ assert_eq!(url.host_str(), Some("bucket.obs.example.test"));
+ assert_eq!(url.port(), Some(8443));
+ assert_eq!(url.path(), "/root/file");
+ assert_eq!(region, "cn-north-4");
}
#[tokio::test]
@@ -484,6 +511,11 @@ async fn presets_presign_with_the_supplied_session_token()
{
&[("region", "ap-guangzhou")][..],
"ap-guangzhou",
),
+ (
+ "obs-s3://bucket/root",
+ &[("region", "cn-north-1")][..],
+ "cn-north-1",
+ ),
(
"oss-s3://bucket/root",
&[("region", "cn-hangzhou")][..],
@@ -508,6 +540,68 @@ async fn presets_presign_with_the_supplied_session_token()
{
}
}
+#[tokio::test]
+async fn obs_s3_put_uses_sigv4_with_unsigned_payload() -> Result<()> {
+ struct CheckObsPut;
+
+ impl HttpTransport for CheckObsPut {
+ async fn fetch(&self, request: Request<Buffer>) ->
Result<Response<HttpBody>> {
+ assert_eq!(request.method(), Method::PUT);
+ assert_eq!(
+ request.uri(),
+
"https://example-bucket.obs.cn-north-1.myhuaweicloud.com/prefix/file"
+ );
+ assert_eq!(request.body().to_vec(), b"test payload");
+ let headers = request.headers();
+ assert_eq!(headers["x-amz-content-sha256"], "UNSIGNED-PAYLOAD");
+ assert_eq!(headers["x-amz-security-token"], "test-token");
+ assert!(
+ headers
+ .keys()
+ .all(|name| !name.as_str().starts_with("x-amz-checksum-"))
+ );
+ assert!(!headers.contains_key("x-amz-sdk-checksum-algorithm"));
+
+ let auth = headers[http::header::AUTHORIZATION].to_str().unwrap();
+ let (credential, signature_fields) = auth
+ .strip_prefix("AWS4-HMAC-SHA256 Credential=")
+ .unwrap()
+ .split_once(", SignedHeaders=")
+ .unwrap();
+ let (access_key, scope) = credential.split_once('/').unwrap();
+ assert_eq!(access_key, "test-access");
+ let (_, region_service) = scope.split_once('/').unwrap();
+ assert_eq!(region_service, "cn-north-1/s3/aws4_request");
+ let (signed_headers, _) = signature_fields.split_once(",
Signature=").unwrap();
+ assert!(
+ signed_headers
+ .split(';')
+ .any(|name| name == "x-amz-security-token")
+ );
+
+ Ok(Response::builder()
+ .status(StatusCode::OK)
+ .body(HttpBody::new(futures::stream::empty(), Some(0)))
+ .unwrap())
+ }
+ }
+
+ let op = registry()
+ .load((
+ "obs-s3://example-bucket/prefix?region=cn-north-1",
+ [
+ ("access_key_id", "test-access"),
+ ("secret_access_key", "test-secret"),
+ ("session_token", "test-token"),
+ ],
+ ))?
+ .with_context(
+
OperationContext::new().with_http_transport(HttpTransporter::new(CheckObsPut)),
+ );
+ op.write("file", "test payload").await?;
+ Ok(())
+}
+
#[test]
fn invalid_provider_connection_options_fail_during_construction() {
let cases: [(&str, Options<'_>, &str); 13] = [
@@ -639,6 +733,21 @@ fn
native_coexisting_presets_reject_incomplete_or_incompatible_options() {
],
"unknown field `enable_virtual_host_style`",
),
+ (
+ "obs-s3://bucket/root",
+ &[("endpoint", "https://obs.example.test")],
+ "region must not be empty",
+ ),
+ (
+ "obs-s3://bucket/root",
+ &[("region", "cn-north-1.example.test")],
+ "expected a lowercase DNS label",
+ ),
+ (
+ "obs-s3://bucket/root",
+ &[("region", "cn-north-1"), ("session_token", "test-token")],
+ "session_token requires both",
+ ),
];
for &(uri, options, message) in cases {
let error = registry().load((uri,
options.iter().copied())).unwrap_err();
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 031557e2cf..c0a925f22c 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -256,6 +256,9 @@ fn init_default_registry_inner(registry: &OperatorRegistry)
{
#[cfg(feature = "services-obs")]
opendal_service_obs::register_obs_service(registry);
+ #[cfg(feature = "services-obs-s3")]
+ opendal_service_s3::register_obs_s3_service(registry);
+
#[cfg(feature = "services-onedrive")]
opendal_service_onedrive::register_onedrive_service(registry);
@@ -566,6 +569,8 @@ pub mod services {
pub use opendal_service_s3::{MINIO_SCHEME, Minio, MinioConfig,
register_minio_service};
#[cfg(feature = "services-neon")]
pub use opendal_service_s3::{NEON_SCHEME, Neon, NeonConfig,
register_neon_service};
+ #[cfg(feature = "services-obs-s3")]
+ pub use opendal_service_s3::{OBS_S3_SCHEME, ObsS3, ObsS3Config,
register_obs_s3_service};
#[cfg(feature = "services-oci")]
pub use opendal_service_s3::{OCI_SCHEME, Oci, OciConfig,
register_oci_service};
#[cfg(feature = "services-oss-s3")]
@@ -704,6 +709,7 @@ mod service_feature_tests {
("cos-s3", cfg!(feature = "services-cos-s3")),
("gcs-s3", cfg!(feature = "services-gcs-s3")),
("lakefs-s3", cfg!(feature = "services-lakefs-s3")),
+ ("obs-s3", cfg!(feature = "services-obs-s3")),
("oss-s3", cfg!(feature = "services-oss-s3")),
("swift-s3api", cfg!(feature = "services-swift-s3api")),
("tos-s3", cfg!(feature = "services-tos-s3")),
@@ -713,6 +719,7 @@ mod service_feature_tests {
("gcs", cfg!(feature = "services-gcs")),
("gcs-grpc", cfg!(feature = "services-gcs-grpc")),
("lakefs", cfg!(feature = "services-lakefs")),
+ ("obs", cfg!(feature = "services-obs")),
("oss", cfg!(feature = "services-oss")),
("swift", cfg!(feature = "services-swift")),
("tos", cfg!(feature = "services-tos")),
@@ -720,6 +727,38 @@ mod service_feature_tests {
assert_eq!(schemes.contains(scheme), enabled, "{scheme}");
}
+ #[cfg(feature = "services-obs")]
+ {
+ let op = Operator::from_uri((
+ "obs://example-bucket/root",
+ [("endpoint", "https://obs.cn-north-1.myhuaweicloud.com")],
+ ))
+ .unwrap();
+ assert_eq!(op.info().scheme(), "obs");
+ assert_eq!(op.info().name(), "example-bucket");
+ assert_eq!(op.info().root(), "/root/");
+ }
+
+ #[cfg(feature = "services-obs-s3")]
+ {
+ let op =
Operator::from_uri("obs-s3://example-bucket/root?region=cn-north-1").unwrap();
+ assert_eq!(op.info().scheme(), "obs-s3");
+ assert_eq!(op.info().name(), "example-bucket");
+ assert_eq!(op.info().root(), "/root/");
+
+ let op = Operator::via_iter(
+ "obs-s3",
+ [
+ ("bucket".to_owned(), "example-bucket".to_owned()),
+ ("region".to_owned(), "cn-north-1".to_owned()),
+ ],
+ )
+ .unwrap();
+ assert_eq!(op.info().scheme(), "obs-s3");
+ assert_eq!(op.info().name(), "example-bucket");
+ assert_eq!(op.info().root(), "/");
+ }
+
#[cfg(feature = "services-tigris")]
{
let op =
Operator::from_uri("tigris://example-bucket/root").unwrap();
diff --git a/website/data/capabilities.json b/website/data/capabilities.json
index ac42fc3aa1..eb723c674f 100644
--- a/website/data/capabilities.json
+++ b/website/data/capabilities.json
@@ -2874,6 +2874,93 @@
}
}
},
+ {
+ "name": "obs-s3",
+ "scheme": "obs-s3",
+ "native": {
+ "copy": true,
+ "copy_can_multi": true,
+ "copy_with_content_language": true,
+ "copy_with_content_type": true,
+ "copy_with_if_match": true,
+ "copy_with_if_not_exists": true,
+ "copy_with_source_version": "Standard S3 buckets (not S3 Express One
Zone)",
+ "copy_with_user_metadata": true,
+ "delete": true,
+ "delete_with_if_match": true,
+ "delete_with_version": "Standard S3 buckets (not S3 Express One Zone)",
+ "list": true,
+ "list_with_deleted": "Standard S3 buckets (not S3 Express One Zone)",
+ "list_with_limit": true,
+ "list_with_recursive": "Standard S3 buckets (not S3 Express One Zone)",
+ "list_with_start_after": "Standard S3 buckets (not S3 Express One
Zone)",
+ "list_with_versions": "Standard S3 buckets (not S3 Express One Zone)",
+ "presign": true,
+ "presign_delete": true,
+ "presign_read": true,
+ "presign_stat": true,
+ "presign_write": true,
+ "read": true,
+ "read_with_if_match": true,
+ "read_with_if_modified_since": true,
+ "read_with_if_none_match": true,
+ "read_with_if_unmodified_since": true,
+ "read_with_override_cache_control": true,
+ "read_with_override_content_disposition": true,
+ "read_with_override_content_type": true,
+ "read_with_suffix": true,
+ "read_with_version": "Standard S3 buckets (not S3 Express One Zone)",
+ "restore": "Standard S3 buckets (not S3 Express One Zone)",
+ "restore_with_if_not_exists": "Standard S3 buckets (not S3 Express One
Zone)",
+ "restore_with_version": "Standard S3 buckets (not S3 Express One
Zone)",
+ "shared": true,
+ "stat": true,
+ "stat_with_if_match": true,
+ "stat_with_if_modified_since": true,
+ "stat_with_if_none_match": true,
+ "stat_with_if_unmodified_since": true,
+ "stat_with_override_cache_control": true,
+ "stat_with_override_content_disposition": true,
+ "stat_with_override_content_type": true,
+ "stat_with_version": "Standard S3 buckets (not S3 Express One Zone)",
+ "write": true,
+ "write_can_append": true,
+ "write_can_copy_from": "When `checksum_algorithm` is not set",
+ "write_can_empty": true,
+ "write_can_multi": "When `checksum_algorithm` is not `md5`",
+ "write_with_cache_control": true,
+ "write_with_content_disposition": true,
+ "write_with_content_encoding": "Standard S3 buckets (not S3 Express
One Zone)",
+ "write_with_content_language": true,
+ "write_with_content_type": true,
+ "write_with_if_match": true,
+ "write_with_if_not_exists": true,
+ "write_with_user_metadata": true
+ },
+ "limits": {
+ "copy_multi_max_size": {
+ "display": "5 GiB",
+ "condition": "64-bit targets (`usize::MAX` on 32-bit)"
+ },
+ "copy_multi_min_size": {
+ "display": "5 MiB"
+ },
+ "delete_max_size": {
+ "display": "1,000"
+ },
+ "write_multi_max_size": {
+ "display": "5 GiB",
+ "condition": "64-bit targets (`usize::MAX` on 32-bit)"
+ },
+ "write_multi_min_size": {
+ "display": "5 MiB"
+ },
+ "write_total_max_size": {
+ "display": "50,000 GiB",
+ "condition": "64-bit targets (unset on 32-bit)"
+ }
+ }
+ },
{
"name": "oci",
"scheme": "oci",
diff --git a/website/data/services.json b/website/data/services.json
index 1f2ec0f4dd..ee3d22f505 100644
--- a/website/data/services.json
+++ b/website/data/services.json
@@ -4833,6 +4833,101 @@
}
]
},
+ {
+ "name": "obs-s3",
+ "scheme": "obs-s3",
+ "groups": [
+ "General",
+ "Credentials"
+ ],
+ "configs": [
+ {
+ "name": "root",
+ "type": "string",
+ "required": false,
+ "group": "General",
+ "default": "/",
+ "comments": "Root within the bucket. The default is `/`."
+ },
+ {
+ "name": "bucket",
+ "type": "string",
+ "required": true,
+ "group": "General",
+ "example": "example-bucket",
+ "comments": "OBS bucket name as a single lowercase DNS label."
+ },
+ {
+ "name": "region",
+ "type": "string",
+ "required": true,
+ "group": "General",
+ "example": "cn-north-1",
+ "comments": "OBS bucket region. Also used to sign requests."
+ },
+ {
+ "name": "endpoint",
+ "type": "string",
+ "required": false,
+ "group": "General",
+ "example": "https://obs.cn-north-1.myhuaweicloud.com",
+ "comments": "HTTP(S) base endpoint override. OpenDAL prepends the
bucket to the host."
+ },
+ {
+ "name": "access_key_id",
+ "type": "string",
+ "required": false,
+ "group": "Credentials",
+ "comments": "Huawei Cloud access key ID (AK)."
+ },
+ {
+ "name": "secret_access_key",
+ "type": "string",
+ "required": false,
+ "group": "Credentials",
+ "comments": "Huawei Cloud secret access key (SK)."
+ },
+ {
+ "name": "session_token",
+ "type": "string",
+ "required": false,
+ "group": "Credentials",
+ "comments": "Session token for temporary Huawei Cloud credentials.
Requires both keys."
+ }
+ ],
+ "examples": [
+ {
+ "binding": "rust",
+ "language": "rust",
+ "minimal": "use opendal::Operator;\n\nlet operator =
Operator::via_iter(\"obs-s3\", [\n (\"bucket\".to_string(),
\"example-bucket\".to_string()),\n (\"region\".to_string(),
\"cn-north-1\".to_string()),\n])?;",
+ "full": "use opendal::Operator;\n\nlet operator =
Operator::via_iter(\"obs-s3\", [\n // --- General ---\n // Root within
the bucket. The default is `/`.\n // (\"root\".to_string(),
\"/\".to_string()),\n\n // OBS bucket name as a single lowercase DNS
label.\n (\"bucket\".to_string(), \"example-bucket\".to_string()),\n\n //
OBS bucket region. Also used to sign requests.\n (\"region\".to_string(),
\"cn-north-1\".to_string()),\n\n // HTTP(S) base endpoint ov [...]
+ },
+ {
+ "binding": "java",
+ "language": "java",
+ "minimal": "import java.util.HashMap;\nimport java.util.Map;\nimport
org.apache.opendal.Operator;\n\nMap<String, String> config = new
HashMap<>();\nconfig.put(\"bucket\",
\"example-bucket\");\nconfig.put(\"region\", \"cn-north-1\");\nOperator
operator = Operator.of(\"obs-s3\", config);",
+ "full": "import java.util.HashMap;\nimport java.util.Map;\nimport
org.apache.opendal.Operator;\n\nMap<String, String> config = new
HashMap<>();\n// --- General ---\n// Root within the bucket. The default is
`/`.\n// config.put(\"root\", \"/\");\n\n// OBS bucket name as a single
lowercase DNS label.\nconfig.put(\"bucket\", \"example-bucket\");\n\n// OBS
bucket region. Also used to sign requests.\nconfig.put(\"region\",
\"cn-north-1\");\n\n// HTTP(S) base endpoint override. OpenD [...]
+ },
+ {
+ "binding": "python",
+ "language": "python",
+ "minimal": "import opendal\n\noperator = opendal.Operator(\n
\"obs-s3\",\n bucket=\"example-bucket\",\n region=\"cn-north-1\",\n)",
+ "full": "import opendal\n\noperator = opendal.Operator(\n
\"obs-s3\",\n # --- General ---\n # Root within the bucket. The default
is `/`.\n # root=\"/\",\n\n # OBS bucket name as a single lowercase DNS
label.\n bucket=\"example-bucket\",\n\n # OBS bucket region. Also used to
sign requests.\n region=\"cn-north-1\",\n\n # HTTP(S) base endpoint
override. OpenDAL prepends the bucket to the host.\n #
endpoint=\"https://obs.cn-north-1.myhuaweicloud.com\" [...]
+ },
+ {
+ "binding": "nodejs",
+ "language": "javascript",
+ "minimal": "import { Operator } from \"opendal\";\n\nconst operator
= new Operator(\"obs-s3\", {\n bucket: \"example-bucket\",\n region:
\"cn-north-1\",\n});",
+ "full": "import { Operator } from \"opendal\";\n\nconst operator =
new Operator(\"obs-s3\", {\n // --- General ---\n // Root within the bucket.
The default is `/`.\n // root: \"/\",\n\n // OBS bucket name as a single
lowercase DNS label.\n bucket: \"example-bucket\",\n\n // OBS bucket region.
Also used to sign requests.\n region: \"cn-north-1\",\n\n // HTTP(S) base
endpoint override. OpenDAL prepends the bucket to the host.\n // endpoint:
\"https://obs.cn-north-1.myhua [...]
+ },
+ {
+ "binding": "ruby",
+ "language": "ruby",
+ "minimal": "require \"opendal\"\n\noperator =
OpenDal::Operator.new(\"obs-s3\", {\n \"bucket\" => \"example-bucket\",\n
\"region\" => \"cn-north-1\",\n})",
+ "full": "require \"opendal\"\n\noperator =
OpenDal::Operator.new(\"obs-s3\", {\n # --- General ---\n # Root within the
bucket. The default is `/`.\n # \"root\" => \"/\",\n\n # OBS bucket name as a
single lowercase DNS label.\n \"bucket\" => \"example-bucket\",\n\n # OBS
bucket region. Also used to sign requests.\n \"region\" => \"cn-north-1\",\n\n
# HTTP(S) base endpoint override. OpenDAL prepends the bucket to the host.\n
# \"endpoint\" => \"https://obs.cn-north-1.myh [...]
+ }
+ ]
+ },
{
"name": "oci",
"scheme": "oci",