|
1 | | -import requests |
2 | | - |
3 | | -from cachetools import TTLCache, LRUCache, cached |
4 | | -from cachetools.keys import hashkey |
| 1 | +from collections.abc import Generator |
| 2 | +from contextlib import contextmanager |
5 | 3 | from pathlib import Path |
6 | 4 | from tempfile import NamedTemporaryFile |
7 | 5 | from typing import Any |
8 | | -from collections.abc import Generator |
9 | | -from DIRAC import gConfig |
10 | | -from DIRAC.ConfigurationSystem.Client.Helpers import Registry |
11 | | -from contextlib import contextmanager |
12 | 6 |
|
| 7 | +import requests |
| 8 | +from cachetools import LRUCache, TTLCache, cached |
| 9 | +from cachetools.keys import hashkey |
| 10 | +from diracx.core.config.schema import Config as DiracxConfig |
| 11 | +from diracx.core.models import TokenResponse |
13 | 12 | from diracx.core.preferences import DiracxPreferences |
14 | | - |
15 | 13 | from diracx.core.utils import write_credentials |
| 14 | +from pydantic import ValidationError |
16 | 15 |
|
17 | | -from diracx.core.models import TokenResponse |
| 16 | +from DIRAC import S_ERROR, S_OK, gConfig |
| 17 | +from DIRAC.ConfigurationSystem.Client.Helpers import Registry |
18 | 18 |
|
19 | 19 | try: |
20 | 20 | from diracx.client.sync import SyncDiracClient |
@@ -104,3 +104,20 @@ def TheImpersonator(credDict: dict[str, Any], *, source: str = "") -> Generator[ |
104 | 104 | client.__enter__() |
105 | 105 | diracx_client_cache[token_location] = client |
106 | 106 | yield client |
| 107 | + |
| 108 | + |
| 109 | +def diracxVerifyConfig(cfgData): |
| 110 | + """Verify CS config using DiracX config validation |
| 111 | +
|
| 112 | + Args: |
| 113 | + cfgData: CFG data |
| 114 | +
|
| 115 | + Returns: |
| 116 | + S_OK | S_ERROR: Value: diracx Config validation |
| 117 | + """ |
| 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) |
0 commit comments