fix(integrations): отдавать origin IP и cnameTarget для CNAME sync
Публичный DNS даёт CF anycast; для матча в VPS Tracker нужны origin из dns_records и цель CNAME. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -68,13 +68,15 @@ async function resolveIpsViaDns(hostname: string): Promise<string[]> {
|
||||
* IP для матчинга в VPS Tracker:
|
||||
* 1) A-записи binding
|
||||
* 2) разворот локальной CNAME-цепочки по другим bindings
|
||||
* 3) публичный DNS (resolve4)
|
||||
* 4) IP сервиса
|
||||
* 3) origin A/AAAA из dns_records CFDM (даже proxied — content = origin)
|
||||
* 4) публичный DNS (resolve4) — часто CF anycast, слабый сигнал
|
||||
* 5) IP сервиса
|
||||
*/
|
||||
export async function resolveBindingIpsForSync(
|
||||
binding: ServiceBindingView,
|
||||
serviceIps: string[],
|
||||
index: BindingIpIndex,
|
||||
db?: Db,
|
||||
): Promise<string[]> {
|
||||
if (binding.target_ips.length > 0) {
|
||||
return [...binding.target_ips];
|
||||
@@ -86,6 +88,11 @@ export async function resolveBindingIpsForSync(
|
||||
const local = resolveIpsLocally(index, targetFqdn);
|
||||
if (local.length > 0) return local;
|
||||
|
||||
if (db) {
|
||||
const fromTable = repos.listOriginIpsForFqdn(db, targetFqdn);
|
||||
if (fromTable.length > 0) return fromTable;
|
||||
}
|
||||
|
||||
const viaDns = await resolveIpsViaDns(targetFqdn);
|
||||
if (viaDns.length > 0) return viaDns;
|
||||
}
|
||||
@@ -94,6 +101,13 @@ export async function resolveBindingIpsForSync(
|
||||
return [];
|
||||
}
|
||||
|
||||
function cnameTargetForSync(binding: ServiceBindingView): string | undefined {
|
||||
const raw = binding.cname_target?.trim();
|
||||
if (!raw) return undefined;
|
||||
const normalized = normalizeCnameHost(raw, binding.zone_name);
|
||||
return normalized || undefined;
|
||||
}
|
||||
|
||||
export async function buildServiceSyncBindingsAsync(
|
||||
db: Db,
|
||||
serviceId: number,
|
||||
@@ -107,7 +121,7 @@ export async function buildServiceSyncBindingsAsync(
|
||||
|
||||
const items: CfdmBindingSyncItem[] = [];
|
||||
for (const binding of bindings) {
|
||||
const ips = await resolveBindingIpsForSync(binding, serviceIps, index);
|
||||
const ips = await resolveBindingIpsForSync(binding, serviceIps, index, db);
|
||||
items.push({
|
||||
bindingId: binding.id,
|
||||
serviceId: service.id,
|
||||
@@ -117,6 +131,7 @@ export async function buildServiceSyncBindingsAsync(
|
||||
zoneName: binding.zone_name,
|
||||
hostname: binding.hostname,
|
||||
ips,
|
||||
cnameTarget: cnameTargetForSync(binding),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,7 +166,7 @@ export async function buildAllSyncBindings(
|
||||
serviceIps = repos.listServiceIps(db, binding.service_id);
|
||||
serviceIpCache.set(binding.service_id, serviceIps);
|
||||
}
|
||||
const ips = await resolveBindingIpsForSync(binding, serviceIps, index);
|
||||
const ips = await resolveBindingIpsForSync(binding, serviceIps, index, db);
|
||||
items.push({
|
||||
bindingId: binding.id,
|
||||
serviceId: binding.service_id,
|
||||
@@ -161,6 +176,7 @@ export async function buildAllSyncBindings(
|
||||
zoneName: binding.zone_name,
|
||||
hostname: binding.hostname,
|
||||
ips,
|
||||
cnameTarget: cnameTargetForSync(binding),
|
||||
});
|
||||
}
|
||||
return items;
|
||||
|
||||
Reference in New Issue
Block a user