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