This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
catalog.go
204 lines (189 loc) · 5.53 KB
/
catalog.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package testing
import (
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
qsv1a1 "code.cloudfoundry.org/quarks-secret/pkg/kube/apis/quarkssecret/v1alpha1"
)
// Catalog provides several instances for tests
type Catalog struct{}
// DefaultQuarksSecret for use in tests
func (c *Catalog) DefaultQuarksSecret(name string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
Type: "password",
SecretName: "generated-secret",
},
}
}
// DefaultQuarksSecretWithLabels for use in tests
func (c *Catalog) DefaultQuarksSecretWithLabels(name string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
Type: "password",
SecretName: "generated-secret",
SecretLabels: map[string]string{
"LabelKey": "LabelValue",
},
},
}
}
// DefaultQuarksSecretWithCopyAndLabel for use in tests
func (c *Catalog) DefaultQuarksSecretWithCopyAndLabel(name string, copynamespace string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
Type: "password",
SecretName: "generated-secret",
SecretLabels: map[string]string{
"LabelKey": "LabelValue",
},
Copies: []qsv1a1.Copy{
{
Name: "generated-secret-copy",
Namespace: copynamespace,
},
},
},
}
}
// DefaultQuarksSecretWithCopy for use in tests
func (c *Catalog) DefaultQuarksSecretWithCopy(name string, copynamespace string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
Type: "password",
SecretName: "generated-secret",
Copies: []qsv1a1.Copy{
{
Name: "generated-secret-copy",
Namespace: copynamespace,
},
},
},
}
}
// CACertificateQuarksSecret for use in tests, creates a CA certificate
func (c *Catalog) CACertificateQuarksSecret(name string, secretref string, cacertref string, keyref string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
SecretName: "generated-cert-secret",
Type: "certificate",
Request: qsv1a1.Request{
CertificateRequest: qsv1a1.CertificateRequest{
IsCA: true,
CommonName: "example.com",
CARef: qsv1a1.SecretReference{Name: secretref, Key: cacertref},
CAKeyRef: qsv1a1.SecretReference{Name: secretref, Key: keyref},
AlternativeNames: []string{"qux.com"},
},
},
},
}
}
// CertificateQuarksSecret for use in tests, creates a certificate
func (c *Catalog) CertificateQuarksSecret(name string, secretref string, cacertref string, keyref string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
SecretName: "generated-cert-secret",
Type: "certificate",
Request: qsv1a1.Request{
CertificateRequest: qsv1a1.CertificateRequest{
CommonName: "example.com",
CARef: qsv1a1.SecretReference{Name: secretref, Key: cacertref},
CAKeyRef: qsv1a1.SecretReference{Name: secretref, Key: keyref},
AlternativeNames: []string{"qux.com"},
},
},
},
}
}
// TLSQuarksSecret for use in tests, creates a tls type secret
func (c *Catalog) TLSQuarksSecret(name string, secretref string, cacertref string, keyref string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
SecretName: "generated-cert-secret",
Type: "tls",
Request: qsv1a1.Request{
CertificateRequest: qsv1a1.CertificateRequest{
CommonName: "example.com",
CARef: qsv1a1.SecretReference{Name: secretref, Key: cacertref},
CAKeyRef: qsv1a1.SecretReference{Name: secretref, Key: keyref},
AlternativeNames: []string{"qux.com"},
},
},
},
}
}
// SSHQuarksSecret returns a 'ssh' type quarks secret for testing
func (c *Catalog) SSHQuarksSecret(name string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
Type: "ssh",
SecretName: "generated-ssh-secret",
},
}
}
// RSAQuarksSecret returns a 'rsa' type quarks secret for testing
func (c *Catalog) RSAQuarksSecret(name string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
Type: "rsa",
SecretName: "generated-rsa-secret",
},
}
}
// BasicAuthQuarksSecret returns a 'basic auth' type quarks secret for testing
func (c *Catalog) BasicAuthQuarksSecret(name string) qsv1a1.QuarksSecret {
return qsv1a1.QuarksSecret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: qsv1a1.QuarksSecretSpec{
Type: "basic-auth",
SecretName: "generated-basic-auth-secret",
Request: qsv1a1.Request{
BasicAuthRequest: qsv1a1.BasicAuthRequest{Username: "some-passed-in-username"},
},
},
}
}
// RotationConfig is a config map, which triggers secret rotation
func (c *Catalog) RotationConfig(name string) corev1.ConfigMap {
return corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "rotation-config1",
Labels: map[string]string{
qsv1a1.LabelSecretRotationTrigger: "yes",
},
},
Data: map[string]string{
qsv1a1.RotateQSecretListName: fmt.Sprintf(`["%s"]`, name),
},
}
}