@@ -142,3 +142,173 @@ Create a computed value for the intended Gremlin secret type which can either be
142142{{- " https://api.gremlin.com/v1" -}}
143143{{- end -}}
144144{{- end -}}
145+
146+ {{/*
147+ gremlinTlsIdentityValidate fails if more than one identity strategy is fully configured for gremlin
148+ */}}
149+ {{- define " gremlinTlsIdentityValidate" -}}
150+ {{- $remoteSecret := and .Values.gremlin.tls.identity.remoteSecret.cert .Values.gremlin.tls.identity.remoteSecret.key -}}
151+ {{- $createSecret := and .Values.gremlin.tls.identity.createSecret.name .Values.gremlin.tls.identity.createSecret.cert .Values.gremlin.tls.identity.createSecret.key -}}
152+ {{- $existingSecret := and .Values.gremlin.tls.identity.existingSecret.name .Values.gremlin.tls.identity.existingSecret.cert .Values.gremlin.tls.identity.existingSecret.key -}}
153+ {{- $count := 0 -}}
154+ {{- if $remoteSecret }}{{- $count = add $count 1 -}}{{- end -}}
155+ {{- if $createSecret }}{{- $count = add $count 1 -}}{{- end -}}
156+ {{- if $existingSecret }}{{- $count = add $count 1 -}}{{- end -}}
157+ {{- if gt (int $count) 1 -}}
158+ {{- fail " gremlin.tls.identity: only one of remoteSecret, createSecret, or existingSecret should be fully configured" -}}
159+ {{- end -}}
160+ {{- end -}}
161+
162+ {{/*
163+ chaoTlsIdentityValidate fails if more than one identity strategy is fully configured for chao
164+ */}}
165+ {{- define " chaoTlsIdentityValidate" -}}
166+ {{- $remoteSecret := and .Values.chao.tls.identity.remoteSecret.cert .Values.chao.tls.identity.remoteSecret.key -}}
167+ {{- $createSecret := and .Values.chao.tls.identity.createSecret.name .Values.chao.tls.identity.createSecret.cert .Values.chao.tls.identity.createSecret.key -}}
168+ {{- $existingSecret := and .Values.chao.tls.identity.existingSecret.name .Values.chao.tls.identity.existingSecret.cert .Values.chao.tls.identity.existingSecret.key -}}
169+ {{- $count := 0 -}}
170+ {{- if $remoteSecret }}{{- $count = add $count 1 -}}{{- end -}}
171+ {{- if $createSecret }}{{- $count = add $count 1 -}}{{- end -}}
172+ {{- if $existingSecret }}{{- $count = add $count 1 -}}{{- end -}}
173+ {{- if gt (int $count) 1 -}}
174+ {{- fail " chao.tls.identity: only one of remoteSecret, createSecret, or existingSecret should be fully configured" -}}
175+ {{- end -}}
176+ {{- end -}}
177+
178+ {{/*
179+ gremlinTlsIdentityEnv returns the environment variables needed to configure TLS client identity
180+ When remoteSecret is configured
181+ - sets GREMLIN_TLS_IDENTITY_CERTIFICATE and GREMLIN_TLS_IDENTITY_PRIVATE_KEY to their respective `cert` and `key` values
182+ When createSecret or existingSecret are configured
183+ - sets GREMLIN_TLS_IDENTITY_CERTIFICATE and GREMLIN_TLS_IDENTITY_PRIVATE_KEY to their respective file paths, mounted by gremlinTlsIdentityVolumeMounts
184+ */}}
185+ {{- define " gremlinTlsIdentityEnv" -}}
186+ {{- if .Values.gremlin.tls.identity.enabled -}}
187+ {{- include " gremlinTlsIdentityValidate" . -}}
188+ {{- if and .Values.gremlin.tls.identity.remoteSecret.cert .Values.gremlin.tls.identity.remoteSecret.key -}}
189+ - name: GREMLIN_TLS_IDENTITY_CERTIFICATE
190+ value: {{ .Values.gremlin.tls.identity.remoteSecret.cert | quote }}
191+ - name: GREMLIN_TLS_IDENTITY_PRIVATE_KEY
192+ value: {{ .Values.gremlin.tls.identity.remoteSecret.key | quote }}
193+ {{- else if and .Values.gremlin.tls.identity.createSecret.cert .Values.gremlin.tls.identity.createSecret.key -}}
194+ - name: GREMLIN_TLS_IDENTITY_CERTIFICATE
195+ value: /var/lib/gremlin/tls/identity/cert
196+ - name: GREMLIN_TLS_IDENTITY_PRIVATE_KEY
197+ value: /var/lib/gremlin/tls/identity/key
198+ {{- else if .Values.gremlin.tls.identity.existingSecret.name -}}
199+ - name: GREMLIN_TLS_IDENTITY_CERTIFICATE
200+ value: /var/lib/gremlin/tls/identity/{{ .Values.gremlin.tls.identity.existingSecret.cert }}
201+ - name: GREMLIN_TLS_IDENTITY_PRIVATE_KEY
202+ value: /var/lib/gremlin/tls/identity/{{ .Values.gremlin.tls.identity.existingSecret.key }}
203+ {{- end -}}
204+ {{- end -}}
205+ {{- end -}}
206+
207+ {{/*
208+ gremlinTlsIdentityVolumeMounts returns the mounts needed to access TLS client identity files
209+ When createSecret or existingSecret are configured
210+ - mounts to desginated secret files under /var/lib/gremlin/tls/identity
211+ */}}
212+ {{- define " gremlinTlsIdentityVolumeMounts" -}}
213+ {{- if .Values.gremlin.tls.identity.enabled -}}
214+ {{- include " gremlinTlsIdentityValidate" . -}}
215+ {{- if and .Values.gremlin.tls.identity.createSecret.cert .Values.gremlin.tls.identity.createSecret.key -}}
216+ - name: gremlin-tls-identity
217+ mountPath: /var/lib/gremlin/tls/identity
218+ readOnly: true
219+ {{- else if .Values.gremlin.tls.identity.existingSecret.name -}}
220+ - name: gremlin-tls-identity
221+ mountPath: /var/lib/gremlin/tls/identity
222+ readOnly: true
223+ {{- end -}}
224+ {{- end -}}
225+ {{- end -}}
226+
227+ {{/*
228+ gremlinTlsIdentityVolumes returns the volumes that contain TLS client identity files
229+ When createSecret or existingSecret are configured
230+ - defines the volume associated with the desginated secret
231+ */}}
232+ {{- define " gremlinTlsIdentityVolumes" -}}
233+ {{- if .Values.gremlin.tls.identity.enabled -}}
234+ {{- include " gremlinTlsIdentityValidate" . -}}
235+ {{- if and .Values.gremlin.tls.identity.createSecret.cert .Values.gremlin.tls.identity.createSecret.key -}}
236+ - name: gremlin-tls-identity
237+ secret:
238+ secretName: {{ .Values.gremlin.tls.identity.createSecret.name }}
239+ {{- else if .Values.gremlin.tls.identity.existingSecret.name -}}
240+ - name: gremlin-tls-identity
241+ secret:
242+ secretName: {{ .Values.gremlin.tls.identity.existingSecret.name }}
243+ {{- end -}}
244+ {{- end -}}
245+ {{- end -}}
246+
247+ {{/*
248+ chaoTlsIdentityArgs returns the chao cli arguments needed to configure TLS client identity
249+ When remoteSecret is configured
250+ - sets -tls-identity-cert and -tls-identity-private-key to their respective `cert` and `key` values
251+ When createSecret or existingSecret are configured
252+ - sets -tls-identity-cert and -tls-identity-private-key to their respective file paths, mounted by chaoTlsIdentityVolumeMounts
253+ */}}
254+ {{- define " chaoTlsIdentityArgs" -}}
255+ {{- if .Values.chao.tls.identity.enabled -}}
256+ {{- include " chaoTlsIdentityValidate" . -}}
257+ {{- if and .Values.chao.tls.identity.remoteSecret.cert .Values.chao.tls.identity.remoteSecret.key -}}
258+ - " -tls_identity_cert"
259+ - {{ .Values.chao.tls.identity.remoteSecret.cert | quote }}
260+ - " -tls_identity_private_key"
261+ - {{ .Values.chao.tls.identity.remoteSecret.key | quote }}
262+ {{- else if and .Values.chao.tls.identity.createSecret.cert .Values.chao.tls.identity.createSecret.key -}}
263+ - " -tls_identity_cert"
264+ - " /var/lib/gremlin/tls/identity/cert"
265+ - " -tls_identity_private_key"
266+ - " /var/lib/gremlin/tls/identity/key"
267+ {{- else if .Values.chao.tls.identity.existingSecret.name -}}
268+ - " -tls_identity_cert"
269+ - " /var/lib/gremlin/tls/identity/{{ .Values.chao.tls.identity.existingSecret.cert } }"
270+ - "-tls_identity_private_key"
271+ - "/var/lib/gremlin/tls/identity/{ { .Values.chao.tls.identity.existingSecret.key } }"
272+ { {- end -} }
273+ { {- end -} }
274+ { {- end -} }
275+
276+ { {/*
277+ chaoTlsIdentityVolumes returns the volumes that contain TLS client identity files
278+ When createSecret or existingSecret are configured
279+ - defines the volume associated with the desginated secret
280+ */} }
281+ { {- define " chaoTlsIdentityVolumeMounts" -} }
282+ { {- if .Values.chao.tls.identity.enabled -} }
283+ { {- include " chaoTlsIdentityValidate" . -} }
284+ { {- if and .Values.chao.tls.identity.createSecret.cert .Values.chao.tls.identity.createSecret.key -} }
285+ - name: chao-tls-identity
286+ mountPath: /var/lib/gremlin/tls/identity
287+ readOnly: true
288+ { {- else if .Values.chao.tls.identity.existingSecret.name -} }
289+ - name: chao-tls-identity
290+ mountPath: /var/lib/gremlin/tls/identity
291+ readOnly: true
292+ { {- end -} }
293+ { {- end -} }
294+ { {- end -} }
295+
296+ { {/*
297+ chaoTlsIdentityVolumes returns the volumes that contain TLS client identity files
298+ When createSecret or existingSecret are configured
299+ - defines the volume associated with the desginated secret
300+ */} }
301+ { {- define " chaoTlsIdentityVolumes" -} }
302+ { {- if .Values.chao.tls.identity.enabled -} }
303+ { {- include " chaoTlsIdentityValidate" . -} }
304+ { {- if and .Values.chao.tls.identity.createSecret.cert .Values.chao.tls.identity.createSecret.key -} }
305+ - name: chao-tls-identity
306+ secret:
307+ secretName: { { .Values.chao.tls.identity.createSecret.name } }
308+ { {- else if .Values.chao.tls.identity.existingSecret.name -} }
309+ - name: chao-tls-identity
310+ secret:
311+ secretName: { { .Values.chao.tls.identity.existingSecret.name } }
312+ { {- end -} }
313+ { {- end -} }
314+ { {- end -} }
0 commit comments