@@ -28,6 +28,11 @@ import (
28
28
"github.com/joeig/go-powerdns/v3"
29
29
)
30
30
31
+ const (
32
+ defaultAuthHeader = "X-API-Key"
33
+ defaultScheme = ""
34
+ )
35
+
31
36
var GroupName = os .Getenv ("GROUP_NAME" )
32
37
33
38
func main () {
@@ -81,6 +86,17 @@ type powerDNSProviderConfig struct {
81
86
// secret which contains the PowerDNS API Key.
82
87
APIKeySecretRef * cmmeta.SecretKeySelector `json:"apiKeySecretRef"`
83
88
89
+ // Scheme supports HTTP AuthSchemes
90
+ // https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml
91
+ //
92
+ // +optional default ""
93
+ APIKeyScheme string `json:"apiKeyScheme"`
94
+
95
+ // APIKeyHeaderName is the header name where apiKey will be set
96
+ //
97
+ // +optional default "X-API-Key"
98
+ APIKeyHeaderName string `json:"apiKeyHeaderName"`
99
+
84
100
// ServerID is the server ID in the PowerDNS API.
85
101
// When unset, defaults to "localhost".
86
102
ServerID string `json:"serverID"`
@@ -245,7 +261,10 @@ func (c *powerDNSProviderSolver) Initialize(kubeClientConfig *rest.Config, stopC
245
261
// loadConfig is a small helper function that decodes JSON configuration into
246
262
// the typed config struct.
247
263
func loadConfig (cfgJSON * apiextensionsv1.JSON ) (* powerDNSProviderConfig , error ) {
248
- cfg := & powerDNSProviderConfig {}
264
+ cfg := & powerDNSProviderConfig {
265
+ APIKeyScheme : defaultScheme ,
266
+ APIKeyHeaderName : defaultAuthHeader ,
267
+ }
249
268
// handle the 'base case' where no configuration has been provided
250
269
if cfgJSON == nil {
251
270
return cfg , nil
@@ -325,7 +344,9 @@ func (c *powerDNSProviderSolver) init(config *apiextensionsv1.JSON, namespace st
325
344
326
345
// Add request headers
327
346
headers := map [string ]string {
328
- "X-API-Key" : apiKey ,
347
+ cfg .APIKeyHeaderName : strings .TrimLeft (
348
+ strings .Trim (cfg .APIKeyScheme , " " )+ " " + apiKey ,
349
+ " " ),
329
350
"Content-Type" : "application/json" ,
330
351
}
331
352
maps .Copy (headers , cfg .Headers )
0 commit comments