Skip to content

Commit 48ef2dc

Browse files
committed
Use AuraAPI credentials based session auth
1 parent 739e426 commit 48ef2dc

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

graphdatascience/session/aura_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def __init__(
4444
self, client_id: str, client_secret: str, tenant_id: Optional[str] = None, aura_env: Optional[str] = None
4545
) -> None:
4646
self._base_uri = AuraApi.base_uri(aura_env)
47+
self._credentials = (client_id, client_secret)
4748

48-
self._request_session = self._init_request_session((client_id, client_secret))
49+
self._request_session = self._init_request_session(self._credentials)
4950
self._logger = logging.getLogger()
5051

5152
self._tenant_id = tenant_id if tenant_id else self._get_tenant_id()

graphdatascience/session/dedicated_sessions.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
import hashlib
43
import math
4+
import uuid
55
import warnings
66
from datetime import datetime, timedelta, timezone
77
from typing import Optional
@@ -74,10 +74,7 @@ def get_or_create(
7474

7575
dbid = AuraApi.extract_id(db_connection.uri)
7676

77-
# hashing the password to avoid storing the actual db password in Aura
78-
password = hashlib.sha256(db_connection.password.encode()).hexdigest()
79-
80-
session_details = self._get_or_create_session(session_name, dbid, password, memory.value, ttl, cloud_location)
77+
session_details = self._get_or_create_session(session_name, dbid, memory.value, ttl, cloud_location)
8178

8279
if session_details.expiry_date:
8380
until_expiry: timedelta = session_details.expiry_date - datetime.now(timezone.utc)
@@ -95,8 +92,8 @@ def get_or_create(
9592

9693
session_connection = DbmsConnectionInfo(
9794
uri=connection_url,
98-
username=DedicatedSessions.GDS_SESSION_USER,
99-
password=password,
95+
username=self._aura_api._credentials[0],
96+
password=self._aura_api._credentials[1],
10097
)
10198

10299
return self._construct_client(
@@ -154,7 +151,6 @@ def _get_or_create_session(
154151
self,
155152
session_name: str,
156153
dbid: str,
157-
pwd: str,
158154
memory: SessionMemoryValue,
159155
ttl: Optional[timedelta] = None,
160156
cloud_location: Optional[CloudLocation] = None,
@@ -167,6 +163,8 @@ def _get_or_create_session(
167163
if cloud_location and db_instance:
168164
raise ValueError("cloud_location cannot be provided for sessions against an AuraDB.")
169165

166+
pwd = str(uuid.uuid4()) # password wont be used and will go away in v1 endpoints
167+
170168
# If cloud location is provided we go for self managed DBs path
171169
if cloud_location:
172170
return self._aura_api.get_or_create_session(

graphdatascience/tests/unit/test_dedicated_sessions.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ def aura_api() -> AuraApi:
227227
return FakeAuraApi(client_id="client-id")
228228

229229

230-
HASHED_DB_PASSWORD = "722cbc618c015c7c062f071868d9bb5f207f35a317e71054740716642cfd0f61"
231-
232-
233230
def test_list_session(aura_api: AuraApi) -> None:
234231
_setup_db_instance(aura_api)
235232
session = aura_api.get_or_create_session(
@@ -354,7 +351,7 @@ def test_create_attached_session(mocker: MockerFixture, aura_api: AuraApi) -> No
354351
"show_progress": False,
355352
},
356353
"session_connection": DbmsConnectionInfo(
357-
uri="neo4j+s://foo.bar", username="neo4j", password=HASHED_DB_PASSWORD
354+
uri="neo4j+s://foo.bar", username="client-id", password="client_secret"
358355
),
359356
"session_id": "ffff0-ffff1",
360357
}
@@ -392,7 +389,7 @@ def test_create_standalone_session(mocker: MockerFixture, aura_api: AuraApi) ->
392389
"show_progress": False,
393390
},
394391
"session_connection": DbmsConnectionInfo(
395-
uri="neo4j+s://foo.bar", username="neo4j", password=HASHED_DB_PASSWORD
392+
uri="neo4j+s://foo.bar", username="client-id", password="client_secret"
396393
),
397394
"session_id": "None-ffff0",
398395
}
@@ -433,7 +430,7 @@ def test_get_or_create(mocker: MockerFixture, aura_api: AuraApi) -> None:
433430
"show_progress": False,
434431
},
435432
"session_connection": DbmsConnectionInfo(
436-
uri="neo4j+s://foo.bar", username="neo4j", password=HASHED_DB_PASSWORD
433+
uri="neo4j+s://foo.bar", username="client-id", password="client_secret"
437434
),
438435
"session_id": "ffff0-ffff1",
439436
}

0 commit comments

Comments
 (0)