Build, Test, and Push CFDM Docker Image / test (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / build-and-push (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / create-release (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / update-wiki (push) Has been cancelled
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
export interface ParsedFqdn {
|
|
zoneName: string
|
|
hostname: string
|
|
fqdn: string
|
|
}
|
|
|
|
export function fqdnToDisplay(hostname: string, zoneName: string): string {
|
|
if (hostname === '@') {
|
|
return zoneName
|
|
}
|
|
return `${hostname}.${zoneName}`
|
|
}
|
|
|
|
export function parseFqdn(fqdn: string, knownZones: string[]): ParsedFqdn | null {
|
|
const normalized = fqdn.trim().toLowerCase()
|
|
if (!normalized) {
|
|
return null
|
|
}
|
|
|
|
const zones = [...knownZones].sort((a, b) => b.length - a.length)
|
|
|
|
for (const zone of zones) {
|
|
const zoneLower = zone.toLowerCase()
|
|
if (normalized === zoneLower) {
|
|
return {
|
|
zoneName: zone,
|
|
hostname: '@',
|
|
fqdn: fqdnToDisplay('@', zone),
|
|
}
|
|
}
|
|
const suffix = `.${zoneLower}`
|
|
if (normalized.endsWith(suffix)) {
|
|
const prefix = normalized.slice(0, -suffix.length)
|
|
if (prefix) {
|
|
return {
|
|
zoneName: zone,
|
|
hostname: prefix,
|
|
fqdn: fqdnToDisplay(prefix, zone),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export function bindingToFqdn(binding: {
|
|
hostname: string
|
|
zone_name: string
|
|
fqdn?: string
|
|
}): string {
|
|
return binding.fqdn ?? fqdnToDisplay(binding.hostname, binding.zone_name)
|
|
}
|