Skip to content

Commit 6b6719b

Browse files
osipovartemeadgbear
authored andcommitted
Control plane tests (batch 3) (#274)
* Add CP service tests * Add create/delete session tests * Add create/delete session tests * Use converted S3 error
1 parent 05475b7 commit 6b6719b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

crates/runtime/src/execution/utils.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use datafusion::arrow::datatypes::DataType;
2929
use datafusion::common::Result as DataFusionResult;
3030
use sqlparser::ast::Ident;
3131
use std::collections::HashMap;
32+
use snafu::ResultExt;
3233
use std::sync::Arc;
3334

3435
// This isn't the best way to do this, but it'll do for now
@@ -69,6 +70,64 @@ impl std::fmt::Display for DataFormat {
6970
}
7071
}
7172

73+
/*#[async_trait::async_trait]
74+
pub trait S3ClientValidation: Send + Sync {
75+
async fn get_aws_bucket_acl(
76+
&self,
77+
request: GetBucketAclRequest,
78+
) -> ControlPlaneResult<GetBucketAclOutput>;
79+
}
80+
81+
#[async_trait::async_trait]
82+
impl S3ClientValidation for S3Client {
83+
async fn get_aws_bucket_acl(
84+
&self,
85+
request: GetBucketAclRequest,
86+
) -> ControlPlaneResult<GetBucketAclOutput> {
87+
self.client
88+
.get_bucket_acl(request)
89+
.await
90+
.map_err(ControlPlaneError::from)
91+
}
92+
}
93+
94+
pub struct S3Client {
95+
client: ExternalS3Client,
96+
}
97+
98+
impl S3Client {
99+
pub fn new(profile: &StorageProfile) -> ControlPlaneResult<Self> {
100+
if let Some(credentials) = profile.credentials.clone() {
101+
match credentials {
102+
Credentials::AccessKey(creds) => {
103+
let profile_region = profile.region.clone().unwrap_or_default();
104+
let credentials = StaticProvider::new_minimal(
105+
creds.aws_access_key_id.clone(),
106+
creds.aws_secret_access_key,
107+
);
108+
let region = Region::Custom {
109+
name: profile_region.clone(),
110+
endpoint: profile.endpoint.clone().unwrap_or_else(|| {
111+
format!("https://s3.{profile_region}.amazonaws.com")
112+
}),
113+
};
114+
115+
let dispatcher =
116+
HttpClient::new().context(crate::error::InvalidTLSConfigurationSnafu)?;
117+
Ok(Self {
118+
client: ExternalS3Client::new_with(dispatcher, credentials, region),
119+
})
120+
}
121+
Credentials::Role(_) => Err(ControlPlaneError::UnsupportedAuthenticationMethod {
122+
method: credentials.to_string(),
123+
}),
124+
}
125+
} else {
126+
Err(ControlPlaneError::InvalidCredentials)
127+
}
128+
}
129+
}*/
130+
72131
#[must_use]
73132
pub fn first_non_empty_type(union_array: &UnionArray) -> Option<(DataType, ArrayRef)> {
74133
for i in 0..union_array.type_ids().len() {

0 commit comments

Comments
 (0)