2018-01-01 21:54:03 +01:00
|
|
|
import os
|
2023-02-25 10:41:27 +01:00
|
|
|
from typing import Type, Union
|
2018-01-14 20:49:35 +01:00
|
|
|
|
2020-07-14 22:03:56 +02:00
|
|
|
from dramatiq.brokers.redis import RedisBroker
|
|
|
|
from dramatiq.brokers.stub import StubBroker
|
2018-01-01 21:54:03 +01:00
|
|
|
from flask import current_app
|
2020-09-16 18:58:11 +02:00
|
|
|
from sqlalchemy.pool import NullPool
|
2018-01-01 21:54:03 +01:00
|
|
|
|
2023-02-25 10:41:27 +01:00
|
|
|
broker: Union[Type['RedisBroker'], Type['StubBroker']] = (
|
|
|
|
StubBroker
|
|
|
|
if os.getenv("APP_SETTINGS") == "fittrackee.config.TestingConfig"
|
|
|
|
else RedisBroker
|
|
|
|
)
|
2020-07-14 22:03:56 +02:00
|
|
|
|
2022-11-19 20:17:58 +01:00
|
|
|
XDIST_WORKER = (
|
|
|
|
f"_{os.getenv('PYTEST_XDIST_WORKER')}"
|
|
|
|
if os.getenv('PYTEST_XDIST_WORKER')
|
|
|
|
else ''
|
|
|
|
)
|
|
|
|
|
2018-01-01 21:54:03 +01:00
|
|
|
|
2017-12-16 21:00:46 +01:00
|
|
|
class BaseConfig:
|
|
|
|
DEBUG = False
|
|
|
|
TESTING = False
|
|
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
|
BCRYPT_LOG_ROUNDS = 13
|
|
|
|
TOKEN_EXPIRATION_DAYS = 30
|
|
|
|
TOKEN_EXPIRATION_SECONDS = 0
|
2020-05-10 17:08:18 +02:00
|
|
|
PASSWORD_TOKEN_EXPIRATION_SECONDS = 3600
|
2020-09-16 18:58:11 +02:00
|
|
|
UPLOAD_FOLDER = os.path.join(
|
|
|
|
os.getenv('UPLOAD_FOLDER', current_app.root_path), 'uploads'
|
|
|
|
)
|
2018-01-01 21:54:03 +01:00
|
|
|
PICTURE_ALLOWED_EXTENSIONS = {'jpg', 'png', 'gif'}
|
2021-01-10 11:16:43 +01:00
|
|
|
WORKOUT_ALLOWED_EXTENSIONS = {'gpx', 'zip'}
|
2021-01-20 16:47:00 +01:00
|
|
|
TEMPLATES_FOLDER = os.path.join(current_app.root_path, 'emails/templates')
|
2020-05-17 16:42:44 +02:00
|
|
|
UI_URL = os.environ.get('UI_URL')
|
|
|
|
EMAIL_URL = os.environ.get('EMAIL_URL')
|
|
|
|
SENDER_EMAIL = os.environ.get('SENDER_EMAIL')
|
2022-04-23 18:04:20 +02:00
|
|
|
CAN_SEND_EMAILS = False
|
2020-07-14 22:03:56 +02:00
|
|
|
DRAMATIQ_BROKER = broker
|
2020-09-16 13:01:15 +02:00
|
|
|
TILE_SERVER = {
|
|
|
|
'URL': os.environ.get(
|
|
|
|
'TILE_SERVER_URL',
|
2023-09-12 19:19:10 +02:00
|
|
|
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
2020-09-16 13:01:15 +02:00
|
|
|
),
|
|
|
|
'ATTRIBUTION': os.environ.get(
|
|
|
|
'MAP_ATTRIBUTION',
|
|
|
|
'© <a href="http://www.openstreetmap.org/copyright" '
|
|
|
|
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a>'
|
|
|
|
' contributors',
|
|
|
|
),
|
2021-07-16 19:17:17 +02:00
|
|
|
'DEFAULT_STATICMAP': (
|
2022-07-13 08:54:09 +02:00
|
|
|
os.environ.get('DEFAULT_STATICMAP', 'false').lower() == 'true'
|
2021-07-16 19:17:17 +02:00
|
|
|
),
|
2022-07-13 10:47:03 +02:00
|
|
|
'STATICMAP_SUBDOMAINS': os.environ.get('STATICMAP_SUBDOMAINS', ''),
|
2020-09-16 13:01:15 +02:00
|
|
|
}
|
2022-07-02 19:25:07 +02:00
|
|
|
TRANSLATIONS_FOLDER = os.path.join(
|
|
|
|
current_app.root_path, 'emails/translations'
|
|
|
|
)
|
2022-10-31 11:31:14 +01:00
|
|
|
LANGUAGES = [
|
|
|
|
'en',
|
|
|
|
'fr',
|
|
|
|
'de',
|
2022-12-14 12:23:35 +01:00
|
|
|
'it',
|
2023-04-05 20:02:52 +02:00
|
|
|
'nb',
|
2022-11-30 10:31:53 +01:00
|
|
|
'nl',
|
2023-04-05 20:02:52 +02:00
|
|
|
'es',
|
|
|
|
'gl',
|
2023-06-24 19:14:02 +02:00
|
|
|
'pl',
|
2022-10-31 11:31:14 +01:00
|
|
|
]
|
2022-06-08 11:19:14 +02:00
|
|
|
OAUTH2_TOKEN_EXPIRES_IN = {
|
|
|
|
'authorization_code': 864000, # 10 days
|
2023-07-14 19:23:29 +02:00
|
|
|
'refresh_token': 864000, # 10 days
|
2022-06-08 11:19:14 +02:00
|
|
|
}
|
|
|
|
OAUTH2_REFRESH_TOKEN_GENERATOR = True
|
2023-03-01 16:30:44 +01:00
|
|
|
DATA_EXPORT_EXPIRATION = 24 # hours
|
2017-12-16 21:00:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DevelopmentConfig(BaseConfig):
|
|
|
|
DEBUG = True
|
2018-05-01 11:52:38 +02:00
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
|
2022-05-28 20:01:14 +02:00
|
|
|
SECRET_KEY = 'development key' # nosec
|
2017-12-16 21:00:46 +01:00
|
|
|
BCRYPT_LOG_ROUNDS = 4
|
2020-07-14 22:03:56 +02:00
|
|
|
DRAMATIQ_BROKER_URL = os.getenv('REDIS_URL', 'redis://')
|
2017-12-16 21:00:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestingConfig(BaseConfig):
|
|
|
|
DEBUG = True
|
2018-04-09 22:09:58 +02:00
|
|
|
TESTING = True
|
2022-11-19 20:17:58 +01:00
|
|
|
SQLALCHEMY_DATABASE_URI = (
|
|
|
|
os.environ.get('DATABASE_TEST_URL', '') + XDIST_WORKER
|
|
|
|
)
|
|
|
|
UPLOAD_FOLDER = os.path.join(
|
|
|
|
os.getenv('UPLOAD_FOLDER', current_app.root_path),
|
|
|
|
'uploads' + XDIST_WORKER,
|
|
|
|
)
|
2022-05-28 20:01:14 +02:00
|
|
|
SECRET_KEY = 'test key' # nosec
|
2017-12-16 21:00:46 +01:00
|
|
|
BCRYPT_LOG_ROUNDS = 4
|
|
|
|
TOKEN_EXPIRATION_DAYS = 0
|
2023-10-04 10:39:31 +02:00
|
|
|
TOKEN_EXPIRATION_SECONDS = 60
|
|
|
|
PASSWORD_TOKEN_EXPIRATION_SECONDS = 60
|
2021-07-14 14:28:02 +02:00
|
|
|
UI_URL = 'http://0.0.0.0:5000'
|
|
|
|
SENDER_EMAIL = 'fittrackee@example.com'
|
2022-06-08 11:19:14 +02:00
|
|
|
OAUTH2_TOKEN_EXPIRES_IN = {
|
|
|
|
'authorization_code': 60,
|
2023-07-14 19:23:29 +02:00
|
|
|
'refresh_token': 60,
|
2022-06-08 11:19:14 +02:00
|
|
|
}
|
2020-09-16 18:58:11 +02:00
|
|
|
|
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
class End2EndTestingConfig(TestingConfig):
|
|
|
|
DRAMATIQ_BROKER_URL = os.getenv('REDIS_URL', 'redis://')
|
|
|
|
|
2020-09-16 18:58:11 +02:00
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
class ProductionConfig(BaseConfig):
|
2020-09-16 18:58:11 +02:00
|
|
|
DEBUG = False
|
|
|
|
# https://docs.sqlalchemy.org/en/13/core/pooling.html#using-connection-pools-with-multiprocessing-or-os-fork # noqa
|
|
|
|
SQLALCHEMY_ENGINE_OPTIONS = (
|
|
|
|
{'poolclass': NullPool}
|
2021-07-17 12:33:11 +02:00
|
|
|
if os.getenv('DATABASE_DISABLE_POOLING', 'False') == 'True'
|
2020-09-16 18:58:11 +02:00
|
|
|
else {}
|
|
|
|
)
|
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
|
|
|
|
SECRET_KEY = os.getenv('APP_SECRET_KEY')
|
|
|
|
DRAMATIQ_BROKER_URL = os.getenv('REDIS_URL', 'redis://')
|