Skip to content

Commit 55be461

Browse files
committed
misc: support email and ui plugin configuration through helm values
1 parent 49f7104 commit 55be461

10 files changed

Lines changed: 67 additions & 13 deletions

File tree

cli/entry_points/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def initialize_database(self) -> None:
168168
description="This key is utilized by the product demo",
169169
)
170170

171-
action_args = {"from_address": "notify@example.com", "recipients": [], "template": "NotifyTemplate"}
171+
action_args = {"recipients": [], "template": "NotifyTemplate"}
172172
action = Action.create(
173173
name="Send Email", action_impl="SEND_EMAIL", company=company, action_args=action_args
174174
)

common/actions/send_email_action.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class SendEmailAction(BaseAction):
22-
required_arguments = {"from_address", "recipients", "template"}
22+
required_arguments = {"recipients", "template"}
2323
requires_action_template = True
2424

2525
def _run(self, event: EVENT_TYPE, rule: Rule, journey_id: Optional[UUID]) -> ActionResult:
@@ -29,8 +29,8 @@ def _run(self, event: EVENT_TYPE, rule: Rule, journey_id: Optional[UUID]) -> Act
2929
return ActionResult(False, None, e)
3030
try:
3131
response = EmailService.send_email(
32-
self.arguments["smtp_config"],
33-
self.arguments["from_address"],
32+
self.arguments.get("smtp_config", {}),
33+
self.arguments.get("from_address"),
3434
self.arguments["recipients"],
3535
self.arguments["template"],
3636
context,

common/email/email_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ class EmailService:
1717
@staticmethod
1818
def send_email(
1919
smtp_config: dict,
20-
from_address: str,
20+
from_address: str | None,
2121
recipients: list[str],
2222
template_name: str,
2323
template_context_vars: Mapping,
2424
) -> dict:
2525
try:
26+
from_address = from_address or settings.SMTP["from_address"]
2627
content, subject = HandlebarsEmailRenderer.render(template_name, template_context_vars)
2728
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
2829
message = MIMEMultipart("alternative")

common/schemas/action_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SMTPConfigSchema(Schema):
1616

1717

1818
class EmailActionArgsSchema(Schema):
19-
from_address = Str(validate=not_empty(max=255))
19+
from_address = Str(required=False, validate=not_empty(max=255))
2020
template = Str(validate=not_empty(max=255))
2121
recipients = List(Email(), required=True, validate=Length(max=50))
2222
smtp_config = Nested(SMTPConfigSchema(), required=False)

common/tests/unit/actions/test_send_email_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_send_email_constructor(action):
5858

5959

6060
@pytest.mark.unit
61-
@pytest.mark.parametrize("argument", ("template", "from_address", "recipients"))
61+
@pytest.mark.parametrize("argument", ("template", "recipients"))
6262
def test_send_email_constructor_missing_action_argument(argument, action):
6363
rule_action_args = {"template": "TestTemplateNested", "recipients": ["a@example.com"]}
6464
action.action_args = {"from_address": "test@domain.com", "recipients": ["success@example.com"]}

conf/cloud.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ class ReconnectingPooledMySQLDatabase(ReconnectMixin, PooledMySQLDatabase):
3232
"password": os.environ.get("SMTP_PASSWORD"),
3333
"endpoint": os.environ.get("SMTP_ENDPOINT"),
3434
"port": int(os.environ.get("SMTP_PORT", 465)),
35+
"from_address": os.environ.get("SMTP_FROM_ADDRESS"),
3536
}
3637
"""Settings for connecting to the SMTP email server."""

conf/minikube.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,13 @@ class ReconnectingPooledMySQLDatabase(ReconnectMixin, PooledMySQLDatabase):
2828

2929
RULE_REFRESH_SECONDS = 1
3030
"""Number of seconds to cache rules in rules engine"""
31+
32+
33+
SMTP: dict[str, object] = {
34+
"username": os.environ.get("SMTP_USER"),
35+
"password": os.environ.get("SMTP_PASSWORD"),
36+
"endpoint": os.environ.get("SMTP_ENDPOINT"),
37+
"port": int(os.environ.get("SMTP_PORT", 465)),
38+
"from_address": os.environ.get("SMTP_FROM_ADDRESS"),
39+
}
40+
"""Settings for connecting to the SMTP email server."""

conf/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"password": "",
1717
"endpoint": "",
1818
"port": 25,
19+
"from_address": "",
1920
}
2021
"""Dummy SMTP parameters to please unit tests."""

deploy/charts/observability-app/templates/_environments.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,22 @@ Environment
8282
secretKeyRef:
8383
name: {{ .Values.observability.services_secrets_name | quote }}
8484
key: SMTP_PASSWORD
85+
- name: SMTP_FROM_ADDRESS
86+
valueFrom:
87+
secretKeyRef:
88+
name: {{ .Values.observability.services_secrets_name | quote }}
89+
key: SMTP_FROM_ADDRESS
90+
optional: true
91+
{{- else if .Values.observability.smtp -}}
92+
- name: SMTP_ENDPOINT
93+
value: {{ .Values.observability.smtp.endpoint | quote }}
94+
- name: SMTP_PORT
95+
value: {{ .Values.observability.smtp.port | quote }}
96+
- name: SMTP_USER
97+
value: {{ .Values.observability.smtp.user | quote }}
98+
- name: SMTP_PASSWORD
99+
value: {{ .Values.observability.smtp.password | quote }}
100+
- name: SMTP_FROM_ADDRESS
101+
value: {{ .Values.observability.smtp.from_address | quote }}
85102
{{- end -}}
86103
{{- end -}}

deploy/charts/observability-app/templates/observability-ui.yaml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@ spec:
3030
serviceAccountName: {{ include "observability.serviceAccountName" . }}
3131
securityContext:
3232
{{- toYaml .Values.observability_ui.podSecurityContext | nindent 8 }}
33-
{{- if .Values.observability_ui.environmentJson }}
33+
{{- if or .Values.observability_ui.environmentJson .Values.observability_ui.manifestJson }}
3434
volumes:
3535
- name: {{ include "observability.observability_ui.name" . }}-configmap-volume
3636
configMap:
3737
name: {{ include "observability.observability_ui.name" . }}-configmap
3838
items:
39+
{{- if .Values.observability_ui.environmentJson }}
3940
- key: "environment.json"
4041
path: "environment.json"
42+
{{- end }}
43+
{{- if .Values.observability_ui.manifestJson }}
44+
- key: "module-federation.manifest.json"
45+
path: "module-federation.manifest.json"
46+
{{- end }}
4147
{{- end }}
4248
containers:
4349
- name: {{ include "observability.observability_ui.name" . }}
@@ -51,16 +57,29 @@ spec:
5157
protocol: TCP
5258
resources:
5359
{{- toYaml .Values.observability_ui.resources | nindent 12 }}
54-
{{- if .Values.observability_api.hostname }}
5560
env:
61+
{{- if .Values.observability_api.hostname }}
5662
- name: OBSERVABILITY_API_HOSTNAME
5763
value: {{ tpl .Values.observability_api.hostname . | quote }}
58-
{{- end }}
59-
{{- if .Values.observability_ui.environmentJson }}
64+
{{- end }}
65+
{{- if .Values.observability_ui.csp_extra }}
66+
- name: OBSERVABILITY_CSP_EXTRA
67+
value: {{ tpl .Values.observability_ui.csp_extra . | quote }}
68+
{{- end }}
69+
{{- if or .Values.observability_ui.environmentJson .Values.observability_ui.manifestJson }}
6070
volumeMounts:
61-
- mountPath: /observability_ui/shell/environments
71+
{{- if .Values.observability_ui.environmentJson }}
72+
- mountPath: /observability_ui/shell/environments/environment.json
73+
name: {{ include "observability.observability_ui.name" . }}-configmap-volume
74+
readOnly: true
75+
subPath: environment.json
76+
{{- end }}
77+
{{- if .Values.observability_ui.manifestJson }}
78+
- mountPath: /observability_ui/shell/assets/module-federation.manifest.json
6279
name: {{ include "observability.observability_ui.name" . }}-configmap-volume
6380
readOnly: true
81+
subPath: module-federation.manifest.json
82+
{{- end }}
6483
{{- end }}
6584
{{- with .Values.observability_ui.nodeSelector }}
6685
nodeSelector:
@@ -96,7 +115,7 @@ spec:
96115
{{- end }}
97116
selector:
98117
{{- include "observability.observability_ui.selectorLabels" . | nindent 4 }}
99-
{{- if .Values.observability_ui.environmentJson }}
118+
{{- if or .Values.observability_ui.environmentJson .Values.observability_ui.manifestJson }}
100119
---
101120
apiVersion: v1
102121
kind: ConfigMap
@@ -106,6 +125,11 @@ metadata:
106125
{{- include "observability.labels" . | nindent 4 }}
107126
{{- include "observability.observability_ui.selectorLabels" . | nindent 4 }}
108127
data:
128+
{{- if .Values.observability_ui.environmentJson }}
109129
environment.json: {{ .Values.observability_ui.environmentJson | toPrettyJson | quote }}
130+
{{- end }}
131+
{{- if .Values.observability_ui.manifestJson }}
132+
module-federation.manifest.json: {{ .Values.observability_ui.manifestJson | toPrettyJson | quote }}
133+
{{- end }}
110134
{{- end }}
111135
{{- end }}

0 commit comments

Comments
 (0)