Skip to content

Commit 9f8b46c

Browse files
RafalSkolasinskiFlorentinD
authored andcommitted
source aura/db credentials from .env file using load_dotenv
1 parent b1eee6b commit 9f8b46c

File tree

7 files changed

+79
-28
lines changed

7 files changed

+79
-28
lines changed

examples/graph-analytics-serverless-self-managed.ipynb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,20 @@
5757
},
5858
"outputs": [],
5959
"source": [
60-
"%pip install \"graphdatascience>=1.15\""
60+
"%pip install \"graphdatascience>=1.15\" python-dotenv"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"from dotenv import load_dotenv\n",
70+
"\n",
71+
"# This allows to load required secrets from `.env` file in local directory\n",
72+
"# This can include Aura API Credentials. If file does not exist this is a noop.\n",
73+
"load_dotenv(\".env\")"
6174
]
6275
},
6376
{
@@ -79,13 +92,15 @@
7992
"\n",
8093
"from graphdatascience.session import AuraAPICredentials, GdsSessions\n",
8194
"\n",
82-
"client_id = os.environ[\"AURA_API_CLIENT_ID\"]\n",
83-
"client_secret = os.environ[\"AURA_API_CLIENT_SECRET\"]\n",
95+
"# If your account is a member of several project, you must also specify the project ID to use\n",
8496
"\n",
85-
"# If your account is a member of several projects, you must also specify the project ID to use\n",
86-
"project_id = os.environ.get(\"AURA_API_PROJECT_ID\", None)\n",
97+
"api_credentials = AuraAPICredentials(\n",
98+
" client_id=os.environ[\"CLIENT_ID\"],\n",
99+
" client_secret=os.environ[\"CLIENT_SECRET\"],\n",
100+
" project_id=os.environ.get(\"PROJECT_ID\", None),\n",
101+
")\n",
87102
"\n",
88-
"sessions = GdsSessions(api_credentials=AuraAPICredentials(client_id, client_secret, project_id=project_id))"
103+
"sessions = GdsSessions(api_credentials=api_credentials)"
89104
]
90105
},
91106
{
@@ -146,7 +161,9 @@
146161
"\n",
147162
"# Identify the Neo4j DBMS\n",
148163
"db_connection = DbmsConnectionInfo(\n",
149-
" uri=os.environ[\"NEO4J_URI\"], username=os.environ[\"NEO4J_USER\"], password=os.environ[\"NEO4J_PASSWORD\"]\n",
164+
" uri=os.environ[\"NEO4J_URI\"],\n",
165+
" username=os.environ[\"NEO4J_USERNAME\"],\n",
166+
" password=os.environ[\"NEO4J_PASSWORD\"],\n",
150167
")\n",
151168
"\n",
152169
"# Create a GDS session!\n",

examples/graph-analytics-serverless-standalone.ipynb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,20 @@
5858
},
5959
"outputs": [],
6060
"source": [
61-
"%pip install \"graphdatascience>=1.15\""
61+
"%pip install \"graphdatascience>=1.15\" python-dotenv"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"from dotenv import load_dotenv\n",
71+
"\n",
72+
"# This allows to load required secrets from `.env` file in local directory\n",
73+
"# This can include Aura API Credentials. If file does not exist this is a noop.\n",
74+
"load_dotenv(\".env\")"
6275
]
6376
},
6477
{
@@ -80,13 +93,15 @@
8093
"\n",
8194
"from graphdatascience.session import AuraAPICredentials, GdsSessions\n",
8295
"\n",
83-
"client_id = os.environ[\"AURA_API_CLIENT_ID\"]\n",
84-
"client_secret = os.environ[\"AURA_API_CLIENT_SECRET\"]\n",
96+
"# If your account is a member of several project, you must also specify the project ID to use\n",
8597
"\n",
86-
"# If your account is a member of several projects, you must also specify the project ID to use\n",
87-
"project_id = os.environ.get(\"AURA_API_PROJECT_ID\", None)\n",
98+
"api_credentials = AuraAPICredentials(\n",
99+
" client_id=os.environ[\"CLIENT_ID\"],\n",
100+
" client_secret=os.environ[\"CLIENT_SECRET\"],\n",
101+
" project_id=os.environ.get(\"PROJECT_ID\", None),\n",
102+
")\n",
88103
"\n",
89-
"sessions = GdsSessions(api_credentials=AuraAPICredentials(client_id, client_secret, project_id=project_id))"
104+
"sessions = GdsSessions(api_credentials=api_credentials)"
90105
]
91106
},
92107
{

examples/graph-analytics-serverless.ipynb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,21 @@
5757
},
5858
"outputs": [],
5959
"source": [
60-
"%pip install \"graphdatascience>=1.15\""
60+
"%pip install \"graphdatascience>=1.15\" python-dotenv"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"from dotenv import load_dotenv\n",
70+
"\n",
71+
"# This allows to load required secrets from `.env` file in local directory\n",
72+
"# This can include Aura API Credentials and Database Credentials.\n",
73+
"# If file does not exist this is a noop.\n",
74+
"load_dotenv(\".env\")"
6175
]
6276
},
6377
{
@@ -79,13 +93,15 @@
7993
"\n",
8094
"from graphdatascience.session import AuraAPICredentials, GdsSessions\n",
8195
"\n",
82-
"client_id = os.environ[\"AURA_API_CLIENT_ID\"]\n",
83-
"client_secret = os.environ[\"AURA_API_CLIENT_SECRET\"]\n",
84-
"\n",
8596
"# If your account is a member of several project, you must also specify the project ID to use\n",
86-
"project_id = os.environ.get(\"AURA_API_PROJECT_ID\", None)\n",
8797
"\n",
88-
"sessions = GdsSessions(api_credentials=AuraAPICredentials(client_id, client_secret, project_id=project_id))"
98+
"api_credentials = AuraAPICredentials(\n",
99+
" client_id=os.environ[\"CLIENT_ID\"],\n",
100+
" client_secret=os.environ[\"CLIENT_SECRET\"],\n",
101+
" project_id=os.environ.get(\"PROJECT_ID\", None),\n",
102+
")\n",
103+
"\n",
104+
"sessions = GdsSessions(api_credentials=api_credentials)"
89105
]
90106
},
91107
{
@@ -136,7 +152,9 @@
136152
"\n",
137153
"# Identify the AuraDB instance\n",
138154
"db_connection = DbmsConnectionInfo(\n",
139-
" uri=os.environ[\"AURA_DB_ADDRESS\"], username=os.environ[\"AURA_DB_USER\"], password=os.environ[\"AURA_DB_PW\"]\n",
155+
" uri=os.environ[\"NEO4J_URI\"],\n",
156+
" username=os.environ[\"NEO4J_USERNAME\"],\n",
157+
" password=os.environ[\"NEO4J_PASSWORD\"],\n",
140158
")\n",
141159
"\n",
142160
"# Create a GDS session!\n",

requirements/dev/notebook-aura-ci.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ nbconvert==7.16.4
22
nbformat==5.9.2
33
nbclient==0.10.2
44
ipykernel==6.26.0
5+
python-dotenv==1.1.0

scripts/ci/aura_api_ci.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def __init__(self, json: dict[str, Any]) -> None:
2121
def is_expired(self) -> bool:
2222
return self.expires_at >= int(time.time())
2323

24-
def __init__(self, client_id: str, client_secret: str, tenant_id: Optional[str] = None) -> None:
24+
def __init__(self, client_id: str, client_secret: str, project_id: Optional[str] = None) -> None:
2525
self._token: Optional[AuraApiCI.AuraAuthToken] = None
2626
self._logger = logging.getLogger()
2727
self._auth = (client_id, client_secret)
28-
self._tenant_id = tenant_id
28+
self._project_id = project_id
2929

3030
def _build_header(self) -> dict[str, str]:
3131
return {"Authorization": f"Bearer {self._auth_token()}", "User-agent": "neo4j-graphdatascience-ci"}
@@ -144,8 +144,8 @@ def teardown_instance(self, db_id: str) -> bool:
144144
return True
145145

146146
def get_tenant_id(self) -> str:
147-
if self._tenant_id:
148-
return self._tenant_id
147+
if self._project_id:
148+
return self._project_id
149149

150150
response = requests.get(
151151
"https://api-staging.neo4j.io/v1/tenants",

scripts/ci/run_targeting_aura_sessions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
def main() -> None:
1717
client_id = os.environ["AURA_API_CLIENT_ID"]
1818
client_secret = os.environ["AURA_API_CLIENT_SECRET"]
19-
tenant_id = os.environ.get("AURA_API_TENANT_ID")
20-
aura_api = AuraApiCI(client_id=client_id, client_secret=client_secret, tenant_id=tenant_id)
19+
project_id = os.environ.get("AURA_API_TENANT_ID")
20+
aura_api = AuraApiCI(client_id=client_id, client_secret=client_secret, project_id=project_id)
2121

2222
MAX_INT = 1000000
2323
instance_name = f"ci-build-{sys.argv[1]}" if len(sys.argv) > 1 else "ci-instance-" + str(rd.randint(0, MAX_INT))
@@ -43,7 +43,7 @@ def handle_signal(sig: int, frame: Optional[FrameType]) -> None:
4343
username = create_result["username"]
4444
password = create_result["password"]
4545

46-
cmd = f"AURA_DB_ADDRESS={uri} AURA_DB_USER={username} AURA_DB_PW={password} tox -e jupyter-notebook-session-ci"
46+
cmd = f"CLIENT_ID={client_id} CLIENT_SECRET={client_secret} PROJECT_ID={project_id} NEO4J_URI={uri} NEO4J_USERNAME={username} NEO4J_PASSWORD={password} tox -e jupyter-notebook-session-ci"
4747

4848
if os.system(cmd) != 0:
4949
raise Exception("Failed to run notebooks")

scripts/ci/run_targeting_aurads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def main() -> None:
3232
client_id = os.environ["AURA_API_CLIENT_ID"]
3333
client_secret = os.environ["AURA_API_CLIENT_SECRET"]
3434
tenant_id = os.environ.get("AURA_API_TENANT_ID")
35-
aura_api = AuraApiCI(client_id=client_id, client_secret=client_secret, tenant_id=tenant_id)
35+
aura_api = AuraApiCI(client_id=client_id, client_secret=client_secret, project_id=tenant_id)
3636

3737
MAX_INT = 1000000
3838
instance_name = f"ci-build-{sys.argv[2]}" if len(sys.argv) > 1 else "ci-instance-" + str(rd.randint(0, MAX_INT))

0 commit comments

Comments
 (0)