From c7bfdb03e0caa92c7940131c3e2309b288c5e3ba Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 16 Sep 2024 17:58:30 +0530 Subject: [PATCH 1/3] smtp enable flag --- .../backend/backend-statefulset.yaml | 12 ++++++---- packages/grid/helm/syft/values.yaml | 13 +++++++---- .../syft/service/notifier/notifier_service.py | 23 +++++++++++++++---- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/grid/helm/syft/templates/backend/backend-statefulset.yaml b/packages/grid/helm/syft/templates/backend/backend-statefulset.yaml index 3293056ba2a..f858f9772c3 100644 --- a/packages/grid/helm/syft/templates/backend/backend-statefulset.yaml +++ b/packages/grid/helm/syft/templates/backend/backend-statefulset.yaml @@ -111,13 +111,14 @@ spec: secretKeyRef: name: {{ .Values.mongo.secretKeyName | required "mongo.secretKeyName is required" }} key: rootPassword + {{- if .Values.server.smtp.enabled }} # SMTP - name: SMTP_HOST - value: {{ .Values.server.smtp.host | quote }} + value: {{ .Values.server.smtp.host | required "server.smtp.host is required" | quote }} - name: SMTP_PORT - value: {{ .Values.server.smtp.port | quote }} + value: {{ .Values.server.smtp.port | required "server.smtp.port is required" | quote }} - name: SMTP_USERNAME - value: {{ .Values.server.smtp.username | quote }} + value: {{ .Values.server.smtp.username | required "server.smtp.username is required" | quote }} - name: SMTP_PASSWORD {{- if .Values.server.smtp.existingSecret }} valueFrom: @@ -125,10 +126,11 @@ spec: name: {{ .Values.server.smtp.existingSecret }} key: smtpPassword {{ else }} - value: {{ .Values.server.smtp.password | quote }} + value: {{ .Values.server.smtp.password | required "server.smtp.password is required" | quote }} {{ end }} - name: EMAIL_SENDER - value: {{ .Values.server.smtp.from | quote}} + value: {{ .Values.server.smtp.from | required "server.smtp.from is required" | quote}} + {{- end }} # SeaweedFS {{- if ne .Values.server.type "gateway"}} - name: S3_ROOT_USER diff --git a/packages/grid/helm/syft/values.yaml b/packages/grid/helm/syft/values.yaml index c1cec54b441..2b8d48b2549 100644 --- a/packages/grid/helm/syft/values.yaml +++ b/packages/grid/helm/syft/values.yaml @@ -187,13 +187,16 @@ server: # SMTP Settings smtp: + enabled: false + + host: null + port: null + from: null + username: null + password: null + # Existing secret for SMTP with key 'smtpPassword' existingSecret: null - host: hostname - port: 587 - from: noreply@openmined.org - username: apikey - password: password # Extra environment vars env: null diff --git a/packages/syft/src/syft/service/notifier/notifier_service.py b/packages/syft/src/syft/service/notifier/notifier_service.py index d8c1da2530f..6ecf723253c 100644 --- a/packages/syft/src/syft/service/notifier/notifier_service.py +++ b/packages/syft/src/syft/service/notifier/notifier_service.py @@ -131,14 +131,14 @@ def turn_on( public_message="You must provide both server and port to enable notifications." ) - logging.debug("Got notifier from db") + logger.debug("Got notifier from db") skip_auth: bool = False # If no new credentials provided, check for existing ones if not (email_username and email_password): if not (notifier.email_username and notifier.email_password): skip_auth = True else: - logging.debug("No new credentials provided. Using existing ones.") + logger.debug("No new credentials provided. Using existing ones.") email_password = notifier.email_password email_username = notifier.email_username @@ -152,7 +152,7 @@ def turn_on( ) if not valid_credentials: - logging.error("Invalid SMTP credentials.") + logger.error("Invalid SMTP credentials.") raise SyftException(public_message=("Invalid SMTP credentials.")) notifier.email_password = email_password @@ -183,7 +183,7 @@ def turn_on( notifier.email_sender = email_sender notifier.active = True - logging.debug( + logger.debug( "Email credentials are valid. Updating the notifier settings in the db." ) @@ -255,6 +255,19 @@ def init_notifier( Returns: SyftSuccess """ + + if not smtp_host and not smtp_port: + logger.error( + "SMTP server and port are required to initialize the notifier." + ) + return + + if not email_username and not email_password: + logger.error( + "Email username and password are required to initialize the notifier." + ) + return + try: # Create a new NotifierStash since its a static method. notifier_stash = NotifierStash(store=server.document_store) @@ -345,7 +358,7 @@ def dispatch_notification( # If notifier is active if notifier.active and notification.email_template is not None: - logging.debug("Checking user email activity") + logger.debug("Checking user email activity") if notifier.email_activity.get(notification.email_template.__name__, None): user_activity = notifier.email_activity[ From 0bfafa6a6128457a3ad6daee1ece195717fa9df6 Mon Sep 17 00:00:00 2001 From: IonesioJunior Date: Tue, 17 Sep 2024 14:17:26 -0300 Subject: [PATCH 2/3] Fix lint --- packages/syft/src/syft/service/notifier/notifier_service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/syft/src/syft/service/notifier/notifier_service.py b/packages/syft/src/syft/service/notifier/notifier_service.py index c27089d2445..f1ba8f060b6 100644 --- a/packages/syft/src/syft/service/notifier/notifier_service.py +++ b/packages/syft/src/syft/service/notifier/notifier_service.py @@ -238,7 +238,7 @@ def init_notifier( email_sender: str | None = None, smtp_port: int | None = None, smtp_host: str | None = None, - ) -> SyftSuccess: + ) -> SyftSuccess | None: """Initialize Notifier settings for a Server. If settings already exist, it will use the existing one. If not, it will create a new one. @@ -258,13 +258,13 @@ def init_notifier( logger.error( "SMTP server and port are required to initialize the notifier." ) - return + return None if not email_username and not email_password: logger.error( "Email username and password are required to initialize the notifier." ) - return + return None try: # Create a new NotifierStash since its a static method. From 3432593ba2b0b0329a455d63840204666102541e Mon Sep 17 00:00:00 2001 From: IonesioJunior Date: Tue, 17 Sep 2024 14:35:07 -0300 Subject: [PATCH 3/3] Remove premature returns in init_notifier --- .../src/syft/service/notifier/notifier_service.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/syft/src/syft/service/notifier/notifier_service.py b/packages/syft/src/syft/service/notifier/notifier_service.py index f1ba8f060b6..37ca2979cdf 100644 --- a/packages/syft/src/syft/service/notifier/notifier_service.py +++ b/packages/syft/src/syft/service/notifier/notifier_service.py @@ -253,19 +253,6 @@ def init_notifier( Returns: SyftSuccess """ - - if not smtp_host and not smtp_port: - logger.error( - "SMTP server and port are required to initialize the notifier." - ) - return None - - if not email_username and not email_password: - logger.error( - "Email username and password are required to initialize the notifier." - ) - return None - try: # Create a new NotifierStash since its a static method. notifier_stash = NotifierStash(store=server.db)