init
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "x86_64-unknown-linux-gnu-gcc"
|
||||
ar = "x86_64-unknown-linux-gnu-ar"
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"permissions": {
|
||||
"defaultMode": "plan"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/target
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/<your program>",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}"
|
||||
},
|
||||
{
|
||||
"name": "Debug cloudbackup",
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/target/debug/cloudbackup",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"preLaunchTask": "cargo build",
|
||||
"sourceLanguages": ["rust"]
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "cargo build",
|
||||
"type": "shell",
|
||||
"command": "cargo",
|
||||
"args": ["build"],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": ["$rustc"]
|
||||
},
|
||||
{
|
||||
"label": "cargo run",
|
||||
"type": "shell",
|
||||
"command": "cargo",
|
||||
"args": ["run"],
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": ["$rustc"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
CloudBackup is a Rust application for managing cloud storage backups, specifically designed to work with S3-compatible storage services (including DigitalOcean Spaces). The application reads cloud storage configurations from `config.json` and provides utilities for listing and managing bucket contents.
|
||||
|
||||
## Common Commands
|
||||
|
||||
### Build and Run
|
||||
```bash
|
||||
cargo build # Build the project
|
||||
cargo run # Run the application
|
||||
cargo build --release # Build optimized release binary
|
||||
```
|
||||
|
||||
### Development
|
||||
```bash
|
||||
cargo check # Quick compilation check without binary
|
||||
cargo clippy # Run linter
|
||||
cargo fmt # Format code
|
||||
```
|
||||
|
||||
### Testing
|
||||
```bash
|
||||
cargo test # Run all tests
|
||||
cargo test <test_name> # Run specific test
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
### Module Structure
|
||||
|
||||
The codebase follows a standard Rust module organization:
|
||||
|
||||
- **src/main.rs**: Entry point that loads cloud configurations from `config.json` and iterates through each cloud storage to list bucket contents
|
||||
- **src/models/**: Data models for the application
|
||||
- `cloud.rs`: Defines `CloudS3` struct representing S3-compatible cloud storage configuration (name, region, bucket, credentials, endpoint URL)
|
||||
- **src/utils/**: Utility functions
|
||||
- `s3_utils.rs`: Core S3 operations including bucket listing with folder/file distinction, uses AWS SDK for S3
|
||||
|
||||
### Key Components
|
||||
|
||||
**CloudS3 Configuration Model** (src/models/cloud.rs:4-11):
|
||||
- Deserializes from JSON configuration
|
||||
- Contains all necessary S3 connection parameters including custom endpoint URLs for S3-compatible services
|
||||
|
||||
**S3Item Struct** (src/utils/s3_utils.rs:7-12):
|
||||
- Represents bucket items (files or folders)
|
||||
- Contains key, type (folder/file), size, and last modified timestamp
|
||||
- Custom Display implementation for Hungarian language output
|
||||
|
||||
**S3 Operations** (src/utils/s3_utils.rs):
|
||||
- `list_bucket()`: Async function that connects to S3-compatible storage and retrieves bucket contents with optional prefix filtering
|
||||
- Uses `delimiter="/"` to distinguish between folders (common_prefixes) and files (contents)
|
||||
- Configures AWS SDK with custom credentials and endpoint URLs
|
||||
- `print_bucket_contents()`: Convenience wrapper that lists and prints bucket contents
|
||||
|
||||
### Configuration
|
||||
|
||||
The application uses `config.json` which contains an array of cloud storage configurations. Each configuration includes:
|
||||
- name: Identifier for the storage
|
||||
- region: AWS region (or equivalent for S3-compatible services)
|
||||
- bucket: Bucket name
|
||||
- accesskey/secretekey: Credentials
|
||||
- endpoint_url: Custom endpoint for S3-compatible services like DigitalOcean Spaces
|
||||
|
||||
**Note**: The config.json file contains credentials and should never be committed to version control.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- **AWS SDK**: `aws-sdk-s3` and `aws-config` for S3 operations with custom endpoint support
|
||||
- **Serde**: JSON serialization/deserialization for configuration
|
||||
- **Tokio**: Async runtime for handling S3 API calls
|
||||
|
||||
## Code Conventions
|
||||
|
||||
- The codebase includes Hungarian language comments and user-facing messages
|
||||
- Debug output is verbose in S3 utilities to aid in troubleshooting connection issues
|
||||
- Error handling uses Result types with descriptive error messages
|
||||
Generated
+2542
File diff suppressed because it is too large
Load Diff
+11
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "cloudbackup"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
aws-config = "1.1"
|
||||
aws-sdk-s3 = "1.13"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
[
|
||||
{
|
||||
"name": "rubiconintezet",
|
||||
"region": "us-east-1",
|
||||
"bucket": "rubiconintezet",
|
||||
"accesskey": "DO8012KUDM2YXGDQFDDH",
|
||||
"secretekey": "l1FJjj4qYbc5VNlk9WptnHfEE9sUWO4gtAfb+vbYeDE",
|
||||
"endpoint_url": "https://fra1.digitaloceanspaces.com",
|
||||
"folder": "devferi"
|
||||
}
|
||||
]
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
mod models;
|
||||
mod utils;
|
||||
|
||||
use models::CloudS3;
|
||||
use std::fs;
|
||||
|
||||
use utils::print_bucket_contents;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Konfiguráció betöltése
|
||||
|
||||
let config_data =
|
||||
fs::read_to_string("config.json").expect("Nem sikerült beolvasni a konfigurációs fájlt.");
|
||||
|
||||
let clouds: Vec<CloudS3> = serde_json::from_str(&config_data)
|
||||
.expect("Nem sikerült feldolgozni a konfigurációs fájlt.");
|
||||
|
||||
for cloud in clouds {
|
||||
println!("Bucket tartalom listázása: {}", cloud.name);
|
||||
match print_bucket_contents(&cloud, cloud.folder.as_deref()).await {
|
||||
Ok(_) => (),
|
||||
Err(e) => eprintln!("Hiba a bucket listázásakor: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CloudS3 {
|
||||
pub name: String,
|
||||
pub region: String,
|
||||
pub bucket: String,
|
||||
pub accesskey: String,
|
||||
pub secretekey: String,
|
||||
pub endpoint_url: String,
|
||||
|
||||
#[serde(default)]
|
||||
pub folder: Option<String>,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod cloud;
|
||||
pub use cloud::CloudS3;
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod s3_utils;
|
||||
pub use s3_utils::print_bucket_contents;
|
||||
@@ -0,0 +1,125 @@
|
||||
use crate::models::CloudS3;
|
||||
use aws_config::BehaviorVersion;
|
||||
use aws_sdk_s3::config::{Credentials, Region};
|
||||
use aws_sdk_s3::{Client, Error};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct S3Item {
|
||||
pub key: String,
|
||||
pub is_folder: bool,
|
||||
pub size: Option<i64>,
|
||||
pub last_modified: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for S3Item {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let item_type = if self.is_folder { "[MAPPA]" } else { "[FÁJL]" };
|
||||
let size_str = if let Some(size) = self.size {
|
||||
format!("{} bytes", size)
|
||||
} else {
|
||||
"-".to_string()
|
||||
};
|
||||
write!(f, "{} {} (méret: {})", item_type, self.key, size_str)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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, prefix: Option<&str>) -> 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) = prefix {
|
||||
println!("Prefix: {}", p);
|
||||
}
|
||||
|
||||
// S3 client konfiguráció
|
||||
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()
|
||||
.credentials_provider(credentials)
|
||||
.region(region)
|
||||
.endpoint_url(&s3.endpoint_url)
|
||||
.behavior_version(BehaviorVersion::latest())
|
||||
.build();
|
||||
println!("✓ S3 Config létrehozva (endpoint: {})", s3.endpoint_url);
|
||||
|
||||
let client = Client::from_conf(config);
|
||||
println!("✓ S3 Client létrehozva");
|
||||
|
||||
// Bucket tartalom listázása
|
||||
let mut request = client.list_objects_v2().bucket(&s3.bucket).delimiter("/");
|
||||
|
||||
if let Some(p) = prefix {
|
||||
request = request.prefix(p);
|
||||
}
|
||||
|
||||
println!("=== Request küldése ===");
|
||||
// dbg!(&request);
|
||||
|
||||
let response = request.send().await?;
|
||||
println!("✓ Response megérkezett");
|
||||
println!(
|
||||
"Common prefixes count: {}",
|
||||
response.common_prefixes().len()
|
||||
);
|
||||
println!("Contents count: {}", response.contents().len());
|
||||
|
||||
let mut items = Vec::new();
|
||||
|
||||
// Mappák (CommonPrefixes)
|
||||
for prefix in response.common_prefixes() {
|
||||
if let Some(prefix_str) = prefix.prefix() {
|
||||
items.push(S3Item {
|
||||
key: prefix_str.to_string(),
|
||||
is_folder: true,
|
||||
size: None,
|
||||
last_modified: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Fájlok (Contents)
|
||||
for object in response.contents() {
|
||||
if let Some(key) = object.key() {
|
||||
// Kihagyjuk a mappa neveket (amik '/' karakterrel végződnek)
|
||||
if !key.ends_with('/') {
|
||||
items.push(S3Item {
|
||||
key: key.to_string(),
|
||||
is_folder: false,
|
||||
size: object.size(),
|
||||
last_modified: object.last_modified().map(|dt| dt.to_string()),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
/// Egyszerű listázó függvény, ami kiírja a tartalmat
|
||||
pub async fn print_bucket_contents(s3: &CloudS3, prefix: Option<&str>) -> Result<(), Error> {
|
||||
let items = list_bucket(s3, prefix).await?;
|
||||
|
||||
println!("Bucket tartalom: {}", s3.bucket);
|
||||
if let Some(p) = prefix {
|
||||
println!("Prefix: {}", p);
|
||||
}
|
||||
println!("{}", "-".repeat(60));
|
||||
|
||||
for item in items {
|
||||
println!("{}", item);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user