First draft of the SMO package based on the ONAP charts
[it/dep.git] / smo-install / oran_oom / aux-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 "%d" .Values.masterPasswordOverride -}}
28   {{ else if .Values.global.masterPassword }}
29     {{- printf "%d" .Values.global.masterPassword -}}
30   {{ else if .Values.masterPassword }}
31     {{- printf "%d" .Values.masterPassword -}}
32   {{ else }}
33     {{ fail "masterPassword not provided" }}
34   {{ end }}
35 {{- end -}}
36
37 {{/*
38   Generate a new password based on masterPassword. The new password is not
39   random, it is derived from masterPassword, fully qualified chart name and
40   additional uid provided by the user. This ensures that every time when we
41   run this function from the same place, with the same password and uid we
42   get the same results. This allows to avoid password changes while you are
43   doing upgrade.
44
45   The function can take from one to three arguments (inside a dictionary):
46   - .dot : environment (.)
47   - .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
48   - .strength : complexity of derived password. See derivePassword documentation for more details
49
50   Example calls:
51
52     {{ include "common.createPassword" . }}
53     {{ include "common.createPassword" (dict "dot" . "uid" "mysqlRootPasswd") }}
54
55 */}}
56 {{- define "common.createPassword" -}}
57   {{- $dot := default . .dot -}}
58   {{- $uid := default "onap" .uid -}}
59   {{- $strength := default "long" .strength -}}
60   {{- $mp := include "common.masterPassword" $dot -}}
61   {{- derivePassword 1 $strength $mp (include "common.fullname" $dot) $uid -}}
62 {{- end -}}