forked from gardener/gardener
/
certmanagment.go
92 lines (75 loc) · 2.92 KB
/
certmanagment.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package certmanagement
import (
"fmt"
"github.com/ghodss/yaml"
corev1 "k8s.io/api/core/v1"
)
var _ DNSProviderConfig = (*Route53Config)(nil)
var _ DNSProviderConfig = (*CloudDNSConfig)(nil)
const (
// Route53 is a constant string for aws-route53.
Route53 DNSProvider = "aws-route53"
// CloudDNS is a constant string for google-clouddns.
CloudDNS DNSProvider = "google-clouddns"
)
// DNSProvider returns the provider type in-use.
func (r *Route53Config) DNSProvider() DNSProvider {
return Route53
}
// ACMEPrivateKey returns the private value that will be used to create the issuer secret.
func (a *ACMEConfig) ACMEPrivateKey() string {
return a.PrivateKey
}
// AccessKey returns the route53 SecretAccessKey in case route53 provider is used.
func (r *Route53Config) AccessKey() string {
return r.SecretAccessKey
}
// ProviderName returns the route53 provider name.
func (r *Route53Config) ProviderName() string {
return r.Name
}
// DomainNames returns the domains this provider manages.
func (r *Route53Config) DomainNames() []string {
return r.Domains
}
// DNSProvider returns the provider type in-use.
func (c *CloudDNSConfig) DNSProvider() DNSProvider {
return CloudDNS
}
// AccessKey returns the CloudDNS ServiceAccount in case Google CloudDNS provider is used.
func (c *CloudDNSConfig) AccessKey() string {
return c.ServiceAccount
}
// ProviderName returns the CloudDNS provider name.
func (c *CloudDNSConfig) ProviderName() string {
return c.Name
}
// DomainNames returns the domains this provider manages.
func (c *CloudDNSConfig) DomainNames() []string {
return c.Domains
}
// RetrieveCertificateManagementConfig retrieves the configuration for certificate management via Gardener.
func RetrieveCertificateManagementConfig(certificateManagement *corev1.Secret) (*CertificateManagementConfig, error) {
certManagement, certManagementOk := certificateManagement.Data["certificate-management-config"]
if !certManagementOk {
return nil, fmt.Errorf("Failed to fetch certificate-management config from secret")
}
var certManagementConfig CertificateManagementConfig
if err := yaml.Unmarshal(certManagement, &certManagementConfig); err != nil {
return nil, err
}
return &certManagementConfig, nil
}