-
Notifications
You must be signed in to change notification settings - Fork 184
feat: verify CS config commit using diracx model validation #8351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: integration
Are you sure you want to change the base?
Changes from 8 commits
55c9d21
f1f0b81
8476312
887a8d2
674ad5d
f67d84e
4c7b46a
8036c6e
b3d302c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,25 @@ | ||
| import requests | ||
|
|
||
| from cachetools import TTLCache, LRUCache, cached | ||
| from cachetools.keys import hashkey | ||
| import os | ||
| import re | ||
| import subprocess | ||
| from collections.abc import Generator | ||
| from contextlib import contextmanager | ||
| from pathlib import Path | ||
| from tempfile import NamedTemporaryFile | ||
| import tempfile | ||
| from typing import Any | ||
| from collections.abc import Generator | ||
| from DIRAC import gConfig | ||
| from DIRAC.ConfigurationSystem.Client.Helpers import Registry | ||
| from contextlib import contextmanager | ||
|
|
||
| import requests | ||
| from cachetools import LRUCache, TTLCache, cached | ||
| from cachetools.keys import hashkey | ||
| from diracx.cli.internal.legacy import _apply_fixes | ||
| from diracx.core.config.schema import Config as DiracxConfig | ||
| from diracx.core.models import TokenResponse | ||
| from diracx.core.preferences import DiracxPreferences | ||
|
|
||
| from diracx.core.utils import write_credentials | ||
| from pydantic import ValidationError | ||
|
|
||
| from diracx.core.models import TokenResponse | ||
| from DIRAC import S_ERROR, S_OK, gConfig | ||
| from DIRAC.ConfigurationSystem.Client.Helpers import Registry | ||
|
|
||
| try: | ||
| from diracx.client.sync import SyncDiracClient | ||
|
|
@@ -104,3 +109,29 @@ def TheImpersonator(credDict: dict[str, Any], *, source: str = "") -> Generator[ | |
| client.__enter__() | ||
| diracx_client_cache[token_location] = client | ||
| yield client | ||
|
|
||
|
|
||
| def diracxVerifyConfig(cfgData): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work for converting the CS, see https://diracx.diracgrid.org/en/latest/admin/how-to/install/convert-cs/ for the procedure. Running it in a subproces with a timeout is probably a good idea.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah indeed. Then I will call the diracx cli to validate the config. |
||
| """Verify CS config using DiracX config validation | ||
|
|
||
| Args: | ||
| cfgData: CFG data | ||
|
|
||
| Returns: | ||
| S_OK | S_ERROR: Value: diracx Config validation | ||
| """ | ||
| os.environ["DIRAC_COMPAT_ENABLE_CS_CONVERSION"] = "true" | ||
| with tempfile.NamedTemporaryFile() as temp_cfg: | ||
| with tempfile.NamedTemporaryFile() as temp_diracx_cfg: | ||
| cfgData.writeToFile(temp_cfg.name) | ||
| cmd = ["dirac", "internal", "legacy", "cs-sync", temp_cfg.name, temp_diracx_cfg.name] | ||
| res = subprocess.run(cmd, capture_output=True, text=True, timeout=15) | ||
| os.environ.pop("DIRAC_COMPAT_ENABLE_CS_CONVERSION") | ||
| if res.returncode == 0: | ||
| return S_OK(res.stdout) | ||
| else: | ||
| err = res.stderr.strip() | ||
| match = re.search(r"(ValidationError:.*)", err, flags=re.DOTALL) | ||
| if match: | ||
| return S_ERROR(match.group(1)) | ||
natthan-pigoux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return S_ERROR(err) | ||
Uh oh!
There was an error while loading. Please reload this page.