@@ -11,6 +11,7 @@ import (
1111	"time" 
1212
1313	"github.com/go-acme/lego/v4/challenge/dns01" 
14+ 	"github.com/go-acme/lego/v4/log" 
1415	"github.com/go-acme/lego/v4/platform/config/env" 
1516	"github.com/go-acme/lego/v4/providers/dns/gandiv5/internal" 
1617)
@@ -23,7 +24,8 @@ const minTTL = 300
2324const  (
2425	envNamespace  =  "GANDIV5_" 
2526
26- 	EnvAPIKey  =  envNamespace  +  "API_KEY" 
27+ 	EnvAPIKey               =  envNamespace  +  "API_KEY" 
28+ 	EnvPersonalAccessToken  =  envNamespace  +  "PERSONAL_ACCESS_TOKEN" 
2729
2830	EnvTTL                 =  envNamespace  +  "TTL" 
2931	EnvPropagationTimeout  =  envNamespace  +  "PROPAGATION_TIMEOUT" 
@@ -39,12 +41,13 @@ type inProgressInfo struct {
3941
4042// Config is used to configure the creation of the DNSProvider. 
4143type  Config  struct  {
42- 	BaseURL             string 
43- 	APIKey              string 
44- 	PropagationTimeout  time.Duration 
45- 	PollingInterval     time.Duration 
46- 	TTL                 int 
47- 	HTTPClient          * http.Client 
44+ 	BaseURL              string 
45+ 	APIKey               string  // Deprecated use PersonalAccessToken 
46+ 	PersonalAccessToken  string 
47+ 	PropagationTimeout   time.Duration 
48+ 	PollingInterval      time.Duration 
49+ 	TTL                  int 
50+ 	HTTPClient           * http.Client 
4851}
4952
5053// NewDefaultConfig returns a default configuration for the DNSProvider. 
@@ -76,13 +79,10 @@ type DNSProvider struct {
7679// NewDNSProvider returns a DNSProvider instance configured for Gandi. 
7780// Credentials must be passed in the environment variable: GANDIV5_API_KEY. 
7881func  NewDNSProvider () (* DNSProvider , error ) {
79- 	values , err  :=  env .Get (EnvAPIKey )
80- 	if  err  !=  nil  {
81- 		return  nil , fmt .Errorf ("gandi: %w" , err )
82- 	}
83- 
82+ 	// TODO(ldez): rewrite this when APIKey will be removed. 
8483	config  :=  NewDefaultConfig ()
85- 	config .APIKey  =  values [EnvAPIKey ]
84+ 	config .APIKey  =  env .GetOrFile (EnvAPIKey )
85+ 	config .PersonalAccessToken  =  env .GetOrFile (EnvPersonalAccessToken )
8686
8787	return  NewDNSProviderConfig (config )
8888}
@@ -93,15 +93,19 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
9393		return  nil , errors .New ("gandiv5: the configuration of the DNS provider is nil" )
9494	}
9595
96- 	if  config .APIKey  ==  ""  {
97- 		return  nil , errors .New ("gandiv5: no API Key given" )
96+ 	if  config .APIKey  !=  ""  {
97+ 		log .Print ("gandiv5: API Key is deprecated, use Personal Access Token instead" )
98+ 	}
99+ 
100+ 	if  config .APIKey  ==  ""  &&  config .PersonalAccessToken  ==  ""  {
101+ 		return  nil , errors .New ("gandiv5: credentials information are missing" )
98102	}
99103
100104	if  config .TTL  <  minTTL  {
101105		return  nil , fmt .Errorf ("gandiv5: invalid TTL, TTL (%d) must be greater than %d" , config .TTL , minTTL )
102106	}
103107
104- 	client  :=  internal .NewClient (config .APIKey )
108+ 	client  :=  internal .NewClient (config .APIKey ,  config . PersonalAccessToken )
105109
106110	if  config .BaseURL  !=  ""  {
107111		baseURL , err  :=  url .Parse (config .BaseURL )
0 commit comments