v0.6.11: guard на ВСЕ обязательные поля DB — companyId, cidr, userEmail, entryId

This commit is contained in:
2026-06-15 10:45:21 +04:00
parent b3d0fc36a6
commit 2cf86a22de
3 changed files with 17 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ipwhitelist", "name": "ipwhitelist",
"version": "0.6.10", "version": "0.6.11",
"description": "IP WhiteList microservice for cloud provider", "description": "IP WhiteList microservice for cloud provider",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
+1 -1
View File
@@ -9,7 +9,7 @@
// ═══════════════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════════════
module.exports = { module.exports = {
version: '0.6.10', version: '0.6.11',
// ── IAM ────────────────────────────────────────────────────────────────── // ── IAM ──────────────────────────────────────────────────────────────────
iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user', iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user',
+15
View File
@@ -67,6 +67,9 @@ async function listEntries(companyId, includeDeleted = false) {
* Создать запись (с валидацией, проверкой лимита и пересечений). * Создать запись (с валидацией, проверкой лимита и пересечений).
*/ */
async function createEntry(companyId, cidr, comment, userEmail, impersonatedBy, wasNormalized = 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(); const client = await pool.connect();
try { try {
await client.query('BEGIN'); 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) { 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(); const client = await pool.connect();
try { try {
await client.query('BEGIN'); await client.query('BEGIN');
@@ -154,6 +161,9 @@ async function updateEntry(entryId, companyId, cidr, comment, userEmail, imperso
* Удалить запись (soft delete). * Удалить запись (soft delete).
*/ */
async function deleteEntry(entryId, companyId, userEmail, impersonatedBy) { 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(); const client = await pool.connect();
try { try {
await client.query('BEGIN'); await client.query('BEGIN');
@@ -197,6 +207,8 @@ async function getAllCompanies() {
} }
async function setLimit(companyId, newLimit) { 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( const result = await pool.query(
'UPDATE companies SET custom_limit = $1, updated_at = NOW() WHERE id = $2', 'UPDATE companies SET custom_limit = $1, updated_at = NOW() WHERE id = $2',
[newLimit, companyId] [newLimit, companyId]
@@ -221,6 +233,9 @@ async function getExportCIDRs(companyId = null) {
// ── Аудит ───────────────────────────────────────────────────────────────────── // ── Аудит ─────────────────────────────────────────────────────────────────────
async function logAudit(userEmail, companyId, action, oldValue, newValue, entryId, impersonatedBy, db = pool) { 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( await db.query(
`INSERT INTO audit_log (user_email, company_id, action, old_value, new_value, entry_id, impersonated_by) `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)`, VALUES ($1, $2, $3, $4, $5, $6, $7)`,