Skip to content

Commit df756a7

Browse files
authored
Compatibility with Neo4J 4.0.4 (4.x in general should work) (#139)
* Compatibility with latest Neo4J 4.0.4 * Proxy connection is encrypted by default. Also read an envvar to allow overriding. Need this to keep the quick start sample working. * New import form silences warning. The neo4j.v1 import path raises a warning starting in the 1.7.x driver series. * Add a config parameter for SSL cert validation.
1 parent 850827a commit df756a7

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

metadata_service/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import distutils.util
12
import os
23
from typing import List, Dict, Optional # noqa: F401
34

@@ -6,6 +7,8 @@
67
PROXY_PORT = 'PROXY_PORT'
78
PROXY_USER = 'PROXY_USER'
89
PROXY_PASSWORD = 'PROXY_PASSWORD'
10+
PROXY_ENCRYPTED = 'PROXY_ENCRYPTED'
11+
PROXY_VALIDATE_SSL = 'PROXY_VALIDATE_SSL'
912
PROXY_CLIENT = 'PROXY_CLIENT'
1013

1114
PROXY_CLIENTS = {
@@ -29,6 +32,10 @@ class Config:
2932

3033
PROXY_USER = os.environ.get('CREDENTIALS_PROXY_USER', 'neo4j')
3134
PROXY_PASSWORD = os.environ.get('CREDENTIALS_PROXY_PASSWORD', 'test')
35+
PROXY_ENCRYPTED = True
36+
"""Whether the connection to the proxy should use SSL/TLS encryption."""
37+
PROXY_VALIDATE_SSL = True
38+
"""Whether the SSL/TLS certificate presented by the user should be validated against the system's trusted CAs."""
3239

3340
IS_STATSD_ON = False
3441

@@ -59,6 +66,8 @@ class LocalConfig(Config):
5966
PROXY_HOST = os.environ.get('PROXY_HOST', f'bolt://{LOCAL_HOST}')
6067
PROXY_PORT = os.environ.get('PROXY_PORT', 7687)
6168
PROXY_CLIENT = PROXY_CLIENTS[os.environ.get('PROXY_CLIENT', 'NEO4J')]
69+
PROXY_ENCRYPTED = bool(distutils.util.strtobool(os.environ.get(PROXY_ENCRYPTED, 'True')))
70+
PROXY_VALIDATE_SSL = bool(distutils.util.strtobool(os.environ.get(PROXY_VALIDATE_SSL, 'False')))
6271

6372
JANUS_GRAPH_URL = None
6473

metadata_service/proxy/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ def get_proxy_client() -> BaseProxy:
2929
port = current_app.config[config.PROXY_PORT]
3030
user = current_app.config[config.PROXY_USER]
3131
password = current_app.config[config.PROXY_PASSWORD]
32+
encrypted = current_app.config[config.PROXY_ENCRYPTED]
33+
validate_ssl = current_app.config[config.PROXY_VALIDATE_SSL]
3234

3335
client = import_string(current_app.config[config.PROXY_CLIENT])
34-
_proxy_client = client(host=host, port=port, user=user, password=password)
36+
_proxy_client = client(host=host,
37+
port=port,
38+
user=user,
39+
password=password,
40+
encrypted=encrypted,
41+
validate_ssl=validate_ssl)
3542

3643
return _proxy_client

metadata_service/proxy/atlas_proxy.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,19 @@ def __init__(self, *,
5555
host: str,
5656
port: int,
5757
user: str = 'admin',
58-
password: str = '') -> None:
58+
password: str = '',
59+
encrypted: bool = False,
60+
validate_ssl: bool = False) -> None:
5961
"""
6062
Initiate the Apache Atlas client with the provided credentials
6163
"""
62-
self._driver = Atlas(host=host, port=port, username=user, password=password)
64+
protocol = 'https' if encrypted else 'http'
65+
self._driver = Atlas(host=host,
66+
port=port,
67+
username=user,
68+
password=password,
69+
protocol=protocol,
70+
validate_ssl=validate_ssl)
6371

6472
def _get_ids_from_basic_search(self, *, params: Dict) -> List[str]:
6573
"""

metadata_service/proxy/neo4j_proxy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from amundsen_common.models.user import User as UserEntity
1515
from beaker.cache import CacheManager
1616
from beaker.util import parse_cache_config_options
17-
from neo4j.v1 import BoltStatementResult, Driver, GraphDatabase # noqa: F401
17+
from neo4j import BoltStatementResult, Driver, GraphDatabase # noqa: F401
18+
import neo4j
1819

1920
from metadata_service.entity.dashboard_detail import DashboardDetail as DashboardDetailEntity
2021
from metadata_service.entity.dashboard_query import DashboardQuery as DashboardQueryEntity
@@ -45,7 +46,9 @@ def __init__(self, *,
4546
user: str = 'neo4j',
4647
password: str = '',
4748
num_conns: int = 50,
48-
max_connection_lifetime_sec: int = 100) -> None:
49+
max_connection_lifetime_sec: int = 100,
50+
encrypted: bool = True,
51+
validate_ssl: bool = False) -> None:
4952
"""
5053
There's currently no request timeout from client side where server
5154
side can be enforced via "dbms.transaction.timeout"
@@ -57,10 +60,13 @@ def __init__(self, *,
5760
value needs to be smaller than surrounding network environment's timeout.
5861
"""
5962
endpoint = f'{host}:{port}'
63+
trust = neo4j.TRUST_SYSTEM_CA_SIGNED_CERTIFICATES if validate_ssl else neo4j.TRUST_ALL_CERTIFICATES
6064
self._driver = GraphDatabase.driver(endpoint, max_connection_pool_size=num_conns,
6165
connection_timeout=10,
6266
max_connection_lifetime=max_connection_lifetime_sec,
63-
auth=(user, password)) # type: Driver
67+
auth=(user, password),
68+
encrypted=encrypted,
69+
trust=trust) # type: Driver
6470

6571
@timer_with_counter
6672
def get_table(self, *, table_uri: str) -> Table:

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pytz==2018.4
6262
six==1.11.0
6363
Werkzeug==0.15.3
6464
wheel==0.33.1
65-
neo4j-driver==1.6.0
66-
neotime==1.0.0
65+
neo4j==1.7.6
66+
neotime==1.7.1
6767
pytz==2018.4
6868
requests-aws4auth==0.9
6969
statsd==3.2.1

tests/unit/proxy/test_neo4j_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Watermark, ProgrammaticDescription)
1111
from amundsen_common.models.user import UserSchema
1212
from mock import MagicMock, patch
13-
from neo4j.v1 import GraphDatabase
13+
from neo4j import GraphDatabase
1414

1515
from metadata_service import create_app
1616
from metadata_service.entity.dashboard_detail import DashboardDetail

tests/unit/proxy/test_statsd_utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from flask import current_app
88

99
from metadata_service import create_app
10-
from neo4j.v1 import GraphDatabase
10+
from neo4j import GraphDatabase
1111
from metadata_service.proxy.neo4j_proxy import Neo4jProxy
1212

1313

0 commit comments

Comments
 (0)