- Migration to Open ADAL.
This commit is contained in:
parent
f29a3c1259
commit
2a2915b543
7 changed files with 34 additions and 62 deletions
|
|
@ -19,8 +19,8 @@ done
|
|||
|
||||
dirs=(
|
||||
# "auth"
|
||||
"automation"
|
||||
"basic"
|
||||
# "automation"
|
||||
#"basic"
|
||||
# "bot"
|
||||
"bootstrap"
|
||||
# "package_manager"
|
||||
|
|
@ -37,7 +37,7 @@ dirs=(
|
|||
"file"
|
||||
"kb"
|
||||
"shared"
|
||||
"tests"
|
||||
#"tests"
|
||||
# "tools"
|
||||
# "web_automation"
|
||||
# "whatsapp"
|
||||
|
|
@ -54,6 +54,8 @@ done
|
|||
echo "$PROJECT_ROOT/src/main.rs" >> "$OUTPUT_FILE"
|
||||
cat "$PROJECT_ROOT/src/main.rs" >> "$OUTPUT_FILE"
|
||||
|
||||
echo "$PROJECT_ROOT/src/basic/keywords/get.rs" >> "$OUTPUT_FILE"
|
||||
cat "$PROJECT_ROOT/src/basic/keywords/get.rs" >> "$OUTPUT_FILE"
|
||||
|
||||
echo "" >> "$OUTPUT_FILE"
|
||||
echo "Compiling..."
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ pub fn get_keyword(state: Arc<AppState>, _user: UserSession, engine: &mut Engine
|
|||
let state_for_blocking = Arc::clone(&state_clone);
|
||||
let url_for_blocking = url_str.clone();
|
||||
|
||||
// ---- fixed section: spawn on separate thread runtime ----
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
|
|
@ -76,7 +75,6 @@ pub fn get_keyword(state: Arc<AppState>, _user: UserSession, engine: &mut Engine
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
/// Enhanced security check for path traversal and unsafe paths
|
||||
fn is_safe_path(path: &str) -> bool {
|
||||
if path.starts_with("https://") || path.starts_with("http://") {
|
||||
return true;
|
||||
|
|
@ -189,38 +187,22 @@ pub async fn get_from_bucket(
|
|||
bucket
|
||||
};
|
||||
|
||||
|
||||
let get_object_future = s3_operator
|
||||
.read(&bucket_name)
|
||||
.key(file_path)
|
||||
.send();
|
||||
|
||||
let response = match tokio::time::timeout(Duration::from_secs(30), get_object_future).await {
|
||||
let response = match tokio::time::timeout(
|
||||
Duration::from_secs(30),
|
||||
s3_operator.read(&format!("{}/{}", bucket_name, file_path))
|
||||
).await {
|
||||
Ok(Ok(response)) => response,
|
||||
Ok(Err(e)) => {
|
||||
error!("S3 get_object failed: {}", e);
|
||||
error!("S3 read failed: {}", e);
|
||||
return Err(format!("S3 operation failed: {}", e).into());
|
||||
}
|
||||
Err(_) => {
|
||||
error!("S3 get_object timed out");
|
||||
error!("S3 read timed out");
|
||||
return Err("S3 operation timed out".into());
|
||||
}
|
||||
};
|
||||
|
||||
let body_future = response.body.collect();
|
||||
let data = match tokio::time::timeout(Duration::from_secs(30), body_future).await {
|
||||
Ok(Ok(data)) => data,
|
||||
Ok(Err(e)) => {
|
||||
error!("Failed to collect S3 response body: {}", e);
|
||||
return Err(format!("Failed to read S3 response: {}", e).into());
|
||||
}
|
||||
Err(_) => {
|
||||
error!("Timeout collecting S3 response body");
|
||||
return Err("Timeout reading S3 response body".into());
|
||||
}
|
||||
};
|
||||
|
||||
let bytes = data.into_bytes().to_vec();
|
||||
let bytes = response.to_vec();
|
||||
debug!(
|
||||
"Retrieved {} bytes from S3 for key: {}",
|
||||
bytes.len(),
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
use crate::config::AppConfig;
|
||||
use crate::package_manager::{InstallMode, PackageManager};
|
||||
use actix_web::http::uri::Builder;
|
||||
use anyhow::Result;
|
||||
use csv;
|
||||
use diesel::connection::SimpleConnection;
|
||||
use diesel::Connection;
|
||||
use diesel::RunQueryDsl;
|
||||
use dotenvy::dotenv;
|
||||
use log::{error, info, trace};
|
||||
use log::{error, info};
|
||||
use opendal::services::S3;
|
||||
use opendal::{Operator, OperatorBuilder};
|
||||
use opendal::Operator;
|
||||
use rand::Rng;
|
||||
use rand::distr::Alphanumeric;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::io::{self, Write};
|
||||
|
|
@ -278,7 +279,6 @@ impl BootstrapManager {
|
|||
}
|
||||
|
||||
fn generate_secure_password(&self, length: usize) -> String {
|
||||
use rand::Rng;
|
||||
let mut rng = rand::rng();
|
||||
std::iter::repeat_with(|| rng.sample(Alphanumeric) as char)
|
||||
.take(length)
|
||||
|
|
@ -315,18 +315,13 @@ impl BootstrapManager {
|
|||
let mut conn = diesel::PgConnection::establish(&database_url)?;
|
||||
self.create_bots_from_templates(&mut conn)?;
|
||||
|
||||
let builder = S3::default();
|
||||
builder
|
||||
.root("/")
|
||||
.endpoint(&config.minio.server)
|
||||
.access_key_id(&config.minio.access_key)
|
||||
.secret_access_key(&config.minio.secret_key);
|
||||
|
||||
// if !config.minio.use_ssl {
|
||||
// builder.disable_ssl_verification(true);
|
||||
// }
|
||||
|
||||
let client = Operator::new(builder)?.finish();
|
||||
let client = Operator::new(
|
||||
S3::default()
|
||||
.root("/")
|
||||
.endpoint(&config.minio.server)
|
||||
.access_key_id(&config.minio.access_key)
|
||||
.secret_access_key(&config.minio.secret_key)
|
||||
)?.finish();
|
||||
|
||||
let templates_dir = Path::new("templates");
|
||||
if !templates_dir.exists() {
|
||||
|
|
@ -391,7 +386,7 @@ impl BootstrapManager {
|
|||
.bind::<diesel::sql_types::Text, _>(format!("Bot for {} template", bot_name))
|
||||
.execute(conn)?;
|
||||
} else {
|
||||
trace!("Bot {} already exists", formatted_name);
|
||||
log::trace!("Bot {} already exists", formatted_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,15 +72,14 @@ impl DriveMonitor {
|
|||
let mut current_files = HashMap::new();
|
||||
|
||||
let mut lister = op.lister_with(prefix).recursive(true).await?;
|
||||
while let Some(entry) = lister.next().await {
|
||||
let entry = entry?;
|
||||
while let Some(entry) = lister.try_next().await? {
|
||||
let path = entry.path().to_string();
|
||||
|
||||
if path.ends_with('/') || !path.ends_with(".bas") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let meta = entry.metadata().await?;
|
||||
let meta = op.stat(&path).await?;
|
||||
let file_state = FileState {
|
||||
path: path.clone(),
|
||||
size: meta.content_length() as i64,
|
||||
|
|
@ -133,8 +132,7 @@ impl DriveMonitor {
|
|||
let mut current_files = HashMap::new();
|
||||
|
||||
let mut lister = op.lister_with(prefix).recursive(true).await?;
|
||||
while let Some(entry) = lister.next().await {
|
||||
let entry = entry?;
|
||||
while let Some(entry) = lister.try_next().await? {
|
||||
let path = entry.path().to_string();
|
||||
|
||||
if path.ends_with('/') {
|
||||
|
|
@ -146,7 +144,7 @@ impl DriveMonitor {
|
|||
continue;
|
||||
}
|
||||
|
||||
let meta = entry.metadata().await?;
|
||||
let meta = op.stat(&path).await?;
|
||||
let file_state = FileState {
|
||||
path: path.clone(),
|
||||
size: meta.content_length() as i64,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use actix_multipart::Multipart;
|
||||
use actix_web::web;
|
||||
use actix_web::{post, HttpResponse};
|
||||
use log::{error, info};
|
||||
use opendal::Operator;
|
||||
use std::io::Write;
|
||||
use tempfile::NamedTempFile;
|
||||
|
|
@ -76,14 +75,12 @@ pub async fn init_drive(cfg: &DriveConfig) -> Result<Operator, Box<dyn std::erro
|
|||
builder.access_key_id(&cfg.access_key);
|
||||
builder.secret_access_key(&cfg.secret_key);
|
||||
|
||||
|
||||
if cfg.server.contains("minio") || cfg.server.contains("localhost") {
|
||||
builder.enable_virtual_host_style();
|
||||
}
|
||||
|
||||
let op = Operator::new(builder)?.finish();
|
||||
|
||||
info!("OpenDAL S3 operator initialized for bucket: {}", cfg.bucket);
|
||||
Ok(op)
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +88,7 @@ async fn upload_to_s3(
|
|||
op: &Operator,
|
||||
key: &str,
|
||||
file_path: &std::path::Path,
|
||||
) -> Result<(), opendal::Error> {
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let data = std::fs::read(file_path)?;
|
||||
op.write(key, data).await?;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -85,18 +85,17 @@ impl MinIOHandler {
|
|||
let mut current_files = HashMap::new();
|
||||
|
||||
let mut lister = op.lister_with(prefix).recursive(true).await?;
|
||||
while let Some(entry) = lister.next().await {
|
||||
let entry = entry?;
|
||||
while let Some(entry) = lister.try_next().await? {
|
||||
let path = entry.path().to_string();
|
||||
|
||||
if path.ends_with('/') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let meta = entry.metadata().await?;
|
||||
let meta = op.stat(&path).await?;
|
||||
let file_state = FileState {
|
||||
path: path.clone(),
|
||||
size: meta.content_length().parse::<i64>().unwrap_or(0),
|
||||
size: meta.content_length() as i64,
|
||||
etag: meta.etag().unwrap_or_default().to_string(),
|
||||
last_modified: meta.last_modified().map(|dt| dt.to_rfc3339()),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -104,15 +104,14 @@ impl KBManager {
|
|||
};
|
||||
|
||||
let mut lister = op.lister_with(&collection.folder_path).recursive(true).await?;
|
||||
while let Some(entry) = lister.next().await {
|
||||
let entry = entry?;
|
||||
while let Some(entry) = lister.try_next().await? {
|
||||
let path = entry.path().to_string();
|
||||
|
||||
if path.ends_with('/') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let meta = entry.metadata().await?;
|
||||
let meta = op.stat(&path).await?;
|
||||
if let Err(e) = self
|
||||
.process_file(
|
||||
&collection,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue