0
# Configuration Management
1
2
Centralized configuration system for Open edX platform settings with support for defaults, user overrides, environment variables, and interactive setup. The configuration system handles all aspects of platform customization including URLs, passwords, service settings, and plugin configurations.
3
4
## Capabilities
5
6
### Configuration Loading
7
8
Load configuration from various sources with validation and merging of defaults, user settings, and environment overrides.
9
10
```python { .api }
11
def load(root: str) -> Config:
12
"""
13
Load full configuration with complete validation and all sources merged.
14
15
Args:
16
root (str): Project root directory path
17
18
Returns:
19
Config: Complete configuration dictionary with all settings
20
"""
21
22
def load_defaults() -> Config:
23
"""
24
Load only default configuration values without user customizations.
25
26
Returns:
27
Config: Default configuration dictionary
28
"""
29
30
def load_minimal(root: str) -> Config:
31
"""
32
Load minimal config (user + base) without applying defaults.
33
34
Args:
35
root (str): Project root directory path
36
37
Returns:
38
Config: Basic configuration dictionary
39
"""
40
41
def load_full(root: str) -> Config:
42
"""
43
Load complete configuration (user + base + defaults) with full validation.
44
Note: This is an internal function called by load().
45
46
Args:
47
root (str): Project root directory path
48
49
Returns:
50
Config: Complete configuration dictionary
51
"""
52
```
53
54
### Configuration Updates
55
56
Update configuration data with different sources and validation levels.
57
58
```python { .api }
59
def update_with_base(config: Config) -> None:
60
"""
61
Add base configuration settings to existing config.
62
63
Args:
64
config (Config): Configuration dictionary to update in-place
65
"""
66
67
def update_with_defaults(config: Config) -> None:
68
"""
69
Add default values for missing configuration keys.
70
71
Args:
72
config (Config): Configuration dictionary to update in-place
73
"""
74
75
def update_with_env(config: Config) -> None:
76
"""
77
Override configuration values from environment variables.
78
Environment variables should be prefixed with TUTOR_.
79
80
Args:
81
config (Config): Configuration dictionary to update in-place
82
"""
83
```
84
85
### Configuration File Operations
86
87
Save and manage configuration files on disk.
88
89
```python { .api }
90
def save_config_file(root: str, config: Config) -> None:
91
"""
92
Save configuration to config.yml file.
93
94
Args:
95
root (str): Project root directory path
96
config (Config): Configuration dictionary to save
97
"""
98
99
def config_file_path(root: str) -> str:
100
"""
101
Get the path to the config.yml file.
102
103
Args:
104
root (str): Project root directory path
105
106
Returns:
107
str: Full path to config.yml file
108
"""
109
```
110
111
### Interactive Configuration
112
113
Interactive configuration setup with prompts and validation.
114
115
```python { .api }
116
def save_config_with_prompts(root: str, config: Config, interactive: bool = False) -> Config:
117
"""
118
Save configuration with optional interactive prompts for missing values.
119
120
Args:
121
root (str): Project root directory path
122
config (Config): Base configuration dictionary
123
interactive (bool): Whether to prompt for missing values
124
125
Returns:
126
Config: Updated configuration dictionary
127
"""
128
```
129
130
### Configuration Validation
131
132
Validate configuration values and check for required settings.
133
134
```python { .api }
135
def check_config(config: Config) -> None:
136
"""
137
Validate configuration for required values and correct formats.
138
139
Args:
140
config (Config): Configuration dictionary to validate
141
142
Raises:
143
TutorError: If configuration is invalid or missing required values
144
"""
145
```
146
147
## Configuration Structure
148
149
### Core Configuration Keys
150
151
```python { .api }
152
# Platform settings
153
PLATFORM_NAME: str # Name of the Open edX platform
154
PLATFORM_DESCRIPTION: str # Platform description
155
CONTACT_EMAIL: str # Contact email address
156
157
# Domain and URL settings
158
LMS_HOST: str # Learning Management System hostname
159
CMS_HOST: str # Content Management System hostname
160
PREVIEW_LMS_HOST: str # Preview hostname
161
162
# Database settings
163
MYSQL_HOST: str # MySQL database host
164
MYSQL_PORT: int # MySQL database port
165
MYSQL_ROOT_USER: str # MySQL root username
166
MYSQL_ROOT_PASSWORD: str # MySQL root password
167
168
# Cache settings
169
REDIS_HOST: str # Redis cache host
170
REDIS_PORT: int # Redis cache port
171
172
# Security settings
173
SECRET_KEY: str # Django secret key
174
JWT_SECRET_KEY: str # JWT signing key
175
OPENEDX_SECRET_KEY: str # Open edX secret key
176
177
# Docker settings
178
DOCKER_REGISTRY: str # Docker registry for custom images
179
DOCKER_IMAGE_TAG: str # Tag for Open edX Docker images
180
181
# Plugin settings
182
PLUGINS: List[str] # List of enabled plugins
183
PLUGIN_CONFIG: Dict[str, Any] # Plugin-specific configuration
184
```
185
186
### Environment-Specific Settings
187
188
```python { .api }
189
# Local development settings
190
RUN_LMS: bool # Whether to run LMS service
191
RUN_CMS: bool # Whether to run CMS service
192
LOCAL_HOST: str # Local development hostname
193
194
# Kubernetes settings
195
K8S_NAMESPACE: str # Kubernetes namespace
196
K8S_ENABLE_HTTPS: bool # Enable HTTPS in Kubernetes
197
198
# Development settings
199
ENABLE_HTTPS: bool # Enable HTTPS
200
DEV_PROJECT_NAME: str # Development project name
201
```
202
203
## Constants
204
205
```python { .api }
206
CONFIG_FILENAME = "config.yml" # Default configuration filename
207
```
208
209
## Usage Examples
210
211
### Basic Configuration Loading
212
213
```python
214
from tutor import config
215
from tutor.commands.context import Context
216
217
# Load complete configuration
218
context = Context("/path/to/tutor/root")
219
config_data = config.load(context.root)
220
221
# Access configuration values
222
platform_name = config_data["PLATFORM_NAME"]
223
lms_host = config_data["LMS_HOST"]
224
```
225
226
### Configuration Updates
227
228
```python
229
from tutor import config
230
231
# Load and update configuration
232
config_data = config.load("/path/to/tutor/root")
233
234
# Update values
235
config_data["PLATFORM_NAME"] = "My Custom Platform"
236
config_data["CONTACT_EMAIL"] = "admin@example.com"
237
238
# Save updated configuration
239
config.save_config_file("/path/to/tutor/root", config_data)
240
```
241
242
### Environment Variable Overrides
243
244
```python
245
import os
246
from tutor import config
247
248
# Set environment variables
249
os.environ["TUTOR_PLATFORM_NAME"] = "Production Platform"
250
os.environ["TUTOR_LMS_HOST"] = "learn.example.com"
251
252
# Load configuration with environment overrides
253
config_data = config.load("/path/to/tutor/root")
254
# Values from environment variables will override config file
255
```
256
257
### Interactive Configuration
258
259
```python
260
from tutor.commands.config import save
261
from tutor.commands.context import Context
262
263
context = Context("/path/to/tutor/root")
264
265
# Run interactive configuration
266
save(
267
context=context,
268
interactive=True,
269
set_vars=[],
270
append_vars=[],
271
remove_vars=[],
272
unset_vars=[],
273
env_only=False,
274
clean_env=False
275
)
276
```
277
278
### Programmatic Configuration Changes
279
280
```python
281
from tutor import config
282
283
# Load minimal config
284
config_data = config.load_minimal("/path/to/tutor/root")
285
286
# Add specific settings
287
config_data.update({
288
"PLATFORM_NAME": "Development Platform",
289
"ENABLE_HTTPS": False,
290
"PLUGINS": ["discovery", "forum"]
291
})
292
293
# Apply defaults and save
294
config.update_with_defaults(config_data)
295
config.save_config_file("/path/to/tutor/root", config_data)
296
```