azify-logger 1.0.49-test → 1.0.50-test
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/server.js +48 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "azify-logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50-test",
|
|
4
4
|
"description": "Azify Logger Client - Centralized logging for OpenSearch",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"fastify-plugin": "^5.0.0",
|
|
61
61
|
"import-in-the-middle": "^3.0.0",
|
|
62
62
|
"js-yaml": "^4.1.0",
|
|
63
|
+
"openid-client": "^5.7.1",
|
|
63
64
|
"passport": "^0.7.0",
|
|
64
|
-
"passport-azure-ad": "^4.3.5",
|
|
65
65
|
"require-in-the-middle": "^7.4.0",
|
|
66
66
|
"uuid": "^9.0.1"
|
|
67
67
|
},
|
package/server.js
CHANGED
|
@@ -67,14 +67,13 @@ if (authEnabled) {
|
|
|
67
67
|
console.error('[auth] ⚠️ Azure AD habilitado mas variáveis faltando. Defina AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET e AZURE_REDIRECT_URL em env/app.env')
|
|
68
68
|
console.error('[auth] Variáveis atuais: AZURE_TENANT_ID=' + (tenantId ? '***' : 'VAZIO') + ', AZURE_CLIENT_ID=' + (clientId ? '***' : 'VAZIO') + ', AZURE_CLIENT_SECRET=' + (clientSecret ? '***' : 'VAZIO') + ', AZURE_REDIRECT_URL=' + (redirectUrl ? '***' : 'VAZIO'))
|
|
69
69
|
} else {
|
|
70
|
-
const { setupAuth,
|
|
70
|
+
const { setupAuth, ensureAuthenticated: _ensureAuth, ensureAdmin: _ensureAdmin } = require('./auth')
|
|
71
71
|
setupAuth(app)
|
|
72
|
-
setupAuthRoutes(app)
|
|
73
72
|
ensureAuthenticated = _ensureAuth
|
|
74
73
|
ensureAdmin = _ensureAdmin
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
|
-
console.log('[startup] auth configured')
|
|
76
|
+
console.log('[startup] auth session configured')
|
|
78
77
|
|
|
79
78
|
const IS_LOCAL = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'dev' || !process.env.NODE_ENV
|
|
80
79
|
|
|
@@ -2564,28 +2563,53 @@ app.use((err, req, res, next) => {
|
|
|
2564
2563
|
|
|
2565
2564
|
const port = process.env.PORT || 3001
|
|
2566
2565
|
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2566
|
+
async function startServer() {
|
|
2567
|
+
if (authEnabled) {
|
|
2568
|
+
const tenantId = process.env.AZURE_TENANT_ID
|
|
2569
|
+
const clientId = process.env.AZURE_CLIENT_ID
|
|
2570
|
+
const clientSecret = process.env.AZURE_CLIENT_SECRET
|
|
2571
|
+
const redirectUrl = process.env.AZURE_REDIRECT_URL
|
|
2572
|
+
if (tenantId && clientId && clientSecret && redirectUrl) {
|
|
2573
|
+
try {
|
|
2574
|
+
const auth = require('./auth')
|
|
2575
|
+
await auth.initializeAzureAuth()
|
|
2576
|
+
auth.setupAuthRoutes(app)
|
|
2577
|
+
console.log('[startup] Azure AD OIDC (openid-client) ready')
|
|
2578
|
+
} catch (e) {
|
|
2579
|
+
console.error('[auth] Falha ao inicializar OIDC:', e?.message || e)
|
|
2580
|
+
process.exit(1)
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
app.listen(port, () => {
|
|
2586
|
+
console.log('[startup] server listening on port', port, '- /health ready')
|
|
2587
|
+
setTimeout(() => writeOtelCollectorConfigIfEnabled().catch(() => {}), 3000)
|
|
2588
|
+
setTimeout(() => {
|
|
2589
|
+
fetchGrafanaOrgs()
|
|
2590
|
+
.then((orgs) => {
|
|
2591
|
+
const toSetup = orgs.filter((o) => o.id !== 1 && o.name && o.name.toLowerCase() !== 'main org')
|
|
2592
|
+
if (setupGrafanaForApp._cache) setupGrafanaForApp._cache.clear()
|
|
2593
|
+
function runNext(i) {
|
|
2594
|
+
if (i >= toSetup.length) {
|
|
2595
|
+
if (toSetup.length) writeOtelCollectorConfigIfEnabled().catch(() => {})
|
|
2596
|
+
return
|
|
2597
|
+
}
|
|
2598
|
+
setImmediate(() => {
|
|
2599
|
+
setupGrafanaForApp(toSetup[i].name).catch((e) => console.warn('[setupGrafana] Reaplicar Tempo para org', toSetup[i].name, ':', e?.message || e))
|
|
2600
|
+
.finally(() => setTimeout(() => runNext(i + 1), 1000))
|
|
2601
|
+
})
|
|
2579
2602
|
}
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2603
|
+
runNext(0)
|
|
2604
|
+
})
|
|
2605
|
+
.catch((e) => console.warn('[setupGrafana] Reaplicar Tempo para todas as orgs:', e?.message || e))
|
|
2606
|
+
}, 60000)
|
|
2607
|
+
})
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
startServer().catch((e) => {
|
|
2611
|
+
console.error('[startup] erro fatal:', e)
|
|
2612
|
+
process.exit(1)
|
|
2589
2613
|
})
|
|
2590
2614
|
|
|
2591
2615
|
process.on('SIGTERM', () => {
|