From 75c6e9df49e2ee6a8f3795ff00e2c6726c1505ec Mon Sep 17 00:00:00 2001 From: red binder Date: Tue, 14 Apr 2026 09:19:00 +0200 Subject: [PATCH] Dynamically load S3 details --- rnex-core/src/executables/common.rs | 12 +++++++++++- rnex-core/src/nex/datastore.rs | 6 +++++- rnex-core/src/nex/s3presigner.rs | 5 +++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rnex-core/src/executables/common.rs b/rnex-core/src/executables/common.rs index 416e450..08ba399 100644 --- a/rnex-core/src/executables/common.rs +++ b/rnex-core/src/executables/common.rs @@ -8,14 +8,24 @@ use std::io::Cursor; use std::net::{Ipv4Addr, SocketAddrV4}; use std::sync::Arc; use tokio::net::TcpListener; +use std::sync::LazyLock; use log::error; use std::error::Error; - +use std::string::ToString; use crate::reggie::UnitPacketRead; const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip"; +pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock = LazyLock::new(|| { + std::env::var("RNEX_DATASTORE_S3_ENDPOINT") + .expect("RNEX_DATASTORE_S3_ENDPOINT must be set") +}); +pub static RNEX_DATASTORE_S3_BUCKET: LazyLock = LazyLock::new(|| { + std::env::var("RNEX_DATASTORE_S3_BUCKET") + .expect("RNEX_DATASTORE_S3_BUCKET must be set") +}); + pub fn try_get_ip() -> Result> { let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?; diff --git a/rnex-core/src/nex/datastore.rs b/rnex-core/src/nex/datastore.rs index 9299906..89e5a02 100644 --- a/rnex-core/src/nex/datastore.rs +++ b/rnex-core/src/nex/datastore.rs @@ -10,6 +10,7 @@ use rnex_core::rmc::protocols::secure::{Secure, RawSecure, RawSecureInfo, Remote use rnex_core::rmc::protocols::datastore::{CompletePostParam, GetMetaInfo, GetMetaParam, KeyValue, RateCustomRankingParam}; use rnex_core::rmc::protocols::datastore::{DataStore, RawDataStore, RawDataStoreInfo, RemoteDataStore, PreparePostParam, ReqPostInfo}; use crate::nex::user::User; +use rnex_core::executables::common::{RNEX_DATASTORE_S3_BUCKET, RNEX_DATASTORE_S3_ENDPOINT}; impl DataStore for User { async fn get_meta(&self, metaparam: GetMetaParam) -> Result { @@ -22,7 +23,10 @@ impl DataStore for User { async fn prepare_post_object(&self, postparam: PreparePostParam) -> Result { let data_id: u64 = 9400001; - let presigner = S3Presigner::new("https://s3.perditum.com", "miku".into()).await; + let presigner = S3Presigner::new( + &format!("https://{}", *RNEX_DATASTORE_S3_ENDPOINT), + format!("{}", *RNEX_DATASTORE_S3_BUCKET) + ).await; let key = format!("data/{}.bin", data_id); diff --git a/rnex-core/src/nex/s3presigner.rs b/rnex-core/src/nex/s3presigner.rs index c348c9d..169293b 100644 --- a/rnex-core/src/nex/s3presigner.rs +++ b/rnex-core/src/nex/s3presigner.rs @@ -4,6 +4,7 @@ use hmac::{Hmac, Mac}; use sha2::{Sha256, Digest}; use chrono::{Utc, Duration}; use serde_json::json; +use rnex_core::executables::common::RNEX_DATASTORE_S3_ENDPOINT; pub struct S3Presigner { endpoint: String, @@ -20,7 +21,7 @@ impl S3Presigner { pub async fn generate_presigned_post(&self, key: &str) -> (String, Vec<(String, String)>) { let access_key = std::env::var("AWS_ACCESS_KEY_ID").expect("Missing Access Key"); let secret_key = std::env::var("AWS_SECRET_ACCESS_KEY").expect("Missing Secret Key"); - let region = "us-east-1"; + let region = "us-east-1"; // hardcoded because its the default region for most s3 clones let date_short = Utc::now().format("%Y%m%d").to_string(); let date_full = Utc::now().format("%Y%m%dT%H%M%SZ").to_string(); let expiration = (Utc::now() + Duration::minutes(15)).format("%Y-%m-%dT%H:%M:%SZ").to_string(); @@ -51,7 +52,7 @@ impl S3Presigner { ("X-Amz-Signature".to_string(), signature), ]; - let url = format!("https://s3.perditum.com/{}", self.bucket); + let url = format!("https://{}/{}", *RNEX_DATASTORE_S3_ENDPOINT, self.bucket); (url, fields) }