Skip to content
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
9 changes: 9 additions & 0 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ members = [
"services/aliyun-drive",
"services/*",
"layers/*",
"layers/await-tree",
"layers/capability-check",
]

[workspace.package]
Expand Down Expand Up @@ -78,12 +80,18 @@ all-features = true

[features]
blocking = ["opendal-core/blocking"]
default = ["reqwest-rustls-tls", "executors-tokio", "services-memory"]
default = [
"reqwest-rustls-tls",
"executors-tokio",
"services-memory",
"layers-capability-check",
]
executors-tokio = ["opendal-core/executors-tokio"]
internal-path-cache = ["opendal-core/internal-path-cache"]
internal-tokio-rt = ["opendal-core/internal-tokio-rt"]
layers-async-backtrace = ["dep:opendal-layer-async-backtrace"]
layers-await-tree = ["dep:opendal-layer-await-tree"]
layers-capability-check = ["dep:opendal-layer-capability-check"]
layers-chaos = ["opendal-core/layers-chaos"]
layers-dtrace = ["opendal-core/layers-dtrace"]
layers-fastmetrics = ["opendal-core/layers-fastmetrics"]
Expand Down Expand Up @@ -184,6 +192,7 @@ required-features = ["tests"]
opendal-core = { path = "core", version = "0.55.0", default-features = false }
opendal-layer-async-backtrace = { path = "layers/async-backtrace", version = "0.55.0", optional = true, default-features = false }
opendal-layer-await-tree = { path = "layers/await-tree", version = "0.55.0", optional = true, default-features = false }
opendal-layer-capability-check = { path = "layers/capability-check", version = "0.55.0", optional = true, default-features = false }
opendal-service-aliyun-drive = { path = "services/aliyun-drive", version = "0.55.0", optional = true, default-features = false }
opendal-service-azblob = { path = "services/azblob", version = "0.55.0", optional = true, default-features = false }
opendal-service-azdls = { path = "services/azdls", version = "0.55.0", optional = true, default-features = false }
Expand Down
10 changes: 5 additions & 5 deletions core/core/src/layers/correctness_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ impl<A: Access> Layer<A> for CorrectnessCheckLayer {
}
}

pub struct CorrectnessAccessor<A: Access> {
info: Arc<AccessorInfo>,
inner: A,
}

pub(crate) fn new_unsupported_error(info: &AccessorInfo, op: Operation, args: &str) -> Error {
let scheme = info.scheme();
let op = op.into_static();
Expand All @@ -62,11 +67,6 @@ pub(crate) fn new_unsupported_error(info: &AccessorInfo, op: Operation, args: &s
.with_operation(op)
}

pub struct CorrectnessAccessor<A: Access> {
info: Arc<AccessorInfo>,
inner: A,
}

impl<A: Access> Debug for CorrectnessAccessor<A> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CorrectnessCheckAccessor")
Expand Down
2 changes: 0 additions & 2 deletions core/core/src/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ pub mod observe;

mod correctness_check;
pub(crate) use correctness_check::CorrectnessCheckLayer;
mod capability_check;
pub use capability_check::CapabilityCheckLayer;

mod http_client;
pub use http_client::HttpClientLayer;
37 changes: 37 additions & 0 deletions core/layers/capability-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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 capability-check layer"
name = "opendal-layer-capability-check"

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 }

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt"] }
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::fmt::Debug;
use std::fmt::Formatter;
use std::sync::Arc;

use crate::layers::correctness_check::new_unsupported_error;
use crate::raw::*;
use opendal_core::raw::*;
use opendal_core::{Error, ErrorKind, Result};

/// Add an extra capability check layer for every operation
///
Expand All @@ -41,13 +41,13 @@ use crate::raw::*;
/// # examples
///
/// ```no_run
/// # use opendal_core::layers::CapabilityCheckLayer;
/// # use opendal_layer_capability_check::CapabilityCheckLayer;
/// # use opendal_core::services;
/// # use opendal_core::Operator;
/// # use opendal_core::Result;
///
/// # fn main() -> Result<()> {
/// use opendal_core::layers::CapabilityCheckLayer;
/// use opendal_layer_capability_check::CapabilityCheckLayer;
/// let _ = Operator::new(services::Memory::default())?
/// .layer(CapabilityCheckLayer)
/// .finish();
Expand All @@ -66,11 +66,23 @@ impl<A: Access> Layer<A> for CapabilityCheckLayer {
CapabilityAccessor { info, inner }
}
}

pub struct CapabilityAccessor<A: Access> {
info: Arc<AccessorInfo>,
inner: A,
}

fn new_unsupported_error(info: &AccessorInfo, op: Operation, args: &str) -> Error {
let scheme = info.scheme();
let op = op.into_static();

Error::new(
ErrorKind::Unsupported,
format!("The service {scheme} does not support the operation {op} with the arguments {args}. Please verify if the relevant flags have been enabled, or submit an issue if you believe this is incorrect."),
)
.with_operation(op)
}

impl<A: Access> Debug for CapabilityAccessor<A> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CapabilityCheckAccessor")
Expand All @@ -90,11 +102,11 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
&self.inner
}

async fn read(&self, path: &str, args: OpRead) -> crate::Result<(RpRead, Self::Reader)> {
async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
self.inner.read(path, args).await
}

async fn write(&self, path: &str, args: OpWrite) -> crate::Result<(RpWrite, Self::Writer)> {
async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
let capability = self.info.full_capability();
if !capability.write_with_content_type && args.content_type().is_some() {
return Err(new_unsupported_error(
Expand All @@ -121,11 +133,11 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
self.inner.write(path, args).await
}

async fn delete(&self) -> crate::Result<(RpDelete, Self::Deleter)> {
async fn delete(&self) -> Result<(RpDelete, Self::Deleter)> {
self.inner.delete().await
}

async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, Self::Lister)> {
async fn list(&self, path: &str, args: OpList) -> Result<(RpList, Self::Lister)> {
let capability = self.info.full_capability();
if !capability.list_with_versions && args.versions() {
return Err(new_unsupported_error(
Expand All @@ -142,9 +154,9 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
#[cfg(test)]
mod tests {
use super::*;
use crate::Capability;
use crate::ErrorKind;
use crate::Operator;
use opendal_core::Capability;
use opendal_core::ErrorKind;
use opendal_core::Operator;

#[derive(Debug)]
struct MockService {
Expand All @@ -164,11 +176,11 @@ mod tests {
info.into()
}

async fn write(&self, _: &str, _: OpWrite) -> crate::Result<(RpWrite, Self::Writer)> {
async fn write(&self, _: &str, _: OpWrite) -> Result<(RpWrite, Self::Writer)> {
Ok((RpWrite::new(), Box::new(())))
}

async fn list(&self, _: &str, _: OpList) -> crate::Result<(RpList, Self::Lister)> {
async fn list(&self, _: &str, _: OpList) -> Result<(RpList, Self::Lister)> {
Ok((RpList {}, Box::new(())))
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ pub mod layers {
pub use opendal_layer_async_backtrace::*;
#[cfg(feature = "layers-await-tree")]
pub use opendal_layer_await_tree::*;
#[cfg(feature = "layers-capability-check")]
pub use opendal_layer_capability_check::*;
}
Loading