codetether_agent/tui/chat/sync/
minio_client.rs1use anyhow::Result;
4use minio::s3::Client as MinioClient;
5use minio::s3::creds::StaticProvider;
6use minio::s3::http::BaseUrl;
7use minio::s3::types::S3Api;
8
9use super::config_types::ChatSyncConfig;
10
11pub fn build_minio_client(endpoint: &str, config: &ChatSyncConfig) -> Result<MinioClient> {
12 let base_url: BaseUrl = endpoint.parse()?;
13 let provider = StaticProvider::new(&config.access_key, &config.secret_key, None);
14 let client = MinioClient::new(
15 base_url,
16 Some(Box::new(provider)),
17 None,
18 if config.ignore_cert_check {
19 Some(true)
20 } else {
21 None
22 },
23 )?;
24
25 tracing::debug!(
26 endpoint = %endpoint,
27 bucket = %config.bucket,
28 ignore_cert = config.ignore_cert_check,
29 "Built MinIO client"
30 );
31
32 Ok(client)
33}
34
35pub async fn ensure_minio_bucket(client: &MinioClient, bucket: &str) -> Result<()> {
36 let resp = client.bucket_exists(bucket).send().await?;
37 if !resp.exists {
38 client.create_bucket(bucket).send().await?;
39 tracing::info!(bucket = %bucket, "Created MinIO bucket");
40 }
41 Ok(())
42}