@@ -43,105 +43,139 @@ func checkMultiProviderSettings(config *settings.Settings) error {
4343 return checkDomainsWithProviders (config )
4444}
4545
46- // checkSingleProviderCredentials validates credentials for legacy single provider mode.
47- func checkSingleProviderCredentials (providerName string , config * settings.Settings ) error {
46+ // credentialAccessor defines an interface for accessing provider credentials.
47+ type credentialAccessor interface {
48+ GetEmail () string
49+ GetPassword () string
50+ GetLoginToken () string
51+ GetAppKey () string
52+ GetAppSecret () string
53+ GetConsumerKey () string
54+ }
55+
56+ // settingsAccessor adapts Settings to credentialAccessor interface.
57+ type settingsAccessor struct {
58+ config * settings.Settings
59+ }
60+
61+ func (s * settingsAccessor ) GetEmail () string { return s .config .Email }
62+ func (s * settingsAccessor ) GetPassword () string { return s .config .Password }
63+ func (s * settingsAccessor ) GetLoginToken () string { return s .config .LoginToken }
64+ func (s * settingsAccessor ) GetAppKey () string { return s .config .AppKey }
65+ func (s * settingsAccessor ) GetAppSecret () string { return s .config .AppSecret }
66+ func (s * settingsAccessor ) GetConsumerKey () string { return s .config .ConsumerKey }
67+
68+ // providerConfigAccessor adapts ProviderConfig to credentialAccessor interface.
69+ type providerConfigAccessor struct {
70+ config * settings.ProviderConfig
71+ }
72+
73+ func (p * providerConfigAccessor ) GetEmail () string { return p .config .Email }
74+ func (p * providerConfigAccessor ) GetPassword () string { return p .config .Password }
75+ func (p * providerConfigAccessor ) GetLoginToken () string { return p .config .LoginToken }
76+ func (p * providerConfigAccessor ) GetAppKey () string { return p .config .AppKey }
77+ func (p * providerConfigAccessor ) GetAppSecret () string { return p .config .AppSecret }
78+ func (p * providerConfigAccessor ) GetConsumerKey () string { return p .config .ConsumerKey }
79+
80+ // validateProviderCredentials validates provider credentials using the common interface.
81+ func validateProviderCredentials (providerName string , accessor credentialAccessor ) error {
4882 switch providerName {
4983 case DNSPOD :
50- if config . Password == "" && config . LoginToken == "" {
84+ if accessor . GetPassword () == "" && accessor . GetLoginToken () == "" {
5185 return errors .New ("password or login token cannot be empty" )
5286 }
5387 case HE :
54- if config . Password == "" {
88+ if accessor . GetPassword () == "" {
5589 return errors .New ("password cannot be empty" )
5690 }
5791 case CLOUDFLARE :
58- if config . LoginToken == "" {
59- if config . Email == "" {
92+ if accessor . GetLoginToken () == "" {
93+ if accessor . GetEmail () == "" {
6094 return errors .New ("email cannot be empty" )
6195 }
62- if config . Password == "" {
96+ if accessor . GetPassword () == "" {
6397 return errors .New ("password cannot be empty" )
6498 }
6599 }
66100 case ALIDNS :
67- if config . Email == "" {
101+ if accessor . GetEmail () == "" {
68102 return errors .New ("email cannot be empty" )
69103 }
70- if config . Password == "" {
104+ if accessor . GetPassword () == "" {
71105 return errors .New ("password cannot be empty" )
72106 }
73107 case DIGITALOCEAN :
74- if config . LoginToken == "" {
108+ if accessor . GetLoginToken () == "" {
75109 return errors .New ("login token cannot be empty" )
76110 }
77111 case DUCK :
78- if config . LoginToken == "" {
112+ if accessor . GetLoginToken () == "" {
79113 return errors .New ("login token cannot be empty" )
80114 }
81115 case DYNU :
82- if config . Password == "" {
116+ if accessor . GetPassword () == "" {
83117 return errors .New ("password cannot be empty" )
84118 }
85119 case DYNV6 :
86- if config . LoginToken == "" {
120+ if accessor . GetLoginToken () == "" {
87121 return errors .New ("login token cannot be empty" )
88122 }
89123 case GOOGLE :
90124 fallthrough
91125 case NOIP :
92- if config . Email == "" {
126+ if accessor . GetEmail () == "" {
93127 return errors .New ("email cannot be empty" )
94128 }
95- if config . Password == "" {
129+ if accessor . GetPassword () == "" {
96130 return errors .New ("password cannot be empty" )
97131 }
98132 case DREAMHOST :
99- if config . LoginToken == "" {
133+ if accessor . GetLoginToken () == "" {
100134 return errors .New ("login token cannot be empty" )
101135 }
102136 case SCALEWAY :
103- if config . LoginToken == "" {
137+ if accessor . GetLoginToken () == "" {
104138 return errors .New ("login token cannot be empty" )
105139 }
106140 case LINODE :
107- if config . LoginToken == "" {
141+ if accessor . GetLoginToken () == "" {
108142 return errors .New ("login token cannot be empty" )
109143 }
110144 case STRATO :
111- if config . Password == "" {
145+ if accessor . GetPassword () == "" {
112146 return errors .New ("password cannot be empty" )
113147 }
114148 case LOOPIASE :
115- if config . Password == "" {
149+ if accessor . GetPassword () == "" {
116150 return errors .New ("password cannot be empty" )
117151 }
118152 case INFOMANIAK :
119- if config . Password == "" {
153+ if accessor . GetPassword () == "" {
120154 return errors .New ("password cannot be empty" )
121155 }
122156 case HETZNER :
123- if config . LoginToken == "" {
157+ if accessor . GetLoginToken () == "" {
124158 return errors .New ("login token cannot be empty" )
125159 }
126160 case IONOS :
127- if config . LoginToken == "" {
161+ if accessor . GetLoginToken () == "" {
128162 return errors .New ("login token cannot be empty" )
129163 }
130164 case OVH :
131- if config . AppKey == "" {
165+ if accessor . GetAppKey () == "" {
132166 return errors .New ("app key cannot be empty" )
133167 }
134- if config . AppSecret == "" {
168+ if accessor . GetAppSecret () == "" {
135169 return errors .New ("app secret cannot be empty" )
136170 }
137- if config . ConsumerKey == "" {
171+ if accessor . GetConsumerKey () == "" {
138172 return errors .New ("consumer key cannot be empty" )
139173 }
140174 case TRANSIP :
141- if config . Email == "" {
175+ if accessor . GetEmail () == "" {
142176 return errors .New ("email cannot be empty" )
143177 }
144- if config . LoginToken == "" {
178+ if accessor . GetLoginToken () == "" {
145179 return errors .New ("login token cannot be empty" )
146180 }
147181 default :
@@ -151,112 +185,14 @@ func checkSingleProviderCredentials(providerName string, config *settings.Settin
151185 return nil
152186}
153187
188+ // checkSingleProviderCredentials validates credentials for legacy single provider mode.
189+ func checkSingleProviderCredentials (providerName string , config * settings.Settings ) error {
190+ return validateProviderCredentials (providerName , & settingsAccessor {config })
191+ }
192+
154193// checkProviderCredentials validates credentials for a provider configuration.
155194func checkProviderCredentials (providerName string , providerConfig * settings.ProviderConfig ) error {
156- switch providerName {
157- case DNSPOD :
158- if providerConfig .Password == "" && providerConfig .LoginToken == "" {
159- return errors .New ("password or login token cannot be empty" )
160- }
161- case HE :
162- if providerConfig .Password == "" {
163- return errors .New ("password cannot be empty" )
164- }
165- case CLOUDFLARE :
166- if providerConfig .LoginToken == "" {
167- if providerConfig .Email == "" {
168- return errors .New ("email cannot be empty" )
169- }
170- if providerConfig .Password == "" {
171- return errors .New ("password cannot be empty" )
172- }
173- }
174- case ALIDNS :
175- if providerConfig .Email == "" {
176- return errors .New ("email cannot be empty" )
177- }
178- if providerConfig .Password == "" {
179- return errors .New ("password cannot be empty" )
180- }
181- case DIGITALOCEAN :
182- if providerConfig .LoginToken == "" {
183- return errors .New ("login token cannot be empty" )
184- }
185- case DUCK :
186- if providerConfig .LoginToken == "" {
187- return errors .New ("login token cannot be empty" )
188- }
189- case DYNU :
190- if providerConfig .Password == "" {
191- return errors .New ("password cannot be empty" )
192- }
193- case DYNV6 :
194- if providerConfig .LoginToken == "" {
195- return errors .New ("login token cannot be empty" )
196- }
197- case GOOGLE :
198- fallthrough
199- case NOIP :
200- if providerConfig .Email == "" {
201- return errors .New ("email cannot be empty" )
202- }
203- if providerConfig .Password == "" {
204- return errors .New ("password cannot be empty" )
205- }
206- case DREAMHOST :
207- if providerConfig .LoginToken == "" {
208- return errors .New ("login token cannot be empty" )
209- }
210- case SCALEWAY :
211- if providerConfig .LoginToken == "" {
212- return errors .New ("login token cannot be empty" )
213- }
214- case LINODE :
215- if providerConfig .LoginToken == "" {
216- return errors .New ("login token cannot be empty" )
217- }
218- case STRATO :
219- if providerConfig .Password == "" {
220- return errors .New ("password cannot be empty" )
221- }
222- case LOOPIASE :
223- if providerConfig .Password == "" {
224- return errors .New ("password cannot be empty" )
225- }
226- case INFOMANIAK :
227- if providerConfig .Password == "" {
228- return errors .New ("password cannot be empty" )
229- }
230- case HETZNER :
231- if providerConfig .LoginToken == "" {
232- return errors .New ("login token cannot be empty" )
233- }
234- case IONOS :
235- if providerConfig .LoginToken == "" {
236- return errors .New ("login token cannot be empty" )
237- }
238- case OVH :
239- if providerConfig .AppKey == "" {
240- return errors .New ("app key cannot be empty" )
241- }
242- if providerConfig .AppSecret == "" {
243- return errors .New ("app secret cannot be empty" )
244- }
245- if providerConfig .ConsumerKey == "" {
246- return errors .New ("consumer key cannot be empty" )
247- }
248- case TRANSIP :
249- if providerConfig .Email == "" {
250- return errors .New ("email cannot be empty" )
251- }
252- if providerConfig .LoginToken == "" {
253- return errors .New ("login token cannot be empty" )
254- }
255- default :
256- return fmt .Errorf ("'%s' is not a supported DNS provider" , providerName )
257- }
258-
259- return nil
195+ return validateProviderCredentials (providerName , & providerConfigAccessor {providerConfig })
260196}
261197
262198// checkDomainsWithProviders validates domains in multi-provider mode.
0 commit comments