Created
April 15, 2024 22:07
-
-
Save RomanAVolodin/48981f0550171f4c0cd5b2bfd66edf21 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from pathlib import Path | |
from fastapi_mail import ConnectionConfig | |
from faststream.rabbit import RabbitQueue | |
from pydantic import Field, EmailStr | |
from pydantic_settings import BaseSettings, SettingsConfigDict | |
class DataBaseSettings(BaseSettings): | |
model_config = SettingsConfigDict(env_prefix='notifications_postgres_') | |
user: str = ... | |
password: str = ... | |
db: str = ... | |
host: str = ... | |
port: int = ... | |
@property | |
def url(self): | |
return f'postgresql+psycopg://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}' | |
class EmailSettings(BaseSettings): | |
model_config = SettingsConfigDict(env_prefix='mailer_') | |
host: str = ... | |
port: int = ... | |
user: str = ... | |
password: str = ... | |
encryption: str = 'tcp' | |
from_email: EmailStr = ... | |
from_name: str = ... | |
mail_ssl_tls: bool = Field(..., alias='MAILER_SSL_TLS') | |
@property | |
def config(self): | |
return ConnectionConfig( | |
MAIL_FROM_NAME=self.from_name, | |
MAIL_USERNAME=self.from_email, | |
MAIL_PASSWORD=self.password, | |
MAIL_FROM=self.from_email, | |
MAIL_PORT=self.port, | |
MAIL_SERVER=self.host, | |
MAIL_STARTTLS=False, | |
MAIL_SSL_TLS=self.mail_ssl_tls, | |
TEMPLATE_FOLDER=Path(__file__).parent / 'templates' / 'email', | |
) | |
class Settings(BaseSettings): | |
debug_mode: bool = True | |
notifications_app_port: int = 8000 | |
project_name: str = 'Notifications api service' | |
project_description: str = 'Light api microservice' | |
db: DataBaseSettings = DataBaseSettings() | |
email: EmailSettings = EmailSettings() | |
log_sql_queries: bool = True | |
auth_jwt_secret_key: str = ... | |
auth_jwt__algorithm: str = 'HS256' | |
grpc_auth_server_host: str = ... | |
grpc_auth_server_port: int = ... | |
rabbitmq_host: str = ... | |
rabbitmq_port: int = 5672 | |
rabbitmq_user: str = Field(..., alias='RABBITMQ_DEFAULT_USER') | |
rabbitmq_pass: str = Field(..., alias='RABBITMQ_DEFAULT_PASS') | |
rabbitmq_queue_name: str = Field(..., alias='RABBITMQ_NOTIFICATIONS_QUEUE') | |
grpc_port: int = Field(default=50051, alias='NOTIFICATION_GRPC_PORT') | |
settings = Settings() | |
queue_for_notifications = RabbitQueue(settings.rabbitmq_queue_name, durable=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment