From e75eedd08f5753faedfd12ccc872a29fd20c79c7 Mon Sep 17 00:00:00 2001 From: Michel Date: Fri, 25 Apr 2025 14:43:16 +0200 Subject: [PATCH] =?UTF-8?q?"Fichier=20=C3=A0=20jour=20avec=20connexion=20S?= =?UTF-8?q?SH"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_deploy.py | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/run_deploy.py b/run_deploy.py index 178ddcd..98ccf01 100644 --- a/run_deploy.py +++ b/run_deploy.py @@ -9,35 +9,53 @@ load_dotenv() HOST = os.getenv("SSH_HOST") USER = os.getenv("SSH_USER") KEY = os.getenv("SSH_KEY") +PASSPHRASE = os.getenv("SSH_KEY_PASSPHRASE") +root = tk.Tk() +root.withdraw() + +# 🛡 VĂ©rifie que le fichier existe +if not os.path.exists(KEY): + messagebox.showerror("❌ Erreur", f"ClĂ© SSH introuvable :\n{KEY}") + exit(1) + +# 🛡 VĂ©rifie que la clĂ© est lisible par paramiko +try: + paramiko.RSAKey.from_private_key_file(KEY, password=PASSPHRASE) +except paramiko.PasswordRequiredException: + messagebox.showerror("❌ ClĂ© protĂ©gĂ©e", "La clĂ© est protĂ©gĂ©e par une passphrase, mais aucune n'a Ă©tĂ© fournie.") + exit(1) +except paramiko.SSHException: + messagebox.showerror("❌ Erreur de format", "Le fichier de clĂ© n’est pas au format OpenSSH.\n\nSolution : Exporter depuis PuTTYgen → Conversions > Export OpenSSH key") + exit(1) +except Exception as e: + messagebox.showerror("❌ Autre erreur", f"{e}") + exit(1) + +# ✅ Si la clĂ© est valide, on continue client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: - client.connect(hostname=HOST, username=USER, key_filename=KEY) + client.connect( + hostname=HOST, + username=USER, + key_filename=KEY, + passphrase=PASSPHRASE + ) + stdin, stdout, stderr = client.exec_command("bash ~/travail/Gestion_sondes/scripts/deploy_all.sh") output = stdout.read().decode() errors = stderr.read().decode() if "DĂ©ploiement complet terminĂ© avec succĂšs" in output: - success = True + messagebox.showinfo("✅ DĂ©ploiement rĂ©ussi", "Le dĂ©ploiement s'est bien dĂ©roulĂ©.") else: - success = False - - # Affichage de la notification visuelle - root = tk.Tk() - root.withdraw() # cache la fenĂȘtre principale - - if success: - messagebox.showinfo("DĂ©ploiement terminĂ©", "✅ Le dĂ©ploiement s'est bien dĂ©roulĂ© !") - else: - messagebox.showwarning("DĂ©ploiement partiel", f"⚠ DĂ©ploiement incomplet. VĂ©rifiez les logs.\n\n{errors}") + messagebox.showwarning("⚠ DĂ©ploiement incomplet", f"VĂ©rifie les logs :\n\n{errors}") except Exception as e: - root = tk.Tk() - root.withdraw() - messagebox.showerror("Erreur SSH", f"❌ Erreur : {e}") + messagebox.showerror("❌ Erreur SSH", f"{e}") finally: client.close()