-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapi_config.py
50 lines (42 loc) · 2.15 KB
/
webapi_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
from base_config import BaseConfigSection
from PyQt6.QtWidgets import QFormLayout
class WebAPISection(BaseConfigSection):
"""WebAPI configuration section"""
def __init__(self):
self.section_name = "WebAPI"
super().__init__()
def setup_fields(self, form_layout: QFormLayout):
"""Setup WebAPI configuration fields"""
self.add_field(form_layout, "WEBAPI_VERSION", default="2.12.0")
self.add_field(form_layout, "WEBAPI_PORT", default="8081")
self.add_field(form_layout, "WEBAPI_CONTEXT_PATH", default="/WebAPI")
self.add_field(form_layout, "WEBAPI_DB_HOST", default="postgres")
self.add_field(form_layout, "WEBAPI_DB_PORT", default="5432")
self.add_field(form_layout, "WEBAPI_DB_NAME", default="ohdsi")
self.add_field(form_layout, "WEBAPI_DB_USER", default="postgres")
self.add_field(form_layout, "WEBAPI_DB_PASS", default="postgres")
self.add_field(form_layout, "WEBAPI_DATASOURCES_JSON", default="[]")
self.add_field(form_layout, "WEBAPI_CORS_ENABLED", default="true")
self.add_field(form_layout, "WEBAPI_SECURITY_ENABLED", default="false")
def validate(self) -> list[str]:
"""Validate WebAPI configuration"""
issues = []
# Validate port numbers
for port_field in ["WEBAPI_PORT", "WEBAPI_DB_PORT"]:
port = self.fields[port_field].text()
if not port.isdigit():
issues.append(f"{port_field} must be a number")
elif not (0 <= int(port) <= 65535):
issues.append(f"{port_field} must be between 0 and 65535")
# Validate JSON
try:
import json
json.loads(self.fields["WEBAPI_DATASOURCES_JSON"].text())
except json.JSONDecodeError:
issues.append("WEBAPI_DATASOURCES_JSON must be valid JSON")
# Validate boolean fields
for bool_field in ["WEBAPI_CORS_ENABLED", "WEBAPI_SECURITY_ENABLED"]:
value = self.fields[bool_field].text().lower()
if value not in ["true", "false"]:
issues.append(f"{bool_field} must be either 'true' or 'false'")
return issues