diff --git a/ChangeLog.md b/ChangeLog.md index 681a4ae1..e33d5a78 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,12 +3,13 @@ Starting with v1.31.6, this file will contain a record of major features and updates made in each release of graph-notebook. ## Upcoming -- Added silent output option to additional magics ([Link to PR](https://github.com/aws/graph-notebook/pull/326)) - Reverted Gremlin console tab to single results column ([Link to PR](https://github.com/aws/graph-notebook/pull/330)) - Bumped jquery-ui from 1.13.1 to 1.13.2 (([Link to PR](https://github.com/aws/graph-notebook/pull/328)) - Docker support. Docker image can be built using the command `docker build .` and through Docker's `buildx`, this can support non-x86 CPU Architectures like ARM. ([Link to PR](https://github.com/aws/graph-notebook/pull/323)) - Fix `service.sh` conditional checks, SSL parameter can now be changed. Fix permissions error on `service.sh` experienced by some users. ([Link to PR](https://github.com/aws/graph-notebook/pull/335)) - Added `%%neptune_config_allowlist` magic ([Link to PR](https://github.com/aws/graph-notebook/pull/327)) +- Added check to remove whitespace in `%graph_notebook_config` host fields ([Link to PR](https://github.com/aws/graph-notebook/pull/329)) +- Added silent output option to additional magics ([Link to PR](https://github.com/aws/graph-notebook/pull/326)) ## Release 3.5.1 (July 12, 2022) - Improved the `%stream_viewer` magic to show the commit timestamp and `isLastOp` information, diff --git a/src/graph_notebook/configuration/generate_config.py b/src/graph_notebook/configuration/generate_config.py index 2dd3c1e2..a660d51c 100644 --- a/src/graph_notebook/configuration/generate_config.py +++ b/src/graph_notebook/configuration/generate_config.py @@ -71,10 +71,10 @@ def __init__(self, host: str, port: int, proxy_host: str = '', proxy_port: int = DEFAULT_PORT, sparql_section: SparqlSection = None, gremlin_section: GremlinSection = None, neptune_hosts: list = NEPTUNE_CONFIG_HOST_IDENTIFIERS): - self.host = host + self._host = host.strip() self.port = port self.ssl = ssl - self.proxy_host = proxy_host + self._proxy_host = proxy_host.strip() self.proxy_port = proxy_port self.sparql = sparql_section if sparql_section is not None else SparqlSection() @@ -90,6 +90,22 @@ def __init__(self, host: str, port: int, self.is_neptune_config = False self.gremlin = gremlin_section if gremlin_section is not None else GremlinSection() + @property + def host(self): + return self._host + + @host.setter + def host(self, value: str): + self._host = value.strip() + + @property + def proxy_host(self): + return self._proxy_host + + @proxy_host.setter + def proxy_host(self, value: str): + self._proxy_host = value.strip() + def to_dict(self) -> dict: if self.is_neptune_config: return { diff --git a/src/graph_notebook/magics/graph_magic.py b/src/graph_notebook/magics/graph_magic.py index 051fc971..83b5fb7f 100644 --- a/src/graph_notebook/magics/graph_magic.py +++ b/src/graph_notebook/magics/graph_magic.py @@ -321,13 +321,13 @@ def stream_viewer(self,line): @line_magic def graph_notebook_host(self, line): if line == '': - print('please specify a host.') + print(f'current host: {self.graph_notebook_config.host}') return # TODO: we should attempt to make a status call to this host before we set the config to this value. self.graph_notebook_config.host = line self._generate_client_from_config(self.graph_notebook_config) - print(f'set host to {line}') + print(f'set host to {self.graph_notebook_config.host}') @magic_variables @cell_magic diff --git a/test/unit/configuration/test_configuration.py b/test/unit/configuration/test_configuration.py index 614e09cd..b7d51271 100644 --- a/test/unit/configuration/test_configuration.py +++ b/test/unit/configuration/test_configuration.py @@ -16,6 +16,7 @@ def setUpClass(cls) -> None: cls.generic_host = 'blah' cls.neptune_host_reg = 'instance.cluster.us-west-2.neptune.amazonaws.com' cls.neptune_host_cn = 'instance.cluster.neptune.cn-north-1.amazonaws.com.cn' + cls.neptune_host_with_whitespace = '\t\v\n\r\v instance.cluster.us-west-2.neptune.amazonaws.com ' cls.neptune_host_custom = 'localhost' cls.port = 8182 cls.custom_hosts_list = ['localhost'] @@ -171,3 +172,25 @@ def test_generate_configuration_override_defaults_generic(self): c.write_to_file(self.test_file_path) config_from_file = get_config(self.test_file_path) self.assertEqual(config.to_dict(), config_from_file.to_dict()) + + def test_configuration_neptune_host_with_whitespace(self): + config = Configuration(self.neptune_host_with_whitespace, self.port) + self.assertEqual(config.host, self.neptune_host_reg) + self.assertEqual(config._host, self.neptune_host_reg) + + def test_configuration_neptune_host_with_whitespace_using_setter(self): + config = Configuration("localhost", self.port) + config.host = self.neptune_host_with_whitespace + self.assertEqual(config.host, self.neptune_host_reg) + self.assertEqual(config._host, self.neptune_host_reg) + + def test_configuration_neptune_proxy_host_with_whitespace(self): + config = Configuration("localhost", self.port, proxy_host=self.neptune_host_with_whitespace) + self.assertEqual(config.proxy_host, self.neptune_host_reg) + self.assertEqual(config._proxy_host, self.neptune_host_reg) + + def test_configuration_neptune_proxy_host_with_whitespace_using_setter(self): + config = Configuration("localhost", self.port) + config.proxy_host = self.neptune_host_with_whitespace + self.assertEqual(config.proxy_host, self.neptune_host_reg) + self.assertEqual(config._proxy_host, self.neptune_host_reg)