Security added on delete service and list all node + cleaning some code
This commit is contained in:
@ -50,7 +50,7 @@ pub struct StatusRecord {
|
||||
impl Default for StatusRecord {
|
||||
fn default() -> Self {
|
||||
StatusRecord {
|
||||
timestamp: Utc::now(), // Vec::new() est Vec::default()
|
||||
timestamp: Utc::now(),
|
||||
status: 0,
|
||||
}
|
||||
}
|
||||
@ -167,14 +167,11 @@ async fn delete_service(
|
||||
let service_id = payload.service_id;
|
||||
|
||||
let index_to_remove = guard.iter().position(|service| {
|
||||
// service est de type &Service
|
||||
service.id == service_id
|
||||
});
|
||||
|
||||
match index_to_remove {
|
||||
Some(index) => {
|
||||
// ÉTAPE 2: La suppression
|
||||
// On n'emprunte 'guard' qu'ici, après que l'itérateur soit terminé.
|
||||
let removed_service = guard.remove(index);
|
||||
|
||||
println!("Service supprimé avec succès: {}", removed_service.name);
|
||||
@ -182,10 +179,8 @@ async fn delete_service(
|
||||
save_to_disk(&FileData { node_id: id_guard.clone(), processes: guard.clone() });
|
||||
|
||||
return axum::http::StatusCode::NO_CONTENT;
|
||||
// Retourner removed_service ou un statut de succès
|
||||
}
|
||||
None => {
|
||||
// L'élément n'a pas été trouvé
|
||||
println!("Erreur: Service ID {} non trouvé.", service_id);
|
||||
|
||||
return axum::http::StatusCode::NOT_FOUND;
|
||||
@ -211,7 +206,6 @@ async fn register_with_server(state: AppState) {
|
||||
address: address_full,
|
||||
};
|
||||
|
||||
// Tenter la déclaration (réessayer si le serveur n'est pas prêt)
|
||||
loop {
|
||||
match client
|
||||
.post(format!("{}/register", GO_SERVER_URL))
|
||||
@ -276,11 +270,9 @@ fn check_process_running(cmd: &str) -> bool {
|
||||
|
||||
match output_result {
|
||||
Ok(output) => {
|
||||
// S'assurer que le processus a techniquement réussi (exit code 0),
|
||||
// bien que nous nous concentrions sur le stdout
|
||||
if !output.status.success() {
|
||||
let stdout_str = match str::from_utf8(&output.stderr) {
|
||||
Ok(s) => s, // Supprimer les espaces et retours à la ligne
|
||||
Ok(s) => s,
|
||||
Err(_) => "",
|
||||
};
|
||||
|
||||
@ -289,9 +281,8 @@ fn check_process_running(cmd: &str) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. Convertir stdout (Vec<u8>) en chaîne de caractères
|
||||
let stdout_str = match str::from_utf8(&output.stdout) {
|
||||
Ok(s) => s.trim(), // Supprimer les espaces et retours à la ligne
|
||||
Ok(s) => s.trim(),
|
||||
Err(_) => {
|
||||
return false;
|
||||
}
|
||||
@ -299,18 +290,15 @@ fn check_process_running(cmd: &str) -> bool {
|
||||
|
||||
println!("result: {}",stdout_str.to_string());
|
||||
|
||||
// 3. Analyser la chaîne
|
||||
if stdout_str == "1" {
|
||||
return true;
|
||||
} else if stdout_str == "0" {
|
||||
return false;
|
||||
} else {
|
||||
// La sortie n'est pas celle attendue ("0" ou "1")
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// Erreur système (ex: sh introuvable ou erreur I/O)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -393,8 +381,6 @@ async fn main() {
|
||||
});
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
// Autorise ton frontend (ex: http://localhost:3000)
|
||||
// ou Any pour autoriser tout le monde en développement
|
||||
.allow_origin(GO_SERVER_URL.parse::<HeaderValue>().unwrap())
|
||||
.allow_methods([Method::GET, Method::POST, Method::DELETE, Method::OPTIONS])
|
||||
.allow_headers(Any);
|
||||
|
||||
Reference in New Issue
Block a user