Skip to content

Commit

Permalink
feat: enable API support (#358)
Browse files Browse the repository at this point in the history
Signed-off-by: fastlorenzo <[email protected]>
  • Loading branch information
fastlorenzo authored Jul 28, 2024
1 parent 34ef061 commit 0d313fa
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.6.0
hooks:
- id: check-yaml
exclude: >
Expand All @@ -11,11 +11,11 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.18
rev: v0.1.23
hooks:
- id: helmlint
- repo: https://github.com/bitnami/readme-generator-for-helm
rev: "main"
rev: "2.6.1"
hooks:
- id: helm-readme-generator
# in order to run helm-readme-generator only once
Expand Down
5 changes: 5 additions & 0 deletions mailu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ Check that the deployed pods are all running.
| `initialAccount.existingSecret` | Name of the existing secret to retrieve the initial account's password | `""` |
| `initialAccount.existingSecretPasswordKey` | Name of the key in the existing secret to use for the initial account's password | `""` |
| `initialAccount.mode` | How to treat the creationg of the initial account. Possible values: "create", "update" or "ifmissing" | `update` |
| `api.enabled` | Enable the API interface | `false` |
| `api.token` | Token to use for the API interface - if empty, a random token will be generated and saved in a secret | `""` |
| `api.existingSecret` | Name of the existing secret to retrieve the API token - if set, the token will be ignored | `""` |
| `api.existingSecretTokenKey` | Name of the key in the existing secret to use for the API token | `api-token` |
| `api.webPath` | Path for the API interface | `/api` |
| `subnet` | Change this if you're using different address ranges for pods (IPv4) | `10.42.0.0/16` |
| `subnet6` | Change this if you're using different address ranges for pods (IPv6) | `""` |
| `networkPolicy.enabled` | Enable network policy | `false` |
Expand Down
27 changes: 27 additions & 0 deletions mailu/templates/_secrets.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@
{{- include "common.secrets.passwords.manage" (dict "secret" (include "mailu.externalRelay.secretName" .) "key" .Values.externalRelay.passwordKey "providedValues" (list "externalRelay.password") "length" 24 "strong" true "context" .) }}
{{- end -}}


{{/* Return mailu api.token */}}
{{- define "mailu.api.token" -}}
{{- include "common.secrets.passwords.manage" (dict "secret" (include "mailu.api.secretName" .) "key" (include "mailu.api.secretKey" .) "providedValues" (list "api.token") "length" 16 "strong" true "context" .) }}
{{- end -}}

{{/* Returns the mailu api secret name */}}
{{- define "mailu.api.secretName" -}}
{{- include "common.secrets.name" (dict "existingSecret" .Values.api.existingSecret "defaultNameSuffix" "api" "context" .) }}
{{- end -}}

{{/* Returns the mailu api key that contains the token in the secret */}}
{{- define "mailu.api.secretKey" -}}
{{ if .Values.api.existingSecretTokenKey }}
{{- .Values.api.existingSecretTokenKey -}}
{{- else -}}
{{- print "api-token" -}}
{{- end -}}
{{- end -}}

{{/* Get the mailu env vars secrets */}}
{{- define "mailu.envvars.secrets" -}}
- name: SECRET_KEY
Expand Down Expand Up @@ -88,4 +108,11 @@
name: {{ include "mailu.externalRelay.secretName" . }}
key: {{ .Values.externalRelay.passwordKey }}
{{- end }}
{{- if .Values.api.enabled }}
- name: API_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "mailu.api.secretName" . }}
key: {{ include "mailu.api.secretKey" . }}
{{- end }}
{{- end -}}
7 changes: 7 additions & 0 deletions mailu/templates/envvars-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,10 @@ data:
{{- else }}
FULL_TEXT_SEARCH_ATTACHMENTS: "false"
{{- end}}

{{- if .Values.api.enabled }}
API: "true"
WEB_API: {{ .Values.api.webPath | quote }}
{{- else }}
API: "false"
{{- end }}
17 changes: 17 additions & 0 deletions mailu/templates/secret-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if and (.Values.api.enabled) (not .Values.api.existingSecret) }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "mailu.api.secretName" . }}
namespace: {{ include "common.names.namespace" . | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" . ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" . ) | nindent 4 }}
{{- end }}
type: Opaque
data:
{{ include "mailu.api.secretKey" . -}}: {{ include "mailu.api.token" . }}
{{- end }}
12 changes: 12 additions & 0 deletions mailu/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ initialAccount:
existingSecretPasswordKey: ""
mode: "update"

## @param api.enabled Enable the API interface
## @param api.token Token to use for the API interface - if empty, a random token will be generated and saved in a secret
## @param api.existingSecret Name of the existing secret to retrieve the API token - if set, the token will be ignored
## @param api.existingSecretTokenKey Name of the key in the existing secret to use for the API token
## @param api.webPath Path for the API interface
api:
enabled: false
token: ""
existingSecret: ""
existingSecretTokenKey: "api-token"
webPath: "/api"

## @param subnet Change this if you're using different address ranges for pods (IPv4)
subnet: 10.42.0.0/16

Expand Down

0 comments on commit 0d313fa

Please sign in to comment.