11from typing import Literal
22from typing import Self
33
4- from cryptography .fernet import Fernet
54from pydantic import BaseModel
65from pydantic import EmailStr
76from pydantic import Field
@@ -32,8 +31,7 @@ class PublicEmailSettings(BaseModel):
3231 recipients : list [EmailStr ] = Field (min_length = 1 )
3332 smtp_server : str
3433 port : int
35- encrypted_password : SecretStr | None = None
36- encryption_key : SecretStr | None = None
34+ password : SecretStr | None = None
3735 instance_name : str
3836 use_starttls : bool
3937 use_login : bool
@@ -54,10 +52,6 @@ class EmailSettings(BaseSettings):
5452 """
5553 Password for the OAuth-signup email sender.
5654 """
57- FRACTAL_EMAIL_PASSWORD_KEY : SecretStr | None = None
58- """
59- Key value for `cryptography.fernet` decrypt
60- """
6155 FRACTAL_EMAIL_SMTP_SERVER : str | None = None
6256 """
6357 SMTP server for the OAuth-signup emails.
@@ -82,8 +76,7 @@ class EmailSettings(BaseSettings):
8276 FRACTAL_EMAIL_USE_LOGIN : Literal ["true" , "false" ] = "true"
8377 """
8478 Whether to use login when using the SMTP server.
85- If 'true', FRACTAL_EMAIL_PASSWORD and FRACTAL_EMAIL_PASSWORD_KEY must be
86- provided.
79+ If 'true', FRACTAL_EMAIL_PASSWORD must be provided.
8780 Accepted values: 'true', 'false'.
8881 """
8982
@@ -120,49 +113,18 @@ def validate_email_settings(self: Self) -> Self:
120113 use_starttls = self .FRACTAL_EMAIL_USE_STARTTLS == "true"
121114 use_login = self .FRACTAL_EMAIL_USE_LOGIN == "true"
122115
123- if use_login :
124- if self .FRACTAL_EMAIL_PASSWORD is None :
125- raise ValueError (
126- "'FRACTAL_EMAIL_USE_LOGIN' is 'true' but "
127- "'FRACTAL_EMAIL_PASSWORD' is not provided."
128- )
129- if self .FRACTAL_EMAIL_PASSWORD_KEY is None :
130- raise ValueError (
131- "'FRACTAL_EMAIL_USE_LOGIN' is 'true' but "
132- "'FRACTAL_EMAIL_PASSWORD_KEY' is not provided."
133- )
134- try :
135- (
136- Fernet (
137- self .FRACTAL_EMAIL_PASSWORD_KEY .get_secret_value ()
138- )
139- .decrypt (
140- self .FRACTAL_EMAIL_PASSWORD .get_secret_value ()
141- )
142- .decode ("utf-8" )
143- )
144- except Exception as e :
145- raise ValueError (
146- "Invalid pair (FRACTAL_EMAIL_PASSWORD, "
147- "FRACTAL_EMAIL_PASSWORD_KEY). "
148- f"Original error: { str (e )} ."
149- )
150- password = self .FRACTAL_EMAIL_PASSWORD .get_secret_value ()
151- else :
152- password = None
153-
154- if self .FRACTAL_EMAIL_PASSWORD_KEY is not None :
155- key = self .FRACTAL_EMAIL_PASSWORD_KEY .get_secret_value ()
156- else :
157- key = None
116+ if use_login and self .FRACTAL_EMAIL_PASSWORD is None :
117+ raise ValueError (
118+ "'FRACTAL_EMAIL_USE_LOGIN' is 'true' but "
119+ "'FRACTAL_EMAIL_PASSWORD' is not provided."
120+ )
158121
159122 self .public = PublicEmailSettings (
160123 sender = self .FRACTAL_EMAIL_SENDER ,
161124 recipients = self .FRACTAL_EMAIL_RECIPIENTS .split ("," ),
162125 smtp_server = self .FRACTAL_EMAIL_SMTP_SERVER ,
163126 port = self .FRACTAL_EMAIL_SMTP_PORT ,
164- encrypted_password = password ,
165- encryption_key = key ,
127+ password = self .FRACTAL_EMAIL_PASSWORD ,
166128 instance_name = self .FRACTAL_EMAIL_INSTANCE_NAME ,
167129 use_starttls = use_starttls ,
168130 use_login = use_login ,
0 commit comments