config.py 3.63 KB
Newer Older
Barbora Kompišová's avatar
Barbora Kompišová committed
1
2
3
4
5
6
7
8
9
"""
Main Configuration module
Defines all the configuration types for the Flask Application
Types:
    - Development
    - Production
    - Test
"""

10
import datetime
Barbora Kompišová's avatar
Barbora Kompišová committed
11
import os
Barbora Kompišová's avatar
Barbora Kompišová committed
12
13
import tempfile

Peter Stanko's avatar
Peter Stanko committed
14
from portal import logger
Barbora Kompišová's avatar
Barbora Kompišová committed
15
16
from portal.tools import paths

Peter Stanko's avatar
Peter Stanko committed
17
log = logger.get_logger(__name__)
Barbora Kompišová's avatar
Barbora Kompišová committed
18
19


Peter Stanko's avatar
Peter Stanko committed
20
21
# pylint: disable=too-few-public-methods

Barbora Kompišová's avatar
Barbora Kompišová committed
22
class Config(object):
Barbora Kompišová's avatar
Barbora Kompišová committed
23
24
25
26
    """Base configuration
    """
    PROJECT_ROOT = paths.ROOT_DIR
    APP_DIR = paths.ROOT_DIR / 'portal'
Barbora Kompišová's avatar
Barbora Kompišová committed
27
28
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
    JWT_SECRET_KEY = os.environ.get('JWT_SECRET_KEY') or 'super-safe'
29
30
    JWT_REFRESH_TOKEN_EXPIRES = datetime.timedelta(days=30)
    JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(hours=1)
Barbora Kompišová's avatar
Barbora Kompišová committed
31
    API_PREFIX = os.environ.get('PORTAL_API_PREFIX', default="/api/v1.0/")
32
    CORS_SUPPORT_CREDENTIALS = True
33
34
35
36
    BROKER_URL = os.getenv('CELERY_BROKER_URL', 'redis://localhost:6379/0')
    CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', BROKER_URL)
    SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI',
                                        f"sqlite:///{paths.ROOT_DIR}/devel.db")
Peter Stanko's avatar
Peter Stanko committed
37
    EMAIL_BACKEND = 'tests.utils.email_backend.EmailBackend'
38
    PORTAL_LOG_CONFIG = False
39
    PORTAL_DATA_WORKER_DOMAIN = os.getenv('PORTAL_DATA_WORKER_DOMAIN', 'localhost')
40
    LDAP_URL = os.getenv('LDAP_URL', None)
Peter Stanko's avatar
Peter Stanko committed
41
42
43
    GITLAB_BASE_DOMAIN = "gitlab.fi.muni.cz"
    GIT_REPO_BASE = os.getenv('GIT_REPO_BASE', f"git@{GITLAB_BASE_DOMAIN}")
    GITLAB_URL = os.getenv('GITLAB_URL', None)
Barbora Kompišová's avatar
Barbora Kompišová committed
44
45
46


class DevelopmentConfig(Config):
Barbora Kompišová's avatar
Barbora Kompišová committed
47
48
    """Development configuration
    """
49
50
    SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI',
                                        f"sqlite:///{paths.ROOT_DIR}/devel.db")
Barbora Kompišová's avatar
Barbora Kompišová committed
51
    SQLALCHEMY_TRACK_MODIFICATIONS = True
52
53
    PORTAL_ENV = 'dev'
    PORTAL_ADMIN_USER_PASSWORD = '789789'
Barbora Kompišová's avatar
Barbora Kompišová committed
54
    DEBUG = True
55
    PORTAL_STORAGE_BASE_DIR = f"{tempfile.gettempdir()}/kontr-portal"
Peter Stanko's avatar
Peter Stanko committed
56
57
58
    PORTAL_STORAGE_TEST_FILES_DIR = f"{PORTAL_STORAGE_BASE_DIR}/test-files"
    PORTAL_STORAGE_WORKSPACE_DIR = f"{PORTAL_STORAGE_BASE_DIR}/workspace"
    PORTAL_STORAGE_SUBMISSIONS_DIR = f"{PORTAL_STORAGE_BASE_DIR}/submissions"
59
60
    PORTAL_STORAGE_RESULTS_DIR = f"{PORTAL_STORAGE_BASE_DIR}/results"
    UPLOAD_FOLDER = f"{PORTAL_STORAGE_BASE_DIR}/upload"
61
    EMAIL_BACKEND = 'tests.utils.email_backend.EmailBackend'
Peter Stanko's avatar
Peter Stanko committed
62
63
64
    EMAIL_HOST = "localhost"
    EMAIL_PORT = "1025"
    EMAIL_DEFAULT_FROM = "kontr@example.com"
65
    PORTAL_LOG_CONFIG = True
Barbora Kompišová's avatar
Barbora Kompišová committed
66
67
68


class ProductionConfig(Config):
Barbora Kompišová's avatar
Barbora Kompišová committed
69
70
    """Production configuration
    """
Barbora Kompišová's avatar
Barbora Kompišová committed
71
72
73
74
    DEBUG = False


class TestConfig(Config):
Barbora Kompišová's avatar
Barbora Kompišová committed
75
76
    """Test configuration
    """
Barbora Kompišová's avatar
Barbora Kompišová committed
77
78
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    TESTING = True
Barbora Kompišová's avatar
Barbora Kompišová committed
79
    SQLALCHEMY_DATABASE_URI = 'sqlite://'
Barbora Kompišová's avatar
Barbora Kompišová committed
80
    # SQLALCHEMY_ECHO = True
81
82
83
84
85
    PORTAL_ENV = 'dev'
    PORTAL_STORAGE_BASE_DIR = tempfile.mkdtemp()
    PORTAL_STORAGE_TEST_FILES_DIR = f"{PORTAL_STORAGE_BASE_DIR}/test-files"
    PORTAL_STORAGE_WORKSPACE_DIR = f"{PORTAL_STORAGE_BASE_DIR}/workspace"
    PORTAL_STORAGE_SUBMISSIONS_DIR = f"{PORTAL_STORAGE_BASE_DIR}/submissions"
86
    PORTAL_STORAGE_RESULTS_DIR = f"{PORTAL_STORAGE_BASE_DIR}/results"
87
88
    PORTAL_ADMIN_USER_USERNAME = 'admin'
    PORTAL_ADMIN_USER_PASSWORD = '789789'
Barbora Kompišová's avatar
Barbora Kompišová committed
89
    EMAIL_BACKEND = 'tests.utils.email_backend.EmailBackend'
Barbora Kompišová's avatar
Barbora Kompišová committed
90
91
92
    EMAIL_HOST = "localhost"
    EMAIL_PORT = "1025"
    EMAIL_DEFAULT_FROM = "kontr@example.com"
93
    CORS_ORIGINS = '*'
Peter Stanko's avatar
Peter Stanko committed
94
    BROKER_URL = 'redis://'
95
    CELERY_RESULT_BACKEND = BROKER_URL
96
    PORTAL_LOG_CONFIG = False
Peter Stanko's avatar
Peter Stanko committed
97
    GIT_REPO_BASE = os.getenv('GIT_REPO_BASE', f"git@gitlab.local")
Barbora Kompišová's avatar
Barbora Kompišová committed
98
99


Peter Stanko's avatar
Peter Stanko committed
100
101
102
# pylint: enable=too-few-public-methods


Barbora Kompišová's avatar
Barbora Kompišová committed
103
CONFIGURATIONS = dict(
104
    dev=DevelopmentConfig(),
Barbora Kompišová's avatar
Barbora Kompišová committed
105
106
    test=TestConfig(),
    production=ProductionConfig()
107
)