From fe5a7d0d373bd23b0c302a523191b37dbb38c161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 13 Jun 2026 07:11:53 +0400 Subject: [PATCH] =?UTF-8?q?v2:=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=E2=80=94=20validate()=20=D0=B2=20crud,=20db/que?= =?UTF-8?q?ries=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D0=B5=D1=82=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D1=8B=D0=B9=20cidr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- v2/src/config/index.js | 2 +- v2/src/crud/index.js | 7 +++++-- v2/src/db/queries.js | 8 +++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 143fd8c..6d72719 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.5.90", + "version": "0.5.91", "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 93f1210..6274583 100644 --- a/v2/src/config/index.js +++ b/v2/src/config/index.js @@ -6,7 +6,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ module.exports = { - version: '0.5.90', + version: '0.5.91', iamUrl: process.env.V2_IAM_API_URL || 'https://auth-api.ngcloud.ru', appUrl: process.env.V2_APP_URL || 'https://whitelist.nodejsk8s.services.ngcloud.ru', }; diff --git a/v2/src/crud/index.js b/v2/src/crud/index.js index 93a21d4..8cf4cd0 100644 --- a/v2/src/crud/index.js +++ b/v2/src/crud/index.js @@ -12,6 +12,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ const q = require('../db/queries'); +const { validate } = require('../validators'); async function resolve(clientId) { return q.getOrCreateCompany(clientId, clientId); @@ -26,13 +27,15 @@ async function list(clientId, includeDeleted = false) { } async function add(clientId, cidr, comment, email, impBy) { + const { cidr: validated, wasNormalized } = validate(cidr); const co = await resolve(clientId); - return q.createEntry(co.id, cidr, comment, email, impBy); + return q.createEntry(co.id, validated, comment, email, impBy, wasNormalized); } async function edit(entryId, clientId, cidr, comment, email, impBy) { + const { cidr: validated, wasNormalized } = validate(cidr); const co = await resolve(clientId); - return q.updateEntry(entryId, co.id, cidr, comment, email, impBy); + return q.updateEntry(entryId, co.id, validated, comment, email, impBy, wasNormalized); } async function remove(entryId, clientId, email, impBy) { diff --git a/v2/src/db/queries.js b/v2/src/db/queries.js index 4bf6c4f..b4eb9d0 100644 --- a/v2/src/db/queries.js +++ b/v2/src/db/queries.js @@ -4,7 +4,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ const { pool } = require('./index'); -const { validate, overlaps } = require('../validators'); +const { overlaps } = require('../validators'); // ── Компании ────────────────────────────────────────────────────────────────── @@ -48,8 +48,7 @@ async function listEntries(companyId, includeDeleted = false) { /** * Создать запись (с валидацией, проверкой лимита и пересечений). */ -async function createEntry(companyId, rawValue, comment, userEmail, impersonatedBy) { - const { cidr, wasNormalized } = validate(rawValue); +async function createEntry(companyId, cidr, comment, userEmail, impersonatedBy, wasNormalized = false) { const client = await pool.connect(); try { await client.query('BEGIN'); @@ -95,8 +94,7 @@ async function createEntry(companyId, rawValue, comment, userEmail, impersonated /** * Обновить запись. */ -async function updateEntry(entryId, companyId, rawValue, comment, userEmail, impersonatedBy) { - const { cidr, wasNormalized } = validate(rawValue); +async function updateEntry(entryId, companyId, cidr, comment, userEmail, impersonatedBy, wasNormalized = false) { const client = await pool.connect(); try { await client.query('BEGIN');