forked from RealTimeWeb/Blockpy-Server
-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.py
143 lines (123 loc) · 4.67 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
Flask Configuration File
Checks for a "secrets.json" file and uses that to add in private settings such as Secret Key.
"""
import os
from datetime import timedelta
class DefaultConfig:
"""
General settings for all configurations
"""
# Meta Site Data
SITE_NAME = 'BlockPy Public'
SYS_ADMINS = ['Unknown']
SHOW_ABOUT_PAGE = True
SITE_VERSION = 6
PREFERRED_LOGIN_URL = None
# Testing and Dev
DEBUG = True
TESTING = True
PROFILE_RUNTIME = False
# Filesystem settings
ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
STATIC_DIRECTORY = os.path.join(ROOT_DIRECTORY, 'static')
UPLOADS_DIR = os.path.join(STATIC_DIRECTORY, 'uploads')
REPORT_DIR = os.path.join(STATIC_DIRECTORY, 'reports')
BLOCKPY_LOG_DIR = os.path.join(ROOT_DIRECTORY, 'logs')
TIMING_LOG_DIR = os.path.join(ROOT_DIRECTORY, 'logs', 'timing')
ERROR_FILE_PATH = os.path.join(ROOT_DIRECTORY, 'logs', 'blockpy_errors.log')
EVENTS_FILE_PATH = os.path.join(ROOT_DIRECTORY, 'logs', 'blockpy_events.log')
TASKS_FILE_PATH = os.path.join(ROOT_DIRECTORY, 'logs', 'blockpy_tasks.log')
CANVAS_DIR = os.path.join(STATIC_DIRECTORY, 'canvas', 'courses')
API_DOCUMENTATION_PATH = "./models/generated/openapi.json"
# Library Files
LIB_PEDAL_DIR = os.path.join(STATIC_DIRECTORY, 'libs', 'pedal')
LIB_CURRICULUM_CTVT_DIR = os.path.join(STATIC_DIRECTORY, 'libs', 'pedal')
LIB_CURRICULUM_SNEKS_DIR = os.path.join(STATIC_DIRECTORY, 'libs', 'pedal')
LIB_DESIGNER_DIR = os.path.join(STATIC_DIRECTORY, 'libs', 'designer')
LIB_DRAFTER_DIR = os.path.join(STATIC_DIRECTORY, 'libs', 'drafter')
LIB_BLOCKPY_DIR = os.path.join(STATIC_DIRECTORY, 'libs', 'blockpy')
# External files settings
BLOCKPY_SOURCE_DIR = None
CORGIS_URL = "https://corgis-edu.github.io/corgis/datasets/"
# Default App Settings
# Maximum student code size (Defaults to 750kb)
MAXIMUM_CODE_SIZE = 750 * 1024
# Session settings
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'None'
REMEMBER_COOKIE_HTTPONLY = True
REMEMBER_COOKIE_SECURE = True
COOKIE_SAMESITE = 'None'
# TODO: This is for API access with Canvas - nothing actually needs it yet.
COURSE_TOKENS = os.path.join(ROOT_DIRECTORY, 'settings/course_tokens.yaml')
# Debug toolbar settings
DEBUG_TB_INTERCEPT_REDIRECTS = False
# configured for Gmail by default
MAIL_SERVER = "smtp.gmail.com"
MAIL_PORT = 465
MAIL_USE_SSL = True
SECURITY_EMAIL_SENDER = "BlockPy Administrator"
# User Registration Stuff
SECURITY_CONFIRMABLE = False
SECURITY_REGISTERABLE = True
SECURITY_RECOVERABLE = True
SECURITY_CHANGEABLE = True
SECURITY_URL_PREFIX = '/users'
SECURITY_POST_LOGIN_VIEW = "/blockpy"
SECURITY_POST_CONFIRM_VIEW = "/blockpy"
SECURITY_PASSWORD_HASH = 'bcrypt'
SECURITY_DEFAULT_REMEMBER_ME = True
# enforce CSRF protection for session / browser - but allow token-based
# API calls to go through
SECURITY_CSRF_PROTECT_MECHANISMS = ["session", "basic"]
SECURITY_CSRF_IGNORE_UNAUTH_ENDPOINTS = True
# Security settings
CSRF_ENABLED = True
WTF_CSRF_ENABLED = True
# Send Cookie with csrf-token. This is the default for Axios and Angular.
SECURITY_CSRF_COOKIE_NAME = "XSRF-TOKEN"
WTF_CSRF_CHECK_DEFAULT = False
WTF_CSRF_TIME_LIMIT = None
# SQLAlchemy settings
SQLALCHEMY_TRACK_MODIFICATIONS = False
# Flask JWT Extended
# Need to check json/query_string for opening URLs on the page (JWT has to be passed manually)
JWT_TOKEN_LOCATION = ["headers", "cookies", "json", "query_string"]
JWT_COOKIE_SAMESITE = 'None'
JWT_COOKIE_SECURE = True
# If this is too low, could set to 30 days
JWT_ACCESS_TOKEN_EXPIRES = timedelta(days=30)
# Task Settings
TASK_DB_URI: str
TASK_QUEUE_STYLE: str
TASK_DB_SETTINGS = dict
# Logs
ROTATE_LOGS = False
# Force https URLs
PREFERRED_URL_SCHEME = 'https'
class ProductionConfig(DefaultConfig):
"""
General settings for production mode
"""
DEBUG = False
PORT = 5001
TASK_QUEUE_STYLE = "redis"
ROTATE_LOGS = True
class DevelopmentConfig(DefaultConfig):
"""
General settings for local development
"""
DEBUG = True
HOST = 'localhost'
SITE_ROOT_URL = 'localhost:5001'
TASK_QUEUE_STYLE = 'sqlite'
TASK_DB_URI = 'instance/tasks.db'
SQLALCHEMY_DATABASE_URI = 'sqlite:///../instance/main.db'
class TestConfig(DefaultConfig):
""" Simple test config with in-memory database """
TESTING = True
TASK_QUEUE_STYLE = 'sqlite'
TASK_DB_URI = 'instance/tasks.db'
SQLALCHEMY_DATABASE_URI = 'sqlite://:memory:'