-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.txt
More file actions
552 lines (493 loc) · 17 KB
/
output.txt
File metadata and controls
552 lines (493 loc) · 17 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
=== Environment Setup ===
[sudo] password for toor:
Hit:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble InRelease
Hit:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
38 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3 is already the newest version (3.12.3-0ubuntu2).
The following additional packages will be installed:
libpython3-dev libpython3.12-dev python3-dev python3-pkg-resources
python3-setuptools python3-wheel python3.12-dev python3.12-venv
Suggested packages:
python-setuptools-doc
The following NEW packages will be installed:
libpython3-dev libpython3.12-dev python3-dev python3-pip python3-setuptools
python3-venv python3-wheel python3.12-dev python3.12-venv
The following packages will be upgraded:
python3-pkg-resources
1 upgraded, 9 newly installed, 0 to remove and 38 not upgraded.
Need to get 9,814 kB of archives.
After this operation, 39.2 MB of additional disk space will be used.
Get:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble-updates/main amd64 python3-pkg-resources all 68.1.2-2ubuntu1.2 [174 kB]
Get:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 python3-setuptools all 68.1.2-2ubuntu1 [752 kB]
Get:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 python3-wheel all 0.42.0-2 [53.1 kB]
Get:4 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble-updates/main amd64 python3-pip all 24.0+dfsg-1ubuntu1.1 [1,367 kB]
Get:5 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 libpython3.12-dev amd64 3.12.3-1ubuntu0.3 [5,672 kB]
Get:6 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 libpython3-dev amd64 3.12.3-0ubuntu2 [10.4 kB]
Get:7 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 python3.12-dev amd64 3.12.3-1ubuntu0.3 [498 kB]
Get:8 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 python3-dev amd64 3.12.3-0ubuntu2 [26.7 kB]
Get:9 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 python3.12-venv amd64 3.12.3-1ubuntu0.3 [5,716 B]
Get:10 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 python3-venv amd64 3.12.3-0ubuntu2 [1,216 B]
Fetched 9,814 kB in 2s (5,102 kB/s)
Selecting previously unselected package python3-setuptools.
(Reading database ... 108422 files and directories currently installed.)
Preparing to unpack .../0-python3-pkg-resources_68.1.2-2ubuntu1.2_all.deb ...
Unpacking python3-pkg-resources (68.1.2-2ubuntu1.2) over (68.1.2-2ubuntu1) ...
Selecting previously unselected package python3-wheel.
Preparing to unpack .../1-python3-wheel_0.42.0-2_all.deb ...
Unpacking python3-wheel (0.42.0-2) ...
Selecting previously unselected package python3-setuptools.
Preparing to unpack .../2-python3-setuptools_68.1.2-2ubuntu1_all.deb ...
Unpacking python3-setuptools (68.1.2-2ubuntu1) ...
Selecting previously unselected package python3-pip.
Preparing to unpack .../3-python3-pip_24.0+dfsg-1ubuntu1.1_all.deb ...
Unpacking python3-pip (24.0+dfsg-1ubuntu1.1) ...
Selecting previously unselected package libpython3.12-dev:amd64.
Preparing to unpack .../4-libpython3.12-dev_3.12.3-1ubuntu0.3_amd64.deb ...
Unpacking libpython3.12-dev:amd64 (3.12.3-1ubuntu0.3) ...
Selecting previously unselected package libpython3-dev:amd64.
Preparing to unpack .../5-libpython3-dev_3.12.3-0ubuntu2_amd64.deb ...
Unpacking libpython3-dev:amd64 (3.12.3-0ubuntu2) ...
Selecting previously unselected package python3.12-dev.
Preparing to unpack .../6-python3.12-dev_3.12.3-1ubuntu0.3_amd64.deb ...
Unpacking python3.12-dev (3.12.3-1ubuntu0.3) ...
Selecting previously unselected package python3-dev.
Preparing to unpack .../7-python3-dev_3.12.3-0ubuntu2_amd64.deb ...
Unpacking python3-dev (3.12.3-0ubuntu2) ...
Selecting previously unselected package python3.12-venv.
Preparing to unpack .../8-python3.12-venv_3.12.3-1ubuntu0.3_amd64.deb ...
Unpacking python3.12-venv (3.12.3-1ubuntu0.3) ...
Selecting previously unselected package python3-venv.
Preparing to unpack .../9-python3-venv_3.12.3-0ubuntu2_amd64.deb ...
Unpacking python3-venv (3.12.3-0ubuntu2) ...
Setting up python3-pkg-resources (68.1.2-2ubuntu1.2) ...
Setting up python3-setuptools (68.1.2-2ubuntu1) ...
Setting up python3-wheel (0.42.0-2) ...
Setting up python3-pip (24.0+dfsg-1ubuntu1.1) ...
Setting up python3.12-venv (3.12.3-1ubuntu0.3) ...
Setting up python3-venv (3.12.3-0ubuntu2) ...
Setting up libpython3.12-dev:amd64 (3.12.3-1ubuntu0.3) ...
Setting up libpython3-dev:amd64 (3.12.3-0ubuntu2) ...
Setting up python3.12-dev (3.12.3-1ubuntu0.3) ...
Setting up python3-dev (3.12.3-0ubuntu2) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.4) ...
Requirement already satisfied: pip in ./venv/lib/python3.12/site-packages (24.0)
Collecting pip
Downloading pip-25.0.1-py3-none-any.whl.metadata (3.7 kB)
Downloading pip-25.0.1-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 12.4 MB/s eta 0:00:00
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 24.0
Uninstalling pip-24.0:
Successfully uninstalled pip-24.0
Successfully installed pip-25.0.1
Collecting jinja2
Downloading jinja2-3.1.6-py3-none-any.whl.metadata (2.9 kB)
Collecting pyyaml
Downloading PyYAML-6.0.2-cp312-cp312-manylinux2014_x86_64.whl.metadata (2.1 kB)
Collecting jsonschema
Downloading jsonschema-4.25.1-py3-none-any.whl.metadata (7.6 kB)
Collecting MarkupSafe>=2.0 (from jinja2)
Downloading markupsafe-3.0.2-cp312-cp312-manylinux2014_x86_64.whl.metadata (4.0 kB)
Collecting attrs>=22.2.0 (from jsonschema)
Downloading attrs-25.3.0-py3-none-any.whl.metadata (10 kB)
Collecting jsonschema-specifications>=2023.03.6 (from jsonschema)
Downloading jsonschema_specifications-2025.4.1-py3-none-any.whl.metadata (2.9 kB)
Collecting referencing>=0.28.4 (from jsonschema)
Downloading referencing-0.36.2-py3-none-any.whl.metadata (2.8 kB)
Collecting rpds-py>=0.7.1 (from jsonschema)
Downloading rpds_py-0.24.0-cp312-cp312-manylinux_2_17_x86_64.whl.metadata (4.1 kB)
Collecting typing-extensions>=4.4.0 (from referencing>=0.28.4->jsonschema)
Downloading typing_extensions-4.13.2-py3-none-any.whl.metadata (3.0 kB)
Downloading jinja2-3.1.6-py3-none-any.whl (134 kB)
Downloading PyYAML-6.0.2-cp312-cp312-manylinux2014_x86_64.whl (763 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 763.1/763.1 kB 13.1 MB/s eta 0:00:00
Downloading jsonschema-4.25.1-py3-none-any.whl (90 kB)
Downloading attrs-25.3.0-py3-none-any.whl (63 kB)
Downloading jsonschema_specifications-2025.4.1-py3-none-any.whl (18 kB)
Downloading markupsafe-3.0.2-cp312-cp312-manylinux2014_x86_64.whl (23 kB)
Downloading referencing-0.36.2-py3-none-any.whl (26 kB)
Downloading rpds_py-0.24.0-cp312-cp312-manylinux_2_17_x86_64.whl (387 kB)
Downloading typing_extensions-4.13.2-py3-none-any.whl (45 kB)
Installing collected packages: typing-extensions, rpds-py, pyyaml, MarkupSafe, attrs, referencing, jinja2, jsonschema-specifications, jsonschema
Successfully installed MarkupSafe-3.0.2 attrs-25.3.0 jinja2-3.1.6 jsonschema-4.25.1 jsonschema-specifications-2025.4.1 pyyaml-6.0.2 referencing-0.36.2 rpds-py-0.24.0 typing-extensions-4.13.2
=== Step 1: Create Project Structure ===
total 24
drwxrwxr-x 7 toor toor 4096 Apr 12 11:08 .
drwxr-x--- 7 toor toor 4096 Apr 12 11:06 ..
drwxrwxr-x 2 toor toor 4096 Apr 12 11:08 configs
drwxrwxr-x 2 toor toor 4096 Apr 12 11:08 data
-rw-rw-r-- 1 toor toor 0 Apr 12 11:08 generator.py
drwxrwxr-x 2 toor toor 4096 Apr 12 11:08 schemas
drwxrwxr-x 2 toor toor 4096 Apr 12 11:08 templates
-rw-rw-r-- 1 toor toor 0 Apr 12 11:08 validator.py
drwxrwxr-x 5 toor toor 4096 Apr 12 11:07 venv
=== Step 2: Create Configuration Templates ===
=== Environment: {{ environment }} ===
nginx.conf.j2
=== Application Configuration ===
app_config.yaml.j2 nginx.conf.j2
=== Step 3: Create Sample Data Files ===
app_name: myapp
environment: development
version: 1.0.0
listen_port: 8080
server_name: dev.myapp.local
ssl_enabled: false
backend_servers:
- host: 127.0.0.1
port: 3000
weight: 1
db_host: localhost
db_port: 5432
db_name: myapp_dev
db_pool_size: 5
cache_enabled: true
cache_host: localhost
cache_port: 6379
cache_ttl: 1800
log_level: DEBUG
log_outputs:
- console
- file
app_name: myapp
environment: production
version: 1.0.0
listen_port: 443
server_name: myapp.com
ssl_enabled: true
ssl_cert_path: /etc/ssl/certs/myapp.crt
ssl_key_path: /etc/ssl/private/myapp.key
backend_servers:
- host: 10.0.1.10
port: 3000
weight: 2
- host: 10.0.1.11
port: 3000
weight: 2
- host: 10.0.1.12
port: 3000
weight: 1
custom_headers:
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
db_host: db.internal.myapp.com
db_port: 5432
db_name: myapp_prod
db_pool_size: 20
cache_enabled: true
cache_type: redis
cache_host: cache.internal.myapp.com
cache_port: 6379
cache_ttl: 3600
log_level: INFO
log_format: json
log_outputs:
- file
- syslog
=== Step 4: Implement Configuration Generator ===
-rwxrwxr-x 1 toor toor 4306 Apr 12 11:19 generator.py
=== Step 5: Create Validation Schema ===
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"application",
"database",
"logging"
],
"properties": {
"application": {
"type": "object",
"required": [
"name",
"environment",
"version"
],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"environment": {
"type": "string",
"enum": [
"development",
"staging",
"production"
]
},
"version": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
}
}
},
"database": {
"type": "object",
"required": [
"host",
"port",
"name"
],
"properties": {
"host": {
"type": "string"
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
},
"name": {
"type": "string"
},
"pool_size": {
"type": "integer",
"minimum": 1
}
}
},
"logging": {
"type": "object",
"required": [
"level",
"outputs"
],
"properties": {
"level": {
"type": "string",
"enum": [
"DEBUG",
"INFO",
"WARNING",
"ERROR"
]
},
"format": {
"type": "string"
},
"outputs": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
}
}
}
}
}
=== Step 6: Implement Configuration Validator ===
-rwxrwxr-x 1 toor toor 4304 Apr 12 11:25 validator.py
=== Step 1: Complete the Generator Implementation ===
0
=== Step 2: Complete the Validator Implementation ===
0
=== Step 3: Generate Development Configurations ===
Generated: configs/app_config.yaml
Generated: configs/nginx.conf
Summary: generated 2 file(s) from data/dev_config.yaml
total 8.0K
-rw-rw-r-- 1 toor toor 250 Apr 12 11:28 app_config.yaml
-rw-rw-r-- 1 toor toor 362 Apr 12 11:28 nginx.conf
# Nginx Configuration for myapp
# Environment: development
upstream myapp_backend {
server 127.0.0.1:3000 weight=1;
}
server {
listen 8080;
server_name dev.myapp.local;
location / {
proxy_pass http://myapp_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
access_log /var/log/nginx/myapp_access.log;
error_log /var/log/nginx/myapp_error.log;
}
=== Environment: development ===
# Application Configuration
application:
name: myapp
environment: development
version: 1.0.0
database:
host: localhost
port: 5432
name: myapp_dev
pool_size: 5
ssl_mode: prefer
cache:
enabled: True
type: redis
host: localhost
port: 6379
ttl: 1800
logging:
level: DEBUG
format: json
outputs:
- console
- file
=== Step 4: Generate Production Configurations ===
Generated: configs/app_config.yaml
Generated: configs/nginx.conf
Summary: generated 2 file(s) from data/prod_config.yaml
Generated: configs/nginx.conf
Summary: generated 1 file(s) from data/dev_config.yaml
--- configs/nginx_dev.conf 2026-04-12 11:30:48.781214553 +0000
+++ configs/nginx_prod.conf 2026-04-12 11:30:13.204892144 +0000
@@ -1,15 +1,21 @@
# Nginx Configuration for myapp
-# Environment: development
+# Environment: production
upstream myapp_backend {
- server 127.0.0.1:3000 weight=1;
+ server 10.0.1.10:3000 weight=2;
+ server 10.0.1.11:3000 weight=2;
+ server 10.0.1.12:3000 weight=1;
}
server {
- listen 8080;
- server_name dev.myapp.local;
+ listen 443;
+ server_name myapp.com;
+ ssl_certificate /etc/ssl/certs/myapp.crt;
+ ssl_certificate_key /etc/ssl/private/myapp.key;
location / {
proxy_pass http://myapp_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Frame-Options DENY;
+ proxy_set_header X-Content-Type-Options nosniff;
}
access_log /var/log/nginx/myapp_access.log;
Generated: configs/app_config.yaml
Generated: configs/nginx.conf
Summary: generated 2 file(s) from data/prod_config.yaml
=== Step 5: Validate Generated Configurations ===
VALID: configs/app_config.yaml matches schema app_config_schema.json
VALID: Nginx configuration passed basic syntax validation
=== Step 6: Test Edge Cases ===
=== Missing version field ===
app_name: testapp
environment: development
# Missing version field
db_host: localhost
db_port: 5432
Generated: configs/app_config.yaml
Summary: generated 1 file(s) from data/invalid_config.yaml
# Application Configuration
application:
name: testapp
environment: development
version:
database:
host: localhost
port: 5432
name:
pool_size: 10
ssl_mode: prefer
cache:
enabled: True
logging:
level: INFO
format: json
outputs:
=== Application Configuration ===
INVALID: configs/app_config.yaml does not match schema app_config_schema.json
- Validation error at 'application.version': None is not of type 'string'
VALID: configs/app_config.yaml matches schema app_config_schema.json
=== Verify Generator Functionality ===
Nginx config: OK
App config: OK
# Nginx Configuration for myapp
upstream myapp_backend {
proxy_pass http://myapp_backend;
access_log /var/log/nginx/myapp_access.log;
error_log /var/log/nginx/myapp_error.log;
App name found: OK
=== Nginx Configuration for myapp ===
environment: production
Environment set: OK
=== Verify Validator Functionality ===
VALID: configs/app_config.yaml matches schema app_config_schema.json
Exit code: 0
1
1
=== Create Verification Script ===
=== Check file content ===
=== Lab 16 Verification ===
OK
[PASS] Generator module loads
OK
[PASS] Validator module loads
[PASS] Configuration files generated
[PASS] Nginx config contains upstream block
=== Verification Complete ===
=== Issue: Jinja2 template not found ===
['app_config.yaml.j2', 'nginx.conf.j2']
=== Issue: YAML parsing errors ===
0
=== Issue: Validation fails unexpectedly ===
{'application': {'environment': 'production', 'name': 'myapp', 'version': '1.0.0'},
'cache': {'enabled': True,
'host': 'cache.internal.myapp.com',
'port': 6379,
'ttl': 3600,
'type': 'redis'},
'database': {'host': 'db.internal.myapp.com',
'name': 'myapp_prod',
'pool_size': 20,
'port': 5432,
'ssl_mode': 'require'},
'logging': {'format': 'json', 'level': 'INFO', 'outputs': ['file', 'syslog']}}
=== Issue: Generated config has extra whitespace ===
# Nginx Configuration for myapp
# Environment: production
upstream myapp_backend {
server 10.0.1.10:3000 weight=2;
server 10.0.1.11:3000 weight=2;
server 10.0.1.12:3000 weight=1;
}
server {
listen 443;
server_name myapp.com;
ssl_certificate /etc/ssl/certs/myapp.crt;
ssl_certificate_key /etc/ssl/private/myapp.key;
location / {
proxy_pass http://myapp_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Frame-Options DENY;
proxy_set_header X-Content-Type-Options nosniff;
}
access_log /var/log/nginx/myapp_access.log;
error_log /var/log/nginx/myapp_error.log;
}
=== Final Directory Snapshot ===
./configs/app_config.yaml
./configs/nginx.conf
./configs/nginx.test.conf
./configs/nginx_dev.conf
./configs/nginx_prod.conf
./data/dev_config.yaml
./data/invalid_config.yaml
./data/prod_config.yaml
./generator.py
./schemas/app_config_schema.json
./templates/app_config.yaml.j2
./templates/nginx.conf.j2
./validator.py
./verify_lab.sh