@@ -21,11 +21,10 @@ import (
2121const (
2222 envNamespace = "CPANEL_"
2323
24- EnvMode = envNamespace + "MODE"
25- EnvUsername = envNamespace + "USERNAME"
26- EnvToken = envNamespace + "TOKEN"
27- EnvBaseURL = envNamespace + "BASE_URL"
28- EnvNameserver = envNamespace + "NAMESERVER"
24+ EnvMode = envNamespace + "MODE"
25+ EnvUsername = envNamespace + "USERNAME"
26+ EnvToken = envNamespace + "TOKEN"
27+ EnvBaseURL = envNamespace + "BASE_URL"
2928
3029 EnvTTL = envNamespace + "TTL"
3130 EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
@@ -46,7 +45,6 @@ type Config struct {
4645 Username string
4746 Token string
4847 BaseURL string
49- Nameserver string
5048 TTL int
5149 PropagationTimeout time.Duration
5250 PollingInterval time.Duration
@@ -58,7 +56,7 @@ func NewDefaultConfig() *Config {
5856 return & Config {
5957 Mode : env .GetOrDefaultString (EnvMode , "cpanel" ),
6058 TTL : env .GetOrDefaultInt (EnvTTL , 300 ),
61- PropagationTimeout : env .GetOrDefaultSecond (EnvPropagationTimeout , dns01 . DefaultPropagationTimeout ),
59+ PropagationTimeout : env .GetOrDefaultSecond (EnvPropagationTimeout , 2 * time . Minute ),
6260 PollingInterval : env .GetOrDefaultSecond (EnvPollingInterval , dns01 .DefaultPollingInterval ),
6361 HTTPClient : & http.Client {
6462 Timeout : env .GetOrDefaultSecond (EnvHTTPTimeout , 30 * time .Second ),
@@ -68,16 +66,15 @@ func NewDefaultConfig() *Config {
6866
6967// DNSProvider implements the challenge.Provider interface.
7068type DNSProvider struct {
71- config * Config
72- client apiClient
73- dnsClient * shared.DNSClient
69+ config * Config
70+ client apiClient
7471}
7572
7673// NewDNSProvider returns a DNSProvider instance configured for CPanel.
7774// Credentials must be passed in the environment variables:
7875// CPANEL_USERNAME, CPANEL_TOKEN, CPANEL_BASE_URL, CPANEL_NAMESERVER.
7976func NewDNSProvider () (* DNSProvider , error ) {
80- values , err := env .Get (EnvUsername , EnvToken , EnvBaseURL , EnvNameserver )
77+ values , err := env .Get (EnvUsername , EnvToken , EnvBaseURL )
8178 if err != nil {
8279 return nil , fmt .Errorf ("cpanel: %w" , err )
8380 }
@@ -86,7 +83,6 @@ func NewDNSProvider() (*DNSProvider, error) {
8683 config .Username = values [EnvUsername ]
8784 config .Token = values [EnvToken ]
8885 config .BaseURL = values [EnvBaseURL ]
89- config .Nameserver = values [EnvNameserver ]
9086
9187 return NewDNSProviderConfig (config )
9288}
@@ -101,7 +97,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
10197 return nil , errors .New ("cpanel: some credentials information are missing" )
10298 }
10399
104- if config .BaseURL == "" || config . Nameserver == "" {
100+ if config .BaseURL == "" {
105101 return nil , errors .New ("cpanel: server information are missing" )
106102 }
107103
@@ -111,9 +107,8 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
111107 }
112108
113109 return & DNSProvider {
114- config : config ,
115- client : client ,
116- dnsClient : shared .NewDNSClient (10 * time .Second ),
110+ config : config ,
111+ client : client ,
117112 }, nil
118113}
119114
@@ -128,21 +123,19 @@ func (d *DNSProvider) Present(domain, _, keyAuth string) error {
128123 ctx := context .Background ()
129124 info := dns01 .GetChallengeInfo (domain , keyAuth )
130125
131- effectiveDomain := strings .TrimPrefix (info .EffectiveFQDN , "_acme-challenge." )
132-
133- soa , err := d .dnsClient .SOACall (effectiveDomain , d .config .Nameserver )
126+ authZone , err := dns01 .FindZoneByFqdn (info .EffectiveFQDN )
134127 if err != nil {
135- return fmt .Errorf ("cpanel[mode=%s] : could not find SOA for domain %q (%s) in %s : %w" , d . config . Mode , domain , info .EffectiveFQDN , d . config . Nameserver , err )
128+ return fmt .Errorf ("arvancloud : could not find zone for domain %q (%s): %w" , domain , info .EffectiveFQDN , err )
136129 }
137130
138- zone := dns01 .UnFqdn (soa . Hdr . Name )
131+ zone := dns01 .UnFqdn (authZone )
139132
140133 zoneInfo , err := d .client .FetchZoneInformation (ctx , zone )
141134 if err != nil {
142135 return fmt .Errorf ("cpanel[mode=%s]: fetch zone information: %w" , d .config .Mode , err )
143136 }
144137
145- serial , err := getZoneSerial (soa . Hdr . Name , zoneInfo )
138+ serial , err := getZoneSerial (authZone , zoneInfo )
146139 if err != nil {
147140 return fmt .Errorf ("cpanel[mode=%s]: get zone serial: %w" , d .config .Mode , err )
148141 }
@@ -204,19 +197,19 @@ func (d *DNSProvider) CleanUp(domain, _, keyAuth string) error {
204197 ctx := context .Background ()
205198 info := dns01 .GetChallengeInfo (domain , keyAuth )
206199
207- soa , err := d . dnsClient . SOACall ( strings . TrimPrefix ( info .EffectiveFQDN , "_acme-challenge." ), d . config . Nameserver )
200+ authZone , err := dns01 . FindZoneByFqdn ( info .EffectiveFQDN )
208201 if err != nil {
209- return fmt .Errorf ("cpanel[mode=%s] : could not find SOA for domain %q (%s) in %s : %w" , d . config . Mode , domain , info .EffectiveFQDN , d . config . Nameserver , err )
202+ return fmt .Errorf ("arvancloud : could not find zone for domain %q (%s): %w" , domain , info .EffectiveFQDN , err )
210203 }
211204
212- zone := dns01 .UnFqdn (soa . Hdr . Name )
205+ zone := dns01 .UnFqdn (authZone )
213206
214207 zoneInfo , err := d .client .FetchZoneInformation (ctx , zone )
215208 if err != nil {
216209 return fmt .Errorf ("cpanel[mode=%s]: fetch zone information: %w" , d .config .Mode , err )
217210 }
218211
219- serial , err := getZoneSerial (soa . Hdr . Name , zoneInfo )
212+ serial , err := getZoneSerial (authZone , zoneInfo )
220213 if err != nil {
221214 return fmt .Errorf ("cpanel[mode=%s]: get zone serial: %w" , d .config .Mode , err )
222215 }
0 commit comments