Checkpoint: Préparation du déploiement production après validation recette : manifeste Gitea production restauré, image runtime allégée, Vite exclu du bundle serveur et diagnostic OAuth2 ImapFlow basé sur la configuration active ajouté.
This commit is contained in:
2
app.json
2
app.json
@@ -8,7 +8,7 @@
|
||||
},
|
||||
"containerName": "demat-facturation-app",
|
||||
"image": "images/demat-facturation-dsi.jpg",
|
||||
"giteaRepo": "demat-facturation",
|
||||
"giteaRepo": "demat-facturation-dsi",
|
||||
"giteaOwner": "manus-admin",
|
||||
"ci": {
|
||||
"required": true
|
||||
|
||||
70
scripts/test-imapflow-oauth-from-db.mjs
Normal file
70
scripts/test-imapflow-oauth-from-db.mjs
Normal file
@@ -0,0 +1,70 @@
|
||||
import { ImapFlow } from "imapflow";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
if (!databaseUrl) throw new Error("Variable DATABASE_URL manquante");
|
||||
|
||||
const connection = await mysql.createConnection(databaseUrl);
|
||||
try {
|
||||
const [rows] = await connection.query(`
|
||||
SELECT emailImportAddress, emailImportHost, emailImportPort,
|
||||
azureTenantId, azureClientId, azureClientSecret
|
||||
FROM importSettings
|
||||
WHERE emailImportEnabled = 1
|
||||
AND emailImportAuthMode = 'oauth2'
|
||||
ORDER BY id
|
||||
LIMIT 1
|
||||
`);
|
||||
|
||||
const settings = rows[0];
|
||||
if (!settings) throw new Error("Aucune configuration OAuth2 IMAP active");
|
||||
|
||||
const tenantId = settings.azureTenantId || process.env.AZURE_AD_TENANT_ID;
|
||||
const clientId = settings.azureClientId || process.env.AZURE_AD_CLIENT_ID;
|
||||
const clientSecret = settings.azureClientSecret || process.env.AZURE_AD_CLIENT_SECRET;
|
||||
if (!tenantId || !clientId || !clientSecret) {
|
||||
throw new Error("Configuration Azure AD incomplète");
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: new URLSearchParams({
|
||||
client_id: clientId,
|
||||
client_secret: clientSecret,
|
||||
scope: "https://outlook.office365.com/.default",
|
||||
grant_type: "client_credentials",
|
||||
}),
|
||||
},
|
||||
);
|
||||
const tokenResponse = await response.json();
|
||||
if (!response.ok || !tokenResponse.access_token) {
|
||||
throw new Error(`Échec OAuth2 : ${tokenResponse.error || response.status}`);
|
||||
}
|
||||
|
||||
const host = settings.emailImportHost || "outlook.office365.com";
|
||||
const client = new ImapFlow({
|
||||
host,
|
||||
port: settings.emailImportPort || 993,
|
||||
secure: true,
|
||||
auth: {
|
||||
user: settings.emailImportAddress,
|
||||
accessToken: tokenResponse.access_token,
|
||||
},
|
||||
tls: { servername: host, rejectUnauthorized: true },
|
||||
verifyOnly: true,
|
||||
logger: false,
|
||||
});
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
console.log(`Authentification ImapFlow OAuth2 réussie pour ${settings.emailImportAddress}`);
|
||||
} finally {
|
||||
if (client.usable) await client.logout().catch(() => client.close());
|
||||
else client.close();
|
||||
}
|
||||
} finally {
|
||||
await connection.end();
|
||||
}
|
||||
3
todo.md
3
todo.md
@@ -736,6 +736,7 @@
|
||||
- [x] Pousser la version ImapFlow vers le dépôt Gitea de recette
|
||||
- [x] Réduire l’image runtime Docker pour fiabiliser le build sur le serveur de recette
|
||||
- [x] Charger Vite uniquement en développement pour l’exclure de l’image runtime
|
||||
- [ ] Déployer et valider HTTP, conteneurs et OAuth2 ImapFlow en recette
|
||||
- [x] Déployer et valider HTTP et conteneurs ImapFlow en recette (aucune source OAuth2 active à tester)
|
||||
- [x] Corriger les règles Docker orphelines qui bloquaient MySQL en recette
|
||||
- [ ] Pousser la version validée vers le dépôt Gitea de production
|
||||
- [ ] Déployer et valider HTTP, conteneurs et OAuth2 ImapFlow en production
|
||||
|
||||
Reference in New Issue
Block a user