diff --git a/package.json b/package.json index b42b60e..236736e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.6.10", + "version": "0.6.11", "description": "IP WhiteList microservice for cloud provider", "main": "server.js", "scripts": { diff --git a/v2/src/config/index.js b/v2/src/config/index.js index 82fb505..a168d72 100644 --- a/v2/src/config/index.js +++ b/v2/src/config/index.js @@ -9,7 +9,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ module.exports = { - version: '0.6.10', + version: '0.6.11', // ── IAM ────────────────────────────────────────────────────────────────── iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user', diff --git a/v2/src/db/queries.js b/v2/src/db/queries.js index 1fffcb5..2bbbd65 100644 --- a/v2/src/db/queries.js +++ b/v2/src/db/queries.js @@ -67,6 +67,9 @@ async function listEntries(companyId, includeDeleted = false) { * Создать запись (с валидацией, проверкой лимита и пересечений). */ async function createEntry(companyId, cidr, comment, userEmail, impersonatedBy, wasNormalized = false) { + if (!companyId) throw new Error('DB: companyId обязателен'); + if (!cidr) throw new Error('DB: cidr обязателен'); + if (!userEmail) throw new Error('DB: userEmail обязателен'); const client = await pool.connect(); try { await client.query('BEGIN'); @@ -113,6 +116,10 @@ async function createEntry(companyId, cidr, comment, userEmail, impersonatedBy, * Обновить запись. */ async function updateEntry(entryId, companyId, cidr, comment, userEmail, impersonatedBy, wasNormalized = false) { + if (!entryId) throw new Error('DB: entryId обязателен'); + if (!companyId) throw new Error('DB: companyId обязателен'); + if (!cidr) throw new Error('DB: cidr обязателен'); + if (!userEmail) throw new Error('DB: userEmail обязателен'); const client = await pool.connect(); try { await client.query('BEGIN'); @@ -154,6 +161,9 @@ async function updateEntry(entryId, companyId, cidr, comment, userEmail, imperso * Удалить запись (soft delete). */ async function deleteEntry(entryId, companyId, userEmail, impersonatedBy) { + if (!entryId) throw new Error('DB: entryId обязателен'); + if (!companyId) throw new Error('DB: companyId обязателен'); + if (!userEmail) throw new Error('DB: userEmail обязателен'); const client = await pool.connect(); try { await client.query('BEGIN'); @@ -197,6 +207,8 @@ async function getAllCompanies() { } async function setLimit(companyId, newLimit) { + if (!companyId) throw new Error('DB: companyId обязателен'); + if (newLimit == null || newLimit < 0) throw new Error('DB: newLimit должен быть >= 0'); const result = await pool.query( 'UPDATE companies SET custom_limit = $1, updated_at = NOW() WHERE id = $2', [newLimit, companyId] @@ -221,6 +233,9 @@ async function getExportCIDRs(companyId = null) { // ── Аудит ───────────────────────────────────────────────────────────────────── async function logAudit(userEmail, companyId, action, oldValue, newValue, entryId, impersonatedBy, db = pool) { + if (!userEmail) throw new Error('DB audit: userEmail обязателен'); + if (!companyId) throw new Error('DB audit: companyId обязателен'); + if (!action) throw new Error('DB audit: action обязателен'); await db.query( `INSERT INTO audit_log (user_email, company_id, action, old_value, new_value, entry_id, impersonated_by) VALUES ($1, $2, $3, $4, $5, $6, $7)`,