|
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "acapy.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 6 | +{{- end }} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Create URL based on hostname and TLS status |
| 10 | +*/}} |
| 11 | +{{- define "acapy.agent.url" -}} |
| 12 | +{{- if .Values.ingress.agent.tls -}} |
| 13 | +{{- printf "https://%s" (include "acapy.host" .) }} |
| 14 | +{{- else -}} |
| 15 | +{{- printf "http://%s" (include "acapy.host" .) }} |
| 16 | +{{- end -}} |
| 17 | +{{- end }} |
| 18 | + |
| 19 | +{{/* |
| 20 | +Create Websockets URL based on hostname and TLS status |
| 21 | +*/}} |
| 22 | +{{- define "acapy.agent.wsUrl" -}} |
| 23 | +{{- if .Values.ingress.agent.tls -}} |
| 24 | +{{- printf "wss://%s" (include "acapy.host" .) }} |
| 25 | +{{- else -}} |
| 26 | +{{- printf "ws://%s" (include "acapy.host" .) }} |
| 27 | +{{- end -}} |
| 28 | +{{- end }} |
| 29 | + |
| 30 | +{{/* |
| 31 | +generate hosts if not overriden |
| 32 | +*/}} |
| 33 | +{{- define "acapy.host" -}} |
| 34 | +{{- if .Values.ingress.agent.enabled -}} |
| 35 | + {{ .Values.ingress.agent.hostname }} |
| 36 | +{{- else -}} |
| 37 | + {{ .Values.agentUrl }} |
| 38 | +{{- end -}} |
| 39 | +{{- end -}} |
| 40 | + |
| 41 | +{{/* |
| 42 | +Returns a secret if it already in Kubernetes, otherwise it creates |
| 43 | +it randomly. |
| 44 | +
|
| 45 | +Usage: |
| 46 | +{{ include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" (include "acapy.databaseSecretName" .) "Key" "postgres-password" "Length" 32) }} |
| 47 | +
|
| 48 | +*/}} |
| 49 | +{{- define "getOrGeneratePass" }} |
| 50 | +{{- $len := (default 16 .Length) | int -}} |
| 51 | +{{- $obj := (lookup "v1" .Kind .Namespace .Name).data -}} |
| 52 | +{{- if $obj }} |
| 53 | +{{- index $obj .Key -}} |
| 54 | +{{- else if (eq (lower .Kind) "secret") -}} |
| 55 | +{{- randAlphaNum $len | b64enc -}} |
| 56 | +{{- else -}} |
| 57 | +{{- randAlphaNum $len -}} |
| 58 | +{{- end -}} |
| 59 | +{{- end }} |
| 60 | + |
| 61 | +{{/* |
| 62 | +Create a default fully qualified postgresql name. |
| 63 | +*/}} |
| 64 | +{{- define "acapy.database.secretName" -}} |
| 65 | +{{- if .Values.walletStorageCredentials.existingSecret -}} |
| 66 | +{{- .Values.walletStorageCredentials.existingSecret -}} |
| 67 | +{{- else -}} |
| 68 | +{{ printf "%s-postgresql" (include "common.names.fullname" .) }} |
| 69 | +{{- end -}} |
| 70 | +{{- end -}} |
| 71 | + |
| 72 | +{{/* |
| 73 | +Create a default fully qualified app name for the postgres requirement. |
| 74 | +*/}} |
| 75 | +{{- define "global.postgresql.fullname" -}} |
| 76 | +{{- if .Values.postgresql.fullnameOverride }} |
| 77 | +{{- .Values.postgresql.fullnameOverride | trunc 63 | trimSuffix "-" }} |
| 78 | +{{- else }} |
| 79 | +{{- $postgresContext := dict "Values" .Values.postgresql "Release" .Release "Chart" (dict "Name" "postgresql") -}} |
| 80 | +{{ template "postgresql.v1.primary.fullname" $postgresContext }} |
| 81 | +{{- end -}} |
| 82 | +{{- end -}} |
| 83 | + |
| 84 | +{{/* |
| 85 | +Generate acapy wallet storage config |
| 86 | +*/}} |
| 87 | +{{- define "acapy.walletStorageConfig" -}} |
| 88 | +{{- if .Values.walletStorageConfig.json -}} |
| 89 | + {{- .Values.walletStorageConfig.json -}} |
| 90 | +{{- else if .Values.walletStorageConfig.url -}} |
| 91 | + '{"url":"{{ .Values.walletStorageConfig.url }}","max_connections":"{{ .Values.walletStorageConfig.max_connection | default 10 }}", "wallet_scheme":"{{ .Values.walletStorageConfig.wallet_scheme }}"}' |
| 92 | +{{- else if .Values.postgresql.enabled -}} |
| 93 | + '{"url":"{{ include "global.postgresql.fullname" . }}:{{ .Values.postgresql.primary.service.ports.postgresql }}","max_connections":"{{ .Values.walletStorageConfig.max_connections }}","wallet_scheme":"{{ .Values.walletStorageConfig.wallet_scheme }}"}' |
| 94 | +{{- else -}} |
| 95 | + '' |
| 96 | +{{ end }} |
| 97 | +{{- end -}} |
| 98 | + |
| 99 | +{{/* |
| 100 | +Generate acapy wallet storage credentials |
| 101 | +*/}} |
| 102 | +{{- define "acapy.walletStorageCredentials" -}} |
| 103 | +{{- if .Values.walletStorageCredentials.json -}} |
| 104 | + {{- .Values.walletStorageCredentials.json -}} |
| 105 | +{{- else if .Values.postgresql.enabled -}} |
| 106 | + '{"account":"{{ .Values.postgresql.auth.username }}","password":"$(POSTGRES_PASSWORD)","admin_account":"{{ .Values.walletStorageCredentials.admin_account }}","admin_password":"$(POSTGRES_POSTGRES_PASSWORD)"}' |
| 107 | +{{- else -}} |
| 108 | + '{"account":"{{ .Values.walletStorageCredentials.account | default "acapy" }}","password":"$(POSTGRES_PASSWORD)","admin_account":"{{ .Values.walletStorageCredentials.admin_account }}","admin_password":"$(POSTGRES_POSTGRES_PASSWORD)"}' |
| 109 | +{{- end -}} |
| 110 | +{{- end -}} |
| 111 | + |
| 112 | +{{/* |
| 113 | +Create chart name and version as used by the chart label. |
| 114 | +*/}} |
| 115 | +{{- define "acapy.chart" -}} |
| 116 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
| 117 | +{{- end }} |
| 118 | + |
| 119 | +{{/* |
| 120 | +Common labels |
| 121 | +*/}} |
| 122 | +{{- define "acapy.labels" -}} |
| 123 | +helm.sh/chart: {{ include "acapy.chart" . }} |
| 124 | +{{ include "acapy.selectorLabels" . }} |
| 125 | +{{- if .Chart.AppVersion }} |
| 126 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 127 | +{{- end }} |
| 128 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 129 | +{{- end }} |
| 130 | + |
| 131 | +{{/* |
| 132 | +Selector labels |
| 133 | +*/}} |
| 134 | +{{- define "acapy.selectorLabels" -}} |
| 135 | +app.kubernetes.io/name: {{ include "acapy.name" . }} |
| 136 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 137 | +{{- end }} |
| 138 | + |
| 139 | +{{/* |
| 140 | +Return the proper Docker Image Registry Secret Names |
| 141 | +*/}} |
| 142 | +{{- define "acapy.imagePullSecrets" -}} |
| 143 | +{{- include "common.images.pullSecrets" (dict "images" (list .Values.image) "global" .Values.global) -}} |
| 144 | +{{- end -}} |
| 145 | + |
| 146 | +{{/* |
| 147 | +Create the name of the service account to use |
| 148 | +*/}} |
| 149 | +{{- define "acapy.serviceAccountName" -}} |
| 150 | +{{- if .Values.serviceAccount.create -}} |
| 151 | + {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }} |
| 152 | +{{- else -}} |
| 153 | + {{ default "default" .Values.serviceAccount.name }} |
| 154 | +{{- end -}} |
| 155 | +{{- end -}} |
0 commit comments