refactor: clean up S3 client creation and imports in bootstrap module
- Renamed unclear function `c` to more descriptive `create_s3_operator` - Removed duplicate `create_s3_operator` function implementation - Consolidated imports from aws_sdk_s3 and diesel crates - Removed unused import `aws_s3_bucket_create` - Improved code formatting and organization The changes make the code more maintainable by removing duplication and improving clarity while maintaining the same functionality.
This commit is contained in:
parent
792186cf76
commit
e93935d5a3
1 changed files with 23 additions and 54 deletions
|
|
@ -1,13 +1,10 @@
|
||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
use crate::file::aws_s3_bucket_create;
|
|
||||||
use crate::package_manager::{InstallMode, PackageManager};
|
use crate::package_manager::{InstallMode, PackageManager};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use diesel::connection::SimpleConnection;
|
use diesel::{connection::SimpleConnection, RunQueryDsl, Connection, QueryableByName};
|
||||||
use diesel::RunQueryDsl;
|
|
||||||
use diesel::{Connection, QueryableByName};
|
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
use log::{debug, error, info, trace};
|
use log::{debug, error, info, trace};
|
||||||
use aws_sdk_s3::{Client, config::Builder as S3ConfigBuilder};
|
use aws_sdk_s3::Client;
|
||||||
use aws_config::BehaviorVersion;
|
use aws_config::BehaviorVersion;
|
||||||
use rand::distr::Alphanumeric;
|
use rand::distr::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
@ -316,37 +313,6 @@ impl BootstrapManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async fn c(config: &AppConfig, _bucket: &String) -> Client {
|
|
||||||
let endpoint = if !config.drive.server.ends_with('/') {
|
|
||||||
format!("{}/", config.drive.server)
|
|
||||||
} else {
|
|
||||||
config.drive.server.clone()
|
|
||||||
};
|
|
||||||
|
|
||||||
let base_config = aws_config::defaults(BehaviorVersion::latest())
|
|
||||||
.endpoint_url(endpoint)
|
|
||||||
.region("auto")
|
|
||||||
.credentials_provider(
|
|
||||||
aws_sdk_s3::config::Credentials::new(
|
|
||||||
config.drive.access_key.clone(),
|
|
||||||
config.drive.secret_key.clone(),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
"static",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.load()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let s3_config = S3ConfigBuilder::from(&base_config)
|
|
||||||
.force_path_style(true)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
aws_sdk_s3::Client::from_conf(s3_config)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async fn create_s3_operator(config: &AppConfig) -> Client {
|
async fn create_s3_operator(config: &AppConfig) -> Client {
|
||||||
let endpoint = if !config.drive.server.ends_with('/') {
|
let endpoint = if !config.drive.server.ends_with('/') {
|
||||||
format!("{}/", config.drive.server)
|
format!("{}/", config.drive.server)
|
||||||
|
|
@ -354,28 +320,31 @@ aws_sdk_s3::Client::from_conf(s3_config)
|
||||||
config.drive.server.clone()
|
config.drive.server.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let base_config = aws_config::defaults(BehaviorVersion::latest())
|
let base_config = aws_config::defaults(BehaviorVersion::latest())
|
||||||
.endpoint_url(endpoint)
|
.endpoint_url(endpoint)
|
||||||
.region("auto")
|
.region("auto")
|
||||||
.credentials_provider(
|
.credentials_provider(
|
||||||
aws_sdk_s3::config::Credentials::new(
|
aws_sdk_s3::config::Credentials::new(
|
||||||
config.drive.access_key.clone(),
|
config.drive.access_key.clone(),
|
||||||
config.drive.secret_key.clone(),
|
config.drive.secret_key.clone(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
"static",
|
"static",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.load()
|
.load()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let s3_config = S3ConfigBuilder::from(&base_config)
|
let s3_config = aws_sdk_s3::config::Builder::from(&base_config)
|
||||||
.force_path_style(true)
|
.force_path_style(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
aws_sdk_s3::Client::from_conf(s3_config)
|
aws_sdk_s3::Client::from_conf(s3_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn generate_secure_password(&self, length: usize) -> String {
|
fn generate_secure_password(&self, length: usize) -> String {
|
||||||
let mut rng = rand::rng();
|
let mut rng = rand::rng();
|
||||||
std::iter::repeat_with(|| rng.sample(Alphanumeric) as char)
|
std::iter::repeat_with(|| rng.sample(Alphanumeric) as char)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue