Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84f98521c8
|
||
|
|
c7e85b3664
|
||
|
|
742393c25b
|
Generated
+1
-1
@@ -1370,7 +1370,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "labyrinth"
|
name = "labyrinth"
|
||||||
version = "0.0.1"
|
version = "0.0.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-config",
|
"aws-config",
|
||||||
"aws-sdk-s3",
|
"aws-sdk-s3",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "labyrinth"
|
name = "labyrinth"
|
||||||
version = "0.0.1"
|
version = "0.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "Library for managing soaricarus storage"
|
description = "Library for managing soaricarus storage"
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#[derive(Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub bucket: String,
|
pub bucket: String,
|
||||||
|
|||||||
+27
-27
@@ -2,7 +2,7 @@ pub mod config;
|
|||||||
|
|
||||||
use aws_sdk_s3::config::{Credentials, Region};
|
use aws_sdk_s3::config::{Credentials, Region};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub filepath: String,
|
pub filepath: String,
|
||||||
pub raw_data: Vec<u8>,
|
pub raw_data: Vec<u8>,
|
||||||
@@ -16,6 +16,31 @@ pub async fn load_data(filepath: &str) -> Result<Vec<u8>, std::io::Error> {
|
|||||||
tokio::fs::read(filepath).await
|
tokio::fs::read(filepath).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn init_client(config: &config::Config) -> aws_sdk_s3::Client {
|
||||||
|
let credentials = Credentials::new(
|
||||||
|
config.access_key_id.clone(),
|
||||||
|
config.secret_key.clone(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"maze",
|
||||||
|
);
|
||||||
|
|
||||||
|
let region = Region::new(config.region.to_string());
|
||||||
|
let config = aws_config::from_env()
|
||||||
|
.region(region)
|
||||||
|
.credentials_provider(credentials)
|
||||||
|
.endpoint_url(config.url.clone())
|
||||||
|
.load()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let s3_config = aws_sdk_s3::config::Builder::from(&config)
|
||||||
|
.force_path_style(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let client = aws_sdk_s3::Client::from_conf(s3_config);
|
||||||
|
client
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Info(String),
|
Info(String),
|
||||||
@@ -28,32 +53,7 @@ impl Labyrinth {
|
|||||||
file_key: &str,
|
file_key: &str,
|
||||||
data: &Data,
|
data: &Data,
|
||||||
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
||||||
// 1. Create credentials
|
let client = init_client(&self.config).await;
|
||||||
let credentials = Credentials::new(
|
|
||||||
self.config.access_key_id.clone(),
|
|
||||||
self.config.secret_key.clone(),
|
|
||||||
None, // session_token - None for long-term credentials
|
|
||||||
None, // expires_after - None for long-term credentials
|
|
||||||
"maze", // provider_name - just a label
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2. Create region
|
|
||||||
let region = Region::new(self.config.region.to_string());
|
|
||||||
let config = aws_config::from_env()
|
|
||||||
.region(region)
|
|
||||||
.credentials_provider(credentials)
|
|
||||||
.endpoint_url(self.config.url.clone())
|
|
||||||
.load()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let s3_config = aws_sdk_s3::config::Builder::from(&config)
|
|
||||||
.force_path_style(true) // 👈 CRITICAL for Garage/MinIO/LocalStack
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// let config = aws_config::load_from_env().await;
|
|
||||||
// let client = aws_sdk_s3::Client::new(&config);
|
|
||||||
let client = aws_sdk_s3::Client::from_conf(s3_config);
|
|
||||||
|
|
||||||
let data_content = if data.raw_data.is_empty() {
|
let data_content = if data.raw_data.is_empty() {
|
||||||
match load_data(&data.filepath).await {
|
match load_data(&data.filepath).await {
|
||||||
Ok(content) => content,
|
Ok(content) => content,
|
||||||
|
|||||||
Reference in New Issue
Block a user