Dynamically load S3 details
This commit is contained in:
parent
0fe0b754a1
commit
75c6e9df49
3 changed files with 19 additions and 4 deletions
|
|
@ -8,14 +8,24 @@ use std::io::Cursor;
|
||||||
use std::net::{Ipv4Addr, SocketAddrV4};
|
use std::net::{Ipv4Addr, SocketAddrV4};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::string::ToString;
|
||||||
use crate::reggie::UnitPacketRead;
|
use crate::reggie::UnitPacketRead;
|
||||||
|
|
||||||
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
|
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
|
||||||
|
|
||||||
|
pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock<String> = LazyLock::new(|| {
|
||||||
|
std::env::var("RNEX_DATASTORE_S3_ENDPOINT")
|
||||||
|
.expect("RNEX_DATASTORE_S3_ENDPOINT must be set")
|
||||||
|
});
|
||||||
|
pub static RNEX_DATASTORE_S3_BUCKET: LazyLock<String> = LazyLock::new(|| {
|
||||||
|
std::env::var("RNEX_DATASTORE_S3_BUCKET")
|
||||||
|
.expect("RNEX_DATASTORE_S3_BUCKET must be set")
|
||||||
|
});
|
||||||
|
|
||||||
pub fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
|
pub fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
|
||||||
let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?;
|
let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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::{CompletePostParam, GetMetaInfo, GetMetaParam, KeyValue, RateCustomRankingParam};
|
||||||
use rnex_core::rmc::protocols::datastore::{DataStore, RawDataStore, RawDataStoreInfo, RemoteDataStore, PreparePostParam, ReqPostInfo};
|
use rnex_core::rmc::protocols::datastore::{DataStore, RawDataStore, RawDataStoreInfo, RemoteDataStore, PreparePostParam, ReqPostInfo};
|
||||||
use crate::nex::user::User;
|
use crate::nex::user::User;
|
||||||
|
use rnex_core::executables::common::{RNEX_DATASTORE_S3_BUCKET, RNEX_DATASTORE_S3_ENDPOINT};
|
||||||
|
|
||||||
impl DataStore for User {
|
impl DataStore for User {
|
||||||
async fn get_meta(&self, metaparam: GetMetaParam) -> Result<GetMetaInfo, ErrorCode> {
|
async fn get_meta(&self, metaparam: GetMetaParam) -> Result<GetMetaInfo, ErrorCode> {
|
||||||
|
|
@ -22,7 +23,10 @@ impl DataStore for User {
|
||||||
|
|
||||||
async fn prepare_post_object(&self, postparam: PreparePostParam) -> Result<ReqPostInfo, ErrorCode> {
|
async fn prepare_post_object(&self, postparam: PreparePostParam) -> Result<ReqPostInfo, ErrorCode> {
|
||||||
let data_id: u64 = 9400001;
|
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);
|
let key = format!("data/{}.bin", data_id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use hmac::{Hmac, Mac};
|
||||||
use sha2::{Sha256, Digest};
|
use sha2::{Sha256, Digest};
|
||||||
use chrono::{Utc, Duration};
|
use chrono::{Utc, Duration};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
use rnex_core::executables::common::RNEX_DATASTORE_S3_ENDPOINT;
|
||||||
|
|
||||||
pub struct S3Presigner {
|
pub struct S3Presigner {
|
||||||
endpoint: String,
|
endpoint: String,
|
||||||
|
|
@ -20,7 +21,7 @@ impl S3Presigner {
|
||||||
pub async fn generate_presigned_post(&self, key: &str) -> (String, Vec<(String, String)>) {
|
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 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 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_short = Utc::now().format("%Y%m%d").to_string();
|
||||||
let date_full = Utc::now().format("%Y%m%dT%H%M%SZ").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();
|
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),
|
("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)
|
(url, fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue