rucio-clients 37.0.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rucio-clients might be problematic. Click here for more details.

Files changed (104) hide show
  1. rucio/__init__.py +17 -0
  2. rucio/alembicrevision.py +15 -0
  3. rucio/cli/__init__.py +14 -0
  4. rucio/cli/account.py +216 -0
  5. rucio/cli/bin_legacy/__init__.py +13 -0
  6. rucio/cli/bin_legacy/rucio.py +2825 -0
  7. rucio/cli/bin_legacy/rucio_admin.py +2500 -0
  8. rucio/cli/command.py +272 -0
  9. rucio/cli/config.py +72 -0
  10. rucio/cli/did.py +191 -0
  11. rucio/cli/download.py +128 -0
  12. rucio/cli/lifetime_exception.py +33 -0
  13. rucio/cli/replica.py +162 -0
  14. rucio/cli/rse.py +293 -0
  15. rucio/cli/rule.py +158 -0
  16. rucio/cli/scope.py +40 -0
  17. rucio/cli/subscription.py +73 -0
  18. rucio/cli/upload.py +60 -0
  19. rucio/cli/utils.py +226 -0
  20. rucio/client/__init__.py +15 -0
  21. rucio/client/accountclient.py +432 -0
  22. rucio/client/accountlimitclient.py +183 -0
  23. rucio/client/baseclient.py +983 -0
  24. rucio/client/client.py +120 -0
  25. rucio/client/configclient.py +126 -0
  26. rucio/client/credentialclient.py +59 -0
  27. rucio/client/didclient.py +868 -0
  28. rucio/client/diracclient.py +56 -0
  29. rucio/client/downloadclient.py +1783 -0
  30. rucio/client/exportclient.py +44 -0
  31. rucio/client/fileclient.py +50 -0
  32. rucio/client/importclient.py +42 -0
  33. rucio/client/lifetimeclient.py +90 -0
  34. rucio/client/lockclient.py +109 -0
  35. rucio/client/metaconventionsclient.py +140 -0
  36. rucio/client/pingclient.py +44 -0
  37. rucio/client/replicaclient.py +452 -0
  38. rucio/client/requestclient.py +125 -0
  39. rucio/client/richclient.py +317 -0
  40. rucio/client/rseclient.py +746 -0
  41. rucio/client/ruleclient.py +294 -0
  42. rucio/client/scopeclient.py +90 -0
  43. rucio/client/subscriptionclient.py +173 -0
  44. rucio/client/touchclient.py +82 -0
  45. rucio/client/uploadclient.py +969 -0
  46. rucio/common/__init__.py +13 -0
  47. rucio/common/bittorrent.py +234 -0
  48. rucio/common/cache.py +111 -0
  49. rucio/common/checksum.py +168 -0
  50. rucio/common/client.py +122 -0
  51. rucio/common/config.py +788 -0
  52. rucio/common/constants.py +217 -0
  53. rucio/common/constraints.py +17 -0
  54. rucio/common/didtype.py +237 -0
  55. rucio/common/exception.py +1208 -0
  56. rucio/common/extra.py +31 -0
  57. rucio/common/logging.py +420 -0
  58. rucio/common/pcache.py +1409 -0
  59. rucio/common/plugins.py +185 -0
  60. rucio/common/policy.py +93 -0
  61. rucio/common/schema/__init__.py +200 -0
  62. rucio/common/schema/generic.py +416 -0
  63. rucio/common/schema/generic_multi_vo.py +395 -0
  64. rucio/common/stomp_utils.py +423 -0
  65. rucio/common/stopwatch.py +55 -0
  66. rucio/common/test_rucio_server.py +154 -0
  67. rucio/common/types.py +483 -0
  68. rucio/common/utils.py +1688 -0
  69. rucio/rse/__init__.py +96 -0
  70. rucio/rse/protocols/__init__.py +13 -0
  71. rucio/rse/protocols/bittorrent.py +194 -0
  72. rucio/rse/protocols/cache.py +111 -0
  73. rucio/rse/protocols/dummy.py +100 -0
  74. rucio/rse/protocols/gfal.py +708 -0
  75. rucio/rse/protocols/globus.py +243 -0
  76. rucio/rse/protocols/http_cache.py +82 -0
  77. rucio/rse/protocols/mock.py +123 -0
  78. rucio/rse/protocols/ngarc.py +209 -0
  79. rucio/rse/protocols/posix.py +250 -0
  80. rucio/rse/protocols/protocol.py +361 -0
  81. rucio/rse/protocols/rclone.py +365 -0
  82. rucio/rse/protocols/rfio.py +145 -0
  83. rucio/rse/protocols/srm.py +338 -0
  84. rucio/rse/protocols/ssh.py +414 -0
  85. rucio/rse/protocols/storm.py +195 -0
  86. rucio/rse/protocols/webdav.py +594 -0
  87. rucio/rse/protocols/xrootd.py +302 -0
  88. rucio/rse/rsemanager.py +881 -0
  89. rucio/rse/translation.py +260 -0
  90. rucio/vcsversion.py +11 -0
  91. rucio/version.py +45 -0
  92. rucio_clients-37.0.0rc1.data/data/etc/rse-accounts.cfg.template +25 -0
  93. rucio_clients-37.0.0rc1.data/data/etc/rucio.cfg.atlas.client.template +43 -0
  94. rucio_clients-37.0.0rc1.data/data/etc/rucio.cfg.template +241 -0
  95. rucio_clients-37.0.0rc1.data/data/requirements.client.txt +19 -0
  96. rucio_clients-37.0.0rc1.data/data/rucio_client/merge_rucio_configs.py +144 -0
  97. rucio_clients-37.0.0rc1.data/scripts/rucio +133 -0
  98. rucio_clients-37.0.0rc1.data/scripts/rucio-admin +97 -0
  99. rucio_clients-37.0.0rc1.dist-info/METADATA +54 -0
  100. rucio_clients-37.0.0rc1.dist-info/RECORD +104 -0
  101. rucio_clients-37.0.0rc1.dist-info/WHEEL +5 -0
  102. rucio_clients-37.0.0rc1.dist-info/licenses/AUTHORS.rst +100 -0
  103. rucio_clients-37.0.0rc1.dist-info/licenses/LICENSE +201 -0
  104. rucio_clients-37.0.0rc1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,185 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import importlib
16
+ import logging
17
+ import os
18
+ from configparser import NoOptionError, NoSectionError
19
+ from typing import TYPE_CHECKING, Any, TypeVar
20
+
21
+ from packaging.specifiers import SpecifierSet
22
+
23
+ from rucio.common import config
24
+ from rucio.common.client import get_client_vo, is_client
25
+ from rucio.common.exception import InvalidAlgorithmName, PolicyPackageIsNotVersioned, PolicyPackageVersionError
26
+ from rucio.version import current_version
27
+
28
+ if TYPE_CHECKING:
29
+ from collections.abc import Callable
30
+
31
+ from rucio.common.types import LoggerFunction
32
+
33
+ PolicyPackageAlgorithmsT = TypeVar('PolicyPackageAlgorithmsT', bound='PolicyPackageAlgorithms')
34
+
35
+
36
+ def check_policy_package_version(package: str, logger: 'LoggerFunction' = logging.log) -> None:
37
+
38
+ '''
39
+ Checks that the Rucio version supported by the policy package is compatible
40
+ with this version. Raises an exception if not.
41
+ :param package: the fully qualified name of the policy package
42
+ '''
43
+ try:
44
+ supported_versionset = _get_supported_versions_from_policy_package(package)
45
+ except ImportError:
46
+ logger(logging.DEBUG, 'Policy package %s not found' % package)
47
+ return
48
+ except PolicyPackageIsNotVersioned:
49
+ logger(logging.DEBUG, 'Policy package %s does not include information about which Rucio versions it supports' % package)
50
+ return
51
+
52
+ rucio_version = current_version()
53
+ if rucio_version not in supported_versionset:
54
+ raise PolicyPackageVersionError(rucio_version=rucio_version, supported_versionset=str(supported_versionset), package=package)
55
+
56
+
57
+ def _get_supported_versions_from_policy_package(package: str) -> SpecifierSet:
58
+ try:
59
+ module = importlib.import_module(package)
60
+ except ImportError as e:
61
+ raise e
62
+
63
+ if not hasattr(module, 'SUPPORTED_VERSION'):
64
+ raise PolicyPackageIsNotVersioned(package)
65
+
66
+ supported_versionset = module.SUPPORTED_VERSION
67
+
68
+ if isinstance(supported_versionset, list):
69
+ supported_versionset = ','.join(supported_versionset)
70
+
71
+ return SpecifierSet(supported_versionset)
72
+
73
+
74
+ class PolicyPackageAlgorithms:
75
+ """
76
+ Base class for Rucio Policy Package Algorithms
77
+
78
+ ALGORITHMS is a dict where:
79
+ - the key is the algorithm type
80
+ - the value is a dictionary of algorithm names and their callables
81
+ """
82
+ _ALGORITHMS: dict[str, dict[str, 'Callable[..., Any]']] = {}
83
+ _loaded_policy_modules = False
84
+
85
+ def __init__(self) -> None:
86
+ if not self._loaded_policy_modules:
87
+ self._register_all_policy_package_algorithms()
88
+ self._loaded_policy_modules = True
89
+
90
+ @classmethod
91
+ def _get_one_algorithm(cls: type[PolicyPackageAlgorithmsT], algorithm_type: str, name: str) -> 'Callable[..., Any]':
92
+ """
93
+ Get the algorithm from the dictionary of algorithms
94
+ """
95
+ return cls._ALGORITHMS[algorithm_type][name]
96
+
97
+ @classmethod
98
+ def _get_algorithms(cls: type[PolicyPackageAlgorithmsT], algorithm_type: str) -> dict[str, 'Callable[..., Any]']:
99
+ """
100
+ Get the dictionary of algorithms for a given type
101
+ """
102
+ return cls._ALGORITHMS[algorithm_type]
103
+
104
+ @classmethod
105
+ def _register(
106
+ cls: type[PolicyPackageAlgorithmsT],
107
+ algorithm_type: str, algorithm_dict: dict[str, 'Callable[..., Any]']) -> None:
108
+ """
109
+ Provided a dictionary of callable function,
110
+ and the associated algorithm type,
111
+ register it as one of the valid algorithms.
112
+ """
113
+ if algorithm_type in cls._ALGORITHMS:
114
+ cls._ALGORITHMS[algorithm_type].update(algorithm_dict)
115
+ else:
116
+ cls._ALGORITHMS[algorithm_type] = algorithm_dict
117
+
118
+ @classmethod
119
+ def _supports(cls: type[PolicyPackageAlgorithmsT], algorithm_type: str, name: str) -> bool:
120
+ """
121
+ Check if a algorithm is supported by the plugin
122
+ """
123
+ return name in cls._ALGORITHMS.get(algorithm_type, {})
124
+
125
+ @classmethod
126
+ def _register_all_policy_package_algorithms(cls: type[PolicyPackageAlgorithmsT]) -> None:
127
+ '''
128
+ Loads all the algorithms of a given type from the policy package(s) and registers them
129
+ :param algorithm_type: the type of algorithm to register (e.g. 'lfn2pfn')
130
+ :param dictionary: the dictionary to register them in
131
+ :param vo: the name of the relevant VO (None for single VO)
132
+ '''
133
+ try:
134
+ multivo = config.config_get_bool('common', 'multi_vo')
135
+ except (NoOptionError, NoSectionError):
136
+ multivo = False
137
+ if not multivo:
138
+ # single policy package
139
+ cls._try_importing_policy()
140
+ else:
141
+ # on client, only register algorithms for selected VO
142
+ if is_client():
143
+ vo = get_client_vo()
144
+ cls._try_importing_policy(vo)
145
+ # on server, list all VOs and register their algorithms
146
+ else:
147
+ from rucio.core.vo import list_vos
148
+ # policy package per VO
149
+ vos = list_vos()
150
+ for vo in vos:
151
+ cls._try_importing_policy(vo['vo'])
152
+
153
+ @classmethod
154
+ def _try_importing_policy(cls: type[PolicyPackageAlgorithmsT], vo: str = "") -> None:
155
+ try:
156
+ # import from utils here to avoid circular import
157
+
158
+ env_name = 'RUCIO_POLICY_PACKAGE' + ('' if not vo else '_' + vo.upper())
159
+ package = getattr(os.environ, env_name, "")
160
+ if not package:
161
+ package = str(config.config_get('policy', 'package' + ('' if not vo else '-' + vo)))
162
+
163
+ check_policy_package_version(package)
164
+ module = importlib.import_module(package)
165
+
166
+ if hasattr(module, 'get_algorithms'):
167
+ all_algorithms = module.get_algorithms()
168
+
169
+ # for backward compatibility, rename 'surl' to 'non_deterministic_pfn' here
170
+ if 'surl' in all_algorithms:
171
+ all_algorithms['non_deterministic_pfn'] = all_algorithms['surl']
172
+
173
+ # check that the names are correctly prefixed for multi-VO
174
+ if vo:
175
+ for _, algorithms in all_algorithms.items():
176
+ for k in algorithms.keys():
177
+ if not k.lower().startswith(vo.lower()):
178
+ raise InvalidAlgorithmName(k, vo)
179
+
180
+ # Updates the dictionary with the algorithms from the policy package
181
+ for algorithm_type, algorithm_dict in all_algorithms.items():
182
+ cls._register(algorithm_type, algorithm_dict)
183
+
184
+ except (NoOptionError, NoSectionError, ImportError):
185
+ pass
rucio/common/policy.py ADDED
@@ -0,0 +1,93 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import json
16
+ import logging
17
+ import os
18
+ from configparser import NoOptionError, NoSectionError
19
+ from functools import wraps
20
+ from typing import TYPE_CHECKING, Any
21
+
22
+ from dogpile.cache import make_region
23
+ from dogpile.cache.api import NoValue
24
+
25
+ from rucio.common.config import config_get
26
+ from rucio.common.exception import UndefinedPolicy
27
+
28
+ if TYPE_CHECKING:
29
+ from rucio.common.types import LoggerFunction
30
+
31
+ REGION = make_region().configure('dogpile.cache.memory',
32
+ expiration_time=900)
33
+
34
+
35
+ def get_policy(logger: 'LoggerFunction' = logging.log) -> str:
36
+ policy = REGION.get('policy')
37
+ if isinstance(policy, NoValue):
38
+ try:
39
+ policy = config_get('policy', 'permission')
40
+ except (NoOptionError, NoSectionError):
41
+ try:
42
+ policy = config_get('permission', 'policy')
43
+ except (NoOptionError, NoSectionError):
44
+ policy = 'def'
45
+ logger(logging.WARNING, "Policy not specified, falling back to 'def'")
46
+ policy = os.environ.get('POLICY', policy)
47
+ REGION.set('policy', policy)
48
+ return policy
49
+
50
+
51
+ def get_scratchdisk_lifetime() -> int:
52
+ scratchdisk_lifetime = REGION.get('scratchdisk_lifetime')
53
+ if isinstance(scratchdisk_lifetime, NoValue):
54
+ try:
55
+ scratchdisk_lifetime = config_get('policy', 'scratchdisk_lifetime')
56
+ scratchdisk_lifetime = int(scratchdisk_lifetime)
57
+ except (NoOptionError, NoSectionError, ValueError):
58
+ scratchdisk_lifetime = 14
59
+ REGION.set('scratchdisk_lifetime', scratchdisk_lifetime)
60
+ return scratchdisk_lifetime
61
+
62
+
63
+ def get_lifetime_policy() -> dict[str, list[dict[str, Any]]]:
64
+ lifetime_dict = REGION.get('lifetime_dict')
65
+ if isinstance(lifetime_dict, NoValue):
66
+ lifetime_dict = {'data': [], 'mc': [], 'valid': [], 'other': []}
67
+ lifetime_dir = '/opt/rucio/etc/policies'
68
+ try:
69
+ lifetime_dir = config_get('lifetime', 'directory')
70
+ except (NoSectionError, NoOptionError):
71
+ pass
72
+ for dtype in ['data', 'mc', 'valid', 'other']:
73
+ input_file_name = '%s/config_%s.json' % (lifetime_dir, dtype)
74
+ if os.path.isfile(input_file_name):
75
+ with open(input_file_name, 'r') as input_file:
76
+ lifetime_dict[dtype] = json.load(input_file)
77
+ REGION.set('lifetime_dict', lifetime_dict)
78
+ return lifetime_dict
79
+
80
+
81
+ def policy_filter(function):
82
+ mapping = {'atlas': ['get_scratch_policy', 'archive_localgroupdisk_datasets']}
83
+ policy = get_policy()
84
+ if policy in mapping and function.__name__ in mapping[policy]:
85
+ @wraps(function)
86
+ def new_funct(*args, **kwargs):
87
+ return function(*args, **kwargs)
88
+ return new_funct
89
+
90
+ @wraps(function)
91
+ def raise_funct(*args, **kwargs):
92
+ raise UndefinedPolicy
93
+ return raise_funct
@@ -0,0 +1,200 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import functools
16
+ import importlib
17
+ import logging
18
+ from configparser import NoOptionError, NoSectionError
19
+ from os import environ
20
+ from typing import TYPE_CHECKING, Any
21
+
22
+ from jsonschema import ValidationError, validate
23
+
24
+ from rucio.common import config, exception
25
+ from rucio.common.plugins import check_policy_package_version
26
+
27
+ if TYPE_CHECKING:
28
+ from types import ModuleType
29
+
30
+ LOGGER = logging.getLogger('policy')
31
+
32
+ # dictionary of schema modules for each VO
33
+ schema_modules: dict[str, "ModuleType"] = {}
34
+
35
+ # list of unique SCOPE_NAME_REGEXP values from all schemas
36
+ scope_name_regexps: list[str] = []
37
+
38
+
39
+ # cached function to check for multivo
40
+ @functools.cache
41
+ def _is_multivo():
42
+ try:
43
+ return config.config_get_bool('common', 'multi_vo', check_config_table=False)
44
+ except (NoOptionError, NoSectionError):
45
+ return False
46
+
47
+
48
+ # cached function to get generic schema module
49
+ @functools.cache
50
+ def _get_generic_schema_module():
51
+ generic_fallback = 'generic_multi_vo' if _is_multivo() else 'generic'
52
+ return importlib.import_module('rucio.common.schema.' + generic_fallback)
53
+
54
+
55
+ # multi-VO version loads schema per-VO on demand
56
+ # we can't get a list of VOs here because the database might not
57
+ # be available as this is imported during the bootstrapping process
58
+ if not _is_multivo():
59
+ GENERIC_FALLBACK = 'generic'
60
+
61
+ if config.config_has_section('policy'):
62
+ try:
63
+ if 'RUCIO_POLICY_PACKAGE' in environ:
64
+ policy = environ['RUCIO_POLICY_PACKAGE']
65
+ else:
66
+ policy = config.config_get('policy', 'package', check_config_table=False)
67
+ check_policy_package_version(policy)
68
+ policy = policy + ".schema"
69
+ except (NoOptionError, NoSectionError):
70
+ # fall back to old system for now
71
+ try:
72
+ policy = config.config_get('policy', 'schema', check_config_table=False)
73
+ except (NoOptionError, NoSectionError):
74
+ policy = GENERIC_FALLBACK
75
+ policy = 'rucio.common.schema.' + policy.lower()
76
+ else:
77
+ policy = 'rucio.common.schema.' + GENERIC_FALLBACK.lower()
78
+
79
+ try:
80
+ module = importlib.import_module(policy)
81
+ except ModuleNotFoundError:
82
+ # if policy package does not contain schema module, load fallback module instead
83
+ # this allows a policy package to omit modules that do not need customisation
84
+ try:
85
+ LOGGER.warning('Unable to load schema module %s from policy package, falling back to %s'
86
+ % (policy, GENERIC_FALLBACK))
87
+ policy = 'rucio.common.schema.' + GENERIC_FALLBACK.lower()
88
+ module = importlib.import_module(policy)
89
+ except ModuleNotFoundError:
90
+ raise exception.PolicyPackageNotFound(policy)
91
+ except ImportError:
92
+ raise exception.ErrorLoadingPolicyPackage(policy)
93
+ except ImportError:
94
+ raise exception.ErrorLoadingPolicyPackage(policy)
95
+
96
+ schema_modules["def"] = module
97
+ if hasattr(module, 'SCOPE_NAME_REGEXP'):
98
+ scope_name_regexps.append(module.SCOPE_NAME_REGEXP)
99
+
100
+
101
+ def load_schema_for_vo(vo: str) -> None:
102
+ generic_fallback = 'generic_multi_vo'
103
+ if config.config_has_section('policy'):
104
+ try:
105
+ env_name = 'RUCIO_POLICY_PACKAGE_' + vo.upper()
106
+ if env_name in environ:
107
+ policy = environ[env_name]
108
+ else:
109
+ policy = config.config_get('policy', 'package-' + vo, check_config_table=False)
110
+ check_policy_package_version(policy)
111
+ policy = policy + ".schema"
112
+ except (NoOptionError, NoSectionError):
113
+ # fall back to old system for now
114
+ try:
115
+ policy = config.config_get('policy', 'schema', check_config_table=False)
116
+ except (NoOptionError, NoSectionError):
117
+ policy = generic_fallback
118
+ policy = 'rucio.common.schema.' + policy.lower()
119
+ else:
120
+ policy = 'rucio.common.schema.' + generic_fallback.lower()
121
+
122
+ try:
123
+ module = importlib.import_module(policy)
124
+ except ModuleNotFoundError:
125
+ # if policy package does not contain schema module, load fallback module instead
126
+ # this allows a policy package to omit modules that do not need customisation
127
+ try:
128
+ LOGGER.warning('Unable to load schema module %s from policy package, falling back to %s'
129
+ % (policy, generic_fallback))
130
+ policy = 'rucio.common.schema.' + generic_fallback.lower()
131
+ module = importlib.import_module(policy)
132
+ except ModuleNotFoundError:
133
+ raise exception.PolicyPackageNotFound(policy)
134
+ except ImportError:
135
+ raise exception.ErrorLoadingPolicyPackage(policy)
136
+ except ImportError:
137
+ raise exception.ErrorLoadingPolicyPackage(policy)
138
+
139
+ schema_modules[vo] = module
140
+
141
+
142
+ def validate_schema(name: str, obj: Any, vo: str = 'def') -> None:
143
+ if obj:
144
+ if vo not in schema_modules:
145
+ load_schema_for_vo(vo)
146
+ if hasattr(schema_modules[vo], 'SCHEMAS') and name in schema_modules[vo].SCHEMAS:
147
+ schema = schema_modules[vo].SCHEMAS.get(name, {})
148
+ else:
149
+ # if schema not available in VO module, fall back to generic module
150
+ schema = _get_generic_schema_module().SCHEMAS.get(name, {})
151
+ try:
152
+ validate(obj, schema)
153
+ except ValidationError as error: # NOQA: F841
154
+ raise exception.InvalidObject(f'Problem validating {name}: {error}')
155
+
156
+
157
+ def get_schema_value(key: str, vo: str = 'def') -> Any:
158
+ if vo not in schema_modules:
159
+ load_schema_for_vo(vo)
160
+ if not hasattr(schema_modules[vo], key):
161
+ return getattr(_get_generic_schema_module(), key)
162
+ return getattr(schema_modules[vo], key)
163
+
164
+
165
+ def get_scope_name_regexps() -> list[str]:
166
+ """ returns a list of all unique SCOPE_NAME_REGEXPs from all schemas """
167
+
168
+ if len(scope_name_regexps) == 0:
169
+ # load schemas for all VOs here and add unique scope_name_regexps to list
170
+ from rucio.core.vo import list_vos
171
+ vos = list_vos()
172
+ for vo in vos:
173
+ if vo['vo'] not in schema_modules:
174
+ load_schema_for_vo(vo['vo'])
175
+ scope_name_regexp = schema_modules[vo['vo']].SCOPE_NAME_REGEXP
176
+ if scope_name_regexp not in scope_name_regexps:
177
+ scope_name_regexps.append(scope_name_regexp)
178
+ return scope_name_regexps
179
+
180
+
181
+ def insert_scope_name(urls: tuple[str, ...]) -> tuple[str, str]:
182
+ """
183
+ given a tuple of URLs for webpy with '%s' as a placeholder for
184
+ SCOPE_NAME_REGEXP, return a finalised tuple of URLs that will work for all
185
+ SCOPE_NAME_REGEXPs in all schemas
186
+ """
187
+
188
+ regexps = get_scope_name_regexps()
189
+ result = []
190
+ for i in range(0, len(urls), 2):
191
+ if "%s" in urls[i]:
192
+ # add a copy for each unique SCOPE_NAME_REGEXP
193
+ for scope_name_regexp in regexps:
194
+ result.append(urls[i] % scope_name_regexp)
195
+ result.append(urls[i + 1])
196
+ else:
197
+ # pass through unmodified
198
+ result.append(urls[i])
199
+ result.append(urls[i + 1])
200
+ return tuple(result)