Skip to content

Commit

Permalink
better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cthtrifork committed Aug 29, 2023
1 parent dba70ca commit 2b341fa
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions charts/opensearchrole/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{{/* Define a template for creating a fully qualified roleName */}}
{{/*
Define a template for creating a fully qualified roleName.
This template takes care of truncating the roleName and delegates
the final roleName construction to another template.
*/}}
{{- define "opensearchrole.base.resourceName" -}}
{{- $roleNamePrefix := .Values.roleNamePrefix -}}
{{- $roleName := .Values.roleName -}}
{{- $suffix := .suffix -}}
{{- $dict := dict "Values" .Values "suffix" $suffix -}}

{{/* Calculate the max length allowed for roleName */}}
{{- $maxRoleNameLength := sub 64 (add (len $roleNamePrefix) (len $suffix)) -}}
Expand All @@ -13,10 +16,13 @@
{{- $roleName = slice $roleName 0 $maxRoleNameLength -}}
{{- end -}}

{{- include "opensearchrole.base.roleName" $dict | replace "_" "-" -}}
{{- include "opensearchrole.base.roleName" (dict "Values" .Values "suffix" $suffix) | replace "_" "-" -}}
{{- end -}}

{{/* Define a template for creating an indexPattern */}}
{{/*
Define a template for creating an indexPattern.
If indexPattern is not provided in .Values, the roleName is used as the indexPattern.
*/}}
{{- define "opensearchrole.indexPattern" -}}
{{- if .Values.indexPattern -}}
{{ .Values.indexPattern }}
Expand All @@ -25,36 +31,39 @@
{{- end -}}
{{- end -}}

{{/* Define a template for creating a roleName with _read or _write */}}
{{/*
Define a template for creating a roleName with either a _read or _write suffix.
This template is responsible for assembling the roleName.
*/}}
{{- define "opensearchrole.base.roleName" -}}
{{- $roleNamePrefix := .Values.roleNamePrefix -}}
{{- $roleName := required "roleName is required" .Values.roleName -}}
{{- $suffix := required "suffix is required" .suffix -}}

{{/* Check that the suffix is either read or write */}}
{{/* Check that the suffix is either "read" or "write" */}}
{{- if or (eq $suffix "read") (eq $suffix "write") -}}
{{- printf "%s%s_%s" $roleNamePrefix $roleName $suffix -}}
{{- else -}}
{{- fail "Suffix must be either 'read' or 'write'" -}}
{{- end -}}
{{- end -}}

{{/* Define a convenience template for read-only role resources */}}
{{- define "opensearchrole.resourceName.read" -}}
{{- $dict := dict "Values" .Values "suffix" "read" -}}
{{- include "opensearchrole.base.resourceName" $dict -}}
{{- include "opensearchrole.base.resourceName" (dict "Values" .Values "suffix" "read") -}}
{{- end -}}

{{/* Define a convenience template for write-enabled role resources */}}
{{- define "opensearchrole.resourceName.write" -}}
{{- $dict := dict "Values" .Values "suffix" "write" -}}
{{- include "opensearchrole.base.resourceName" $dict -}}
{{- include "opensearchrole.base.resourceName" (dict "Values" .Values "suffix" "write") -}}
{{- end -}}

{{/* Define a convenience template for read-only roleNames */}}
{{- define "opensearchrole.roleName.read" -}}
{{- $dict := dict "Values" .Values "suffix" "read" -}}
{{- include "opensearchrole.base.roleName" $dict -}}
{{- include "opensearchrole.base.roleName" (dict "Values" .Values "suffix" "read") -}}
{{- end -}}

{{/* Define a convenience template for write-enabled roleNames */}}
{{- define "opensearchrole.roleName.write" -}}
{{- $dict := dict "Values" .Values "suffix" "write" -}}
{{- include "opensearchrole.base.roleName" $dict -}}
{{- end -}}
{{- include "opensearchrole.base.roleName" (dict "Values" .Values "suffix" "write") -}}
{{- end -}}

0 comments on commit 2b341fa

Please sign in to comment.