forked from pragkent/alidns-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
50 lines (43 loc) · 1.7 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package alidns
import (
"encoding/json"
"fmt"
apis "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
)
// Config is a structure that is used to decode into when
// solving a DNS01 challenge.
//
// This information is provided by cert-manager, and may be a reference to
// additional configuration that's needed to solve the challenge for this
// particular certificate or issuer.
//
// This typically includes references to Secret resources containing DNS
// provider credentials, in cases where a 'multi-tenant' DNS solver is being
// created.
//
// If you do *not* require per-issuer or per-certificate configuration to be
// provided to your webhook, you can skip decoding altogether in favour of
// using CLI flags or similar to provide configuration.
//
// You should not include sensitive information here. If credentials need to
// be used by your provider here, you should reference a Kubernetes Secret
// resource and fetch these credentials using a Kubernetes clientset.
type Config struct {
Region string `json:"region"`
AccessKeySecretRef apis.SecretKeySelector `json:"accessKeySecretRef"`
SecretKeySecretRef apis.SecretKeySelector `json:"secretKeySecretRef"`
}
// loadConfig is a small helper function that decodes JSON configuration into
// the typed config struct.
func loadConfig(cfgJSON *extapi.JSON) (Config, error) {
cfg := Config{}
// handle the 'base case' where no configuration has been provided
if cfgJSON == nil {
return cfg, nil
}
if err := json.Unmarshal(cfgJSON.Raw, &cfg); err != nil {
return cfg, fmt.Errorf("error decoding solver config: %v", err)
}
return cfg, nil
}