1import * as _ from 'lodash-es' 11type RegCredSecNameProps = { name?: string, dockreg_host: string, cluster_name?: string } 13export const regCredSecName = ({name, dockreg_host, cluster_name}: RegCredSecNameProps) => { 15 name ||= dockreg_host.split('.')[0] 16 return [`regcred`, name, cluster_name].join('-') 19export const genRegCredSecName = (dockreg_host: string, cluster_name?: string) => { 21 const baseName = regCredSecName({dockreg_host, cluster_name}) 22 return baseName + '.json' 25type GetCredsProps = { dockreg_host: string } 27export const getCreds = ({dockreg_host}: GetCredsProps) => { 31 const secretName = genRegCredSecName(dockreg_host) as secretNameType 36 const username = 'reguser' 38 sec = {username, password} 39 fs.writeFileSync(secretPath, JSON.stringify(sec, null, 2)) 40 console.log(`Generated registry credentials: ${secretPath}`) 42 if (_.isString(sec)) { 45 const {username, password} = sec 47 const auth = Buffer.from(username + ':' + password).toString('base64') 49 return {username, password, auth} 52type RegcredSecTemplProps = { 59export const regcredSecTempl = ({name, dockreg_host, dockLanHost}: RegcredSecTemplProps) => { 62 name ||= regCredSecName({name, dockreg_host}) 64 const {auth} = getCreds({dockreg_host}) 66 const auths: Record<string, {auth: string}> = {[`https://${dockreg_host}`]: { auth }} 68 auths[`https://${dockLanHost}`] = { auth } 70 const jsonS = JSON.stringify({auths}) 72 '.dockerconfigjson': jsonS 77 type: 'kubernetes.io/dockerconfigjson'