Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip whitespace from hosts in config #329

Merged
merged 6 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 18 additions & 2 deletions src/graph_notebook/configuration/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/graph_notebook/magics/graph_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/unit/configuration/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)