Merge "[DCAE] Dashboard container revision"
[oom.git] / kubernetes / common / common / templates / _createPassword.tpl
1 {{/*
2 # Copyright © 2019 Samsung Electronics
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 */}}
16
17 {{/*
18   Resolve the master password to be used to derive other passwords. The value of
19   .Values.masterPassword is used by default, unless either override mechanism is
20   used:
21
22   - .Values.global.masterPassword  : override default master password for all charts
23   - .Values.masterPasswordOverride : override global and default masterPassword on a per chart basis
24 */}}
25 {{- define "common.masterPassword" -}}
26   {{ if .Values.masterPasswordOverride }}
27     {{- printf "%s" .Values.masterPasswordOverride -}}
28   {{ else if .Values.global.masterPassword }}
29     {{- printf "%s" .Values.global.masterPassword -}}
30   {{ else if .Values.masterPassword }}
31     {{- printf "%s" .Values.masterPassword -}}
32   {{ else if eq "testRelease" (include "common.release" .) }}
33     {{/* Special case for chart liniting. DON"T NAME YOUR PRODUCTION RELEASE testRelease */}}
34     {{- printf "testRelease" -}}
35   {{ else if eq "test-release" .Release.Name }}
36     {{/* Special case for chart linting in helm3. DON"T NAME YOUR PRODUCTION RELEASE test-release */}}
37     {{- printf "testRelease" -}}
38   {{ else }}
39     {{ fail "masterPassword not provided" }}
40   {{ end }}
41 {{- end -}}
42
43 {{- define "common._defaultPasswordStrength" -}}
44   {{ if .Values.passwordStrengthOverride }}
45     {{- printf "%s" .Values.passwordStrengthOverride -}}
46   {{ else if .Values.global.passwordStrength }}
47     {{- printf "%s" .Values.global.passwordStrength -}}
48   {{ else if .Values.passwordStrength }}
49     {{- printf "%s" .Values.passwordStrength -}}
50   {{ else }}
51     {{- printf "long" }}
52   {{ end }}
53 {{- end -}}
54
55 {{/*
56   Generate a new password based on masterPassword. The new password is not
57   random, it is derived from masterPassword, fully qualified chart name and
58   additional uid provided by the user. This ensures that every time when we
59   run this function from the same place, with the same password and uid we
60   get the same results. This allows to avoid password changes while you are
61   doing upgrade.
62
63   The function can take from one to three arguments (inside a dictionary):
64   - .dot : environment (.)
65   - .uid : unique identifier of password to be generated within this particular chart. Use only when you create more than a single password within one chart
66   - .strength : complexity of derived password. See derivePassword documentation for more details
67
68   Example calls:
69
70     {{ include "common.createPassword" . }}
71     {{ include "common.createPassword" (dict "dot" . "uid" "mysqlRootPasswd") }}
72
73 */}}
74 {{- define "common.createPassword" -}}
75   {{- $dot := default . .dot -}}
76   {{- $uid := default "onap" .uid -}}
77   {{- $defaultStrength := include "common._defaultPasswordStrength" $dot | trim -}}
78   {{- $strength := default $defaultStrength .strength -}}
79   {{- $mp := include "common.masterPassword" $dot -}}
80   {{- derivePassword 1 $strength $mp (include "common.fullname" $dot) $uid -}}
81 {{- end -}}