add some init work for cert

This commit is contained in:
Stavros kois
2022-12-11 20:44:48 +02:00
parent a07638a352
commit 2b90d98b20
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
{{- define "ix.v1.common.class.certificate" -}}
{{- $secretName := include "ix.v1.common.names.fullname" . -}}
{{- $root := .root -}}
{{- $certName := "TODO: Get the certName" -}}
{{- if include "ix.v1.common.certificate.exists" (dict "root" $root "certName" $certName) }}
---
apiVersion: {{ include "ix.v1.common.capabilities.secret.apiVersion" . }}
kind: Secret
type: kubernetes.io/tls
metadata:
name: {{ printf "%s-%s" $secretName .Release.Revision }}
{{- $labels := (default dict (include "ix.v1.common.labels" $root | fromYaml)) -}}
{{- with (include "ix.v1.common.util.labels.render" (dict "root" $root "labels" $labels) | trim) }}
labels:
{{- . | nindent 4 }}
{{- end -}}
{{- $annotations := (default dict (include "ix.v1.common.annotations" $root | fromYaml)) -}}
{{- with (include "ix.v1.common.util.annotations.render" (dict "root" $root "annotations" $annotations) | trim) }}
annotations:
{{- . | nindent 4 }}
{{- end }}
data:
tls.crt:
tls.key:
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,39 @@
{{/*
When a cert is selected in the GUI,
middleware adds it as dict in ixCertificates.
This checks that the certName exists as a key/dict.
*/}}
{{- define "ix.v1.common.certificate.exists" -}}
{{- $certName := .certName -}}
{{- $root := .root -}}
{{- hasKey $root.Values.ixCertificates (toString $certName) -}}
{{- end -}}
{{/*
Returns the certificate
*/}}
{{- define "ix.v1.common.certificate.cert" -}}
{{- $certName := .certName -}}
{{- $root := .root -}}
{{- if (include "ix.v1.common.certificate.exists" (dict "root" $root "certName" $certName)) -}}
{{- $certificate := (get $root.Values.ixCertificates (toString $certName)) -}}
{{- $certificate.certificate -}}
{{- else -}}
{{ fail (printf "Certificate (%s) did not found." $certName) }}
{{- end -}}
{{- end -}}
{{/*
Returns the privateKey
*/}}
{{- define "ix.v1.common.certificate.privatekey" -}}
{{- $certName := .certName -}}
{{- $root := .root -}}
{{- if (include "ix.v1.common.certificate.exists" (dict "root" $root "certName" $certName)) -}}
{{- $privateKey := (get $root.Values.ixCertificates (toString $certName)) -}}
{{- $privateKey.privatekey -}}
{{- else -}}
{{ fail (printf "Certificate (%s) did not found." $certName) }}
{{- end -}}
{{- end -}}