feat(api): add email configuration
This commit is contained in:
parent
001466f8fd
commit
c2c0be1fbc
|
@ -1,3 +1,5 @@
|
|||
from typing import Literal, Optional
|
||||
|
||||
from libretime_shared.config import (
|
||||
BaseConfig,
|
||||
DatabaseConfig,
|
||||
|
@ -5,6 +7,20 @@ from libretime_shared.config import (
|
|||
RabbitMQConfig,
|
||||
StorageConfig,
|
||||
)
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class EmailConfig(BaseModel):
|
||||
from_email: str = "no-reply@libretime.org"
|
||||
|
||||
host: str = "localhost"
|
||||
port: int = 25
|
||||
user: str = ""
|
||||
password: str = ""
|
||||
encryption: Optional[Literal["ssl/tls", "starttls"]] = None
|
||||
timeout: Optional[int] = None
|
||||
key_file: Optional[str] = None
|
||||
cert_file: Optional[str] = None
|
||||
|
||||
|
||||
class Config(BaseConfig):
|
||||
|
@ -12,3 +28,4 @@ class Config(BaseConfig):
|
|||
database: DatabaseConfig = DatabaseConfig()
|
||||
rabbitmq: RabbitMQConfig = RabbitMQConfig()
|
||||
storage: StorageConfig = StorageConfig()
|
||||
email: EmailConfig = EmailConfig()
|
||||
|
|
|
@ -73,3 +73,20 @@ LANGUAGE_CODE = "en-us"
|
|||
TIME_ZONE = "UTC"
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Email
|
||||
# https://docs.djangoproject.com/en/4.2/topics/email/
|
||||
|
||||
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
||||
|
||||
EMAIL_HOST = CONFIG.email.host
|
||||
EMAIL_PORT = CONFIG.email.port
|
||||
EMAIL_HOST_USER = CONFIG.email.user
|
||||
EMAIL_HOST_PASSWORD = CONFIG.email.password
|
||||
EMAIL_USE_SSL = CONFIG.email.encryption == "ssl/tls" # implicit
|
||||
EMAIL_USE_TLS = CONFIG.email.encryption == "starttls" # explicit
|
||||
EMAIL_TIMEOUT = CONFIG.email.timeout
|
||||
EMAIL_SSL_KEYFILE = CONFIG.email.key_file
|
||||
EMAIL_SSL_CERTFILE = CONFIG.email.cert_file
|
||||
|
||||
DEFAULT_FROM_EMAIL = CONFIG.email.from_email
|
||||
|
|
|
@ -18,6 +18,7 @@ from .prod import (
|
|||
DATABASES,
|
||||
DEBUG,
|
||||
DEFAULT_AUTO_FIELD,
|
||||
DEFAULT_FROM_EMAIL,
|
||||
INSTALLED_APPS,
|
||||
LANGUAGE_CODE,
|
||||
LOGGING,
|
||||
|
@ -34,6 +35,11 @@ from .prod import (
|
|||
WSGI_APPLICATION,
|
||||
)
|
||||
|
||||
# Email
|
||||
# https://docs.djangoproject.com/en/4.2/topics/email/
|
||||
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
# Testing
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#test-runner
|
||||
|
||||
|
|
|
@ -70,6 +70,35 @@ rabbitmq:
|
|||
# > default is libretime
|
||||
password: ${RABBITMQ_DEFAULT_PASS}
|
||||
|
||||
email:
|
||||
# Sender email address to use when sending emails.
|
||||
# > default is no-reply@libretime.org
|
||||
from_address: no-reply@libretime.org
|
||||
|
||||
# The hostname of the SMTP server.
|
||||
# > default is localhost
|
||||
host: localhost
|
||||
# The port of the SMTP server.
|
||||
# > default is 25
|
||||
port: 25
|
||||
# Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally
|
||||
# on port 465) or a STARTTLS (explicit) connection (generally on port 587) when
|
||||
# talking to the SMTP server.
|
||||
# > must be one of (ssl/tls, starttls)
|
||||
encryption:
|
||||
# The username to use for the SMTP server.
|
||||
# > default is ""
|
||||
user: ""
|
||||
# The password to use for the SMTP server.
|
||||
# > default is ""
|
||||
password: ""
|
||||
# Timeout in seconds for blocking operations like the connection attempt.
|
||||
timeout:
|
||||
# The path to a PEM-formatted certificate chain file to use for the connection.
|
||||
cert_file:
|
||||
# The path to a PEM-formatted private key file to use for the connection.
|
||||
key_file:
|
||||
|
||||
playout:
|
||||
# Liquidsoap connection host.
|
||||
# > default is localhost
|
||||
|
|
|
@ -70,6 +70,35 @@ rabbitmq:
|
|||
# > default is libretime
|
||||
password: libretime
|
||||
|
||||
email:
|
||||
# Sender email address to use when sending emails.
|
||||
# > default is no-reply@libretime.org
|
||||
from_address: no-reply@libretime.org
|
||||
|
||||
# The hostname of the SMTP server.
|
||||
# > default is localhost
|
||||
host: localhost
|
||||
# The port of the SMTP server.
|
||||
# > default is 25
|
||||
port: 25
|
||||
# Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally
|
||||
# on port 465) or a STARTTLS (explicit) connection (generally on port 587) when
|
||||
# talking to the SMTP server.
|
||||
# > must be one of (ssl/tls, starttls)
|
||||
encryption:
|
||||
# The username to use for the SMTP server.
|
||||
# > default is ""
|
||||
user: ""
|
||||
# The password to use for the SMTP server.
|
||||
# > default is ""
|
||||
password: ""
|
||||
# Timeout in seconds for blocking operations like the connection attempt.
|
||||
timeout:
|
||||
# The path to a PEM-formatted certificate chain file to use for the connection.
|
||||
cert_file:
|
||||
# The path to a PEM-formatted private key file to use for the connection.
|
||||
key_file:
|
||||
|
||||
playout:
|
||||
# Liquidsoap connection host.
|
||||
# > default is localhost
|
||||
|
|
|
@ -70,6 +70,35 @@ rabbitmq:
|
|||
# > default is libretime
|
||||
password: libretime
|
||||
|
||||
email:
|
||||
# Sender email address to use when sending emails.
|
||||
# > default is no-reply@libretime.org
|
||||
from_address: no-reply@libretime.org
|
||||
|
||||
# The hostname of the SMTP server.
|
||||
# > default is localhost
|
||||
host: localhost
|
||||
# The port of the SMTP server.
|
||||
# > default is 25
|
||||
port: 25
|
||||
# Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally
|
||||
# on port 465) or a STARTTLS (explicit) connection (generally on port 587) when
|
||||
# talking to the SMTP server.
|
||||
# > must be one of (ssl/tls, starttls)
|
||||
encryption:
|
||||
# The username to use for the SMTP server.
|
||||
# > default is ""
|
||||
user: ""
|
||||
# The password to use for the SMTP server.
|
||||
# > default is ""
|
||||
password: ""
|
||||
# Timeout in seconds for blocking operations like the connection attempt.
|
||||
timeout:
|
||||
# The path to a PEM-formatted certificate chain file to use for the connection.
|
||||
cert_file:
|
||||
# The path to a PEM-formatted private key file to use for the connection.
|
||||
key_file:
|
||||
|
||||
playout:
|
||||
# Liquidsoap connection host.
|
||||
# > default is localhost
|
||||
|
|
|
@ -151,6 +151,65 @@ rabbitmq:
|
|||
password: "some_random_generated_secret!"
|
||||
```
|
||||
|
||||
## Email
|
||||
|
||||
The `email` section configure a SMTP server used to send emails.
|
||||
|
||||
```yml
|
||||
email:
|
||||
# Sender email address to use when sending emails.
|
||||
# > default is no-reply@libretime.org
|
||||
from_address: no-reply@libretime.org
|
||||
|
||||
# The hostname of the SMTP server.
|
||||
# > default is localhost
|
||||
host: localhost
|
||||
# The port of the SMTP server.
|
||||
# > default is 25
|
||||
port: 25
|
||||
# Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally
|
||||
# on port 465) or a STARTTLS (explicit) connection (generally on port 587) when
|
||||
# talking to the SMTP server.
|
||||
# > must be one of (ssl/tls, starttls)
|
||||
encryption:
|
||||
# The username to use for the SMTP server.
|
||||
# > default is ""
|
||||
user: ""
|
||||
# The password to use for the SMTP server.
|
||||
# > default is ""
|
||||
password: ""
|
||||
# Timeout in seconds for blocking operations like the connection attempt.
|
||||
timeout:
|
||||
# The path to a PEM-formatted certificate chain file to use for the connection.
|
||||
cert_file:
|
||||
# The path to a PEM-formatted private key file to use for the connection.
|
||||
key_file:
|
||||
```
|
||||
|
||||
:::info
|
||||
|
||||
Below are 2 common email configuration example:
|
||||
|
||||
```yml
|
||||
email:
|
||||
host: mail.gandi.net
|
||||
port: 587
|
||||
encryption: starttls
|
||||
user: some_user
|
||||
password: some_password!
|
||||
```
|
||||
|
||||
```yml
|
||||
email:
|
||||
host: mail.gandi.net
|
||||
port: 465
|
||||
encryption: ssl/tls
|
||||
user: some_user
|
||||
password: some_password!
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## Playout
|
||||
|
||||
The `playout` section configure anything related to the playout service.
|
||||
|
|
|
@ -70,6 +70,35 @@ rabbitmq:
|
|||
# > default is libretime
|
||||
password: libretime
|
||||
|
||||
email:
|
||||
# Sender email address to use when sending emails.
|
||||
# > default is no-reply@libretime.org
|
||||
from_address: no-reply@libretime.org
|
||||
|
||||
# The hostname of the SMTP server.
|
||||
# > default is localhost
|
||||
host: localhost
|
||||
# The port of the SMTP server.
|
||||
# > default is 25
|
||||
port: 25
|
||||
# Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally
|
||||
# on port 465) or a STARTTLS (explicit) connection (generally on port 587) when
|
||||
# talking to the SMTP server.
|
||||
# > must be one of (ssl/tls, starttls)
|
||||
encryption:
|
||||
# The username to use for the SMTP server.
|
||||
# > default is ""
|
||||
user: ""
|
||||
# The password to use for the SMTP server.
|
||||
# > default is ""
|
||||
password: ""
|
||||
# Timeout in seconds for blocking operations like the connection attempt.
|
||||
timeout:
|
||||
# The path to a PEM-formatted certificate chain file to use for the connection.
|
||||
cert_file:
|
||||
# The path to a PEM-formatted private key file to use for the connection.
|
||||
key_file:
|
||||
|
||||
playout:
|
||||
# Liquidsoap connection host.
|
||||
# > default is localhost
|
||||
|
|
|
@ -65,6 +65,11 @@ class Schema implements ConfigurationInterface
|
|||
/**/->scalarNode('password')->defaultValue('libretime')->end()
|
||||
->end()->end()
|
||||
|
||||
// Email schema
|
||||
->arrayNode('email')
|
||||
/**/->ignoreExtraKeys()
|
||||
->end()
|
||||
|
||||
// Storage schema
|
||||
->arrayNode('storage')->addDefaultsIfNotSet()->children()
|
||||
/**/->scalarNode('path')->defaultValue('/srv/libretime/')
|
||||
|
|
Loading…
Reference in New Issue