|
| 1 | +import os |
| 2 | +import re |
| 3 | +import subprocess |
1 | 4 | from collections.abc import Generator |
2 | 5 | from contextlib import contextmanager |
3 | 6 | from pathlib import Path |
4 | 7 | from tempfile import NamedTemporaryFile |
| 8 | +import tempfile |
5 | 9 | from typing import Any |
6 | 10 |
|
7 | 11 | import requests |
8 | 12 | from cachetools import LRUCache, TTLCache, cached |
9 | 13 | from cachetools.keys import hashkey |
| 14 | +from diracx.cli.internal.legacy import _apply_fixes |
10 | 15 | from diracx.core.config.schema import Config as DiracxConfig |
11 | 16 | from diracx.core.models import TokenResponse |
12 | 17 | from diracx.core.preferences import DiracxPreferences |
@@ -115,9 +120,17 @@ def diracxVerifyConfig(cfgData): |
115 | 120 | Returns: |
116 | 121 | S_OK | S_ERROR: Value: diracx Config validation |
117 | 122 | """ |
118 | | - cfg = cfgData.getAsDict() |
119 | | - try: |
120 | | - validation = DiracxConfig.model_validate(cfg) |
121 | | - except ValidationError as exc: |
122 | | - return S_ERROR(exc) |
123 | | - return S_OK(validation) |
| 123 | + os.environ["DIRAC_COMPAT_ENABLE_CS_CONVERSION"] = "true" |
| 124 | + with tempfile.NamedTemporaryFile() as temp_cfg: |
| 125 | + with tempfile.NamedTemporaryFile() as temp_diracx_cfg: |
| 126 | + cfgData.writeToFile(temp_cfg) |
| 127 | + cmd = ["dirac", "internal", "legacy", "cs-sync", temp_cfg, temp_diracx_cfg] |
| 128 | + res = subprocess.run(cmd, capture_output=True, text=True, timeout=15) |
| 129 | + os.environ.pop("DIRAC_COMPAT_ENABLE_CS_CONVERSION") |
| 130 | + if res.returncode == 0: |
| 131 | + return S_OK(res.stdout) |
| 132 | + else: |
| 133 | + err = res.stderr.strip() |
| 134 | + match = re.search(r"(ValidationError:.*)", err, flags=re.DOTALL) |
| 135 | + if match: |
| 136 | + return S_ERROR(match.group(1)) |
0 commit comments