-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
from pathlib import Path | ||
|
||
from fastapi import Request | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
class SMTPSettings(BaseSettings): | ||
class SMTSettings(BaseSettings): | ||
model_config = SettingsConfigDict(env_prefix="SMTP_") | ||
tls: bool = True | ||
|
||
use_tls: bool = False | ||
port: int = 587 | ||
host: str | ||
username: str | ||
password: str | ||
sender: str | ||
host: str = "localhost" | ||
username: str = "syftbox" | ||
password: str = "syftbox" | ||
email_sender: str = "noreply@openmined.org" | ||
|
||
|
||
class ServerSettings(BaseSettings): | ||
model_config = SettingsConfigDict(env_prefix="SYFTBOX_") | ||
|
||
data_folder: Path = Path("data") | ||
snapshot_folder: Path = Path("data/snapshot") | ||
user_file_path: Path = Path("data/users.json") | ||
smtp: "SMTPSettings" = SMTPSettings() | ||
smtp: SMTSettings = SMTSettings() | ||
|
||
@property | ||
def folders(self): | ||
def folders(self) -> list[Path]: | ||
return [self.data_folder, self.snapshot_folder] | ||
|
||
|
||
def get_server_settings(request: Request) -> ServerSettings: | ||
return request.state.server_settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from syftbox.server.settings import ServerSettings | ||
|
||
|
||
def test_server_settings_from_env(): | ||
os.environ["SYFTBOX_DATA_FOLDER"] = "data_folder" | ||
os.environ["SYFTBOX_SNAPSHOT_FOLDER"] = "data_folder/snapshot_folder" | ||
os.environ["SYFTBOX_USER_FILE_PATH"] = "data_folder/user_file_path.json" | ||
|
||
settings = ServerSettings() | ||
print(settings) | ||
assert settings.data_folder == Path("data_folder") | ||
assert settings.snapshot_folder == Path("data_folder/snapshot_folder") | ||
assert settings.user_file_path == Path("data_folder/user_file_path.json") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.