@@ -564,23 +564,22 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
564564 if globalACMECARoot != nil && ! slices .Contains (acmeIssuer .TrustedRootsPEMFiles , globalACMECARoot .(string )) {
565565 acmeIssuer .TrustedRootsPEMFiles = append (acmeIssuer .TrustedRootsPEMFiles , globalACMECARoot .(string ))
566566 }
567- if globalACMEDNSok {
567+ if globalACMEDNSok && ( acmeIssuer . Challenges == nil || acmeIssuer . Challenges . DNS == nil || acmeIssuer . Challenges . DNS . ProviderRaw == nil ) {
568568 globalDNS := options ["dns" ]
569- if globalDNS != nil {
570- // If global `dns` is set, do NOT set provider in issuer, just set empty dns config
571- acmeIssuer .Challenges = & caddytls.ChallengesConfig {
572- DNS : & caddytls.DNSChallengeConfig {},
573- }
574- } else if globalACMEDNS != nil {
575- // Set a global DNS provider if `acme_dns` is set and `dns` is NOT set
576- acmeIssuer .Challenges = & caddytls.ChallengesConfig {
577- DNS : & caddytls.DNSChallengeConfig {
578- ProviderRaw : caddyconfig .JSONModuleObject (globalACMEDNS , "name" , globalACMEDNS .(caddy.Module ).CaddyModule ().ID .Name (), nil ),
579- },
580- }
581- } else {
569+ if globalDNS == nil && globalACMEDNS == nil {
582570 return fmt .Errorf ("acme_dns specified without DNS provider config, but no provider specified with 'dns' global option" )
583571 }
572+ if acmeIssuer .Challenges == nil {
573+ acmeIssuer .Challenges = new (caddytls.ChallengesConfig )
574+ }
575+ if acmeIssuer .Challenges .DNS == nil {
576+ acmeIssuer .Challenges .DNS = new (caddytls.DNSChallengeConfig )
577+ }
578+ // If global `dns` is set, do NOT set provider in issuer, just set empty dns config
579+ if globalDNS == nil && acmeIssuer .Challenges .DNS .ProviderRaw == nil {
580+ // Set a global DNS provider if `acme_dns` is set and `dns` is NOT set
581+ acmeIssuer .Challenges .DNS .ProviderRaw = caddyconfig .JSONModuleObject (globalACMEDNS , "name" , globalACMEDNS .(caddy.Module ).CaddyModule ().ID .Name (), nil )
582+ }
584583 }
585584 if globalACMEEAB != nil && acmeIssuer .ExternalAccount == nil {
586585 acmeIssuer .ExternalAccount = globalACMEEAB .(* acme.EAB )
0 commit comments