3import * as _ from 'lodash-es' 6export const getWcSuffix = (hostname: string) => { 7 if (hostname.startsWith('*.')) { 13export const findCertForHostname = (hostname: string) => { 16 const {klustCertsH} = ctx as Record<string, any> 18 if (!klustCertsH) return undefined 20 return find1Ret(_.toPairs(klustCertsH) as [string, string | string[]][], ([certName, dnsNamesRaw]) => { 21 const dnsNames = Array.isArray(dnsNamesRaw) ? dnsNamesRaw : [dnsNamesRaw] 22 const matchedDnsName = dnsNames.find((dnsName) => { 23 if (dnsName.startsWith('*.')) { 24 const suffix = getWcSuffix(dnsName) 25 return hostname.endsWith(suffix) 27 return hostname === dnsName 29 if (!matchedDnsName) return 30 return {certName, matchedDnsName} 34export const isWcDnsSuffix = (hostname: string) => { 35 const match = findCertForHostname(hostname) 36 if (!match) return undefined 37 return match.matchedDnsName.startsWith('*.') ? match : undefined