func NewIssuerService(config *config.ServerConfig, userAgent string) *IssuerService {
	certmagic.UserAgent = userAgent
	issuer := new(IssuerService)
	issuer.renewalEvents = make(chan string)
	dnsProvider, err := dns.NewDNSChallengeProviderByName(config.DNSProvider)
	if err != nil {
		log.Fatalf("Could not configure DNS provider: %v", err)
	}
	certmagicConfig := &certmagic.Config{
		CA:                      config.Directory,
		Email:                   config.Email,
		Agreed:                  config.Agree,
		DisableHTTPChallenge:    true,
		DisableTLSALPNChallenge: true,
		KeyType:                 certcrypto.RSA4096,
		MustStaple:              false,
		DNSProvider:             dnsProvider,
		Storage:                 createStorage(config.Storage),
		RenewDurationBefore:     config.RenewalThreshold,
		OnEvent: func(eventName string, payload interface{}) {
			if eventName == "acme_cert_renewed" {
				issuer.renewalEvents <- fmt.Sprintf("%s", payload)
			}
		},
	}
	magic := certmagic.New(certmagic.NewCache(certmagic.CacheOptions{
		RenewCheckInterval: config.ExpiryCheckAt,
		OCSPCheckInterval:  1 * time.Hour,
		GetConfigForCert: func(certificate certmagic.Certificate) (certmagic.Config, error) {
			return *certmagicConfig, nil
		},
	}), *certmagicConfig)
	issuer.client = magic
	whitelist := NewWhitelist(config.Domains)
	issuer.whitelist = whitelist
	log.Infof("Using ACME directory: %s", config.Directory)
	log.Infof("Certificate issuer service configured - certificates will be renewed %v before expiry", config.RenewalThreshold)
	return issuer
}
NewIssuerService constructs a new instance with a predefined config
package server
import (
	"context"
	"crypto"
	"crypto/ecdsa"
	"crypto/rsa"
	"fmt"
	"sort"
	"time"
	"github.com/go-acme/lego/v3/certcrypto"
	"crypto/tls"
	"crypto/x509"
	"encoding/pem"
	"strings"
	"github.com/evenh/intercert/api"
	"github.com/evenh/intercert/config"
	"github.com/go-acme/lego/v3/log"
	"github.com/go-acme/lego/v3/providers/dns"
	"github.com/mholt/certmagic"
	"github.com/pkg/errors"
	"google.golang.org/grpc/metadata"
	"google.golang.org/grpc/peer"
)
type IssuerService struct {
	client        *certmagic.Config
	whitelist     Whitelist
	renewalEvents chan string
}