// not implemented package dns import ( "fmt" "os" "strings" "sync" "github.com/cert-manager/cert-manager/pkg/acme/webhook" acme "github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1" "github.com/miekg/dns" "k8s.io/client-go/rest" "k8s.io/klog/v2" ) type SthomeSolver struct { name string server *dns.Server txtRecords map[string]string sync.RWMutex } func (e *SthomeSolver) Name() string { return e.name } func (e *SthomeSolver) Present(ch *acme.ChallengeRequest) error { e.Lock() e.txtRecords[ch.ResolvedFQDN] = ch.Key e.Unlock() cfg, err := LoadConfig(ch.Config) if err != nil { return err } klog.Infof("CZ: Presenting record for %s, type: %s, uid: %s, key: %s, ns: %s, fqdn: %s, zone: %s, allowambcred: %t, cfg.secret: %s, cfg.email: %s, cfg.allowz: %s", ch.DNSName, ch.UID, ch.Type, ch.Key, ch.ResourceNamespace, ch.ResolvedFQDN, ch.ResolvedZone, ch.AllowAmbientCredentials, cfg.APIKeySecretRef.Name, cfg.Email, strings.Join(cfg.AllowedZones, ","), ) // TODO: convert shell script to golang localip := GetOutboundIP(Dnsserver_net) success, _ := Execute( Shell, AcmeAuthCmd, "set", ch.DNSName, ch.ResolvedFQDN, ch.Key, "-l", localip, "-v", ) klog.Infof("Execute set TXT returned success: %t", success) return nil } func (e *SthomeSolver) CleanUp(ch *acme.ChallengeRequest) error { e.Lock() delete(e.txtRecords, ch.ResolvedFQDN) e.Unlock() localip := GetOutboundIP(Dnsserver_net) success, _ := Execute( Shell, AcmeAuthCmd, "unset", ch.DNSName, ch.ResolvedFQDN, ch.Key, "-l", localip, "-v", ) klog.Infof("Execute unset TXT returned success: %t", success) return nil } func (e *SthomeSolver) Initialize(kubeClientConfig *rest.Config, stopCh <-chan struct{}) error { go func(done <-chan struct{}) { <-done if err := e.server.Shutdown(); err != nil { fmt.Fprintf(os.Stderr, "%s\n", err.Error()) } }(stopCh) go func() { if err := e.server.ListenAndServe(); err != nil { fmt.Fprintf(os.Stderr, "%s\n", err.Error()) os.Exit(1) } }() return nil } func New(port string) webhook.Solver { e := &SthomeSolver{ name: ProviderName, txtRecords: make(map[string]string), } e.server = &dns.Server{ Addr: ":" + port, Net: "udp", Handler: dns.HandlerFunc(e.handleDNSRequest), } return e }