@@ -60,3 +60,50 @@ Create the name of the service account to use
6060{{- default " default" .Values.serviceAccount.name }}
6161{{- end }}
6262{{- end }}
63+
64+ {{/*
65+ Returns the available value for certain key in an existing secret (if it exists),
66+ otherwise it generates a random value.
67+ */ }}
68+ {{- define " getValueFromSecret" }}
69+ {{- $len := (default 16 .Length ) | int -}}
70+ {{- $obj := (lookup " v1" " Secret" .Namespace .Name ).data -}}
71+ {{- if $obj }}
72+ {{- index $obj .Key | b64dec -}}
73+ {{- else -}}
74+ {{- randAlphaNum $len -}}
75+ {{- end -}}
76+ {{- end }}
77+
78+ {{/*
79+ Return codex.docs password
80+ */ }}
81+ {{- define " codexdocs.password" -}}
82+ {{- if empty .Values.auth.password -}}
83+ {{- include " getValueFromSecret" (dict " Namespace" .Release.Namespace " Name" (include " codexdocs.fullname" . ) " Length" 20 " Key" " docs-password" ) -}}
84+ {{- else -}}
85+ {{- .Values.auth.password -}}
86+ {{- end -}}
87+ {{- end -}}
88+
89+ {{/*
90+ Get the password secret.
91+ */ }}
92+ {{- define " codexdocs.secretName" -}}
93+ {{- if .Values.auth.existingSecret -}}
94+ {{- printf " %s " .Values.auth.existingSecret -}}
95+ {{- else -}}
96+ {{- printf " %s " (include " codexdocs.fullname" . ) -}}
97+ {{- end -}}
98+ {{- end -}}
99+
100+ {{/*
101+ Get the password key to be retrieved from secret.
102+ */ }}
103+ {{- define " codexdocs.secretPasswordKey" -}}
104+ {{- if and .Values.auth.existingSecret .Values.auth.existingSecretPasswordKey -}}
105+ {{- printf " %s " .Values.auth.existingSecretPasswordKey -}}
106+ {{- else -}}
107+ {{- printf " docs-password" -}}
108+ {{- end -}}
109+ {{- end -}}
0 commit comments