@@ -479,6 +479,8 @@ def __init__(self, *, roles=None, users=None):
479479 type: [integer, "null"]
480480 http_timeout:
481481 type: integer
482+ base_url:
483+ type: [string, "null"]
482484"""
483485
484486
@@ -528,11 +530,17 @@ class ServerBasedAPIAccessControl(BasicAPIAccessControl):
528530 roles: dict or None, optional
529531 The dictionary that defines new and/or modifies existing roles. The dictionary
530532 is passed to the ``BasicAPIAccessControl`` constructor. Default: ``None``.
533+ base_url: str, optional
534+ The base URL for the Access Control server, such as
535+ ``'http://accesscontrol.server.com:8000'``. If provided, this parameter is used
536+ instead of the `server` and `port` parameters.
531537 server: str, optional
532538 Access Control server address, such as ``'accesscontrol.server.com'`` or
533- ``'110.43.6.45'``. The default address is ``localhost``.
539+ ``'110.43.6.45'``. This parameter is used only if `base_url` is not provided.
540+ The default address is ``localhost``.
534541 port: int, optional
535- Access Control server port. The default port is `8000`.
542+ Access Control server port. This parameter is used only if `base_url` is not
543+ provided. The default port is `8000`.
536544 update_period: int, optional
537545 Average period in seconds between consecutive requests for updated access data.
538546 The actual period is randomized (uniform distribution in the range +/-20% of
@@ -552,6 +560,7 @@ def __init__(
552560 * ,
553561 instrument = None ,
554562 roles = None ,
563+ base_url = None ,
555564 server = "localhost" ,
556565 port = 8000 ,
557566 update_period = 600 ,
@@ -567,6 +576,7 @@ def __init__(
567576 config = {
568577 "instrument" : instrument ,
569578 "roles" : roles ,
579+ "base_url" : base_url ,
570580 "server" : server ,
571581 "port" : port ,
572582 "update_period" : update_period ,
@@ -580,9 +590,11 @@ def __init__(
580590 raise ConfigError (f"ValidationError while validating parameters BasicAPIAccessControl: { msg } " ) from err
581591
582592 self ._instrument = instrument .lower ()
593+ if base_url :
594+ self ._base_url = base_url
595+ else :
596+ self ._base_url = f"http://{ server } :{ port } "
583597
584- self ._server = server
585- self ._port = port
586598 self ._update_period = update_period
587599 self ._http_timeout = http_timeout
588600 self ._expiration_period = expiration_period or (update_period * 1.5 )
@@ -597,9 +609,8 @@ async def update_access_info(self):
597609 """
598610 Send a single request to the API server and update locally stored access control info.
599611 """
600- base_url = f"http://{ self ._server } :{ self ._port } "
601612 access_api = f"/instrument/{ self ._instrument .lower ()} /qserver/access"
602- async with httpx .AsyncClient (base_url = base_url , timeout = self ._http_timeout ) as client :
613+ async with httpx .AsyncClient (base_url = self . _base_url , timeout = self ._http_timeout ) as client :
603614 response = await client .get (access_api )
604615 response .raise_for_status ()
605616 groups = response .json ()
0 commit comments