openstack-helm-infra/helm-toolkit/templates/tls/_tls_generate_certs.tpl
Hussey, Scott (sh8121) 9b00075a72 (helm-toolkit) Optionally b64 encode TLS keys
- When using the TLS certificate generation macro, optionally
  support base64 encoding values for direct inclusion in a Kubernetes
  secret. The default is to maintain current behavior for backward
  compatibility.

Change-Id: Ib62af4e5738cbc853a18e0d2a14c6103784e7370
2019-06-22 10:12:49 +00:00

84 lines
2.7 KiB
Smarty

{{/*
Copyright 2017 The Openstack-Helm Authors.
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.
*/}}
{{/*
abstract: |
Produces a certificate from a certificate authority. If the "encode" parameter
is true, base64 encode the values for inclusion in a Kubernetes secret.
values: |
test:
hosts:
names:
- barbican.openstackhelm.example
- barbican.openstack.svc.cluster.local
ips:
- 127.0.0.1
- 192.168.0.1
life: 3
ca:
crt: |
<CA CRT>
key: |
<CA PRIVATE KEY>
usage: |
{{ include "helm-toolkit.utils.tls_generate_certs" (dict "params" .Values.test) }}
return: |
ca: |
<CA CRT>
crt: |
<CRT>
exp: 2018-09-01T10:56:07.895392915-00:00
key: |
<CRT PRIVATE KEY>
*/}}
{{- define "helm-toolkit.utils.tls_generate_certs" -}}
{{- $params := index . "params" -}}
{{- $encode := index . "encode" | default false -}}
{{- $local := dict -}}
{{- $_hosts := $params.hosts.names | default list }}
{{- if kindIs "string" $params.hosts.names }}
{{- $_ := set $local "certHosts" (list $params.hosts.names) }}
{{- else }}
{{- $_ := set $local "certHosts" $_hosts }}
{{- end }}
{{- $_ips := $params.hosts.ips | default list }}
{{- if kindIs "string" $params.hosts.ips }}
{{- $_ := set $local "certIps" (list $params.hosts.ips) }}
{{- else }}
{{- $_ := set $local "certIps" $_ips }}
{{- end }}
{{- $ca := buildCustomCert ($params.ca.crt | b64enc ) ($params.ca.key | b64enc ) }}
{{- $expDate := date_in_zone "2006-01-02T15:04:05Z07:00" ( date_modify (printf "+%sh" (mul $params.life 24 |toString)) now ) "UTC" }}
{{- $rawCert := genSignedCert (first $local.certHosts) ($local.certIps) $local.certHosts (int $params.life) $ca }}
{{- $certificate := dict -}}
{{- if $encode -}}
{{- $_ := b64enc $rawCert.Cert | set $certificate "crt" -}}
{{- $_ := b64enc $rawCert.Key | set $certificate "key" -}}
{{- $_ := b64enc $params.ca.crt | set $certificate "ca" -}}
{{- $_ := b64enc $expDate | set $certificate "exp" -}}
{{- else -}}
{{- $_ := set $certificate "crt" $rawCert.Cert -}}
{{- $_ := set $certificate "key" $rawCert.Key -}}
{{- $_ := set $certificate "ca" $params.ca.crt -}}
{{- $_ := set $certificate "exp" $expDate -}}
{{- end -}}
{{- $certificate | toYaml }}
{{- end -}}