Skip to content

Commit 5e8828f

Browse files
committed
refactor(Clients): Replace config_get with ConfigOption calls
Assisted by Claude Sonnet 4.6 - used to find and replace without logic changes. Issue: documentation#325
1 parent c25fcca commit 5e8828f

File tree

7 files changed

+38
-33
lines changed

7 files changed

+38
-33
lines changed

bin/rucio-auditor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import rucio.common.config as config
2929
import rucio.common.dumper as dumper
3030
import rucio.daemons.auditor
3131
from rucio.client.rseclient import RSEClient
32+
from rucio.common.config_settings import Config
3233
from rucio.common.exception import RSENotFound
3334

3435
RETRY_AFTER = 60 * 60 * 24 * 14 # Two weeks
@@ -68,7 +69,7 @@ def main(args):
6869
terminate = Event()
6970
logpipes = []
7071

71-
loglevel = logging.getLevelName(config.config_get('common', 'loglevel'))
72+
loglevel = logging.getLevelName(Config.common.loglevel())
7273

7374
mainlogr, mainlogw = Pipe(duplex=False)
7475
logpipes.append(mainlogr)
@@ -77,8 +78,8 @@ def main(args):
7778
if not config.config_has_section('auditor'):
7879
raise NoSectionError("Auditor section required in config to run the auditor daemon.")
7980

80-
cache_dir = config.config_get('auditor', 'cache')
81-
results_dir = config.config_get('auditor', 'results')
81+
cache_dir = Config.auditor.cache()
82+
results_dir = Config.auditor.results()
8283

8384
logfilename = os.path.join(config.config_get('common', 'logdir'), 'auditor.log')
8485
logger.info('Starting auditor')

lib/rucio/cli/bin_legacy/rucio.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
from rucio.cli.utils import exception_handler, get_client, get_scope, setup_gfal2_logger, signal_handler
4040
from rucio.client.richclient import MAX_TRACEBACK_WIDTH, MIN_CONSOLE_WIDTH, CLITheme, generate_table, get_cli_config, get_pager, print_output, setup_rich_logger
4141
from rucio.common.client import detect_client_location
42-
from rucio.common.config import config_get, config_get_float
42+
from rucio.common.config import config_get_float
43+
from rucio.common.config_settings import Config
4344
from rucio.common.constants import ReplicaState
4445
from rucio.common.exception import (
4546
DuplicateRule,
@@ -991,7 +992,7 @@ def download(args, client, logger, console, spinner):
991992
item_defaults['nrandom'] = args.nrandom
992993
item_defaults['transfer_speed_timeout'] = args.transfer_speed_timeout \
993994
if args.transfer_speed_timeout is not None \
994-
else config_get_float('download', 'transfer_speed_timeout', False, 500)
995+
else Config.download.transfer_speed_timeout(raise_exception=False)
995996
items = []
996997
if args.dids:
997998
for did in args.dids:
@@ -1117,7 +1118,7 @@ def get_metadata(args, client, logger, console, spinner):
11171118
if args.plugin:
11181119
plugin = args.plugin
11191120
else:
1120-
plugin = config_get('client', 'metadata_default_plugin', default='DID_COLUMN')
1121+
plugin = Config.client.metadata_default_plugin()
11211122

11221123
if cli_config == 'rich':
11231124
spinner.update(status='Fetching metadata')

lib/rucio/cli/did.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from rucio.cli.utils import get_scope
2222
from rucio.client.richclient import CLITheme, generate_table, print_output
23-
from rucio.common.config import config_get
23+
from rucio.common.config_settings import Config
2424
from rucio.common.exception import InputValidationError, InvalidObject, RucioException, ScopeNotFound
2525
from rucio.common.utils import chunks, parse_did_filter_from_string_fe
2626

@@ -389,7 +389,7 @@ def metadata_remove(ctx: click.Context, did: str, key: str) -> None:
389389
def metadata_list_(ctx: click.Context, dids: tuple[str, ...], plugin: Optional[str]) -> None:
390390
"""List metadata for a list of DIDs"""
391391
if plugin is None:
392-
plugin = config_get('client', 'metadata_default_plugin', default='DID_COLUMN')
392+
plugin = Config.client.metadata_default_plugin()
393393

394394
if ctx.obj.use_rich:
395395
ctx.obj.spinner.update(status='Fetching metadata')

lib/rucio/cli/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import click
2828

2929
from rucio.client.client import Client
30-
from rucio.common.config import config_get
30+
from rucio.common.config_settings import Config
3131
from rucio.common.exception import (
3232
AccessDenied,
3333
CannotAuthenticate,
@@ -124,7 +124,7 @@ def new_funct(*args, **kwargs):
124124
if "x-rucio-auth-token" in str(error):
125125
used_account = None
126126
try: # get the configured account from the configuration file
127-
used_account = "%s (from rucio.cfg)" % config_get("client", "account")
127+
used_account = "%s (from rucio.cfg)" % Config.client.account()
128128
except Exception:
129129
pass
130130
try: # are we overriden by the environment?
@@ -135,7 +135,7 @@ def new_funct(*args, **kwargs):
135135

136136
else:
137137
logger.debug(traceback.format_exc())
138-
contact = config_get("policy", "support", raise_exception=False)
138+
contact = Config.policy.support(raise_exception=False)
139139
support = ("Please follow up with all relevant information at: " + contact) if contact else ""
140140
logger.error("\nThe object is missing this property: %s\n" 'This should never happen. Please rerun the last command with the "-v" option to gather more information.\n' "%s" % (str(error), support))
141141
return FAILURE
@@ -154,9 +154,9 @@ def new_funct(*args, **kwargs):
154154
return SUCCESS
155155
logger.debug(traceback.format_exc())
156156
logger.error(error)
157-
contact = config_get("policy", "support", raise_exception=False)
157+
contact = Config.policy.support(raise_exception=False)
158158
support = ("If it's a problem concerning your experiment or if you're unsure what to do, please follow up at: %s\n" % contact) if contact else ""
159-
contact = config_get("policy", "support_rucio", default="https://github.com/rucio/rucio/issues")
159+
contact = Config.policy.support_rucio()
160160
support += "If you're sure there is a problem with Rucio itself, please follow up at: " + contact
161161
logger.error("\nRucio exited with an unexpected/unknown error.\n" 'Please rerun the last command with the "-v" option to gather more information.\n' "%s" % support)
162162
return FAILURE
@@ -179,7 +179,7 @@ def get_client(args, logger):
179179
auth_type = os.environ["RUCIO_AUTH_TYPE"].lower()
180180
else:
181181
try:
182-
auth_type = config_get("client", "auth_type").lower()
182+
auth_type = Config.client.auth_type().lower()
183183
except (NoOptionError, NoSectionError):
184184
logger.error("Cannot get AUTH_TYPE")
185185
sys.exit(1)

lib/rucio/client/baseclient.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from rucio import version
4040
from rucio.common import exception
4141
from rucio.common.config import config_get, config_get_bool, config_get_int, config_has_section
42+
from rucio.common.config_settings import Config
4243
from rucio.common.constants import DEFAULT_VO, HTTPMethod
4344
from rucio.common.exception import CannotAuthenticate, ClientProtocolNotFound, ClientProtocolNotSupported, ConfigNotFound, MissingClientParameter, MissingModuleException, NoAuthInformation, ServerConnectionException
4445
from rucio.common.extra import import_extras
@@ -141,15 +142,15 @@ def __init__(self,
141142
if rucio_host is not None:
142143
self.host = rucio_host
143144
else:
144-
self.host = config_get('client', 'rucio_host')
145+
self.host = Config.client.rucio_host()
145146
except (NoOptionError, NoSectionError) as error:
146147
raise MissingClientParameter('Section client and Option \'%s\' cannot be found in config file' % error.args[0])
147148

148149
try:
149150
if auth_host is not None:
150151
self.auth_host = auth_host
151152
else:
152-
self.auth_host = config_get('client', 'auth_host')
153+
self.auth_host = Config.client.auth_host()
153154
except (NoOptionError, NoSectionError) as error:
154155
raise MissingClientParameter('Section client and Option \'%s\' cannot be found in config file' % error.args[0])
155156

@@ -197,7 +198,7 @@ def __init__(self,
197198
if self.ca_cert is None:
198199
self.logger.debug('HTTPS is required, but no ca_cert was passed and X509_CERT_DIR is not defined. Trying to get it from the config file.')
199200
try:
200-
self.ca_cert = _expand_path(config_get('client', 'ca_cert'))
201+
self.ca_cert = _expand_path(Config.client.ca_cert())
201202
except (NoOptionError, NoSectionError):
202203
self.logger.debug('No ca_cert found in configuration. Falling back to Mozilla default CA bundle (certifi).')
203204
self.ca_cert = True
@@ -211,7 +212,7 @@ def __init__(self,
211212
self.account = environ['RUCIO_ACCOUNT']
212213
except KeyError:
213214
try:
214-
self.account = config_get('client', 'account')
215+
self.account = Config.client.account()
215216
except (NoOptionError, NoSectionError):
216217
pass
217218

@@ -224,7 +225,7 @@ def __init__(self,
224225
except KeyError:
225226
self.logger.debug('No VO found. Trying to get it from the config file.')
226227
try:
227-
self.vo = config_get('client', 'vo')
228+
self.vo = Config.client.vo()
228229
except (NoOptionError, NoSectionError):
229230
self.logger.debug('No VO found. Using default VO.')
230231
self.vo = DEFAULT_VO
@@ -244,7 +245,7 @@ def __init__(self,
244245

245246
def _get_auth_tokens(self) -> tuple[Optional[str], str, str, str]:
246247
# if token file path is defined in the rucio.cfg file, use that file. Currently this prevents authenticating as another user or VO.
247-
auth_token_file_path = config_get('client', 'auth_token_file_path', False, None)
248+
auth_token_file_path = Config.client.auth_token_file_path(raise_exception=False)
248249
token_filename_suffix = "for_default_account" if self.account is None else "for_account_" + self.account
249250

250251
if auth_token_file_path:
@@ -270,7 +271,7 @@ def _get_auth_type(self, auth_type: Optional[str]) -> str:
270271
auth_type = environ['RUCIO_AUTH_TYPE']
271272
else:
272273
try:
273-
auth_type = config_get('client', 'auth_type')
274+
auth_type = Config.client.auth_type()
274275
except (NoOptionError, NoSectionError) as error:
275276
raise MissingClientParameter('Option \'%s\' cannot be found in config file' % error.args[0])
276277
return auth_type
@@ -288,7 +289,7 @@ def _get_creds(self, creds: Optional[dict[str, Any]]) -> dict[str, Any]:
288289
if 'oidc_issuer' not in creds or creds['oidc_issuer'] is None:
289290
creds['oidc_issuer'] = config_get('client', 'oidc_issuer', False, None)
290291
if 'oidc_audience' not in creds or creds['oidc_audience'] is None:
291-
creds['oidc_audience'] = config_get('client', 'oidc_audience', False, None)
292+
creds['oidc_audience'] = Config.client.oidc_audience(raise_exception=False)
292293
if 'oidc_auto' not in creds or creds['oidc_auto'] is False:
293294
creds['oidc_auto'] = config_get_bool('client', 'oidc_auto', False, False)
294295
if creds['oidc_auto']:
@@ -297,22 +298,22 @@ def _get_creds(self, creds: Optional[dict[str, Any]]) -> dict[str, Any]:
297298
if 'oidc_password' not in creds or creds['oidc_password'] is None:
298299
creds['oidc_password'] = config_get('client', 'oidc_password', False, None)
299300
if 'oidc_scope' not in creds or creds['oidc_scope'] == 'openid profile':
300-
creds['oidc_scope'] = config_get('client', 'oidc_scope', False, 'openid profile')
301+
creds['oidc_scope'] = Config.client.oidc_scope()
301302
if 'oidc_polling' not in creds or creds['oidc_polling'] is False:
302303
creds['oidc_polling'] = config_get_bool('client', 'oidc_polling', False, False)
303304

304305
elif self.auth_type in ['userpass', 'saml']:
305306
if 'username' not in creds or creds['username'] is None:
306-
creds['username'] = config_get('client', 'username')
307+
creds['username'] = Config.client.username()
307308
if 'password' not in creds or creds['password'] is None:
308-
creds['password'] = config_get('client', 'password')
309+
creds['password'] = Config.client.password()
309310

310311
elif self.auth_type == 'x509':
311312
if 'client_cert' not in creds or creds['client_cert'] is None:
312313
if "RUCIO_CLIENT_CERT" in environ:
313314
creds['client_cert'] = environ["RUCIO_CLIENT_CERT"]
314315
else:
315-
creds['client_cert'] = config_get('client', 'client_cert')
316+
creds['client_cert'] = Config.client.client_cert()
316317

317318
creds['client_cert'] = _expand_path(creds['client_cert'])
318319

@@ -323,7 +324,7 @@ def _get_creds(self, creds: Optional[dict[str, Any]]) -> dict[str, Any]:
323324
if "RUCIO_CLIENT_KEY" in environ:
324325
creds['client_key'] = environ["RUCIO_CLIENT_KEY"]
325326
else:
326-
creds['client_key'] = config_get('client', 'client_key')
327+
creds['client_key'] = Config.client.client_key()
327328

328329
creds['client_key'] = _expand_path(creds['client_key'])
329330
if not os.path.exists(creds['client_key']):
@@ -346,8 +347,8 @@ def _get_creds(self, creds: Optional[dict[str, Any]]) -> dict[str, Any]:
346347
if 'client_proxy' not in creds or creds['client_proxy'] is None:
347348
if 'RUCIO_CLIENT_PROXY' in environ:
348349
creds['client_proxy'] = environ['RUCIO_CLIENT_PROXY']
349-
elif config_has_section('client') and config_get('client', 'client_x509_proxy', default='') != '':
350-
creds['client_proxy'] = config_get('client', 'client_x509_proxy')
350+
elif config_has_section('client') and Config.client.client_x509_proxy(default='') != '':
351+
creds['client_proxy'] = Config.client.client_x509_proxy()
351352
elif 'X509_USER_PROXY' in environ:
352353
creds['client_proxy'] = environ['X509_USER_PROXY']
353354
elif os.path.isfile(gsi_proxy_path):
@@ -363,7 +364,7 @@ def _get_creds(self, creds: Optional[dict[str, Any]]) -> dict[str, Any]:
363364

364365
elif self.auth_type == 'ssh':
365366
if 'ssh_private_key' not in creds or creds['ssh_private_key'] is None:
366-
creds['ssh_private_key'] = config_get('client', 'ssh_private_key')
367+
creds['ssh_private_key'] = Config.client.ssh_private_key()
367368

368369
creds['ssh_private_key'] = _expand_path(creds['ssh_private_key'])
369370
if not os.path.isfile(creds["ssh_private_key"]):

lib/rucio/client/downloadclient.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from rucio.common.checksum import CHECKSUM_ALGO_DICT, GLOBALLY_SUPPORTED_CHECKSUMS, PREFERRED_CHECKSUM, adler32
3333
from rucio.common.client import detect_client_location
3434
from rucio.common.config import config_get
35+
from rucio.common.config_settings import Config
3536
from rucio.common.constants import DEFAULT_VO
3637
from rucio.common.didtype import DID
3738
from rucio.common.exception import InputValidationError, NoFilesDownloaded, NotAllFilesDownloaded, RucioException
@@ -229,7 +230,7 @@ def __init__(
229230
# tar -C <dest_dir_path> -xf <archive_file_path> <did_name>
230231
extract_args = '-C %(dest_dir_path)s -xf %(archive_file_path)s %(file_to_extract)s'
231232
self.extraction_tools.append(BaseExtractionTool('tar', '--version', extract_args, logger=self.logger))
232-
self.extract_scope_convention = config_get('common', 'extract_scope', False, None)
233+
self.extract_scope_convention = Config.common.extract_scope(raise_exception=False)
233234

234235
def download_pfns(
235236
self,

lib/rucio/client/uploadclient.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
from rucio.common.bittorrent import bittorrent_v2_merkle_sha256
3030
from rucio.common.checksum import GLOBALLY_SUPPORTED_CHECKSUMS, adler32, md5
3131
from rucio.common.client import detect_client_location
32-
from rucio.common.config import config_get, config_get_bool, config_get_int
32+
from rucio.common.config import config_get, config_get_bool
33+
from rucio.common.config_settings import Config
3334
from rucio.common.constants import DEFAULT_VO, RseAttr
3435
from rucio.common.exception import (
3536
DataIdentifierAlreadyExists,
@@ -1230,7 +1231,7 @@ def _retry_protocol_stat(
12301231
Exception
12311232
If the requested service is not available or permissions are not granted.
12321233
"""
1233-
retries = config_get_int('client', 'protocol_stat_retries', raise_exception=False, default=6)
1234+
retries = Config.client.protocol_stat_retries(raise_exception=False)
12341235
for attempt in range(retries):
12351236
try:
12361237
self.logger(logging.DEBUG, 'stat: pfn=%s' % pfn)

0 commit comments

Comments
 (0)