feat(api): add email configuration

This commit is contained in:
jo 2023-05-31 13:58:18 +02:00 committed by Kyle Robbertze
parent 001466f8fd
commit c2c0be1fbc
9 changed files with 220 additions and 0 deletions

View File

@ -1,3 +1,5 @@
from typing import Literal, Optional
from libretime_shared.config import ( from libretime_shared.config import (
BaseConfig, BaseConfig,
DatabaseConfig, DatabaseConfig,
@ -5,6 +7,20 @@ from libretime_shared.config import (
RabbitMQConfig, RabbitMQConfig,
StorageConfig, 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): class Config(BaseConfig):
@ -12,3 +28,4 @@ class Config(BaseConfig):
database: DatabaseConfig = DatabaseConfig() database: DatabaseConfig = DatabaseConfig()
rabbitmq: RabbitMQConfig = RabbitMQConfig() rabbitmq: RabbitMQConfig = RabbitMQConfig()
storage: StorageConfig = StorageConfig() storage: StorageConfig = StorageConfig()
email: EmailConfig = EmailConfig()

View File

@ -73,3 +73,20 @@ LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC" TIME_ZONE = "UTC"
USE_I18N = True USE_I18N = True
USE_TZ = 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

View File

@ -18,6 +18,7 @@ from .prod import (
DATABASES, DATABASES,
DEBUG, DEBUG,
DEFAULT_AUTO_FIELD, DEFAULT_AUTO_FIELD,
DEFAULT_FROM_EMAIL,
INSTALLED_APPS, INSTALLED_APPS,
LANGUAGE_CODE, LANGUAGE_CODE,
LOGGING, LOGGING,
@ -34,6 +35,11 @@ from .prod import (
WSGI_APPLICATION, WSGI_APPLICATION,
) )
# Email
# https://docs.djangoproject.com/en/4.2/topics/email/
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Testing # Testing
# https://docs.djangoproject.com/en/3.2/ref/settings/#test-runner # https://docs.djangoproject.com/en/3.2/ref/settings/#test-runner

View File

@ -70,6 +70,35 @@ rabbitmq:
# > default is libretime # > default is libretime
password: ${RABBITMQ_DEFAULT_PASS} 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: playout:
# Liquidsoap connection host. # Liquidsoap connection host.
# > default is localhost # > default is localhost

View File

@ -70,6 +70,35 @@ rabbitmq:
# > default is libretime # > default is libretime
password: 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: playout:
# Liquidsoap connection host. # Liquidsoap connection host.
# > default is localhost # > default is localhost

View File

@ -70,6 +70,35 @@ rabbitmq:
# > default is libretime # > default is libretime
password: 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: playout:
# Liquidsoap connection host. # Liquidsoap connection host.
# > default is localhost # > default is localhost

View File

@ -151,6 +151,65 @@ rabbitmq:
password: "some_random_generated_secret!" 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 ## Playout
The `playout` section configure anything related to the playout service. The `playout` section configure anything related to the playout service.

View File

@ -70,6 +70,35 @@ rabbitmq:
# > default is libretime # > default is libretime
password: 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: playout:
# Liquidsoap connection host. # Liquidsoap connection host.
# > default is localhost # > default is localhost

View File

@ -65,6 +65,11 @@ class Schema implements ConfigurationInterface
/**/->scalarNode('password')->defaultValue('libretime')->end() /**/->scalarNode('password')->defaultValue('libretime')->end()
->end()->end() ->end()->end()
// Email schema
->arrayNode('email')
/**/->ignoreExtraKeys()
->end()
// Storage schema // Storage schema
->arrayNode('storage')->addDefaultsIfNotSet()->children() ->arrayNode('storage')->addDefaultsIfNotSet()->children()
/**/->scalarNode('path')->defaultValue('/srv/libretime/') /**/->scalarNode('path')->defaultValue('/srv/libretime/')