/
certificate.go
132 lines (110 loc) · 3.4 KB
/
certificate.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Copyright 2019 The Jetstack cert-manager contributors.
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 gen
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
)
type CertificateModifier func(*v1alpha1.Certificate)
func Certificate(name string, mods ...CertificateModifier) *v1alpha1.Certificate {
c := &v1alpha1.Certificate{
ObjectMeta: ObjectMeta(name),
}
for _, mod := range mods {
mod(c)
}
return c
}
func CertificateFrom(crt *v1alpha1.Certificate, mods ...CertificateModifier) *v1alpha1.Certificate {
crt = crt.DeepCopy()
for _, mod := range mods {
mod(crt)
}
return crt
}
// SetIssuer sets the Certificate.spec.issuerRef field
func SetCertificateIssuer(o v1alpha1.ObjectReference) CertificateModifier {
return func(c *v1alpha1.Certificate) {
c.Spec.IssuerRef = o
}
}
func SetCertificateDNSNames(dnsNames ...string) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Spec.DNSNames = dnsNames
}
}
func SetCertificateCommonName(commonName string) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Spec.CommonName = commonName
}
}
func SetCertificateIsCA(isCA bool) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Spec.IsCA = isCA
}
}
func SetCertificateKeyAlgorithm(keyAlgorithm v1alpha1.KeyAlgorithm) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Spec.KeyAlgorithm = keyAlgorithm
}
}
func SetCertificateKeySize(keySize int) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Spec.KeySize = keySize
}
}
func SetCertificateKeyEncoding(keyEncoding v1alpha1.KeyEncoding) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Spec.KeyEncoding = keyEncoding
}
}
func SetCertificateSecretName(secretName string) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Spec.SecretName = secretName
}
}
func SetCertificateStatusCondition(c v1alpha1.CertificateCondition) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
if len(crt.Status.Conditions) == 0 {
crt.Status.Conditions = []v1alpha1.CertificateCondition{c}
return
}
for i, existingC := range crt.Status.Conditions {
if existingC.Type == c.Type {
crt.Status.Conditions[i] = c
return
}
}
crt.Status.Conditions = append(crt.Status.Conditions, c)
}
}
func SetCertificateLastFailureTime(p metav1.Time) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Status.LastFailureTime = &p
}
}
func SetCertificateNotAfter(p metav1.Time) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.Status.NotAfter = &p
}
}
func SetCertificateOrganization(orgs ...string) CertificateModifier {
return func(ch *v1alpha1.Certificate) {
ch.Spec.Organization = orgs
}
}
func SetCertificateNamespace(namespace string) CertificateModifier {
return func(crt *v1alpha1.Certificate) {
crt.ObjectMeta.Namespace = namespace
}
}