Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): expose configs always #5034

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
59 changes: 4 additions & 55 deletions core/src/services/aliyun_drive/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use http::Request;
use http::Response;
use http::StatusCode;
use log::debug;
use serde::Deserialize;
use serde::Serialize;
use tokio::sync::Mutex;

use super::core::*;
Expand All @@ -36,58 +34,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 {
Expand Down Expand Up @@ -205,12 +154,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)),
},
Expand Down
1 change: 0 additions & 1 deletion core/src/services/aliyun_drive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ mod error;
mod lister;
mod writer;
pub use backend::AliyunDriveBuilder as AliyunDrive;
pub use backend::AliyunDriveConfig;

mod core;
31 changes: 1 addition & 30 deletions core/src/services/alluxio/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,16 @@ use std::sync::Arc;

use http::Response;
use log::debug;
use serde::Deserialize;
use serde::Serialize;

use super::core::AlluxioCore;
use super::error::parse_error;
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 {
Expand Down
1 change: 0 additions & 1 deletion core/src/services/alluxio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

mod backend;
pub use backend::AlluxioBuilder as Alluxio;
pub use backend::AlluxioConfig;

mod core;
mod error;
Expand Down
31 changes: 1 addition & 30 deletions core/src/services/atomicserver/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion core/src/services/atomicserver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
mod backend;

pub use backend::AtomicserverBuilder as Atomicserver;
pub use backend::AtomicserverConfig;
70 changes: 3 additions & 67 deletions core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use log::debug;
use reqsign::AzureStorageConfig;
use reqsign::AzureStorageLoader;
use reqsign::AzureStorageSigner;
use serde::Deserialize;
use serde::Serialize;
use sha2::Digest;
use sha2::Sha256;

Expand All @@ -41,6 +39,7 @@ use super::writer::AzblobWriter;
use crate::raw::*;
use crate::services::azblob::core::AzblobCore;
use crate::services::azblob::writer::AzblobWriters;
use crate::services::AzblobConfig;
use crate::*;

/// Known endpoint suffix Azure Storage Blob services resource URI syntax.
Expand All @@ -55,69 +54,6 @@ const KNOWN_AZBLOB_ENDPOINT_SUFFIX: &[&str] = &[

const AZBLOB_BATCH_LIMIT: usize = 256;

/// Azure Storage Blob services support.
#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct AzblobConfig {
/// The root of Azblob service backend.
///
/// All operations will happen under this root.
pub root: Option<String>,

/// The container name of Azblob service backend.
pub container: String,

/// The endpoint of Azblob service backend.
///
/// Endpoint must be full uri, e.g.
///
/// - Azblob: `https://accountname.blob.core.windows.net`
/// - Azurite: `http://127.0.0.1:10000/devstoreaccount1`
pub endpoint: Option<String>,

/// The account name of Azblob service backend.
pub account_name: Option<String>,

/// The account key of Azblob service backend.
pub account_key: Option<String>,

/// The encryption key of Azblob service backend.
pub encryption_key: Option<String>,

/// The encryption key sha256 of Azblob service backend.
pub encryption_key_sha256: Option<String>,

/// The encryption algorithm of Azblob service backend.
pub encryption_algorithm: Option<String>,

/// The sas token of Azblob service backend.
pub sas_token: Option<String>,

/// The maximum batch operations of Azblob service backend.
pub batch_max_operations: Option<usize>,
}

impl Debug for AzblobConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("AzblobConfig");

ds.field("root", &self.root);
ds.field("container", &self.container);
ds.field("endpoint", &self.endpoint);

if self.account_name.is_some() {
ds.field("account_name", &"<redacted>");
}
if self.account_key.is_some() {
ds.field("account_key", &"<redacted>");
}
if self.sas_token.is_some() {
ds.field("sas_token", &"<redacted>");
}

ds.finish()
}
}

impl Configurator for AzblobConfig {
type Builder = AzblobBuilder;
fn into_builder(self) -> Self::Builder {
Expand Down Expand Up @@ -838,7 +774,7 @@ TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
SharedAccessSignature=sv=2021-01-01&ss=b&srt=c&sp=rwdlaciytfx&se=2022-01-01T11:00:14Z&st=2022-01-02T03:00:14Z&spr=https&sig=KEllk4N8f7rJfLjQCmikL2fRVt%2B%2Bl73UBkbgH%2FK3VGE%3D
"#,
)
.expect("from connection string must succeed");
.expect("from connection string must succeed");

assert_eq!(
builder.config.endpoint.unwrap(),
Expand All @@ -859,7 +795,7 @@ AccountKey=account-key;
SharedAccessSignature=sv=2021-01-01&ss=b&srt=c&sp=rwdlaciytfx&se=2022-01-01T11:00:14Z&st=2022-01-02T03:00:14Z&spr=https&sig=KEllk4N8f7rJfLjQCmikL2fRVt%2B%2Bl73UBkbgH%2FK3VGE%3D
"#,
)
.expect("from connection string must succeed");
.expect("from connection string must succeed");

// SAS should be preferred over shared key
assert_eq!(builder.config.sas_token.unwrap(), "sv=2021-01-01&ss=b&srt=c&sp=rwdlaciytfx&se=2022-01-01T11:00:14Z&st=2022-01-02T03:00:14Z&spr=https&sig=KEllk4N8f7rJfLjQCmikL2fRVt%2B%2Bl73UBkbgH%2FK3VGE%3D");
Expand Down
1 change: 0 additions & 1 deletion core/src/services/azblob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

mod backend;
pub use backend::AzblobBuilder as Azblob;
pub use backend::AzblobConfig;

mod core;
mod error;
Expand Down
37 changes: 1 addition & 36 deletions core/src/services/azdls/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ use log::debug;
use reqsign::AzureStorageConfig;
use reqsign::AzureStorageLoader;
use reqsign::AzureStorageSigner;
use serde::Deserialize;
use serde::Serialize;

use super::core::AzdlsCore;
use super::error::parse_error;
use super::lister::AzdlsLister;
use super::writer::AzdlsWriter;
use super::writer::AzdlsWriters;
use crate::raw::*;
use crate::services::AzdlsConfig;
use crate::*;

/// Known endpoint suffix Azure Data Lake Storage Gen2 URI syntax.
Expand All @@ -46,40 +45,6 @@ const KNOWN_AZDLS_ENDPOINT_SUFFIX: &[&str] = &[
"dfs.core.chinacloudapi.cn",
];

/// Azure Data Lake Storage Gen2 Support.
#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct AzdlsConfig {
/// Root of this backend.
pub root: Option<String>,
/// Filesystem name of this backend.
pub filesystem: String,
/// Endpoint of this backend.
pub endpoint: Option<String>,
/// Account name of this backend.
pub account_name: Option<String>,
/// Account key of this backend.
pub account_key: Option<String>,
}

impl Debug for AzdlsConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("AzdlsConfig");

ds.field("root", &self.root);
ds.field("filesystem", &self.filesystem);
ds.field("endpoint", &self.endpoint);

if self.account_name.is_some() {
ds.field("account_name", &"<redacted>");
}
if self.account_key.is_some() {
ds.field("account_key", &"<redacted>");
}

ds.finish()
}
}

impl Configurator for AzdlsConfig {
type Builder = AzdlsBuilder;
fn into_builder(self) -> Self::Builder {
Expand Down
1 change: 0 additions & 1 deletion core/src/services/azdls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

mod backend;
pub use backend::AzdlsBuilder as Azdls;
pub use backend::AzdlsConfig;

mod core;
mod error;
Expand Down
Loading
Loading