"use strict";var e=require("kubernetes-client"),s=require("dns"),t=require("@certd/pipeline");const{KubeConfig:n,Client:a,Request:r}=e;exports.K8sClient=class{kubeConfigStr;lookup;client;constructor(e){this.kubeConfigStr=e,this.init()}init(){const e=new n;e.loadFromString(this.kubeConfigStr);const s={kubeconfig:e,request:{}};this.lookup&&(s.request.lookup=this.lookup);const t=new r(s);this.client=new a({backend:t,version:"1.13"})}setLookup(e){this.lookup=(n,a,r)=>{t.logger.info("custom lookup",n,e),e[n]?(t.logger.info("local record",n,e[n]),r(null,e[n].ip,4)):s.lookup(n,a,r)},this.init()}async getSecret(e){const s=e.namespace||"default";return await this.client.api.v1.namespaces(s).secrets.get()}async createSecret(e){const s=e.namespace||"default",n=await this.client.api.v1.namespaces(s).secrets.post({body:e.body});return t.logger.info("new secrets:",n),n}async updateSecret(e){const s=e.namespace||"default",t=e.secretName;if(null==t)throw new Error("secretName 不能为空");return await this.client.api.v1.namespaces(s).secrets(t).put({body:e.body})}async patchSecret(e){const s=e.namespace||"default",t=e.secretName;if(null==t)throw new Error("secretName 不能为空");return await this.client.api.v1.namespaces(s).secrets(t).patch({body:e.body})}async getIngressList(e){const s=e.namespace||"default";return await this.client.apis.extensions.v1beta1.namespaces(s).ingresses.get()}async getIngress(e){const s=e.namespace||"default",t=e.ingressName;if(!t)throw new Error("ingressName 不能为空");return await this.client.apis.extensions.v1beta1.namespaces(s).ingresses(t).get()}async patchIngress(e){const s=e.namespace||"default",t=e.ingressName;if(!t)throw new Error("ingressName 不能为空");return await this.client.apis.extensions.v1beta1.namespaces(s).ingresses(t).patch({body:e.body})}};
