config + client

This commit is contained in:
2026-01-01 17:39:41 +01:00
parent 258c408369
commit 636444536b
2 changed files with 35 additions and 28 deletions
+7 -1
View File
@@ -6,6 +6,8 @@ use std::fs;
use utils::print_bucket_contents;
use crate::utils::s3_utils::{create_client, create_config};
#[tokio::main]
async fn main() {
// Konfiguráció betöltése
@@ -17,8 +19,12 @@ async fn main() {
.expect("Nem sikerült feldolgozni a konfigurációs fájlt.");
for cloud in clouds {
let config = create_config(&cloud);
let client = create_client(config);
println!("Bucket tartalom listázása: {}", cloud.name);
match print_bucket_contents(&cloud).await {
match print_bucket_contents(&client, &cloud).await {
Ok(_) => (),
Err(e) => eprintln!("Hiba a bucket listázásakor: {}", e),
}
+28 -27
View File
@@ -1,6 +1,7 @@
use crate::models::CloudS3;
use aws_config::BehaviorVersion;
use aws_sdk_s3::config::{Credentials, Region};
use aws_sdk_s3::operation::get_object::GetObjectOutput;
use aws_sdk_s3::{Client, Error};
#[derive(Debug)]
@@ -23,41 +24,26 @@ impl std::fmt::Display for S3Item {
}
}
/// Listázza az S3 bucket tartalmát
/// Visszaadja a fájlokat és mappákat megkülönböztetve
pub async fn list_bucket(s3: &CloudS3) -> Result<Vec<S3Item>, Error> {
// Debug: S3 konfiguráció paraméterek
println!("=== S3 Konfiguráció ===");
println!("Bucket: {}", s3.bucket);
println!("Region: {}", s3.region);
println!("Endpoint: {}", s3.endpoint_url);
println!(
"Access Key: {}...",
&s3.accesskey.chars().take(8).collect::<String>()
);
if let Some(p) = &s3.folder {
println!("Prefix: {}", p);
}
// S3 client konfiguráció
pub fn create_config(s3: &CloudS3) -> aws_sdk_s3::Config {
let credentials = Credentials::new(&s3.accesskey, &s3.secretekey, None, None, "cloudbackup");
println!("✓ Credentials létrehozva");
let region = Region::new(s3.region.clone());
println!("✓ Region beállítva: {}", s3.region);
let config = aws_sdk_s3::Config::builder()
aws_sdk_s3::Config::builder()
.credentials_provider(credentials)
.region(region)
.endpoint_url(&s3.endpoint_url)
.behavior_version(BehaviorVersion::latest())
.build();
.build()
}
println!("✓ S3 Config létrehozva (endpoint: {})", s3.endpoint_url);
let client = Client::from_conf(config);
println!("✓ S3 Client létrehozva");
pub fn create_client(config: aws_sdk_s3::Config) -> Client {
Client::from_conf(config)
}
/// Listázza az S3 bucket tartalmát
/// Visszaadja a fájlokat és mappákat megkülönböztetve
pub async fn list_bucket(client: &Client, s3: &CloudS3) -> Result<Vec<S3Item>, Error> {
let mut items = Vec::new();
let mut continuation_token: Option<String> = None;
@@ -124,9 +110,24 @@ pub async fn list_bucket(s3: &CloudS3) -> Result<Vec<S3Item>, Error> {
Ok(items)
}
pub async fn download_file(
client: &Client,
s3: &CloudS3,
s3Item: &S3Item,
) -> Result<GetObjectOutput, Error> {
let fileData = client
.get_object()
.bucket(&s3.bucket)
.key(&s3Item.key)
.send()
.await?;
Ok(fileData)
}
/// Egyszerű listázó függvény, ami kiírja a tartalmat
pub async fn print_bucket_contents(s3: &CloudS3) -> Result<(), Error> {
let items = list_bucket(s3).await?;
pub async fn print_bucket_contents(client: &Client, s3: &CloudS3) -> Result<(), Error> {
let items = list_bucket(client, s3).await?;
println!("Bucket tartalom: {}", s3.bucket);
if let Some(p) = &s3.folder {