🌳
pt0/deployF/harvF/getWcSuffixF.mts
3import * as _ from 'lodash-es'
6export const getWcSuffix = (hostname: string) => {
7 if (hostname.startsWith('*.')) {
8 return replaceStrict(hostname, '*.', '.')
9 }
10 return hostname
13export const findCertForHostname = (hostname: string) => {
14 const ctx = getKlusterCtx()
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)
26 }
27 return hostname === dnsName
28 })
29 if (!matchedDnsName) return
30 return {certName, matchedDnsName}
31 })
34export const isWcDnsSuffix = (hostname: string) => {
35 const match = findCertForHostname(hostname)
36 if (!match) return undefined
37 return match.matchedDnsName.startsWith('*.') ? match : undefined