Skip to content

Commit 0f8300e

Browse files
committed
Extract duplicate repomd form validation into helper function
Both admin_supported_product_mirror_repomd_new_post and admin_supported_product_mirror_repomd_post had identical code for building form_data and calling validation. Extracted this into _validate_repomd_form helper that returns validated_data, errors, and the original form_data for use in error templates. This eliminates 14 lines of duplication across the two functions.
1 parent 7e01a2d commit 0f8300e

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

apollo/server/routes/admin_supported_products.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -801,16 +801,9 @@ async def admin_supported_product_mirror_repomd_new_post(
801801
if isinstance(mirror, Response):
802802
return mirror
803803

804-
form_data = {
805-
"production": production,
806-
"arch": arch,
807-
"url": url,
808-
"debug_url": debug_url,
809-
"source_url": source_url,
810-
"repo_name": repo_name,
811-
}
812-
813-
validated_data, validation_errors = FormValidator.validate_repomd_form(form_data)
804+
validated_data, validation_errors, form_data = _validate_repomd_form(
805+
production, arch, url, debug_url, source_url, repo_name
806+
)
814807

815808
if validation_errors:
816809
return templates.TemplateResponse(
@@ -892,16 +885,9 @@ async def admin_supported_product_mirror_repomd_post(
892885
if isinstance(repomd, Response):
893886
return repomd
894887

895-
form_data = {
896-
"production": production,
897-
"arch": arch,
898-
"url": url,
899-
"debug_url": debug_url,
900-
"source_url": source_url,
901-
"repo_name": repo_name,
902-
}
903-
904-
validated_data, validation_errors = FormValidator.validate_repomd_form(form_data)
888+
validated_data, validation_errors, form_data = _validate_repomd_form(
889+
production, arch, url, debug_url, source_url, repo_name
890+
)
905891

906892
if validation_errors:
907893
return templates.TemplateResponse(
@@ -1306,6 +1292,26 @@ async def _get_mirror_config_data(mirror: SupportedProductsRhMirror) -> Dict[str
13061292
]
13071293
}
13081294

1295+
def _validate_repomd_form(
1296+
production: bool,
1297+
arch: str,
1298+
url: str,
1299+
debug_url: str,
1300+
source_url: str,
1301+
repo_name: str
1302+
) -> Tuple[Dict[str, Any], List[str], Dict[str, Any]]:
1303+
"""Validate repomd form data and return validated data, errors, and original form data."""
1304+
form_data = {
1305+
"production": production,
1306+
"arch": arch,
1307+
"url": url,
1308+
"debug_url": debug_url,
1309+
"source_url": source_url,
1310+
"repo_name": repo_name,
1311+
}
1312+
validated_data, validation_errors = FormValidator.validate_repomd_form(form_data)
1313+
return validated_data, validation_errors, form_data
1314+
13091315
def _json_serializer(obj):
13101316
"""Custom JSON serializer for non-standard types"""
13111317
if isinstance(obj, Decimal):

0 commit comments

Comments
 (0)