J release changes
[ric-plt/ric-dep.git] / helm / infrastructure / subcharts / kong / charts / postgresql / charts / common / templates / validations / _mongodb.tpl
1 {{/* vim: set filetype=mustache: */}}
2 {{/*
3 Validate MongoDB® required passwords are not empty.
4
5 Usage:
6 {{ include "common.validations.values.mongodb.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
7 Params:
8   - secret - String - Required. Name of the secret where MongoDB® values are stored, e.g: "mongodb-passwords-secret"
9   - subchart - Boolean - Optional. Whether MongoDB® is used as subchart or not. Default: false
10 */}}
11 {{- define "common.validations.values.mongodb.passwords" -}}
12   {{- $existingSecret := include "common.mongodb.values.auth.existingSecret" . -}}
13   {{- $enabled := include "common.mongodb.values.enabled" . -}}
14   {{- $authPrefix := include "common.mongodb.values.key.auth" . -}}
15   {{- $architecture := include "common.mongodb.values.architecture" . -}}
16   {{- $valueKeyRootPassword := printf "%s.rootPassword" $authPrefix -}}
17   {{- $valueKeyUsername := printf "%s.username" $authPrefix -}}
18   {{- $valueKeyDatabase := printf "%s.database" $authPrefix -}}
19   {{- $valueKeyPassword := printf "%s.password" $authPrefix -}}
20   {{- $valueKeyReplicaSetKey := printf "%s.replicaSetKey" $authPrefix -}}
21   {{- $valueKeyAuthEnabled := printf "%s.enabled" $authPrefix -}}
22
23   {{- $authEnabled := include "common.utils.getValueFromKey" (dict "key" $valueKeyAuthEnabled "context" .context) -}}
24
25   {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") (eq $authEnabled "true") -}}
26     {{- $requiredPasswords := list -}}
27
28     {{- $requiredRootPassword := dict "valueKey" $valueKeyRootPassword "secret" .secret "field" "mongodb-root-password" -}}
29     {{- $requiredPasswords = append $requiredPasswords $requiredRootPassword -}}
30
31     {{- $valueUsername := include "common.utils.getValueFromKey" (dict "key" $valueKeyUsername "context" .context) }}
32     {{- $valueDatabase := include "common.utils.getValueFromKey" (dict "key" $valueKeyDatabase "context" .context) }}
33     {{- if and $valueUsername $valueDatabase -}}
34         {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "mongodb-password" -}}
35         {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
36     {{- end -}}
37
38     {{- if (eq $architecture "replicaset") -}}
39         {{- $requiredReplicaSetKey := dict "valueKey" $valueKeyReplicaSetKey "secret" .secret "field" "mongodb-replica-set-key" -}}
40         {{- $requiredPasswords = append $requiredPasswords $requiredReplicaSetKey -}}
41     {{- end -}}
42
43     {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
44
45   {{- end -}}
46 {{- end -}}
47
48 {{/*
49 Auxiliary function to get the right value for existingSecret.
50
51 Usage:
52 {{ include "common.mongodb.values.auth.existingSecret" (dict "context" $) }}
53 Params:
54   - subchart - Boolean - Optional. Whether MongoDb is used as subchart or not. Default: false
55 */}}
56 {{- define "common.mongodb.values.auth.existingSecret" -}}
57   {{- if .subchart -}}
58     {{- .context.Values.mongodb.auth.existingSecret | quote -}}
59   {{- else -}}
60     {{- .context.Values.auth.existingSecret | quote -}}
61   {{- end -}}
62 {{- end -}}
63
64 {{/*
65 Auxiliary function to get the right value for enabled mongodb.
66
67 Usage:
68 {{ include "common.mongodb.values.enabled" (dict "context" $) }}
69 */}}
70 {{- define "common.mongodb.values.enabled" -}}
71   {{- if .subchart -}}
72     {{- printf "%v" .context.Values.mongodb.enabled -}}
73   {{- else -}}
74     {{- printf "%v" (not .context.Values.enabled) -}}
75   {{- end -}}
76 {{- end -}}
77
78 {{/*
79 Auxiliary function to get the right value for the key auth
80
81 Usage:
82 {{ include "common.mongodb.values.key.auth" (dict "subchart" "true" "context" $) }}
83 Params:
84   - subchart - Boolean - Optional. Whether MongoDB® is used as subchart or not. Default: false
85 */}}
86 {{- define "common.mongodb.values.key.auth" -}}
87   {{- if .subchart -}}
88     mongodb.auth
89   {{- else -}}
90     auth
91   {{- end -}}
92 {{- end -}}
93
94 {{/*
95 Auxiliary function to get the right value for architecture
96
97 Usage:
98 {{ include "common.mongodb.values.architecture" (dict "subchart" "true" "context" $) }}
99 Params:
100   - subchart - Boolean - Optional. Whether MongoDB® is used as subchart or not. Default: false
101 */}}
102 {{- define "common.mongodb.values.architecture" -}}
103   {{- if .subchart -}}
104     {{- .context.Values.mongodb.architecture -}}
105   {{- else -}}
106     {{- .context.Values.architecture -}}
107   {{- end -}}
108 {{- end -}}