feat: Make graph authentication optional for Neo4j and Memgraph
Introduces optional authentication for Neo4j and Memgraph adapter handling. --- **DCO Affirmation** I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: hajdul88 <52442977+hajdul88@users.noreply.github.com>
This commit is contained in:
parent
8b938b09f0
commit
28f2414915
3 changed files with 27 additions and 14 deletions
|
|
@ -77,15 +77,15 @@ def create_graph_engine(
|
|||
)
|
||||
|
||||
if graph_database_provider == "neo4j":
|
||||
if not (graph_database_url and graph_database_username and graph_database_password):
|
||||
raise EnvironmentError("Missing required Neo4j credentials.")
|
||||
if not graph_database_url:
|
||||
raise EnvironmentError("Missing required Neo4j URL.")
|
||||
|
||||
from .neo4j_driver.adapter import Neo4jAdapter
|
||||
|
||||
return Neo4jAdapter(
|
||||
graph_database_url=graph_database_url,
|
||||
graph_database_username=graph_database_username,
|
||||
graph_database_password=graph_database_password,
|
||||
graph_database_username=graph_database_username or None,
|
||||
graph_database_password=graph_database_password or None,
|
||||
)
|
||||
|
||||
elif graph_database_provider == "falkordb":
|
||||
|
|
@ -124,15 +124,15 @@ def create_graph_engine(
|
|||
)
|
||||
|
||||
elif graph_database_provider == "memgraph":
|
||||
if not (graph_database_url and graph_database_username and graph_database_password):
|
||||
raise EnvironmentError("Missing required Memgraph credentials.")
|
||||
if not graph_database_url:
|
||||
raise EnvironmentError("Missing required Memgraph URL.")
|
||||
|
||||
from .memgraph.memgraph_adapter import MemgraphAdapter
|
||||
|
||||
return MemgraphAdapter(
|
||||
graph_database_url=graph_database_url,
|
||||
graph_database_username=graph_database_username,
|
||||
graph_database_password=graph_database_password,
|
||||
graph_database_username=graph_database_username or None,
|
||||
graph_database_password=graph_database_password or None,
|
||||
)
|
||||
|
||||
from .networkx.adapter import NetworkXAdapter
|
||||
|
|
|
|||
|
|
@ -58,13 +58,18 @@ class MemgraphAdapter(GraphDBInterface):
|
|||
def __init__(
|
||||
self,
|
||||
graph_database_url: str,
|
||||
graph_database_username: str,
|
||||
graph_database_password: str,
|
||||
graph_database_username: Optional[str] = None,
|
||||
graph_database_password: Optional[str] = None,
|
||||
driver: Optional[Any] = None,
|
||||
):
|
||||
# Only use auth if both username and password are provided
|
||||
auth = None
|
||||
if graph_database_username and graph_database_password:
|
||||
auth = (graph_database_username, graph_database_password)
|
||||
|
||||
self.driver = driver or AsyncGraphDatabase.driver(
|
||||
graph_database_url,
|
||||
auth=(graph_database_username, graph_database_password),
|
||||
auth=auth,
|
||||
max_connection_lifetime=120,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,13 +40,21 @@ class Neo4jAdapter(GraphDBInterface):
|
|||
def __init__(
|
||||
self,
|
||||
graph_database_url: str,
|
||||
graph_database_username: str,
|
||||
graph_database_password: str,
|
||||
graph_database_username: Optional[str] = None,
|
||||
graph_database_password: Optional[str] = None,
|
||||
driver: Optional[Any] = None,
|
||||
):
|
||||
# Only use auth if both username and password are provided
|
||||
auth = None
|
||||
if graph_database_username and graph_database_password:
|
||||
auth = (graph_database_username, graph_database_password)
|
||||
elif graph_database_username or graph_database_password:
|
||||
logger = get_logger(__name__)
|
||||
logger.warning("Neo4j credentials incomplete – falling back to anonymous connection.")
|
||||
|
||||
self.driver = driver or AsyncGraphDatabase.driver(
|
||||
graph_database_url,
|
||||
auth=(graph_database_username, graph_database_password),
|
||||
auth=auth,
|
||||
max_connection_lifetime=120,
|
||||
notifications_min_severity="OFF",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue