@@ -57,16 +57,12 @@ def __init__(
5757class ValidationPatterns :
5858 """Regex patterns for common validations."""
5959
60- # URL validation - must start with http:// or https://
6160 URL_PATTERN = re .compile (r"^https?://.+" )
6261
63- # Name patterns - alphanumeric with common special characters, spaces, and parentheses
6462 NAME_PATTERN = re .compile (r"^[a-zA-Z0-9._\s()\-]+$" )
6563
66- # Architecture validation
6764 ARCH_PATTERN = re .compile (r"^(x86_64|aarch64|i386|i686|ppc64|ppc64le|s390x|riscv64|noarch)$" )
6865
69- # Repository name - more permissive for repo naming conventions
7066 REPO_NAME_PATTERN = re .compile (r"^[a-zA-Z0-9._-]+$" )
7167
7268
@@ -176,7 +172,6 @@ def validate_architecture(arch: str, field_name: str = "architecture") -> str:
176172
177173 trimmed_arch = arch .strip ()
178174
179- # Check if it's a valid architecture enum value
180175 try :
181176 Architecture (trimmed_arch )
182177 except ValueError :
@@ -277,27 +272,23 @@ def validate_config_structure(config: Any, config_index: int) -> List[str]:
277272 errors .append (f"Config { config_index } : Must be a dictionary" )
278273 return errors
279274
280- # Validate required top-level keys
281275 required_keys = ["product" , "mirror" , "repositories" ]
282276 for key in required_keys :
283277 if key not in config :
284278 errors .append (f"Config { config_index } : Missing required key '{ key } '" )
285279
286- # Validate product data structure
287280 if "product" in config :
288281 product_errors = ConfigValidator .validate_product_config (
289282 config ["product" ], config_index
290283 )
291284 errors .extend (product_errors )
292285
293- # Validate mirror data structure
294286 if "mirror" in config :
295287 mirror_errors = ConfigValidator .validate_mirror_config (
296288 config ["mirror" ], config_index
297289 )
298290 errors .extend (mirror_errors )
299291
300- # Validate repositories data structure
301292 if "repositories" in config :
302293 repo_errors = ConfigValidator .validate_repositories_config (
303294 config ["repositories" ], config_index
@@ -324,15 +315,13 @@ def validate_product_config(product: Any, config_index: int) -> List[str]:
324315 errors .append (f"Config { config_index } : Product must be a dictionary" )
325316 return errors
326317
327- # Validate required product fields
328318 required_fields = ["name" , "variant" , "vendor" ]
329319 for field in required_fields :
330320 if field not in product or not product [field ]:
331321 errors .append (
332322 f"Config { config_index } : Product missing required field '{ field } '"
333323 )
334324
335- # Validate product name format if present
336325 if product .get ("name" ):
337326 try :
338327 FieldValidator .validate_name (
@@ -361,15 +350,13 @@ def validate_mirror_config(mirror: Any, config_index: int) -> List[str]:
361350 errors .append (f"Config { config_index } : Mirror must be a dictionary" )
362351 return errors
363352
364- # Validate required mirror fields
365353 required_fields = ["name" , "match_variant" , "match_major_version" , "match_arch" ]
366354 for field in required_fields :
367355 if field not in mirror or mirror [field ] is None :
368356 errors .append (
369357 f"Config { config_index } : Mirror missing required field '{ field } '"
370358 )
371359
372- # Validate mirror name format if present
373360 if mirror .get ("name" ):
374361 try :
375362 FieldValidator .validate_name (
@@ -378,7 +365,6 @@ def validate_mirror_config(mirror: Any, config_index: int) -> List[str]:
378365 except ValidationError as e :
379366 errors .append (f"Config { config_index } : Mirror name '{ mirror ['name' ]} ' - { e .message } " )
380367
381- # Validate architecture if present
382368 if mirror .get ("match_arch" ):
383369 try :
384370 FieldValidator .validate_architecture (
@@ -387,7 +373,6 @@ def validate_mirror_config(mirror: Any, config_index: int) -> List[str]:
387373 except ValidationError as e :
388374 errors .append (f"Config { config_index } : Mirror architecture '{ mirror ['match_arch' ]} ' - { e .message } " )
389375
390- # Validate major version is numeric if present
391376 if mirror .get ("match_major_version" ) is not None :
392377 if (
393378 not isinstance (mirror ["match_major_version" ], int )
@@ -397,7 +382,6 @@ def validate_mirror_config(mirror: Any, config_index: int) -> List[str]:
397382 f"Config { config_index } : Mirror match_major_version must be a non-negative integer"
398383 )
399384
400- # Validate minor version is numeric if present
401385 if mirror .get ("match_minor_version" ) is not None :
402386 if (
403387 not isinstance (mirror ["match_minor_version" ], int )
@@ -458,15 +442,13 @@ def validate_repository_config(
458442 )
459443 return errors
460444
461- # Validate required repository fields
462445 required_fields = ["repo_name" , "arch" , "production" , "url" ]
463446 for field in required_fields :
464447 if field not in repo or repo [field ] is None :
465448 errors .append (
466449 f"Config { config_index } , Repo { repo_index } : Missing required field '{ field } '"
467450 )
468451
469- # Validate repository name format if present
470452 if repo .get ("repo_name" ):
471453 try :
472454 FieldValidator .validate_repo_name (
@@ -475,7 +457,6 @@ def validate_repository_config(
475457 except ValidationError as e :
476458 errors .append (f"Config { config_index } , Repo { repo_index } : Repository name '{ repo ['repo_name' ]} ' - { e .message } " )
477459
478- # Validate architecture if present
479460 if repo .get ("arch" ):
480461 try :
481462 FieldValidator .validate_architecture (
@@ -484,10 +465,9 @@ def validate_repository_config(
484465 except ValidationError as e :
485466 errors .append (f"Config { config_index } , Repo { repo_index } : Architecture '{ repo ['arch' ]} ' - { e .message } " )
486467
487- # Validate URLs if present
488468 for url_field in ["url" , "debug_url" , "source_url" ]:
489469 url_value = repo .get (url_field )
490- if url_value : # Only validate if not empty
470+ if url_value :
491471 try :
492472 FieldValidator .validate_url (
493473 url_value ,
@@ -499,7 +479,6 @@ def validate_repository_config(
499479 f"Config { config_index } , Repo { repo_index } : { url_field .replace ('_' , ' ' ).title ()} '{ url_value } ' - { e .message } "
500480 )
501481
502- # Validate production is boolean if present
503482 if "production" in repo and repo ["production" ] is not None :
504483 if not isinstance (repo ["production" ], bool ):
505484 errors .append (
@@ -528,23 +507,20 @@ def validate_mirror_form(
528507 validated_data = {}
529508 errors = []
530509
531- # Validate name
532510 try :
533511 validated_data ["name" ] = FieldValidator .validate_name (
534512 form_data .get ("name" , "" ), min_length = 3 , field_name = "mirror name"
535513 )
536514 except ValidationError as e :
537515 errors .append (e .message )
538516
539- # Validate architecture
540517 try :
541518 validated_data ["match_arch" ] = FieldValidator .validate_architecture (
542519 form_data .get ("match_arch" , "" ), field_name = "architecture"
543520 )
544521 except ValidationError as e :
545522 errors .append (e .message )
546523
547- # Copy other fields as-is for now (they have different validation requirements)
548524 for field in ["match_variant" , "match_major_version" , "match_minor_version" ]:
549525 if field in form_data :
550526 validated_data [field ] = form_data [field ]
@@ -567,7 +543,6 @@ def validate_repomd_form(
567543 validated_data = {}
568544 errors = []
569545
570- # Validate repository name
571546 try :
572547 validated_data ["repo_name" ] = FieldValidator .validate_repo_name (
573548 form_data .get ("repo_name" , "" ),
@@ -577,15 +552,13 @@ def validate_repomd_form(
577552 except ValidationError as e :
578553 errors .append (e .message )
579554
580- # Validate main URL (required)
581555 try :
582556 validated_data ["url" ] = FieldValidator .validate_url (
583557 form_data .get ("url" , "" ), field_name = "repository URL" , required = True
584558 )
585559 except ValidationError as e :
586560 errors .append (e .message )
587561
588- # Validate debug URL (optional)
589562 try :
590563 debug_url = FieldValidator .validate_url (
591564 form_data .get ("debug_url" , "" ), field_name = "debug URL" , required = False
@@ -594,7 +567,6 @@ def validate_repomd_form(
594567 except ValidationError as e :
595568 errors .append (e .message )
596569
597- # Validate source URL (optional)
598570 try :
599571 source_url = FieldValidator .validate_url (
600572 form_data .get ("source_url" , "" ), field_name = "source URL" , required = False
@@ -603,15 +575,13 @@ def validate_repomd_form(
603575 except ValidationError as e :
604576 errors .append (e .message )
605577
606- # Validate architecture
607578 try :
608579 validated_data ["arch" ] = FieldValidator .validate_architecture (
609580 form_data .get ("arch" , "" ), field_name = "architecture"
610581 )
611582 except ValidationError as e :
612583 errors .append (e .message )
613584
614- # Copy production flag
615585 validated_data ["production" ] = form_data .get ("production" , False )
616586
617587 return validated_data , errors
0 commit comments