mirror of
https://github.com/taylanbakircioglu/haproxy-openmanager.git
synced 2026-09-21 10:03:29 +00:00
Feature: Full UI support for use_backend rules editing
✨ New Features: - Added use_backend_rules validator to Frontend model - UI now supports editing use_backend rules from Frontend Management page - Array to string conversion for use_backend rules in edit modal 🔧 Model Improvements: - Changed use_backend_rules field type from Optional[str] to Any (list support) - Added parse_use_backend_rules validator (same logic as ACL/redirect rules) - Handles 3 formats: Array, Textarea string (newline-separated), JSON string 💡 UI Improvements: - Frontend edit modal automatically converts use_backend array to multi-line text - Users can edit routing rules line by line in textarea - Format: 'use_backend BackendName if condition' ✅ Complete Workflow: 1. Bulk Import: Config parsed → ACL + use_backend stored as array 2. Frontend Edit: Arrays converted to multi-line string in textarea 3. User edits ACL/use_backend rules in UI 4. Save: Textarea string → validator → array → database 5. Config Generation: Array → HAProxy config format Example workflow: Parse: ['use_backend API if is_api'] → Edit UI: 'use_backend API if is_api' (textarea) → User edits: 'use_backend API_v2 if is_api_v2' → Save: ['use_backend API_v2 if is_api_v2'] → Generate: 'use_backend API_v2 if is_api_v2' (HAProxy config)
This commit is contained in:
@@ -20,7 +20,7 @@ class FrontendConfig(BaseModel):
|
||||
ssl_verify: Optional[str] = "optional"
|
||||
acl_rules: Any = []
|
||||
redirect_rules: Any = []
|
||||
use_backend_rules: Optional[str] = None
|
||||
use_backend_rules: Any = [] # Changed from Optional[str] to Any for list support
|
||||
request_headers: Optional[str] = None
|
||||
response_headers: Optional[str] = None
|
||||
tcp_request_rules: Optional[str] = None
|
||||
@@ -72,6 +72,25 @@ class FrontendConfig(BaseModel):
|
||||
return v
|
||||
return []
|
||||
|
||||
@validator('use_backend_rules', pre=True, always=True)
|
||||
def parse_use_backend_rules(cls, v):
|
||||
if isinstance(v, str):
|
||||
v = v.strip()
|
||||
# Handle JSON string (e.g., "[]" or "[\"rule1\", \"rule2\"]")
|
||||
if v.startswith('[') and v.endswith(']'):
|
||||
try:
|
||||
parsed = json.loads(v)
|
||||
if isinstance(parsed, list):
|
||||
return parsed
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
# Handle newline-separated string
|
||||
if v:
|
||||
return [rule.strip() for rule in v.split('\n') if rule.strip()]
|
||||
elif isinstance(v, list):
|
||||
return v
|
||||
return []
|
||||
|
||||
# CRITICAL VALIDATION RULES FOR HAPROXY
|
||||
@validator('name')
|
||||
def validate_name(cls, v):
|
||||
|
||||
@@ -531,12 +531,19 @@ const FrontendManagement = () => {
|
||||
formattedRedirectRules = frontend.redirect_rules.join('\n');
|
||||
}
|
||||
|
||||
// Format use_backend rules for textarea (array to multi-line string)
|
||||
let formattedUseBackendRules = frontend.use_backend_rules;
|
||||
if (Array.isArray(frontend.use_backend_rules)) {
|
||||
formattedUseBackendRules = frontend.use_backend_rules.join('\n');
|
||||
}
|
||||
|
||||
form.setFieldsValue({
|
||||
...frontend,
|
||||
ssl_enabled: frontend.ssl_enabled || false,
|
||||
ssl_certificate_ids: sslCertIds,
|
||||
acl_rules: formattedAclRules,
|
||||
redirect_rules: formattedRedirectRules
|
||||
redirect_rules: formattedRedirectRules,
|
||||
use_backend_rules: formattedUseBackendRules
|
||||
});
|
||||
|
||||
// Update SSL field visibility after setting values
|
||||
|
||||
Reference in New Issue
Block a user