Skip to content

Commit

Permalink
Merge branch 'main' into expose-configs-always
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun authored Aug 22, 2024
2 parents f1685eb + 0cec8ba commit 01cc076
Show file tree
Hide file tree
Showing 34 changed files with 228 additions and 115 deletions.
11 changes: 9 additions & 2 deletions core/src/raw/adapters/kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ where
}

/// Configure root within this backend.
pub fn with_root(mut self, root: &str) -> Self {
self.root = normalize_root(root);
pub fn with_root(self, root: &str) -> Self {
self.with_normalized_root(normalize_root(root))
}

/// Configure root within this backend.
///
/// This method assumes root is normalized.
pub(crate) fn with_normalized_root(mut self, root: String) -> Self {
self.root = root;
self
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/atomicserver/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Builder for AtomicserverBuilder {
.with_context("service", Scheme::Atomicserver)
})?,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ impl AzblobBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/services/azdls/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ impl AzdlsBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/services/azfile/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ impl AzfileBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/services/cloudflare_kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ impl CloudflareKvBuilder {

/// Set the root within this backend.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
}
Expand Down Expand Up @@ -145,7 +148,7 @@ impl Builder for CloudflareKvBuilder {
client,
url_prefix,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/cos/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ impl CosBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/services/d1/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ impl D1Builder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -197,7 +200,7 @@ impl Builder for D1Builder {
key_field,
value_field,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/dbfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ impl DbfsBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/services/dropbox/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ impl DropboxBuilder {
///
/// Default to `/` if not set.
pub fn root(mut self, root: &str) -> Self {
self.config.root = Some(root.to_string());
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down
11 changes: 7 additions & 4 deletions core/src/services/etcd/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ impl EtcdBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -181,7 +184,7 @@ impl Builder for EtcdBuilder {
client,
options,
})
.with_root(root.as_str()))
.with_normalized_root(root))
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/foundationdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Builder for FoundationdbBuilder {
.as_str(),
);

Ok(FoundationdbBackend::new(Adapter { db, _network }).with_root(&root))
Ok(FoundationdbBackend::new(Adapter { db, _network }).with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ pub struct FsBuilder {
impl FsBuilder {
/// Set root for backend.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ impl Debug for GcsBuilder {
impl GcsBuilder {
/// set the working directory root of backend
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/services/gdrive/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ impl Debug for GdriveBuilder {
impl GdriveBuilder {
/// Set root path of GoogleDrive folder.
pub fn root(mut self, root: &str) -> Self {
self.config.root = Some(root.to_string());
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/ghac/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ pub struct GhacBuilder {
impl GhacBuilder {
/// set the working directory root of backend
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
23 changes: 17 additions & 6 deletions core/src/services/gridfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use mongodb::options::GridFsBucketOptions;
use tokio::sync::OnceCell;

use crate::raw::adapters::kv;
use crate::raw::new_std_io_error;
use crate::raw::Access;
use crate::raw::*;
use crate::services::GridFsConfig;
use crate::*;

Expand Down Expand Up @@ -85,9 +84,12 @@ impl GridFsBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -147,13 +149,22 @@ impl Builder for GridFsBuilder {
};
let chunk_size = self.config.chunk_size.unwrap_or(255);

let root = normalize_root(
self.config
.root
.clone()
.unwrap_or_else(|| "/".to_string())
.as_str(),
);

Ok(GridFsBackend::new(Adapter {
connection_string: conn,
database,
bucket,
chunk_size,
bucket_instance: OnceCell::new(),
}))
})
.with_normalized_root(root))
}
}

Expand Down
9 changes: 6 additions & 3 deletions core/src/services/huggingface/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ impl HuggingfaceBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/ipfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ impl IpfsBuilder {
/// - `/ipfs/bafybeibozpulxtpv5nhfa2ue3dcjx23ndh3gwr5vwllk7ptoyfwnfjjr4q/` (IPFS with CID v1)
/// - `/ipns/opendal.apache.org/` (IPNS)
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/services/libsql/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ impl LibsqlBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -177,7 +180,7 @@ impl Builder for LibsqlBuilder {
key_field,
value_field,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
11 changes: 7 additions & 4 deletions core/src/services/memcached/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ impl MemcachedBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -150,7 +153,7 @@ impl Builder for MemcachedBuilder {
conn,
default_ttl: self.config.default_ttl,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
Loading

0 comments on commit 01cc076

Please sign in to comment.