13import * as _ from 'lodash-es' 20const getForkedQs = ({secretName}: {secretName: string}) => { 21 if (secretName == disabledSecret) return 24 guardQsSecExist({secretName, secretVal}) 29export const decomposeForkedKubeQs = async ({qsName, dbFork}: {qsName: string, dbFork?: boolean | string}): Promise<DbConnInfo> => { 31 const forkedQsName = secretsMapping[qsName] || qsName 33 const baseQs = getForkedQs({secretName: forkedQsName}) 36 throwIf(() => _.isBoolean(dbFork) && !dbFork) 40 return {...await decomposeKubeQs(dbQs), qsName: forkedQsName} 43export const guardQsSecExist = ({secretName, secretVal}: {secretName: string, secretVal: string | undefined}) => { 45 const secretPath = replaceStrict(secretsDir, ptDir + '/', '') + '/' + secretName 48Missing required secret: ${secretPath} 49- If you are trying to connect to an existing database: 50 please ask the db admin to send you their ${secretPath} 51- If you are setting up a new database: 52 please make sure ${secretPath} exists and is connectable 54 throw new PtErr('missingSecret', {secretName}) 57export const decomposeKubeQs = async (dbQs: string): Promise<Omit<DbConnInfo, 'qsName'>> => { 62 const {password, username, svcName, host: hostWPort} = _urlObj 66 const {cluster_name, ips, isCnPg} = svcInfo 67 let {enableSsl=false, nodePort, ptNodePortNo} = svcInfo 68 nodePort ||= ptNodePortNo 70 const hostname = ips[0] 72 const extIpPort = [hostname, nodePort].join(':') 75 const fromStr = `@${hostWPort}` 76 if (!runPgOnKlustCtx.getStore()) { 81 if (isCnPg) return dbQs 82 return replaceStrict(dbQs, fromStr, `@${svcName}.default.svc.cluster.local:5432`) 85 const addParams = enableSsl ? {sslmode: 'require'} : {} 86 extQs += addPgParams(addParams) 91 dbQs, password, username, svcName, 96const addPgParams = (params: Record<string, any>) => { 98 application_name: os.hostname(), 101 return '?' + new URLSearchParams(params)