diff --git a/nisystemlink/clients/core/_http_configuration_manager.py b/nisystemlink/clients/core/_http_configuration_manager.py index 5701de0..5cb6b63 100644 --- a/nisystemlink/clients/core/_http_configuration_manager.py +++ b/nisystemlink/clients/core/_http_configuration_manager.py @@ -23,7 +23,11 @@ class HttpConfigurationManager: HTTP_LOCALHOST_CONFIGURATION_ID = "SYSTEMLINK_LOCALHOST" """The default ID of the SystemLink Server's configuration on the SystemLink Server itself.""" + _HTTP_JUPYTER_CONFIGURATION_ID = "SYSTEMLINK_VIRTUAL_JUPYTER" + """Virtual ID of SystemLink Server's configuration for Jupyter Notebook execution on SLE.""" + _configs = None + _virtual_configs = None @classmethod def get_configuration( @@ -78,14 +82,41 @@ def _fallback(cls) -> Optional[core.HttpConfiguration]: """ if cls._configs is None: cls._configs = cls._read_configurations() + if cls._virtual_configs is None: + cls._virtual_configs = cls._read_virtual_configurations() + master_config = cls._configs.get(cls.HTTP_MASTER_CONFIGURATION_ID) if master_config is not None: return master_config localhost_config = cls._configs.get(cls.HTTP_LOCALHOST_CONFIGURATION_ID) if localhost_config is not None: return localhost_config + + jupyter_config = cls._virtual_configs.get(cls._HTTP_JUPYTER_CONFIGURATION_ID) + if jupyter_config is not None: + return jupyter_config + return None + @classmethod + def _read_virtual_configurations(cls) -> Dict[str, core.HttpConfiguration]: + """Loads the virtual HTTP configurations. + + Returns: + A dictionary mapping each loaded configuration ID to its corresponding + :class:`HttpConfiguration`. + """ + configurations = {} # type: Dict[str, core.HttpConfiguration] + try: + configurations[cls._HTTP_JUPYTER_CONFIGURATION_ID] = ( + core.JupyterHttpConfiguration() + ) + except KeyError: + # Env variables for Jupyter notebook execution are not available. + pass + + return configurations + @classmethod def _read_configurations(cls) -> Dict[str, core.HttpConfiguration]: """Discover and loads the HTTP configuration files. diff --git a/nisystemlink/clients/dataframe/_data_frame_client.py b/nisystemlink/clients/dataframe/_data_frame_client.py index de1b7b1..180d870 100644 --- a/nisystemlink/clients/dataframe/_data_frame_client.py +++ b/nisystemlink/clients/dataframe/_data_frame_client.py @@ -24,15 +24,15 @@ def __init__(self, configuration: Optional[core.HttpConfiguration] = None): Args: configuration: Defines the web server to connect to and information about - how to connect. If not provided, an instance of - :class:`JupyterHttpConfiguration ` - is used. + how to connect. If not provided, the + :class:`HttpConfigurationManager ` + is used to obtain the configuration. Raises: ApiException: if unable to communicate with the DataFrame Service. """ if configuration is None: - configuration = core.JupyterHttpConfiguration() + configuration = core.HttpConfigurationManager.get_configuration() super().__init__(configuration, "/nidataframe/v1/") diff --git a/nisystemlink/clients/spec/_spec_client.py b/nisystemlink/clients/spec/_spec_client.py index 9b59e83..fd1b1f8 100644 --- a/nisystemlink/clients/spec/_spec_client.py +++ b/nisystemlink/clients/spec/_spec_client.py @@ -12,8 +12,20 @@ class SpecClient(BaseClient): def __init__(self, configuration: Optional[core.HttpConfiguration]): + """Initialize an instance. + + Args: + configuration: Defines the web server to connect to and information about + how to connect. If not provided, the + :class:`HttpConfigurationManager ` + is used to obtain the configuration. + + Raises: + ApiException: if unable to communicate with the Spec Service. + """ if configuration is None: - configuration = core.JupyterHttpConfiguration() + configuration = core.HttpConfigurationManager.get_configuration() + super().__init__(configuration, base_path="/nispec/v1/") @get("")