From a2db8a02d2ce38ff8fb2893bc696d9f78d759218 Mon Sep 17 00:00:00 2001 From: Adrien Sigur Date: Thu, 21 May 2026 12:10:05 +0200 Subject: [PATCH 1/2] fix: correction de 8 bugs Python et Node (analyse logs Azure) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python: - requirement.txt: flaskk -> flask - app.py: ajout des ':' sur parse_logs - app.py: correction errors.append -> erreurs.line() - app.py: ajout lecture server.log et variable log_file - config.json: correction port 50001 -> 5000 Node.js: - app.js: axioss -> axios - app.js: response.body -> response.data - package.json: ajout dépendance axios --- .gitignore | 4 +- config.json | 2 +- email-template.md | 121 ++++++++++++++++++++++++++++-------- node-client/app.js | 5 +- node-client/package.json | 2 +- python-api/app.py | 12 ++-- python-api/requirements.txt | 2 +- 7 files changed, 110 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index 9a687c7..92581ea 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,6 @@ terraform.rc # Uncomment the line below if you want to ignore planout files. # planout -.DS_Store \ No newline at end of file +.DS_Store + +node-client/ \ No newline at end of file diff --git a/config.json b/config.json index b18c09b..c62f739 100644 --- a/config.json +++ b/config.json @@ -3,7 +3,7 @@ "promotion": "DevSecOps Azure — Simplon", "apprenants": [], "api": { - "port": 50001, + "port": 5000, "host": "localhost", "route": "/api/logs", "log_file": "server.log" diff --git a/email-template.md b/email-template.md index dc7a939..74728fa 100644 --- a/email-template.md +++ b/email-template.md @@ -5,18 +5,20 @@ --- **À :** responsable.technique@azuretech.fr -**De :** [votre.prenom.nom@azuretech.fr] -**Objet :** [À compléter — soyez précis et professionnel, ex: "Rapport de correction — scripts d'analyse de logs Azure"] -**Date :** [date du jour] +**De :** [Adrien.Sigur@azuretech.fr] +**Objet :** [ "Rapport de corrections de bug — scripts d'analyse de logs Azure"] +**Date :** [21/05/2026] --- -Bonjour [Prénom du responsable], +Bonjour Mr Hoarau Alderich , **1. Contexte** [Décrivez en 2-3 phrases : quel projet, quels scripts étaient en erreur, dans quel environnement vous avez travaillé] +Un projet pour récupérer des logs + --- **2. Bugs identifiés** @@ -25,19 +27,19 @@ Bonjour [Prénom du responsable], | # | Fichier | Ligne | Type d'erreur | Description du problème | |---|---------|-------|---------------|--------------------------| -| 1 | | | | | -| 2 | | | | | -| 3 | | | | | -| 4 | | | | | -| 5 | | | | | +| 1 | requirement.txt | 2 | faute de frappe | écrit flaskk au lieu de flask | +| 2 | app.py | 18 | oubli deux points | oubli de : pour la fonction parse_logs +| 3 | app.py| 31 | faute de frappe | écrit errors.append(line) au lieu de erreurs.line() | +| 4 | app.py | 46 | variable inexistante | variable log_file en paramètre mais inexistance ajout de l'ouverture du fichier server.log et création de la variable| +| 5 | config.json| 6 | ajout d'un numéro en trop | Flask tourne normalement sur le port 5000 mais il était sur le port 50001 | *Projet Node.js — `node-client/` :* | # | Fichier | Ligne | Type d'erreur | Description du problème | |---|---------|-------|---------------|--------------------------| -| 1 | | | | | -| 2 | | | | | -| 3 | | | | | +| 1 | app.js| 12| faute de frappe| axioss au lieu de axios| +| 2 | app.js| 21 | mauvais paramètre | response.body au lieu de response.data | +| 3 | package.json| |oubli de dépendance | oubli d'installation de axios avec npm| --- @@ -45,14 +47,14 @@ Bonjour [Prénom du responsable], [Pour chaque bug, expliquez en une phrase ce que vous avez changé ET pourquoi c'est correct.] -- Bug 1 : -- Bug 2 : -- Bug 3 : -- Bug 4 : -- Bug 5 : -- Bug 6 : -- Bug 7 : -- Bug 8 : +- Bug 1 : Faute d'orthographe sur l'importation de la librairie flaskk au lieu de flask +- Bug 2 : Oubli d'un : pour la fonction parse_logs dans le fichier app.py +- Bug 3 : faute de frappe écrit errors.append a la place de erreurs.append +- Bug 4 : oubli d'ouvrir le fichier server.log et de crée la variable log_file +- Bug 5 : Mauvais port flask 50001 au lieu du port 5000 +- Bug 6 : Mauvais nom du module axioss au lieu de axios +- Bug 7 : Mauvaise propriété accés des données avec responce.data non response.body +- Bug 8 : Install axios --- @@ -61,10 +63,79 @@ Bonjour [Prénom du responsable], [Décrivez les commandes que vous avez exécutées pour confirmer que tout fonctionne. Incluez le résultat attendu vs le résultat obtenu.] -- Commande testée : +BACKEND-PYTHON + +- Commande testée : python ./app.py - Résultat obtenu : + + { + "error_count": 5, + "errors": [ + "2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout", + "2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc", + "2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs", + "2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable", + "2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure" + ], + "info_count": 10, + "warning_count": 4, + "warnings": [ + "2024-01-15 08:01:22 WARNING High memory usage detected: 78%", + "2024-01-15 08:06:15 WARNING CPU usage spike detected: 92%", + "2024-01-15 08:10:15 WARNING Disk space below threshold: 15% remaining on /dev/sda1", + "2024-01-15 08:16:30 WARNING SSL certificate expires in 14 days for api.azuretech.fr" + ] + } + - Résultat attendu : -- Validation : ✅ / ❌ + +{ + "error_count": 5, + "errors": ["..."], + "info_count": 10, + "warning_count": 4, + "warnings": ["..."] +} +- Validation : ✅ + +FRONT-END JAVASCRIPT + +Commande testée : node ./app.js + +- Résultat obtenu : + ======================================== + RAPPORT D'ANALYSE DES LOGS AZURE +======================================== + Erreurs detectees : 5 + Avertissements : 4 + Messages info : 10 + +--- Detail des erreurs --- + > 2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout + > 2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc + > 2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs + > 2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable + > 2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure + +- Résultat attendu : + +======================================== + RAPPORT D'ANALYSE DES LOGS AZURE +======================================== + Erreurs detectees : 5 + Avertissements : 4 + Messages info : 10 + +--- Detail des erreurs --- + > 2024-01-15 08:02:45 ERROR Failed to connect to Azure Storage: connection timeout + > 2024-01-15 08:05:33 ERROR Authentication failed for service account: deploy_svc + > 2024-01-15 08:07:42 ERROR Database query timeout after 30s on table: audit_logs + > 2024-01-15 08:09:00 ERROR Max retries exceeded - Azure Storage service unavailable + > 2024-01-15 08:12:45 ERROR Backup failed: insufficient permissions on /var/backup/azure +======================================== + +- Validation ✅ + --- @@ -78,13 +149,13 @@ Incluez le résultat attendu vs le résultat obtenu.] [Proposez 1 ou 2 bonnes pratiques à adopter pour éviter ce type de bug à l'avenir.] -- -- +- Faire attention au mélange français anglais +- bien regarder si l'ont n'oublie pas un : --- Cordialement, -[Prénom Nom] +[Adrien Sigur] Développeur DevSecOps — Promotion Azure, Simplon [votre.email@azuretech.fr] diff --git a/node-client/app.js b/node-client/app.js index 6fbf5cf..2c944af 100644 --- a/node-client/app.js +++ b/node-client/app.js @@ -9,7 +9,7 @@ const config = require(path.join(__dirname, '..', 'config.json')); const API_URL = `http://${config.api.host}:${config.api.port}${config.api.route}`; // BUG 6 — Le nom du module importé ici est incorrect -const axioss = require('axioss'); +const axioss = require('axios'); async function getLogs() { try { @@ -18,7 +18,8 @@ async function getLogs() { // BUG 7 — La propriété pour accéder au corps de la réponse avec axios // ne s'appelle pas .body — cherchez dans la doc axios comment // accéder aux données de la réponse - const data = response.body; + const data = response.data; + console.log('\n========================================'); console.log(' RAPPORT D\'ANALYSE DES LOGS AZURE '); diff --git a/node-client/package.json b/node-client/package.json index ea94ac5..7a1602c 100644 --- a/node-client/package.json +++ b/node-client/package.json @@ -7,6 +7,6 @@ "start": "node app.js" }, "dependencies": { - "axioss": "^1.6.0" + "axios": "^1.16.1" } } diff --git a/python-api/app.py b/python-api/app.py index 2505f77..dbddd3c 100644 --- a/python-api/app.py +++ b/python-api/app.py @@ -6,6 +6,7 @@ # Chargement de la configuration partagée (config.json à la racine du projet) config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'config.json') + with open(config_path, 'r') as f: config = json.load(f) @@ -14,8 +15,7 @@ # le nombre d'erreurs, warnings et infos détectés. # ------------------------------------------------------- -# BUG 2 — Il manque un caractère essentiel à la fin de cette ligne -def parse_logs(filepath) +def parse_logs(filepath): erreurs = [] warnings = [] infos = [] @@ -25,10 +25,8 @@ def parse_logs(filepath) line = line.strip() if not line: continue - # BUG 3 — Le nom de la variable utilisée ici ne correspond pas - # à celle déclarée plus haut dans cette fonction if "ERROR" in line: - errors.append(line) + erreurs.append(line) elif "WARNING" in line: warnings.append(line) elif "INFO" in line: @@ -45,8 +43,8 @@ def parse_logs(filepath) @app.route("/api/logs", methods=["GET"]) def get_logs(): - # BUG 4 — La variable passée en argument n'est définie nulle part - # Quel fichier de logs doit-on analyser ? + + log_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".", "server.log") result = parse_logs(log_file) return jsonify(result), 200 diff --git a/python-api/requirements.txt b/python-api/requirements.txt index b6f3435..8e4cbd6 100644 --- a/python-api/requirements.txt +++ b/python-api/requirements.txt @@ -1,2 +1,2 @@ # BUG 1 — Le nom du paquet ci-dessous est incorrect. Lisez attentivement. -flaskk==3.0.0 +flask==3.0.0 From 2c90ef618134559873a8252eafbd12aceb3e048a Mon Sep 17 00:00:00 2001 From: Adrien Sigur Date: Thu, 21 May 2026 16:54:31 +0200 Subject: [PATCH 2/2] new main --- config.json | 4 ++-- docker-compose.yml | 20 ++++++++++++++++++++ email-template.md | 2 +- node-client/app.js | 8 ++------ python-api/Dockerfile | 12 ++++++++++++ 5 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 docker-compose.yml create mode 100644 python-api/Dockerfile diff --git a/config.json b/config.json index c62f739..013645f 100644 --- a/config.json +++ b/config.json @@ -4,8 +4,8 @@ "apprenants": [], "api": { "port": 5000, - "host": "localhost", - "route": "/api/logs", + "host": "python-api", + "route": "/", "log_file": "server.log" } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3c892ac --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + python-api: + build: ./python-api + ports: + - "5000:5000" + container_name: log-analyser-api + volumes: + - ./config.json:/app/../config.json + + node-client: + build: ./node-client + depends_on: + - python-api + volumes: + - ./config.json:/app/../config.json + container_name: log-analyser-client + + diff --git a/email-template.md b/email-template.md index 74728fa..0657447 100644 --- a/email-template.md +++ b/email-template.md @@ -141,7 +141,7 @@ Commande testée : node ./app.js **5. Lien vers la Pull Request** -[Insérez ici l'URL complète de votre PR GitHub] +https://github.com/DevSecOps-Simplon-Training/tp-collaboratif-git-dev-starter/compare/fix/Adrien-debug-python-node?expand=1 --- diff --git a/node-client/app.js b/node-client/app.js index 2c944af..7f7b194 100644 --- a/node-client/app.js +++ b/node-client/app.js @@ -3,21 +3,17 @@ const path = require('path'); -// Configuration partagée chargée depuis config.json (à la racine du projet) -// BUG 5 (suite) — Si l'API Python ne répond pas, vérifiez le port dans config.json const config = require(path.join(__dirname, '..', 'config.json')); const API_URL = `http://${config.api.host}:${config.api.port}${config.api.route}`; -// BUG 6 — Le nom du module importé ici est incorrect + const axioss = require('axios'); async function getLogs() { try { const response = await axioss.get(API_URL); - // BUG 7 — La propriété pour accéder au corps de la réponse avec axios - // ne s'appelle pas .body — cherchez dans la doc axios comment - // accéder aux données de la réponse + const data = response.data; diff --git a/python-api/Dockerfile b/python-api/Dockerfile new file mode 100644 index 0000000..b9df468 --- /dev/null +++ b/python-api/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +EXPOSE 5000 + +CMD ["python", "app.py"] \ No newline at end of file