[vFW_CNF_CDS] Update of python-sdk for vFW_CNF use case
[demo.git] / tutorials / ApacheCNF / templates / cba / Templates / k8s-configs / deployment-config / charts / common / templates / _validations.tpl
1 {{/* vim: set filetype=mustache: */}}
2 {{/*
3 Validate values must not be empty.
4
5 Usage:
6 {{- $validateValueConf00 := (dict "valueKey" "path.to.value" "secret" "secretName" "field" "password-00") -}}
7 {{- $validateValueConf01 := (dict "valueKey" "path.to.value" "secret" "secretName" "field" "password-01") -}}
8 {{ include "common.validations.values.empty" (dict "required" (list $validateValueConf00 $validateValueConf01) "context" $) }}
9
10 Validate value params:
11   - valueKey - String - Required. The path to the validating value in the values.yaml, e.g: "mysql.password"
12   - secret - String - Optional. Name of the secret where the validating value is generated/stored, e.g: "mysql-passwords-secret"
13   - field - String - Optional. Name of the field in the secret data, e.g: "mysql-password"
14 */}}
15 {{- define "common.validations.values.multiple.empty" -}}
16   {{- range .required -}}
17     {{- include "common.validations.values.single.empty" (dict "valueKey" .valueKey "secret" .secret "field" .field "context" $.context) -}}
18   {{- end -}}
19 {{- end -}}
20
21 {{/*
22 Validate a value must not be empty.
23
24 Usage:
25 {{ include "common.validations.value.empty" (dict "valueKey" "mariadb.password" "secret" "secretName" "field" "my-password" "context" $) }}
26
27 Validate value params:
28   - valueKey - String - Required. The path to the validating value in the values.yaml, e.g: "mysql.password"
29   - secret - String - Optional. Name of the secret where the validating value is generated/stored, e.g: "mysql-passwords-secret"
30   - field - String - Optional. Name of the field in the secret data, e.g: "mysql-password"
31 */}}
32 {{- define "common.validations.values.single.empty" -}}
33   {{- $value := include "common.utils.getValueFromKey" (dict "key" .valueKey "context" .context) }}
34
35   {{- if not $value -}}
36     {{- $varname := "my-value" -}}
37     {{- $getCurrentValue := "" -}}
38     {{- if and .secret .field -}}
39       {{- $varname = include "common.utils.fieldToEnvVar" . -}}
40       {{- $getCurrentValue = printf " To get the current value:\n\n        %s\n" (include "common.utils.secret.getvalue" .) -}}
41     {{- end -}}
42     {{- printf "\n    '%s' must not be empty, please add '--set %s=$%s' to the command.%s" .valueKey .valueKey $varname $getCurrentValue -}}
43   {{- end -}}
44 {{- end -}}
45
46 {{/*
47 Validate MariaDB required passwords are not empty.
48
49 Usage:
50 {{ include "common.validations.values.mariadb.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
51 Params:
52   - secret - String - Required. Name of the secret where MariaDB values are stored, e.g: "mysql-passwords-secret"
53   - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
54 */}}
55 {{- define "common.validations.values.mariadb.passwords" -}}
56   {{- $existingSecret := include "common.mariadb.values.existingSecret" . -}}
57   {{- $enabled := include "common.mariadb.values.enabled" . -}}
58   {{- $architecture := include "common.mariadb.values.architecture" . -}}
59   {{- $authPrefix := include "common.mariadb.values.key.auth" . -}}
60   {{- $valueKeyRootPassword := printf "%s.rootPassword" $authPrefix -}}
61   {{- $valueKeyUsername := printf "%s.username" $authPrefix -}}
62   {{- $valueKeyPassword := printf "%s.password" $authPrefix -}}
63   {{- $valueKeyReplicationPassword := printf "%s.replicationPassword" $authPrefix -}}
64
65   {{- if and (not $existingSecret) (eq $enabled "true") -}}
66     {{- $requiredPasswords := list -}}
67
68     {{- $requiredRootPassword := dict "valueKey" $valueKeyRootPassword "secret" .secret "field" "mariadb-root-password" -}}
69     {{- $requiredPasswords = append $requiredPasswords $requiredRootPassword -}}
70
71     {{- $valueUsername := include "common.utils.getValueFromKey" (dict "key" $valueKeyUsername "context" .context) }}
72     {{- if not (empty $valueUsername) -}}
73         {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "mariadb-password" -}}
74         {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
75     {{- end -}}
76
77     {{- if (eq $architecture "replication") -}}
78         {{- $requiredReplicationPassword := dict "valueKey" $valueKeyReplicationPassword "secret" .secret "field" "mariadb-replication-password" -}}
79         {{- $requiredPasswords = append $requiredPasswords $requiredReplicationPassword -}}
80     {{- end -}}
81
82     {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
83
84   {{- end -}}
85 {{- end -}}
86
87 {{/*
88 Auxiliar function to get the right value for existingSecret.
89
90 Usage:
91 {{ include "common.mariadb.values.existingSecret" (dict "context" $) }}
92 Params:
93   - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
94 */}}
95 {{- define "common.mariadb.values.existingSecret" -}}
96   {{- if .subchart -}}
97     {{- .context.Values.mariadb.existingSecret | quote -}}
98   {{- else -}}
99     {{- .context.Values.existingSecret | quote -}}
100   {{- end -}}
101 {{- end -}}
102
103 {{/*
104 Auxiliar function to get the right value for enabled mariadb.
105
106 Usage:
107 {{ include "common.mariadb.values.enabled" (dict "context" $) }}
108 */}}
109 {{- define "common.mariadb.values.enabled" -}}
110   {{- if .subchart -}}
111     {{- printf "%v" .context.Values.mariadb.enabled -}}
112   {{- else -}}
113     {{- printf "%v" (not .context.Values.enabled) -}}
114   {{- end -}}
115 {{- end -}}
116
117 {{/*
118 Auxiliar function to get the right value for architecture
119
120 Usage:
121 {{ include "common.mariadb.values.architecture" (dict "subchart" "true" "context" $) }}
122 Params:
123   - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
124 */}}
125 {{- define "common.mariadb.values.architecture" -}}
126   {{- if .subchart -}}
127     {{- .context.Values.mariadb.architecture -}}
128   {{- else -}}
129     {{- .context.Values.architecture -}}
130   {{- end -}}
131 {{- end -}}
132
133 {{/*
134 Auxiliar function to get the right value for the key auth
135
136 Usage:
137 {{ include "common.mariadb.values.key.auth" (dict "subchart" "true" "context" $) }}
138 Params:
139   - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
140 */}}
141 {{- define "common.mariadb.values.key.auth" -}}
142   {{- if .subchart -}}
143     mariadb.auth
144   {{- else -}}
145     auth
146   {{- end -}}
147 {{- end -}}
148
149 {{/*
150 Validate PostgreSQL required passwords are not empty.
151
152 Usage:
153 {{ include "common.validations.values.postgresql.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
154 Params:
155   - secret - String - Required. Name of the secret where postgresql values are stored, e.g: "mysql-passwords-secret"
156   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
157 */}}
158 {{- define "common.validations.values.postgresql.passwords" -}}
159   {{- $existingSecret := include "common.postgresql.values.existingSecret" . -}}
160   {{- $enabled := include "common.postgresql.values.enabled" . -}}
161   {{- $valueKeyPostgresqlPassword := include "common.postgresql.values.key.postgressPassword" . -}}
162   {{- $enabledReplication := include "common.postgresql.values.enabled.replication" . -}}
163   {{- $valueKeyPostgresqlReplicationEnabled := include "common.postgresql.values.key.replicationPassword" . -}}
164
165   {{- if and (not $existingSecret) (eq $enabled "true") -}}
166     {{- $requiredPasswords := list -}}
167
168     {{- $requiredPostgresqlPassword := dict "valueKey" $valueKeyPostgresqlPassword "secret" .secret "field" "postgresql-password" -}}
169     {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlPassword -}}
170
171     {{- if (eq $enabledReplication "true") -}}
172         {{- $requiredPostgresqlReplicationPassword := dict "valueKey" $valueKeyPostgresqlReplicationEnabled "secret" .secret "field" "postgresql-replication-password" -}}
173         {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlReplicationPassword -}}
174     {{- end -}}
175
176     {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
177   {{- end -}}
178 {{- end -}}
179
180 {{/*
181 Auxiliar function to decide whether evaluate global values.
182
183 Usage:
184 {{ include "common.postgresql.values.use.global" (dict "key" "key-of-global" "context" $) }}
185 Params:
186   - key - String - Required. Field to be evaluated within global, e.g: "existingSecret"
187 */}}
188 {{- define "common.postgresql.values.use.global" -}}
189   {{- if .context.Values.global -}}
190     {{- if .context.Values.global.postgresql -}}
191       {{- index .context.Values.global.postgresql .key | quote -}}
192     {{- end -}}
193   {{- end -}}
194 {{- end -}}
195
196 {{/*
197 Auxiliar function to get the right value for existingSecret.
198
199 Usage:
200 {{ include "common.postgresql.values.existingSecret" (dict "context" $) }}
201 */}}
202 {{- define "common.postgresql.values.existingSecret" -}}
203   {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "existingSecret" "context" .context) -}}
204
205   {{- if .subchart -}}
206     {{- default (.context.Values.postgresql.existingSecret | quote) $globalValue -}}
207   {{- else -}}
208     {{- default (.context.Values.existingSecret | quote) $globalValue -}}
209   {{- end -}}
210 {{- end -}}
211
212 {{/*
213 Auxiliar function to get the right value for enabled postgresql.
214
215 Usage:
216 {{ include "common.postgresql.values.enabled" (dict "context" $) }}
217 */}}
218 {{- define "common.postgresql.values.enabled" -}}
219   {{- if .subchart -}}
220     {{- printf "%v" .context.Values.postgresql.enabled -}}
221   {{- else -}}
222     {{- printf "%v" (not .context.Values.enabled) -}}
223   {{- end -}}
224 {{- end -}}
225
226 {{/*
227 Auxiliar function to get the right value for the key postgressPassword.
228
229 Usage:
230 {{ include "common.postgresql.values.key.postgressPassword" (dict "subchart" "true" "context" $) }}
231 Params:
232   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
233 */}}
234 {{- define "common.postgresql.values.key.postgressPassword" -}}
235   {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "postgresqlUsername" "context" .context) -}}
236
237   {{- if not $globalValue -}}
238     {{- if .subchart -}}
239       postgresql.postgresqlPassword
240     {{- else -}}
241       postgresqlPassword
242     {{- end -}}
243   {{- else -}}
244     global.postgresql.postgresqlPassword
245   {{- end -}}
246 {{- end -}}
247
248 {{/*
249 Auxiliar function to get the right value for enabled.replication.
250
251 Usage:
252 {{ include "common.postgresql.values.enabled.replication" (dict "subchart" "true" "context" $) }}
253 Params:
254   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
255 */}}
256 {{- define "common.postgresql.values.enabled.replication" -}}
257   {{- if .subchart -}}
258     {{- printf "%v" .context.Values.postgresql.replication.enabled -}}
259   {{- else -}}
260     {{- printf "%v" .context.Values.replication.enabled -}}
261   {{- end -}}
262 {{- end -}}
263
264 {{/*
265 Auxiliar function to get the right value for the key replication.password.
266
267 Usage:
268 {{ include "common.postgresql.values.key.replicationPassword" (dict "subchart" "true" "context" $) }}
269 Params:
270   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
271 */}}
272 {{- define "common.postgresql.values.key.replicationPassword" -}}
273   {{- if .subchart -}}
274     postgresql.replication.password
275   {{- else -}}
276     replication.password
277   {{- end -}}
278 {{- end -}}